Skip to content

Commit

Permalink
fix: rework tests (hamba#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma committed Jun 13, 2022
1 parent db47089 commit 3fe0a4d
Show file tree
Hide file tree
Showing 26 changed files with 587 additions and 527 deletions.
25 changes: 13 additions & 12 deletions codec_marshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/hamba/avro"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestDecoder_TextUnmarshalerPtr(t *testing.T) {
Expand All @@ -16,12 +17,12 @@ func TestDecoder_TextUnmarshalerPtr(t *testing.T) {
data := []byte{0x28, 0x32, 0x30, 0x32, 0x30, 0x2d, 0x30, 0x31, 0x2d, 0x30, 0x32, 0x54, 0x30, 0x33, 0x3a, 0x30, 0x34, 0x3a, 0x30, 0x35, 0x5a}
schema := "string"
dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var ts TestTimestampPtr
err = dec.Decode(&ts)

assert.NoError(t, err)
require.NoError(t, err)
want := TestTimestampPtr(time.Date(2020, 01, 02, 03, 04, 05, 00, time.UTC))
assert.Equal(t, want, ts)
}
Expand All @@ -32,12 +33,12 @@ func TestDecoder_TextUnmarshalerPtrPtr(t *testing.T) {
data := []byte{0x28, 0x32, 0x30, 0x32, 0x30, 0x2d, 0x30, 0x31, 0x2d, 0x30, 0x32, 0x54, 0x30, 0x33, 0x3a, 0x30, 0x34, 0x3a, 0x30, 0x35, 0x5a}
schema := "string"
dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var ts *TestTimestampPtr
err = dec.Decode(&ts)

assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, ts)
want := TestTimestampPtr(time.Date(2020, 01, 02, 03, 04, 05, 00, time.UTC))
assert.Equal(t, want, *ts)
Expand All @@ -49,7 +50,7 @@ func TestDecoder_TextUnmarshalerError(t *testing.T) {
data := []byte{0x28, 0x32, 0x30, 0x32, 0x30, 0x2d, 0x30, 0x31, 0x2d, 0x30, 0x32, 0x54, 0x30, 0x33, 0x3a, 0x30, 0x34, 0x3a, 0x30, 0x35, 0x5a}
schema := "string"
dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var ts *TestTimestampError
err = dec.Decode(&ts)
Expand All @@ -63,12 +64,12 @@ func TestEncoder_TextMarshaler(t *testing.T) {
schema := "string"
buf := bytes.NewBuffer([]byte{})
enc, err := avro.NewEncoder(schema, buf)
assert.NoError(t, err)
require.NoError(t, err)
ts := TestTimestamp(time.Date(2020, 01, 02, 03, 04, 05, 00, time.UTC))

err = enc.Encode(ts)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, []byte{0x28, 0x32, 0x30, 0x32, 0x30, 0x2d, 0x30, 0x31, 0x2d, 0x30, 0x32, 0x54, 0x30, 0x33, 0x3a, 0x30, 0x34, 0x3a, 0x30, 0x35, 0x5a}, buf.Bytes())
}

Expand All @@ -78,12 +79,12 @@ func TestEncoder_TextMarshalerPtr(t *testing.T) {
schema := "string"
buf := bytes.NewBuffer([]byte{})
enc, err := avro.NewEncoder(schema, buf)
assert.NoError(t, err)
require.NoError(t, err)
ts := TestTimestampPtr(time.Date(2020, 01, 02, 03, 04, 05, 00, time.UTC))

err = enc.Encode(&ts)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, []byte{0x28, 0x32, 0x30, 0x32, 0x30, 0x2d, 0x30, 0x31, 0x2d, 0x30, 0x32, 0x54, 0x30, 0x33, 0x3a, 0x30, 0x34, 0x3a, 0x30, 0x35, 0x5a}, buf.Bytes())
}

Expand All @@ -93,12 +94,12 @@ func TestEncoder_TextMarshalerPtrNil(t *testing.T) {
schema := "string"
buf := bytes.NewBuffer([]byte{})
enc, err := avro.NewEncoder(schema, buf)
assert.NoError(t, err)
require.NoError(t, err)
var ts *TestTimestampPtr

err = enc.Encode(ts)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, []byte{0x00}, buf.Bytes())
}

Expand All @@ -108,7 +109,7 @@ func TestEncoder_TextMarshalerError(t *testing.T) {
schema := "string"
buf := bytes.NewBuffer([]byte{})
enc, err := avro.NewEncoder(schema, buf)
assert.NoError(t, err)
require.NoError(t, err)
ts := TestTimestampError{}

err = enc.Encode(&ts)
Expand Down
71 changes: 36 additions & 35 deletions codec_skip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hamba/avro"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestDecoder_SkipBool(t *testing.T) {
Expand All @@ -22,12 +23,12 @@ func TestDecoder_SkipBool(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -45,12 +46,12 @@ func TestDecoder_SkipInt(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -68,12 +69,12 @@ func TestDecoder_SkipLong(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -89,12 +90,12 @@ func TestDecoder_SkipFloat(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -112,12 +113,12 @@ func TestDecoder_SkipDouble(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -135,12 +136,12 @@ func TestDecoder_SkipBytes(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -158,12 +159,12 @@ func TestDecoder_SkipString(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -181,12 +182,12 @@ func TestDecoder_SkipRecord(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -205,12 +206,12 @@ func TestDecoder_SkipRef(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -228,12 +229,12 @@ func TestDecoder_SkipEnum(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -251,12 +252,12 @@ func TestDecoder_SkipArray(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -274,12 +275,12 @@ func TestDecoder_SkipArrayBlocks(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -297,12 +298,12 @@ func TestDecoder_SkipMap(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -320,12 +321,12 @@ func TestDecoder_SkipMapBlocks(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -343,12 +344,12 @@ func TestDecoder_SkipUnion(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -366,12 +367,12 @@ func TestDecoder_SkipUnionNull(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}

Expand All @@ -389,7 +390,7 @@ func TestDecoder_SkipUnionInvalidSchema(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)
Expand All @@ -411,11 +412,11 @@ func TestDecoder_SkipFixed(t *testing.T) {
}`

dec, err := avro.NewDecoder(schema, bytes.NewReader(data))
assert.NoError(t, err)
require.NoError(t, err)

var got TestPartialRecord
err = dec.Decode(&got)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, TestPartialRecord{B: "foo"}, got)
}
Loading

0 comments on commit 3fe0a4d

Please sign in to comment.