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
|
package core
import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
func TestEncoder(t *testing.T) {
in := Test{
Num1: 1,
Time1: time.Now().Truncate(time.Second),
Str1: "test string",
Num2: 2,
Bin1: []byte{0x01, 0x02, 0x03},
Num3: 3,
Str2: "こんにちは",
Num4: 4,
}
data, err := Encode(in)
if err != nil {
t.Error(err)
}
out, err := Decode(data)
if err != nil {
t.Error(err)
}
if diff := cmp.Diff(in, out); diff != "" {
t.Errorf("structs are different (-in +out):\n%s", diff)
}
}
|