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 17, 2024
1 parent c1a9eca commit 33866b8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
uses: dawidd6/action-download-artifact@v2.27.0
with:
workflow: ci-lint.yml
workflow_conclusion: ""
name: golangci-lint-report
if_no_artifact_found: warn

Expand All @@ -54,6 +55,7 @@ jobs:
uses: dawidd6/action-download-artifact@v2.27.0
with:
workflow: ci-test.yml
workflow_conclusion: ""
name: go-test-results
if_no_artifact_found: warn

Expand Down
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ linters:
# These are all considered deprecated: https://github.com/golangci/golangci-lint/issues/1841
- deadcode
- structcheck
- unused
- varcheck
linters-settings:
exhaustive:
Expand Down
17 changes: 17 additions & 0 deletions fail.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package wsrpc

import (
"errors"
"os"
"testing"
)

func FailLintOutOfTestFile(t *testing.T) {
const UnusedVar = 1 // lint should complain for unused variable
const ALL_CAPS = 10 // should be camel cased
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 fail_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package wsrpc

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 33866b8

Please sign in to comment.