Skip to content

Commit

Permalink
CI tester
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chudilka1 committed Jul 18, 2024
1 parent 579f5cf commit 1d173d3
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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:
Expand Down
39 changes: 39 additions & 0 deletions go/ocr2/decryptionplugin/fail_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
39 changes: 39 additions & 0 deletions go/tdh2/fail_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 1d173d3

Please sign in to comment.