-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialize_test.go
43 lines (37 loc) · 1.09 KB
/
serialize_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package cacheit
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type testStruct struct {
Message string
Value int
Time time.Time
IntSlice []int
StringSlice []string
Map map[string]interface{}
}
var testStructData = testStruct{
Message: "Hello, this is a mock message!",
Value: 42,
IntSlice: []int{1, 2, 3, 4, 5},
StringSlice: []string{"apple", "banana", "cherry"},
Map: map[string]interface{}{
"name": "John Doe",
"address": "123 Main St",
"phone": "555-555-5555",
"email": "[email protected]",
},
}
func TestJSONSerializer(t *testing.T) {
t.Run("serialize and un serialize", func(t *testing.T) {
serializer := &JSONSerializer{}
data, err := serializer.Serialize(testStructData)
assert.NoError(t, err, "Serialize should not return an error")
var unSerializedData testStruct
err = serializer.UnSerialize(data, &unSerializedData)
assert.NoError(t, err, "UnSerialize should not return an error")
assert.Equal(t, testStructData, unSerializedData, "Serialized and UnSerialized data should be equal")
})
}