Skip to content

Commit

Permalink
Moved test files back to root dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Rens Rikkerink authored and ikkerens committed Mar 5, 2019
1 parent 712d4dd commit 35df515
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
46 changes: 22 additions & 24 deletions tests/errors_test.go → errors_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package tests
package ikea

import (
"bytes"
"errors"
"math"
"testing"

"github.com/ikkerens/ikeapack"
)

func TestReadPointer(t *testing.T) {
Expand All @@ -17,7 +15,7 @@ func TestReadPointer(t *testing.T) {
}()

var i int
_ = ikea.Unpack(nil, i)
_ = Unpack(nil, i)
}

func TestUseInt(t *testing.T) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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()
}
}
Expand All @@ -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()
}

Expand All @@ -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()
}
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -155,7 +153,7 @@ func TestLenVariableNil(t *testing.T) {
s := struct {
A *string
}{}
ikea.Len(&s)
Len(&s)
}

func TestReadErrors(t *testing.T) {
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand Down
16 changes: 7 additions & 9 deletions tests/full_test.go → full_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package ikea

import (
"bytes"
Expand All @@ -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
}
Expand Down Expand Up @@ -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()
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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()
}
Expand All @@ -117,13 +115,13 @@ 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 {
A uint8
}

func (p *testUnpackerOnly) Unpack(r io.Reader) error {
return ikea.Unpack(r, &p.A)
return Unpack(r, &p.A)
}
8 changes: 3 additions & 5 deletions tests/primitives_test.go → primitives_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package ikea

import (
"bytes"
Expand All @@ -7,8 +7,6 @@ import (
"os"
"reflect"
"testing"

"github.com/ikkerens/ikeapack"
)

func TestBool(t *testing.T) {
Expand Down Expand Up @@ -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()
}
Expand Down
8 changes: 3 additions & 5 deletions tests/testdata_test.go → testdata_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package tests
package ikea

import (
"encoding/hex"
"io"

"github.com/ikkerens/ikeapack"
)

/* Test types */
Expand Down Expand Up @@ -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
}

Expand All @@ -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 */
Expand Down

0 comments on commit 35df515

Please sign in to comment.