]> git.r.bdr.sh - rbdr/mobius/blame - hotline/news_test.go
Update go.yml
[rbdr/mobius] / hotline / news_test.go
CommitLineData
72dd37f1
JH
1package hotline
2
3import (
72dd37f1
JH
4 "reflect"
5 "testing"
6)
7
8func TestNewsCategoryListData15_MarshalBinary(t *testing.T) {
9 type fields struct {
9cf66aea 10 Type [2]byte
72dd37f1
JH
11 Name string
12 Articles map[uint32]*NewsArtData
13 SubCats map[string]NewsCategoryListData15
14 Count []byte
15 AddSN []byte
16 DeleteSN []byte
17 GUID []byte
18 }
19 tests := []struct {
20 name string
21 fields fields
22 wantData []byte
23 wantErr bool
24 }{
25 {
26 name: "returns expected bytes when type is a bundle",
27 fields: fields{
9cf66aea 28 Type: [2]byte{0x00, 0x02},
72dd37f1
JH
29 Articles: map[uint32]*NewsArtData{
30 uint32(1): {
31 Title: "",
32 Poster: "",
33 Data: "",
34 },
35 },
36 Name: "foo",
37 },
38 wantData: []byte{
39 0x00, 0x02,
40 0x00, 0x01,
41 0x03,
42 0x66, 0x6f, 0x6f,
43 },
44 wantErr: false,
45 },
46 {
47 name: "returns expected bytes when type is a category",
48 fields: fields{
9cf66aea 49 Type: [2]byte{0x00, 0x03},
72dd37f1
JH
50 Articles: map[uint32]*NewsArtData{
51 uint32(1): {
52 Title: "",
53 Poster: "",
54 Data: "",
55 },
56 },
57 Name: "foo",
58 },
59 wantData: []byte{
60 0x00, 0x03,
61 0x00, 0x01,
62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63 0x00, 0x00, 0x00, 0x01,
64 0x00, 0x00, 0x00, 0x02,
65 0x03,
66 0x66, 0x6f, 0x6f,
67 },
68 wantErr: false,
69 },
70 }
71 for _, tt := range tests {
72 t.Run(tt.name, func(t *testing.T) {
73 newscat := &NewsCategoryListData15{
74 Type: tt.fields.Type,
75 Name: tt.fields.Name,
76 Articles: tt.fields.Articles,
77 SubCats: tt.fields.SubCats,
78 Count: tt.fields.Count,
79 AddSN: tt.fields.AddSN,
80 DeleteSN: tt.fields.DeleteSN,
81 GUID: tt.fields.GUID,
82 }
83 gotData, err := newscat.MarshalBinary()
9cf66aea 84 if newscat.Type == [2]byte{0, 3} {
72dd37f1
JH
85 // zero out the random GUID before comparison
86 for i := 4; i < 20; i++ {
87 gotData[i] = 0
88 }
89 }
90 if (err != nil) != tt.wantErr {
91 t.Errorf("MarshalBinary() error = %v, wantErr %v", err, tt.wantErr)
92 return
93 }
94 if !reflect.DeepEqual(gotData, tt.wantData) {
95 t.Errorf("MarshalBinary() gotData = %v, want %v", gotData, tt.wantData)
96 }
97 })
98 }
99}