-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add Go-related workflows and steps
- Loading branch information
Showing
5 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Assess Go code quality | ||
|
||
on: | ||
push: | ||
paths: | ||
- ".github/workflows/go-code-quality.yml" | ||
- "cmd/**" | ||
- "internal/**" | ||
|
||
jobs: | ||
assess-go-code-quality: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: "go.mod" | ||
|
||
- name: Check code format | ||
run: | | ||
output=$(gofmt -s -l .) | ||
if [ -n "$output" ]; then | ||
echo "$output" | ||
exit 1; | ||
fi | ||
- name: Run linter | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: v1.54.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"syscall" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestGraphQLService(t *testing.T) { | ||
t.Run("it stops when the context is cancelled", func(t *testing.T) { | ||
service := GraphQLService{} | ||
setupEnvVars() | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
exit := make(chan error) | ||
|
||
go func() { | ||
<-time.After(100 * time.Millisecond) | ||
if err := service.Start(ctx); err != nil { | ||
exit <- err | ||
} | ||
}() | ||
|
||
<-time.After(200 * time.Millisecond) | ||
cancel() | ||
|
||
err := <-exit | ||
exitError, ok := err.(*exec.ExitError) | ||
if !ok || !assertExitErrorWasCausedBy(exitError, syscall.SIGTERM) { | ||
fmt.Printf("service exited for the wrong reason: %v", err) | ||
t.FailNow() | ||
} | ||
}) | ||
} | ||
|
||
func setupEnvVars() { | ||
abs, _ := filepath.Abs("../../../offchain/target/debug") | ||
os.Setenv("PATH", abs) | ||
os.Setenv("POSTGRES_PASSWORD", "pw") | ||
} | ||
|
||
func assertExitErrorWasCausedBy(err *exec.ExitError, signal syscall.Signal) bool { | ||
status := err.Sys().(syscall.WaitStatus) | ||
return status.Signal() == signal | ||
} |