Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IND-2428 test.yml updated with unit test coverage and linting #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Checkout Code
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Determine Go version
id: get-go-version
run: |
Expand All @@ -21,20 +22,38 @@ jobs:
runs-on: ubuntu-latest
needs: [get-go-version]
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
- name: Chekout Code
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Setup Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- run: 'exit $(( $(gofmt -s -l . | wc -l) != 0 ))'
- name: Check formatting
run: 'exit $(( $(gofmt -s -l . | wc -l) != 0 ))'

test:
name: codec test
runs-on: ubuntu-latest
needs: [get-go-version]
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
- name: Checkout Code
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Setup Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- name: Run golangci-lint
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5
- run: go test -v ./codec
- run: go test -tags codecgen.exec -v ./codec
- run: go test -tags codecgen.exec -v ./codec
- name: Generate coverage report
run: go test -v -coverprofile=coverage.out ./...
- name: Upload coverage report
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808
with:
path: coverage.out
name: Coverage-report
- name: Display coverage report
run: go tool cover -func=coverage.out
- name: Build Go
run: go build ./...
9 changes: 9 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
linters:
enable:
- errcheck
- gosimple
disable:
- unused
- ineffassign
- staticcheck
output_format: colored-line-number
1 change: 0 additions & 1 deletion codec/bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func doBenchCheck(name string, encfn benchEncFn, decfn benchDecFn) {
} else {
logT(nil, "\t%10s: len: %d bytes,\t encode: %v,\t decode: %v", name, encLen, encDur, decDur)
}
return
}

