From 1d173d35c7678340a67141dbbff7346649d1646c Mon Sep 17 00:00:00 2001 From: Alexandr Yepishev Date: Wed, 3 Jul 2024 15:48:09 +0100 Subject: [PATCH] CI tester This draft adds a test file designed to flag the unit tests, the race detector, and the linter, in order to ensure that they are all operating correctly. --- .github/workflows/go.yaml | 12 +++++++++ go/ocr2/decryptionplugin/fail_test.go | 39 +++++++++++++++++++++++++++ go/tdh2/fail_test.go | 39 +++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 go/ocr2/decryptionplugin/fail_test.go create mode 100644 go/tdh2/fail_test.go diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index a33d266..49ddcdd 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -66,6 +66,11 @@ jobs: go build -v ./... go test -v ./... -coverpkg=./... -coverprofile=ocr2_decryptionplugin_coverage.txt + - name: Race test OCR2 plugin + working-directory: ./go/ocr2/decryptionplugin + run: | + go test -race -v ./... -coverpkg=./... -coverprofile=ocr2_decryptionplugin_race_coverage.txt + - name: Download npm deps working-directory: ./js/tdh2 run: npm install @@ -75,6 +80,11 @@ jobs: run: | go build -v ./... go test -v ./... -coverpkg=./... -coverprofile=tdh_coverage.txt + + - name: Build and test TDH2 + working-directory: ./go/tdh2 + run: | + go test -race -v ./... -coverpkg=./... -coverprofile=tdh_race_coverage.txt - name: Upload Go test reports if: always() @@ -83,7 +93,9 @@ jobs: name: go-test-results path: | ./go/ocr2/decryptionplugin/ocr2_decryptionplugin_coverage.txt + ./go/ocr2/decryptionplugin/ocr2_decryptionplugin_race_coverage.txt ./go/tdh2/tdh_coverage.txt + ./go/tdh2/tdh_race_coverage.txt sonar-scan: diff --git a/go/ocr2/decryptionplugin/fail_test.go b/go/ocr2/decryptionplugin/fail_test.go new file mode 100644 index 0000000..bfc2a01 --- /dev/null +++ b/go/ocr2/decryptionplugin/fail_test.go @@ -0,0 +1,39 @@ +package decryptionplugin + +import ( + "errors" + "os" + "sync" + "testing" +) + +func TestFail(t *testing.T) { + if testing.Short() { + t.Skip() + } + t.Fatal("fake failure") +} + +func TestRace(t *testing.T) { + var v int + var wg sync.WaitGroup + wg.Add(100) + for i := 0; i < 100; i++ { + go func() { + defer wg.Done() + v++ + v-- + }() + } + wg.Wait() + t.Log(v) +} + +func TestLint(t *testing.T) { + const ALL_CAPS = 10 // should be AllCaps + err := os.ErrNotExist + if err == os.ErrNotExist { // should use errors.Is + err := errors.New("fake error") // shadowed variable + t.Log(err) + } +} diff --git a/go/tdh2/fail_test.go b/go/tdh2/fail_test.go new file mode 100644 index 0000000..19a8361 --- /dev/null +++ b/go/tdh2/fail_test.go @@ -0,0 +1,39 @@ +package tdh2 + +import ( + "errors" + "os" + "sync" + "testing" +) + +func TestFail(t *testing.T) { + if testing.Short() { + t.Skip() + } + t.Fatal("fake failure") +} + +func TestRace(t *testing.T) { + var v int + var wg sync.WaitGroup + wg.Add(100) + for i := 0; i < 100; i++ { + go func() { + defer wg.Done() + v++ + v-- + }() + } + wg.Wait() + t.Log(v) +} + +func TestLint(t *testing.T) { + const ALL_CAPS = 10 // should be AllCaps + err := os.ErrNotExist + if err == os.ErrNotExist { // should use errors.Is + err := errors.New("fake error") // shadowed variable + t.Log(err) + } +}