From 80c02828ca9e4eb0e4a1877275baae14d330a2d9 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Sun, 3 May 2020 15:45:09 +0200 Subject: [PATCH] feat(project): Add GitHub Actions testing workflow (#289) GitHub actions is a workflow engine. This testing workflow will - keep everything inside GitHub (one platform) - reduce dependency to an external service (TravisCI) - introduce stricter testing (next to unit tests, staticcheck, fmt, vet) * fix(tests): TestIssueService_GetEditMeta_Fail fails on windows due to error message checking We check the error string in TestIssueService_GetEditMeta_Fail. On different operting systems, this error message is different. See - Linux: TestIssueService_GetEditMeta_Fail: metaissue_test.go:456: Error Get "http://127.0.0.1:65328/rest/api/2/issue/PROJ-9001/editmeta": dial tcp 127.0.0.1:65328: connect: connection refused - Windows: Error Get "http://127.0.0.1:50122/rest/api/2/issue/PROJ-9001/editmeta": dial tcp 127.0.0.1:50122: connectex: No connection could be made because the target machine actively refused it. Now we check the error type instead of the error message * chore(tests): Support only the current + the last two versions go-jira follows Go's Release Policy for testing. See https://golang.org/doc/devel/release.html#policy Related #290 --- .github/workflows/testing.yml | 43 +++++++++++++++++++++++++++++++++++ metaissue_test.go | 7 +++--- 2 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/testing.yml diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..a131647 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,43 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: + +jobs: + test: + name: Test and lint + strategy: + matrix: + go-version: [1.x, 1.13.x, 1.12.x] + platform: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.platform }} + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: 1.14 + + # Caching go modules to speed up the run + - uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Run go fmt + if: runner.os != 'Windows' + run: diff -u <(echo -n) <(gofmt -d -s .) + + - name: Run go vet + run: make vet + + - name: Run staticcheck + run: make staticcheck + + - name: Run Unit tests. + run: make test \ No newline at end of file diff --git a/metaissue_test.go b/metaissue_test.go index 92e3b07..a77951a 100644 --- a/metaissue_test.go +++ b/metaissue_test.go @@ -3,7 +3,7 @@ package jira import ( "fmt" "net/http" - "strings" + "net/url" "testing" ) @@ -451,9 +451,8 @@ func TestIssueService_GetEditMeta_Fail(t *testing.T) { t.Error("Expected to receive an error, received nil instead") } - expectedError := "connection refused" - if !strings.Contains(err.Error(), expectedError) { - t.Errorf("Expected to receive error containing %s, received %v instead", expectedError, err.Error()) + if _, ok := err.(*url.Error); !ok { + t.Errorf("Expected to receive an *url.Error, got %T instead", err) } }