func fnBenchmarkEncode(b *testing.B, encName string, ts interface{}, encfn benchEncFn) {
Expand Down
3 changes: 1 addition & 2 deletions codec/bench/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"sync"
"testing"
Expand Down Expand Up @@ -132,7 +131,7 @@ var (
)

func init() {
log.SetOutput(ioutil.Discard) // don't allow things log to standard out/err
log.SetOutput(io.Discard) // don't allow things log to standard out/err
testHEDs = make([]testHED, 0, 32)
testHandles = append(testHandles,
// testNoopH,
Expand Down
23 changes: 15 additions & 8 deletions codec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"math/rand"
"net"
Expand Down Expand Up @@ -1291,7 +1290,9 @@ func testCodecRpcOne(t *testing.T, rr Rpc, h Handle, doRequest bool, exitSleepMs
defer func() { jsonH.TermWhitespace = false }()
}
srv := rpc.NewServer()
srv.Register(testRpcInt)
if err := srv.Register(testRpcInt); err != nil {
t.Fatal(err)
}
ln, err := net.Listen("tcp", "127.0.0.1:0") // listen on ipv4 localhost
logT(t, "connFn: addr: %v, network: %v, port: %v", ln.Addr(), ln.Addr().Network(), (ln.Addr().(*net.TCPAddr)).Port)
// log("listener: %v", ln.Addr())
Expand Down Expand Up @@ -1673,7 +1674,7 @@ func doTestRawValue(t *testing.T, name string, h Handle) {
func doTestPythonGenStreams(t *testing.T, name string, h Handle) {
testOnce.Do(testInitAll)
logT(t, "TestPythonGenStreams-%v", name)
tmpdir, err := ioutil.TempDir("", "golang-"+name+"-test")
tmpdir, err := os.MkdirTemp("", "golang-"+name+"-test")
if err != nil {
logT(t, "-------- Unable to create temp directory\n")
failT(t)
Expand Down Expand Up @@ -1707,7 +1708,7 @@ func doTestPythonGenStreams(t *testing.T, name string, h Handle) {
logT(t, "..............................................")
logT(t, " Testing: #%d: %T, %#v\n", i, v, v)
var bss []byte
bss, err = ioutil.ReadFile(filepath.Join(tmpdir, strconv.Itoa(i)+"."+name+".golden"))
bss, err = os.ReadFile(filepath.Join(tmpdir, strconv.Itoa(i)+"."+name+".golden"))
if err != nil {
logT(t, "-------- Error reading golden file: %d. Err: %v", i, err)
failT(t)
Expand Down Expand Up @@ -1795,7 +1796,9 @@ func doTestMsgpackRpcSpecGoClientToPythonSvc(t *testing.T) {
var mArgs MsgpackSpecRpcMultiArgs = []interface{}{"A1", "B2", "C3"}
checkErrT(t, cl.Call("Echo123", mArgs, &rstr))
checkEqualT(t, rstr, "1:A1 2:B2 3:C3", "rstr=")
cmd.Process.Kill()
if err := cmd.Process.Kill(); err != nil {
t.Fatal(err)
}
}

func doTestMsgpackRpcSpecPythonClientToGoSvc(t *testing.T) {
Expand Down Expand Up @@ -2083,7 +2086,7 @@ func doTestLargeContainerLen(t *testing.T, h Handle) {
func testRandomFillRV(v reflect.Value) {
testOnce.Do(testInitAll)
fneg := func() int64 {
i := rand.Intn(1)
i := rand.Intn(2)
if i == 1 {
return 1
}
Expand Down Expand Up @@ -2394,7 +2397,11 @@ func doTestScalars(t *testing.T, name string, h Handle) {
func doTestIntfMapping(t *testing.T, name string, h Handle) {
testOnce.Do(testInitAll)
rti := reflect.TypeOf((*testIntfMapI)(nil)).Elem()
defer func() { basicHandle(h).Intf2Impl(rti, nil) }()
defer func() {
if err := basicHandle(h).Intf2Impl(rti, nil); err != nil {
t.Fatal(err)
}
}()

type T9 struct {
I testIntfMapI
Expand Down Expand Up @@ -2705,7 +2712,7 @@ func TestBufioDecReader(t *testing.T) {
var r = strings.NewReader(s)
var br = &bufioDecReader{buf: make([]byte, 0, 13)}
br.r = r
b, err := ioutil.ReadAll(br.r)
b, err := io.ReadAll(br.r)
if err != nil {
panic(err)
}
Expand Down
12 changes: 8 additions & 4 deletions codec/gen-internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"go/format"
"io"
"io/ioutil"
"strings"
"sync"
"text/template"
Expand Down Expand Up @@ -258,7 +257,7 @@ func genInternalGoFile(r io.Reader, w io.Writer) (err error) {

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

tmplstr, err := ioutil.ReadAll(r)
tmplstr, err := io.ReadAll(r)
if err != nil {
return
}
Expand All @@ -275,10 +274,15 @@ func genInternalGoFile(r io.Reader, w io.Writer) (err error) {

bout, err := format.Source(out.Bytes())
if err != nil {
w.Write(out.Bytes()) // write out if error, so we can still see.
if _, err := w.Write(out.Bytes()); err != nil {
return err
}
// write out if error, so we can still see.
// w.Write(bout) // write out if error, as much as possible, so we can still see.
return
}
w.Write(bout)
if _, err := w.Write(bout); err != nil {
return err
}
return
}
4 changes: 2 additions & 2 deletions codec/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ func (x *BasicHandle) fn(rt reflect.Type, checkFastpath, checkCodecSelfer bool)
xfnf2 := fastpathAV[idx].decfn
fn.fd = func(d *Decoder, xf *codecFnInfo, xrv reflect.Value) {
if xrv.Kind() == reflect.Ptr {
xfnf2(d, xf, xrv.Convert(reflect.PtrTo(xrt)))
xfnf2(d, xf, xrv.Convert(reflect.PointerTo(xrt)))
} else {
xfnf2(d, xf, xrv.Convert(xrt))
}
Expand Down Expand Up @@ -1917,7 +1917,7 @@ func rgetResolveSFI(rt reflect.Type, x []structFieldInfo, pv *typeInfoLoadArray)
}

func implIntf(rt, iTyp reflect.Type) (base bool, indir bool) {
return rt.Implements(iTyp), reflect.PtrTo(rt).Implements(iTyp)
return rt.Implements(iTyp), reflect.PointerTo(rt).Implements(iTyp)
}

// isEmptyStruct is only called from isEmptyValue, and checks if a struct is empty:
Expand Down
3 changes: 1 addition & 2 deletions codec/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"sync"
"testing"
Expand Down Expand Up @@ -132,7 +131,7 @@ var (
)

func init() {
log.SetOutput(ioutil.Discard) // don't allow things log to standard out/err
log.SetOutput(io.Discard) // don't allow things log to standard out/err
testHEDs = make([]testHED, 0, 32)
testHandles = append(testHandles,
// testNoopH,
Expand Down
Loading