From 347c80f7d21a1bb0eb374eddcbe7e1143113598d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Wed, 13 Nov 2024 14:31:47 +0100 Subject: [PATCH 1/5] test --- .github/workflows/test.yml | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f4a0af1..36877f44 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,8 +5,11 @@ permissions: pull-requests: write jobs: test: - name: test - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + steps: - name: checkout uses: actions/checkout@v4 @@ -18,13 +21,35 @@ jobs: - name: test env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed for GitHub badge storer integration test - run: make test + run: go test -timeout=60s -race -count=1 -failfast -shuffle=on ./... -coverprofile=./cover.${{ matrix.os }}.profile -covermode=atomic -coverpkg=./... + + - name: upload cover profile artifact + uses: actions/upload-artifact@v3 + with: + name: cover.${{ matrix.os }} + path: cover.${{ matrix.os }}.profile + + check-coverage: + runs-on: ubuntu-latest + needs: test + + steps: + - name: download cover.ubuntu-latest + uses: actions/download-artifact@v3 + with: + name: cover.ubuntu-latest + - name: download cover.macos-latest + uses: actions/download-artifact@v3 + with: + name: cover.macos-latest + - name: check test coverage id: coverage uses: vladopajic/go-test-coverage@v2 with: config: ./.github/.testcoverage.yml + profile: cover.ubuntu-latest.profile,cover.macos-latest.profile git-branch: badges git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }} From a51dde585aa5eb145023238195a3b29a03d9a85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Wed, 13 Nov 2024 14:35:50 +0100 Subject: [PATCH 2/5] fix test --- pkg/testcoverage/badgestorer/github_test.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/testcoverage/badgestorer/github_test.go b/pkg/testcoverage/badgestorer/github_test.go index d1877592..758c8a41 100644 --- a/pkg/testcoverage/badgestorer/github_test.go +++ b/pkg/testcoverage/badgestorer/github_test.go @@ -7,6 +7,7 @@ import ( "github.com/google/go-github/v56/github" "github.com/stretchr/testify/assert" + "golang.org/x/exp/rand" . "github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage/badgestorer" ) @@ -51,7 +52,7 @@ func Test_Github(t *testing.T) { Owner: "vladopajic", Repository: "go-test-coverage", Branch: "badges-integration-test", - FileName: "badge.svg", + FileName: "badge-" + randString() + ".svg", } s := NewGithub(cfg) @@ -105,3 +106,14 @@ func deleteFile(t *testing.T, cfg Git) { ) assert.NoError(t, err) } + +func randString() string { + letterRunes := []rune("abcdefghijklmnopqrstuvwxyz") + + b := make([]rune, rand.Intn(10)) + for i := range b { + b[i] = letterRunes[rand.Intn(len(letterRunes))] + } + + return string(b) +} From d8c806e724e19c88ca64d82472250bf8535ea67d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Wed, 13 Nov 2024 14:38:55 +0100 Subject: [PATCH 3/5] fix --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 36877f44..e3e1a3bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,6 +34,9 @@ jobs: needs: test steps: + - name: checkout + uses: actions/checkout@v4 + - name: download cover.ubuntu-latest uses: actions/download-artifact@v3 with: From bc29adb471e2d475b657297b52f15d7c86317e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Wed, 13 Nov 2024 14:46:18 +0100 Subject: [PATCH 4/5] added comments --- pkg/testcoverage/badgestorer/github_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/testcoverage/badgestorer/github_test.go b/pkg/testcoverage/badgestorer/github_test.go index 758c8a41..081030dd 100644 --- a/pkg/testcoverage/badgestorer/github_test.go +++ b/pkg/testcoverage/badgestorer/github_test.go @@ -52,7 +52,9 @@ func Test_Github(t *testing.T) { Owner: "vladopajic", Repository: "go-test-coverage", Branch: "badges-integration-test", - FileName: "badge-" + randString() + ".svg", + // random badge name must be used because two tests running from different platforms + // in CI can cause race condition if badge has the same name + FileName: "badge-" + randString() + ".svg", } s := NewGithub(cfg) From d064139242ddcfa220661dabd385d8a48f19f618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Paji=C4=87?= Date: Wed, 13 Nov 2024 14:50:47 +0100 Subject: [PATCH 5/5] cleanup --- pkg/testcoverage/badgestorer/github_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/testcoverage/badgestorer/github_test.go b/pkg/testcoverage/badgestorer/github_test.go index 081030dd..012ee386 100644 --- a/pkg/testcoverage/badgestorer/github_test.go +++ b/pkg/testcoverage/badgestorer/github_test.go @@ -54,7 +54,7 @@ func Test_Github(t *testing.T) { Branch: "badges-integration-test", // random badge name must be used because two tests running from different platforms // in CI can cause race condition if badge has the same name - FileName: "badge-" + randString() + ".svg", + FileName: "badge_" + randString() + ".svg", } s := NewGithub(cfg) @@ -111,10 +111,11 @@ func deleteFile(t *testing.T, cfg Git) { func randString() string { letterRunes := []rune("abcdefghijklmnopqrstuvwxyz") + l := len(letterRunes) b := make([]rune, rand.Intn(10)) for i := range b { - b[i] = letterRunes[rand.Intn(len(letterRunes))] + b[i] = letterRunes[rand.Intn(l)] } return string(b)