| OLD | NEW |
| 1 package util | 1 package util |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "testing" | 4 "testing" |
| 5 | 5 |
| 6 assert "github.com/stretchr/testify/require" | 6 assert "github.com/stretchr/testify/require" |
| 7 ) | 7 ) |
| 8 | 8 |
| 9 func TestJSONCodec(t *testing.T) { | 9 func TestJSONCodec(t *testing.T) { |
| 10 type myTestType struct { | |
| 11 A int | |
| 12 B string | |
| 13 } | |
| 14 | |
| 15 itemCodec := JSONCodec(&myTestType{}) | 10 itemCodec := JSONCodec(&myTestType{}) |
| 16 testInstance := &myTestType{5, "hello"} | 11 testInstance := &myTestType{5, "hello"} |
| 17 jsonBytes, err := itemCodec.Encode(testInstance) | 12 jsonBytes, err := itemCodec.Encode(testInstance) |
| 18 assert.Nil(t, err) | 13 assert.Nil(t, err) |
| 19 | 14 |
| 20 decodedInstance, err := itemCodec.Decode(jsonBytes) | 15 decodedInstance, err := itemCodec.Decode(jsonBytes) |
| 21 assert.Nil(t, err) | 16 assert.Nil(t, err) |
| 22 assert.IsType(t, &myTestType{}, decodedInstance) | 17 assert.IsType(t, &myTestType{}, decodedInstance) |
| 23 assert.Equal(t, testInstance, decodedInstance) | 18 assert.Equal(t, testInstance, decodedInstance) |
| 24 | 19 |
| 25 arrCodec := JSONCodec([]*myTestType{}) | 20 arrCodec := JSONCodec([]*myTestType{}) |
| 26 testArr := []*myTestType{&myTestType{1, "1"}, &myTestType{2, "2"}} | 21 testArr := []*myTestType{&myTestType{1, "1"}, &myTestType{2, "2"}} |
| 27 jsonBytes, err = arrCodec.Encode(testArr) | 22 jsonBytes, err = arrCodec.Encode(testArr) |
| 28 assert.Nil(t, err) | 23 assert.Nil(t, err) |
| 29 | 24 |
| 30 decodedArr, err := arrCodec.Decode(jsonBytes) | 25 decodedArr, err := arrCodec.Decode(jsonBytes) |
| 31 assert.Nil(t, err) | 26 assert.Nil(t, err) |
| 32 assert.IsType(t, []*myTestType{}, decodedArr) | 27 assert.IsType(t, []*myTestType{}, decodedArr) |
| 33 assert.Equal(t, testArr, decodedArr) | 28 assert.Equal(t, testArr, decodedArr) |
| 34 } | 29 } |
| 30 |
| 31 func TestMemLRUCache(t *testing.T) { |
| 32 cache := NewMemLRUCache(0) |
| 33 UnitTestLRUCache(t, cache) |
| 34 } |
| OLD | NEW |