Skip to content

Commit 1d173d3

Browse files
committed
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.
1 parent 579f5cf commit 1d173d3

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

.github/workflows/go.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ jobs:
6666
go build -v ./...
6767
go test -v ./... -coverpkg=./... -coverprofile=ocr2_decryptionplugin_coverage.txt
6868
69+
- name: Race test OCR2 plugin
70+
working-directory: ./go/ocr2/decryptionplugin
71+
run: |
72+
go test -race -v ./... -coverpkg=./... -coverprofile=ocr2_decryptionplugin_race_coverage.txt
73+
6974
- name: Download npm deps
7075
working-directory: ./js/tdh2
7176
run: npm install
@@ -75,6 +80,11 @@ jobs:
7580
run: |
7681
go build -v ./...
7782
go test -v ./... -coverpkg=./... -coverprofile=tdh_coverage.txt
83+
84+
- name: Build and test TDH2
85+
working-directory: ./go/tdh2
86+
run: |
87+
go test -race -v ./... -coverpkg=./... -coverprofile=tdh_race_coverage.txt
7888
7989
- name: Upload Go test reports
8090
if: always()
@@ -83,7 +93,9 @@ jobs:
8393
name: go-test-results
8494
path: |
8595
./go/ocr2/decryptionplugin/ocr2_decryptionplugin_coverage.txt
96+
./go/ocr2/decryptionplugin/ocr2_decryptionplugin_race_coverage.txt
8697
./go/tdh2/tdh_coverage.txt
98+
./go/tdh2/tdh_race_coverage.txt
8799
88100
89101
sonar-scan:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package decryptionplugin
2+
3+
import (
4+
"errors"
5+
"os"
6+
"sync"
7+
"testing"
8+
)
9+
10+
func TestFail(t *testing.T) {
11+
if testing.Short() {
12+
t.Skip()
13+
}
14+
t.Fatal("fake failure")
15+
}
16+
17+
func TestRace(t *testing.T) {
18+
var v int
19+
var wg sync.WaitGroup
20+
wg.Add(100)
21+
for i := 0; i < 100; i++ {
22+
go func() {
23+
defer wg.Done()
24+
v++
25+
v--
26+
}()
27+
}
28+
wg.Wait()
29+
t.Log(v)
30+
}
31+
32+
func TestLint(t *testing.T) {
33+
const ALL_CAPS = 10 // should be AllCaps
34+
err := os.ErrNotExist
35+
if err == os.ErrNotExist { // should use errors.Is
36+
err := errors.New("fake error") // shadowed variable
37+
t.Log(err)
38+
}
39+
}

go/tdh2/fail_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package tdh2
2+
3+
import (
4+
"errors"
5+
"os"
6+
"sync"
7+
"testing"
8+
)
9+
10+
func TestFail(t *testing.T) {
11+
if testing.Short() {
12+
t.Skip()
13+
}
14+
t.Fatal("fake failure")
15+
}
16+
17+
func TestRace(t *testing.T) {
18+
var v int
19+
var wg sync.WaitGroup
20+
wg.Add(100)
21+
for i := 0; i < 100; i++ {
22+
go func() {
23+
defer wg.Done()
24+
v++
25+
v--
26+
}()
27+
}
28+
wg.Wait()
29+
t.Log(v)
30+
}
31+
32+
func TestLint(t *testing.T) {
33+
const ALL_CAPS = 10 // should be AllCaps
34+
err := os.ErrNotExist
35+
if err == os.ErrNotExist { // should use errors.Is
36+
err := errors.New("fake error") // shadowed variable
37+
t.Log(err)
38+
}
39+
}

0 commit comments

Comments
 (0)