Skip to content

Commit 2394cfe

Browse files
committed
IND-2428 test.yml updated with unit test coverage and linting
1 parent d2abad8 commit 2394cfe

File tree

8 files changed

+62
-26
lines changed

8 files changed

+62
-26
lines changed

.github/workflows/test.yaml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ jobs:
99
outputs:
1010
go-version: ${{ steps.get-go-version.outputs.go-version }}
1111
steps:
12-
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
12+
- name: Checkout Code
13+
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
1314
- name: Determine Go version
1415
id: get-go-version
1516
run: |
@@ -21,20 +22,38 @@ jobs:
2122
runs-on: ubuntu-latest
2223
needs: [get-go-version]
2324
steps:
24-
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
25-
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
25+
- name: Chekout Code
26+
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
27+
- name: Setup Go
28+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
2629
with:
2730
go-version: ${{ needs.get-go-version.outputs.go-version }}
28-
- run: 'exit $(( $(gofmt -s -l . | wc -l) != 0 ))'
31+
- name: Check formatting
32+
run: 'exit $(( $(gofmt -s -l . | wc -l) != 0 ))'
2933

3034
test:
3135
name: codec test
3236
runs-on: ubuntu-latest
3337
needs: [get-go-version]
3438
steps:
35-
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
36-
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
39+
- name: Checkout Code
40+
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
41+
- name: Setup Go
42+
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
3743
with:
3844
go-version: ${{ needs.get-go-version.outputs.go-version }}
45+
- name: Run golangci-lint
46+
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5
3947
- run: go test -v ./codec
40-
- run: go test -tags codecgen.exec -v ./codec
48+
- run: go test -tags codecgen.exec -v ./codec
49+
- name: Generate coverage report
50+
run: go test -v -coverprofile=coverage.out ./...
51+
- name: Upload coverage report
52+
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808
53+
with:
54+
path: coverage.out
55+
name: Coverage-report
56+
- name: Display coverage report
57+
run: go tool cover -func=coverage.out
58+
- name: Build Go
59+
run: go build ./...

.golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
linters:
2+
enable:
3+
- errcheck
4+
- gosimple
5+
disable:
6+
- unused
7+
- ineffassign
8+
- staticcheck
9+
output_format: colored-line-number

codec/bench/bench_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func doBenchCheck(name string, encfn benchEncFn, decfn benchDecFn) {
172172
} else {
173173
logT(nil, "\t%10s: len: %d bytes,\t encode: %v,\t decode: %v", name, encLen, encDur, decDur)
174174
}
175-
return
176175
}
177176

