|
| 1 | +package encoding |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
| 8 | + |
| 9 | +var tsBytes = []byte{0x30, 0xff, 0x81, 0x3, 0x1, 0x1, 0xa, 0x74, 0x65, 0x73, 0x74, |
| 10 | + 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x1, 0xff, 0x82, 0x0, 0x1, 0x3, 0x1, 0x3, |
| 11 | + 0x46, 0x6f, 0x6f, 0x1, 0xc, 0x0, 0x1, 0x3, 0x42, 0x61, 0x72, 0x1, 0x8, 0x0, |
| 12 | + 0x1, 0x3, 0x42, 0x61, 0x7a, 0x1, 0x4, 0x0, 0x0, 0x0, 0x15, 0xff, 0x82, 0x1, |
| 13 | + 0x9, 0x66, 0x6f, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x1, 0xfe, 0x45, |
| 14 | + 0x40, 0x1, 0xff, 0xf6, 0x0} |
| 15 | + |
| 16 | +var ts = testStruct{ |
| 17 | + Foo: "foostring", |
| 18 | + Bar: 42.0, |
| 19 | + Baz: 123, |
| 20 | +} |
| 21 | + |
| 22 | +func TestGobCodec_Marshal(t *testing.T) { |
| 23 | + gc := GobCodec{} |
| 24 | + data, err := gc.Marshal(testStruct{ |
| 25 | + Foo: "foostring", |
| 26 | + Bar: 42.0, |
| 27 | + Baz: 123, |
| 28 | + }) |
| 29 | + assert.NoError(t, err) |
| 30 | + assert.Equal(t, tsBytes, data) |
| 31 | +} |
| 32 | + |
| 33 | +func TestGobCodec_Unmarshal(t *testing.T) { |
| 34 | + gc := GobCodec{} |
| 35 | + var data testStruct |
| 36 | + assert.NoError(t, gc.Unmarshal(tsBytes, &data)) |
| 37 | + assert.Equal(t, ts, data) |
| 38 | +} |
0 commit comments