From 35df5158b97fe1552edf6df6a57dd123ed0165ee Mon Sep 17 00:00:00 2001 From: Rens Rikkerink Date: Tue, 5 Mar 2019 21:40:21 +0100 Subject: [PATCH] Moved test files back to root dir --- .travis.yml | 2 +- tests/errors_test.go => errors_test.go | 46 +++++++++---------- tests/full_test.go => full_test.go | 16 +++---- .../primitives_test.go => primitives_test.go | 8 ++-- tests/testdata_test.go => testdata_test.go | 8 ++-- 5 files changed, 36 insertions(+), 44 deletions(-) rename tests/errors_test.go => errors_test.go (73%) rename tests/full_test.go => full_test.go (92%) rename tests/primitives_test.go => primitives_test.go (92%) rename tests/testdata_test.go => testdata_test.go (96%) diff --git a/.travis.yml b/.travis.yml index a217491..f80d094 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,6 @@ script: - diff <(gofmt -d .) <(echo -n) - go vet -x ./... # - golint -set_exit_status ./... - - go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... + - go test -v -race -coverprofile=coverage.txt -covermode=atomic after_success: - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/tests/errors_test.go b/errors_test.go similarity index 73% rename from tests/errors_test.go rename to errors_test.go index 9d0da98..d097b47 100644 --- a/tests/errors_test.go +++ b/errors_test.go @@ -1,12 +1,10 @@ -package tests +package ikea import ( "bytes" "errors" "math" "testing" - - "github.com/ikkerens/ikeapack" ) func TestReadPointer(t *testing.T) { @@ -17,7 +15,7 @@ func TestReadPointer(t *testing.T) { }() var i int - _ = ikea.Unpack(nil, i) + _ = Unpack(nil, i) } func TestUseInt(t *testing.T) { @@ -28,7 +26,7 @@ func TestUseInt(t *testing.T) { }() var i int - _ = ikea.Unpack(nil, &i) // int is not supported + _ = Unpack(nil, &i) // int is not supported } func TestUseUint(t *testing.T) { @@ -39,7 +37,7 @@ func TestUseUint(t *testing.T) { }() var ui uint - _ = ikea.Unpack(nil, &ui) // uint is not supported + _ = Unpack(nil, &ui) // uint is not supported } func TestUnsupportedType(t *testing.T) { @@ -50,37 +48,37 @@ func TestUnsupportedType(t *testing.T) { }() var ui complex64 - _ = ikea.Unpack(nil, &ui) // uint is not supported + _ = Unpack(nil, &ui) // uint is not supported } func TestVariableLengthOverflow(t *testing.T) { overflow := new(bytes.Buffer) - _ = ikea.Pack(overflow, uint32(math.MaxInt32+1)) + _ = Pack(overflow, uint32(math.MaxInt32+1)) var t1 struct { Data struct{} `ikea:"compress:9"` } - if err := ikea.Unpack(overflow, &t1); err == nil { + if err := Unpack(overflow, &t1); err == nil { t.FailNow() } overflow.Reset() - _ = ikea.Pack(overflow, uint32(math.MaxInt32+1)) + _ = Pack(overflow, uint32(math.MaxInt32+1)) var t2 map[string]struct{} - if err := ikea.Unpack(overflow, &t2); err == nil { + if err := Unpack(overflow, &t2); err == nil { t.FailNow() } overflow.Reset() - _ = ikea.Pack(overflow, uint32(math.MaxInt32+1)) + _ = Pack(overflow, uint32(math.MaxInt32+1)) var t3 []struct{} - if err := ikea.Unpack(overflow, &t3); err == nil { + if err := Unpack(overflow, &t3); err == nil { t.FailNow() } overflow.Reset() - _ = ikea.Pack(overflow, uint32(math.MaxInt32+1)) + _ = Pack(overflow, uint32(math.MaxInt32+1)) var t4 string - if err := ikea.Unpack(overflow, &t4); err == nil { + if err := Unpack(overflow, &t4); err == nil { t.FailNow() } } @@ -89,7 +87,7 @@ func TestCompressionInitError(t *testing.T) { s1 := struct { Data []byte `ikea:"compress:10"` }{make([]byte, 10)} - if err := ikea.Pack(new(bytes.Buffer), &s1); err == nil { + if err := Pack(new(bytes.Buffer), &s1); err == nil { t.Fail() } @@ -101,13 +99,13 @@ func TestCompressionInitError(t *testing.T) { t.FailNow() } }() - _ = ikea.Pack(new(bytes.Buffer), &s2) + _ = Pack(new(bytes.Buffer), &s2) } func TestInvalidUTF8(t *testing.T) { var invalid string b := bytes.NewBuffer([]byte{0x00, 0x00, 0x00, 0x01, 0xF1}) - if ikea.Unpack(b, &invalid) == nil { + if Unpack(b, &invalid) == nil { t.FailNow() } } @@ -122,7 +120,7 @@ func TestPackFixedNil(t *testing.T) { s := struct { A *uint32 }{} - _ = ikea.Pack(new(bytes.Buffer), &s) + _ = Pack(new(bytes.Buffer), &s) } func TestPackVariableNil(t *testing.T) { @@ -135,14 +133,14 @@ func TestPackVariableNil(t *testing.T) { s := struct { A *string }{} - _ = ikea.Pack(new(bytes.Buffer), &s) + _ = Pack(new(bytes.Buffer), &s) } func TestLenFixedNil(t *testing.T) { s := struct { A *uint32 }{} - ikea.Len(&s) // Unlike all other nil values, this should succeed + Len(&s) // Unlike all other nil values, this should succeed } func TestLenVariableNil(t *testing.T) { @@ -155,7 +153,7 @@ func TestLenVariableNil(t *testing.T) { s := struct { A *string }{} - ikea.Len(&s) + Len(&s) } func TestReadErrors(t *testing.T) { @@ -165,7 +163,7 @@ func TestReadErrors(t *testing.T) { tst := new(testStruct) err := errors.New("start of errors") for err != nil { - err = ikea.Unpack(e, tst) + err = Unpack(e, tst) if err == nil && e.pass != len(testData) { t.FailNow() } @@ -179,7 +177,7 @@ func TestWriteErrors(t *testing.T) { // Reading error tests err := errors.New("start of errors") for err != nil { - err = ikea.Pack(e, source) + err = Pack(e, source) if err == nil && e.pass != len(testData) { t.FailNow() } diff --git a/tests/full_test.go b/full_test.go similarity index 92% rename from tests/full_test.go rename to full_test.go index 48934c3..934aa6e 100644 --- a/tests/full_test.go +++ b/full_test.go @@ -1,4 +1,4 @@ -package tests +package ikea import ( "bytes" @@ -9,15 +9,13 @@ import ( "strconv" "strings" "testing" - - "github.com/ikkerens/ikeapack" ) /* Tests */ func TestOutput(t *testing.T) { buf := new(bytes.Buffer) - if err := ikea.Pack(buf, source); err != nil { + if err := Pack(buf, source); err != nil { t.Error(err) return } @@ -49,7 +47,7 @@ func TestOutput(t *testing.T) { } // Unpack it var test map[string]string - if err := ikea.Unpack(buf, &test); err != nil { + if err := Unpack(buf, &test); err != nil { fmt.Printf("Failing TestWrite, could not unpack map: %s\n", err.Error()) t.FailNow() } @@ -66,7 +64,7 @@ func TestCompleteRead(t *testing.T) { buf.Write(testData) tst := new(testStruct) - if err := ikea.Unpack(buf, tst); err != nil { + if err := Unpack(buf, tst); err != nil { t.Error(err) return } @@ -100,7 +98,7 @@ func TestCompleteRead(t *testing.T) { } func TestLen(t *testing.T) { - if l := ikea.Len(source); l != len(testData) { + if l := Len(source); l != len(testData) { fmt.Printf("Failing TestLen, Len reported an incorrect value %d, should be %d", l, len(testData)) t.FailNow() } @@ -117,7 +115,7 @@ type testPackerOnly struct { } func (p *testPackerOnly) Pack(w io.Writer) error { - return ikea.Pack(w, &p.A) + return Pack(w, &p.A) } type testUnpackerOnly struct { @@ -125,5 +123,5 @@ type testUnpackerOnly struct { } func (p *testUnpackerOnly) Unpack(r io.Reader) error { - return ikea.Unpack(r, &p.A) + return Unpack(r, &p.A) } diff --git a/tests/primitives_test.go b/primitives_test.go similarity index 92% rename from tests/primitives_test.go rename to primitives_test.go index e4a1b67..065344d 100644 --- a/tests/primitives_test.go +++ b/primitives_test.go @@ -1,4 +1,4 @@ -package tests +package ikea import ( "bytes" @@ -7,8 +7,6 @@ import ( "os" "reflect" "testing" - - "github.com/ikkerens/ikeapack" ) func TestBool(t *testing.T) { @@ -86,13 +84,13 @@ func TestString(t *testing.T) { func typeTest(t *testing.T, typ string, value, compare interface{}) { var b bytes.Buffer - if err := ikea.Pack(&b, value); err != nil { + if err := Pack(&b, value); err != nil { _, _ = fmt.Fprintf(os.Stderr, "Failing %s, could not write value: %s\n", typ, err.Error()) t.FailNow() } target := reflect.New(reflect.TypeOf(value).Elem()) - if err := ikea.Unpack(&b, target.Interface()); err != nil { + if err := Unpack(&b, target.Interface()); err != nil { _, _ = fmt.Fprintf(os.Stderr, "Failing %s, could not read value: %s\n", typ, err.Error()) t.FailNow() } diff --git a/tests/testdata_test.go b/testdata_test.go similarity index 96% rename from tests/testdata_test.go rename to testdata_test.go index e404109..d214dbc 100644 --- a/tests/testdata_test.go +++ b/testdata_test.go @@ -1,10 +1,8 @@ -package tests +package ikea import ( "encoding/hex" "io" - - "github.com/ikkerens/ikeapack" ) /* Test types */ @@ -47,7 +45,7 @@ type testInterface struct { func (t *testInterface) Unpack(r io.Reader) error { var temp int64 - if err := ikea.Unpack(r, &temp); err != nil { + if err := Unpack(r, &temp); err != nil { return err } @@ -57,7 +55,7 @@ func (t *testInterface) Unpack(r io.Reader) error { } func (t *testInterface) Pack(w io.Writer) error { - return ikea.Pack(w, t.A+10) + return Pack(w, t.A+10) } /* Test data */