]>
Commit | Line | Data |
---|---|---|
1 | package hotline | |
2 | ||
3 | import ( | |
4 | "reflect" | |
5 | "testing" | |
6 | ) | |
7 | ||
8 | func TestTrackerRegistration_Payload(t *testing.T) { | |
9 | type fields struct { | |
10 | Port []byte | |
11 | UserCount int | |
12 | PassID []byte | |
13 | Name string | |
14 | Description string | |
15 | } | |
16 | tests := []struct { | |
17 | name string | |
18 | fields fields | |
19 | want []byte | |
20 | }{ | |
21 | { | |
22 | name: "returns expected payload bytes", | |
23 | fields: fields{ | |
24 | Port: []byte{0x00, 0x10}, | |
25 | UserCount: 2, | |
26 | PassID: []byte{0x00, 0x00, 0x00, 0x01}, | |
27 | Name: "Test Serv", | |
28 | Description: "Fooz", | |
29 | }, | |
30 | want: []byte{ | |
31 | 0x00, 0x01, | |
32 | 0x00, 0x10, | |
33 | 0x00, 0x02, | |
34 | 0x00, 0x00, | |
35 | 0x00, 0x00, 0x00, 0x01, | |
36 | 0x09, | |
37 | 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x65, 0x72, 0x76, | |
38 | 0x04, | |
39 | 0x46, 0x6f, 0x6f, 0x7a, | |
40 | }, | |
41 | }, | |
42 | } | |
43 | for _, tt := range tests { | |
44 | t.Run(tt.name, func(t *testing.T) { | |
45 | tr := &TrackerRegistration{ | |
46 | Port: tt.fields.Port, | |
47 | UserCount: tt.fields.UserCount, | |
48 | PassID: tt.fields.PassID, | |
49 | Name: tt.fields.Name, | |
50 | Description: tt.fields.Description, | |
51 | } | |
52 | if got := tr.Payload(); !reflect.DeepEqual(got, tt.want) { | |
53 | t.Errorf("Payload() = %v, want %v", got, tt.want) | |
54 | } | |
55 | }) | |
56 | } | |
57 | } |