178177
func fnBenchmarkEncode(b *testing.B, encName string, ts interface{}, encfn benchEncFn) {

codec/bench/shared_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545
"flag"
4646
"fmt"
4747
"io"
48-
"io/ioutil"
4948
"log"
5049
"sync"
5150
"testing"
@@ -132,7 +131,7 @@ var (
132131
)
133132

134133
func init() {
135-
log.SetOutput(ioutil.Discard) // don't allow things log to standard out/err
134+
log.SetOutput(io.Discard) // don't allow things log to standard out/err
136135
testHEDs = make([]testHED, 0, 32)
137136
testHandles = append(testHandles,
138137
// testNoopH,

codec/codec_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"errors"
1111
"fmt"
1212
"io"
13-
"io/ioutil"
1413
"math"
1514
"math/rand"
1615
"net"
@@ -1291,7 +1290,9 @@ func testCodecRpcOne(t *testing.T, rr Rpc, h Handle, doRequest bool, exitSleepMs
12911290
defer func() { jsonH.TermWhitespace = false }()
12921291
}
12931292
srv := rpc.NewServer()
1294-
srv.Register(testRpcInt)
1293+
if err := srv.Register(testRpcInt); err != nil {
1294+
t.Fatal(err)
1295+
}
12951296
ln, err := net.Listen("tcp", "127.0.0.1:0") // listen on ipv4 localhost
12961297
logT(t, "connFn: addr: %v, network: %v, port: %v", ln.Addr(), ln.Addr().Network(), (ln.Addr().(*net.TCPAddr)).Port)
12971298
// log("listener: %v", ln.Addr())
@@ -1673,7 +1674,7 @@ func doTestRawValue(t *testing.T, name string, h Handle) {
16731674
func doTestPythonGenStreams(t *testing.T, name string, h Handle) {
16741675
testOnce.Do(testInitAll)
16751676
logT(t, "TestPythonGenStreams-%v", name)
1676-
tmpdir, err := ioutil.TempDir("", "golang-"+name+"-test")
1677+
tmpdir, err := os.MkdirTemp("", "golang-"+name+"-test")
16771678
if err != nil {
16781679
logT(t, "-------- Unable to create temp directory\n")
16791680
failT(t)
@@ -1707,7 +1708,7 @@ func doTestPythonGenStreams(t *testing.T, name string, h Handle) {
17071708
logT(t, "..............................................")
17081709
logT(t, " Testing: #%d: %T, %#v\n", i, v, v)
17091710
var bss []byte
1710-
bss, err = ioutil.ReadFile(filepath.Join(tmpdir, strconv.Itoa(i)+"."+name+".golden"))
1711+
bss, err = os.ReadFile(filepath.Join(tmpdir, strconv.Itoa(i)+"."+name+".golden"))
17111712
if err != nil {
17121713
logT(t, "-------- Error reading golden file: %d. Err: %v", i, err)
17131714
failT(t)
@@ -1795,7 +1796,9 @@ func doTestMsgpackRpcSpecGoClientToPythonSvc(t *testing.T) {
17951796
var mArgs MsgpackSpecRpcMultiArgs = []interface{}{"A1", "B2", "C3"}
17961797
checkErrT(t, cl.Call("Echo123", mArgs, &rstr))
17971798
checkEqualT(t, rstr, "1:A1 2:B2 3:C3", "rstr=")
1798-
cmd.Process.Kill()
1799+
if err := cmd.Process.Kill(); err != nil {
1800+
t.Fatal(err)
1801+
}
17991802
}
18001803

18011804
func doTestMsgpackRpcSpecPythonClientToGoSvc(t *testing.T) {
@@ -2083,7 +2086,7 @@ func doTestLargeContainerLen(t *testing.T, h Handle) {
20832086
func testRandomFillRV(v reflect.Value) {
20842087
testOnce.Do(testInitAll)
20852088
fneg := func() int64 {
2086-
i := rand.Intn(1)
2089+
i := rand.Intn(2)
20872090
if i == 1 {
20882091
return 1
20892092
}
@@ -2394,7 +2397,11 @@ func doTestScalars(t *testing.T, name string, h Handle) {
23942397
func doTestIntfMapping(t *testing.T, name string, h Handle) {
23952398
testOnce.Do(testInitAll)
23962399
rti := reflect.TypeOf((*testIntfMapI)(nil)).Elem()
2397-
defer func() { basicHandle(h).Intf2Impl(rti, nil) }()
2400+
defer func() {
2401+
if err := basicHandle(h).Intf2Impl(rti, nil); err != nil {
2402+
t.Fatal(err)
2403+
}
2404+
}()
23982405

23992406
type T9 struct {
24002407
I testIntfMapI
@@ -2705,7 +2712,7 @@ func TestBufioDecReader(t *testing.T) {
27052712
var r = strings.NewReader(s)
27062713
var br = &bufioDecReader{buf: make([]byte, 0, 13)}
27072714
br.r = r
2708-
b, err := ioutil.ReadAll(br.r)
2715+
b, err := io.ReadAll(br.r)
27092716
if err != nil {
27102717
panic(err)
27112718
}

codec/gen-internal.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"errors"
99
"go/format"
1010
"io"
11-
"io/ioutil"
1211
"strings"
1312
"sync"
1413
"text/template"
@@ -258,7 +257,7 @@ func genInternalGoFile(r io.Reader, w io.Writer) (err error) {
258257

259258
t := template.New("").Funcs(genInternalTmplFuncs)
260259

261-
tmplstr, err := ioutil.ReadAll(r)
260+
tmplstr, err := io.ReadAll(r)
262261
if err != nil {
263262
return
264263
}
@@ -275,10 +274,15 @@ func genInternalGoFile(r io.Reader, w io.Writer) (err error) {
275274

276275
bout, err := format.Source(out.Bytes())
277276
if err != nil {
278-
w.Write(out.Bytes()) // write out if error, so we can still see.
277+
if _, err := w.Write(out.Bytes()); err != nil {
278+
return err
279+
}
280+
// write out if error, so we can still see.
279281
// w.Write(bout) // write out if error, as much as possible, so we can still see.
280282
return
281283
}
282-
w.Write(bout)
284+
if _, err := w.Write(bout); err != nil {
285+
return err
286+
}
283287
return
284288
}

codec/helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ func (x *BasicHandle) fn(rt reflect.Type, checkFastpath, checkCodecSelfer bool)
741741
xfnf2 := fastpathAV[idx].decfn
742742
fn.fd = func(d *Decoder, xf *codecFnInfo, xrv reflect.Value) {
743743
if xrv.Kind() == reflect.Ptr {
744-
xfnf2(d, xf, xrv.Convert(reflect.PtrTo(xrt)))
744+
xfnf2(d, xf, xrv.Convert(reflect.PointerTo(xrt)))
745745
} else {
746746
xfnf2(d, xf, xrv.Convert(xrt))
747747
}
@@ -1917,7 +1917,7 @@ func rgetResolveSFI(rt reflect.Type, x []structFieldInfo, pv *typeInfoLoadArray)
19171917
}
19181918

19191919
func implIntf(rt, iTyp reflect.Type) (base bool, indir bool) {
1920-
return rt.Implements(iTyp), reflect.PtrTo(rt).Implements(iTyp)
1920+
return rt.Implements(iTyp), reflect.PointerTo(rt).Implements(iTyp)
19211921
}
19221922

19231923
// isEmptyStruct is only called from isEmptyValue, and checks if a struct is empty:

codec/shared_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545
"flag"
4646
"fmt"
4747
"io"
48-
"io/ioutil"
4948
"log"
5049
"sync"
5150
"testing"
@@ -132,7 +131,7 @@ var (
132131
)
133132

134133
func init() {
135-
log.SetOutput(ioutil.Discard) // don't allow things log to standard out/err
134+
log.SetOutput(io.Discard) // don't allow things log to standard out/err
136135
testHEDs = make([]testHED, 0, 32)
137136
testHandles = append(testHandles,
138137
// testNoopH,

0 commit comments

Comments
 (0)