-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from CubicrootXYZ/golang-test-workflow
add workflow for golang unittesting
- Loading branch information
Showing
8 changed files
with
92 additions
and
3 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,32 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
workdir: | ||
required: false | ||
default: "./" | ||
type: string | ||
services: | ||
required: false | ||
type: string | ||
default: '{}' | ||
env: | ||
required: false | ||
type: string | ||
default: '{}' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
if: "!startsWith(github.ref, 'refs/tags/')" | ||
container: | ||
image: cubicrootxyz/golang-ci:v1.22.5-3 | ||
options: --user root | ||
services: ${{ fromJSON(inputs.services) }} | ||
env: ${{ fromJSON(inputs.env) }} | ||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
- name: Run tests | ||
run: (cd ${{ inputs.workdir }} && CGO_ENABLED=1 && go test -cover -race ./...) |
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,9 @@ | ||
on: push | ||
|
||
jobs: | ||
golang_test: | ||
uses: ./.github/workflows/golang_test.yaml | ||
with: | ||
workdir: "tests/golang_test/" | ||
services: '{"database": {"image": "mysql:8.0", "ports": ["3306:3306"]}}' | ||
env: '{"TESTENV": "value"}' |
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 |
---|---|---|
|
@@ -26,9 +26,28 @@ jobs: | |
To ensure code quality use the provided `golang_quality` workflow. It runs multiple analysis tools. | ||
|
||
```yaml | ||
permissions: | ||
# Required by golangci job to write annotations to the merge request. | ||
contents: read | ||
checks: write | ||
jobs: | ||
golang_quality: | ||
uses: CubicrootXYZ/Workflows/.github/workflows/[email protected] | ||
with: | ||
workdir: "golang/application/subfolder" | ||
workdir: "golang/application/subfolder/" | ||
``` | ||
|
||
### Execute Tests | ||
|
||
To execute golang tests use the provided `golang_test` workflow. | ||
|
||
```yaml | ||
jobs: | ||
golang_test: | ||
uses: ./.github/workflows/golang_test.yaml | ||
with: | ||
workdir: "tests/golang_test/" | ||
services: '{"database": {"image": "mysql:8.0", "ports": ["3306:3306"]}}' | ||
env: '{"TESTENV": "value"}' | ||
``` |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module golang_quality | ||
|
||
go 1.22.1 | ||
go 1.22.5 |
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,3 @@ | ||
module golangtest | ||
|
||
go 1.22.5 |
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,7 @@ | ||
package golangtest | ||
|
||
import "fmt" | ||
|
||
func DoSomething(input string) { | ||
fmt.Println(input) | ||
} |
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,19 @@ | ||
package golangtest_test | ||
|
||
import ( | ||
"golangtest" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestSomething(t *testing.T) { | ||
golangtest.DoSomething("a test") | ||
} | ||
|
||
func TestEnvVarsAreSet(t *testing.T) { | ||
v := os.Getenv("TESTENV") | ||
t.Logf("env var is: %s", v) | ||
if v != "value" { | ||
t.Fail() | ||
} | ||
} |