]>
Commit | Line | Data |
---|---|---|
72dd37f1 JH |
1 | package hotline |
2 | ||
3 | import ( | |
4 | "github.com/stretchr/testify/assert" | |
5 | "testing" | |
6 | ) | |
7 | ||
8 | func TestFilePath_UnmarshalBinary(t *testing.T) { | |
9 | type fields struct { | |
10 | ItemCount []byte | |
11 | Items []FilePathItem | |
12 | } | |
13 | type args struct { | |
14 | b []byte | |
15 | } | |
16 | tests := []struct { | |
17 | name string | |
18 | args args | |
19 | want FilePath | |
20 | wantErr bool | |
21 | }{ | |
22 | { | |
23 | name: "unmarshals bytes into struct", | |
24 | args: args{b: []byte{ | |
25 | 0x00, 0x02, | |
26 | 0x00, 0x00, | |
27 | 0x0f, | |
28 | 0x46, 0x69, 0x72, 0x73, 0x74, 0x20, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x20, 0x44, 0x69, 0x72, | |
29 | 0x00, 0x00, | |
30 | 0x08, | |
31 | 0x41, 0x20, 0x53, 0x75, 0x62, 0x44, 0x69, 0x72, | |
32 | }}, | |
33 | want: FilePath{ | |
00d1ef67 | 34 | ItemCount: [2]byte{0x00, 0x02}, |
72dd37f1 JH |
35 | Items: []FilePathItem{ |
36 | { | |
37 | Len: 0x0f, | |
38 | Name: []byte("First Level Dir"), | |
39 | }, | |
40 | { | |
41 | Len: 0x08, | |
42 | Name: []byte("A SubDir"), | |
43 | }, | |
44 | }, | |
45 | }, | |
46 | wantErr: false, | |
47 | }, | |
48 | } | |
49 | for _, tt := range tests { | |
50 | t.Run(tt.name, func(t *testing.T) { | |
51 | var fp FilePath | |
52 | if err := fp.UnmarshalBinary(tt.args.b); (err != nil) != tt.wantErr { | |
53 | t.Errorf("UnmarshalBinary() error = %v, wantErr %v", err, tt.wantErr) | |
54 | } | |
55 | if !assert.Equal(t, tt.want, fp) { | |
56 | t.Errorf("Read() got = %v, want %v", fp, tt.want) | |
57 | } | |
58 | }) | |
59 | } | |
60 | } |