Skip to content

Commit fb44ffb

Browse files
committed
simplify bundle test code
1 parent 457fe5c commit fb44ffb

File tree

1 file changed

+65
-65
lines changed

1 file changed

+65
-65
lines changed

bundle_test.go

+65-65
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestBundleBytes(t *testing.T) {
1616
Input: Bundle{Timetag: 10},
1717
Output: bytes.Join([][]byte{
1818
ToBytes(BundleTag),
19-
[]byte{0, 0, 0, 0, 0, 0, 0, 0x0A},
19+
{0, 0, 0, 0, 0, 0, 0, 0x0A},
2020
}, []byte{}),
2121
},
2222
{
@@ -34,12 +34,12 @@ func TestBundleBytes(t *testing.T) {
3434
},
3535
Output: bytes.Join([][]byte{
3636
ToBytes(BundleTag),
37-
[]byte{0, 0, 0, 0, 0, 0, 0, 0x0A},
38-
[]byte{0, 0, 0, 0x14},
39-
[]byte{'/', 'f', 'o', 'o', 0, 0, 0, 0},
40-
[]byte{',', TypetagInt, TypetagFloat, 0},
41-
[]byte{0, 0, 0, 2},
42-
[]byte{0x40, 0xA7, 0x67, 0xA1},
37+
{0, 0, 0, 0, 0, 0, 0, 0x0A},
38+
{0, 0, 0, 0x14},
39+
{'/', 'f', 'o', 'o', 0, 0, 0, 0},
40+
{',', TypetagInt, TypetagFloat, 0},
41+
{0, 0, 0, 2},
42+
{0x40, 0xA7, 0x67, 0xA1},
4343
}, []byte{}),
4444
},
4545
// Bundle within a bundle.
@@ -69,19 +69,19 @@ func TestBundleBytes(t *testing.T) {
6969
},
7070
Output: bytes.Join([][]byte{
7171
ToBytes(BundleTag),
72-
[]byte{0, 0, 0, 0, 0, 0, 0, 0x0A}, // Timetag
73-
[]byte{0, 0, 0, 0x24}, // Length of first bundle element
72+
{0, 0, 0, 0, 0, 0, 0, 0x0A}, // Timetag
73+
{0, 0, 0, 0x24}, // Length of first bundle element
7474
ToBytes(BundleTag),
75-
[]byte{0, 0, 0, 0, 0, 0, 0, 0x14}, // Timetag
76-
[]byte{0, 0, 0, 0x10}, // Length of first element of bundle within bundle.
77-
[]byte{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
78-
[]byte{TypetagPrefix, TypetagFloat, 0, 0},
79-
[]byte{0x3F, 0x80, 0x00, 0x00},
80-
[]byte{0, 0, 0, 0x14}, // Length of second bundle element
81-
[]byte{'/', 'f', 'o', 'o', 0, 0, 0, 0},
82-
[]byte{TypetagPrefix, TypetagInt, TypetagFloat, 0},
83-
[]byte{0, 0, 0, 2},
84-
[]byte{0x40, 0xA7, 0x67, 0xA1},
75+
{0, 0, 0, 0, 0, 0, 0, 0x14}, // Timetag
76+
{0, 0, 0, 0x10}, // Length of first element of bundle within bundle.
77+
{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
78+
{TypetagPrefix, TypetagFloat, 0, 0},
79+
{0x3F, 0x80, 0x00, 0x00},
80+
{0, 0, 0, 0x14}, // Length of second bundle element
81+
{'/', 'f', 'o', 'o', 0, 0, 0, 0},
82+
{TypetagPrefix, TypetagInt, TypetagFloat, 0},
83+
{0, 0, 0, 2},
84+
{0x40, 0xA7, 0x67, 0xA1},
8585
}, []byte{}),
8686
},
8787
} {
@@ -172,7 +172,7 @@ func TestParseBundle(t *testing.T) {
172172
Input: bytes.Join(
173173
[][]byte{
174174
append([]byte("#bundle"), 0),
175-
[]byte{1, 2, 3, 4, 5, 6, 7},
175+
{1, 2, 3, 4, 5, 6, 7},
176176
},
177177
[]byte{},
178178
),
@@ -185,9 +185,9 @@ func TestParseBundle(t *testing.T) {
185185
Input: bytes.Join(
186186
[][]byte{
187187
append([]byte("#bundle"), 0),
188-
[]byte{1, 2, 3, 4, 5, 6, 7, 8},
189-
[]byte{0, 0, 0, 4},
190-
[]byte{'%', 'n', 'o', 0},
188+
{1, 2, 3, 4, 5, 6, 7, 8},
189+
{0, 0, 0, 4},
190+
{'%', 'n', 'o', 0},
191191
},
192192
[]byte{},
193193
),
@@ -201,10 +201,10 @@ func TestParseBundle(t *testing.T) {
201201
[][]byte{
202202
append([]byte("#bundle"), 0),
203203
Timetag(50).Bytes(),
204-
[]byte{0, 0, 0, 0x10},
205-
[]byte{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
206-
[]byte{TypetagPrefix, TypetagInt, 0, 0},
207-
[]byte{0, 0, 0, 7},
204+
{0, 0, 0, 0x10},
205+
{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
206+
{TypetagPrefix, TypetagInt, 0, 0},
207+
{0, 0, 0, 7},
208208
},
209209
[]byte{},
210210
),
@@ -226,7 +226,7 @@ func TestParseBundle(t *testing.T) {
226226
[][]byte{
227227
append([]byte("#bundle"), 0),
228228
Timetag(50).Bytes(),
229-
[]byte{0, 0, 0x10},
229+
{0, 0, 0x10},
230230
},
231231
[]byte{},
232232
),
@@ -240,10 +240,10 @@ func TestParseBundle(t *testing.T) {
240240
[][]byte{
241241
append([]byte("#bundle"), 0),
242242
Timetag(50).Bytes(),
243-
[]byte{0, 0, 0, 0x20},
244-
[]byte{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
245-
[]byte{TypetagPrefix, TypetagInt, 0, 0},
246-
[]byte{0, 0, 0, 7},
243+
{0, 0, 0, 0x20},
244+
{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
245+
{TypetagPrefix, TypetagInt, 0, 0},
246+
{0, 0, 0, 7},
247247
},
248248
[]byte{},
249249
),
@@ -257,14 +257,14 @@ func TestParseBundle(t *testing.T) {
257257
[][]byte{
258258
append([]byte("#bundle"), 0),
259259
Timetag(50).Bytes(),
260-
[]byte{0, 0, 0, 0x10},
261-
[]byte{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
262-
[]byte{TypetagPrefix, TypetagInt, 0, 0},
263-
[]byte{0, 0, 0, 7},
264-
[]byte{0, 0, 0, 0x10},
265-
[]byte{'/', 'b', 'o', 'r', 'k', 0, 0, 0},
266-
[]byte{TypetagPrefix, TypetagFloat, 0, 0},
267-
[]byte{0x40, 0x48, 0xf5, 0xc3},
260+
{0, 0, 0, 0x10},
261+
{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
262+
{TypetagPrefix, TypetagInt, 0, 0},
263+
{0, 0, 0, 7},
264+
{0, 0, 0, 0x10},
265+
{'/', 'b', 'o', 'r', 'k', 0, 0, 0},
266+
{TypetagPrefix, TypetagFloat, 0, 0},
267+
{0x40, 0x48, 0xf5, 0xc3},
268268
},
269269
[]byte{},
270270
),
@@ -290,10 +290,10 @@ func TestParseBundle(t *testing.T) {
290290
[][]byte{
291291
append([]byte("#bundle"), 0),
292292
Timetag(50).Bytes(),
293-
[]byte{0, 0, 0, 0x10},
294-
[]byte{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
295-
[]byte{TypetagPrefix, TypetagInt, 'Q', 0},
296-
[]byte{0, 0, 0, 7},
293+
{0, 0, 0, 0x10},
294+
{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
295+
{TypetagPrefix, TypetagInt, 'Q', 0},
296+
{0, 0, 0, 7},
297297
},
298298
[]byte{},
299299
),
@@ -305,22 +305,22 @@ func TestParseBundle(t *testing.T) {
305305
{
306306
Input: bytes.Join([][]byte{
307307
ToBytes(BundleTag),
308-
[]byte{0, 0, 0, 0, 0, 0, 0, 0x0A}, // Timetag
309-
[]byte{0, 0, 0, 0x24}, // Length of first bundle element
308+
{0, 0, 0, 0, 0, 0, 0, 0x0A}, // Timetag
309+
{0, 0, 0, 0x24}, // Length of first bundle element
310310
ToBytes(BundleTag),
311-
[]byte{0, 0, 0, 0, 0, 0, 0, 0x14}, // Timetag
312-
[]byte{0, 0, 0, 0x10}, // Length of first element of bundle within bundle.
313-
[]byte{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
314-
[]byte{TypetagPrefix, TypetagFloat, 0, 0},
315-
[]byte{0x3F, 0x80, 0x00, 0x00},
316-
[]byte{0, 0, 0, 0x14}, // Length of second bundle element
317-
[]byte{'/', 'f', 'o', 'o', 0, 0, 0, 0},
318-
[]byte{TypetagPrefix, TypetagInt, TypetagFloat, 0},
319-
[]byte{0, 0, 0, 2},
320-
[]byte{0x40, 0xA7, 0x67, 0xA1},
321-
[]byte{0, 0, 0, 0x10}, // Length of third bundleelement
311+
{0, 0, 0, 0, 0, 0, 0, 0x14}, // Timetag
312+
{0, 0, 0, 0x10}, // Length of first element of bundle within bundle.
313+
{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
314+
{TypetagPrefix, TypetagFloat, 0, 0},
315+
{0x3F, 0x80, 0x00, 0x00},
316+
{0, 0, 0, 0x14}, // Length of second bundle element
317+
{'/', 'f', 'o', 'o', 0, 0, 0, 0},
318+
{TypetagPrefix, TypetagInt, TypetagFloat, 0},
319+
{0, 0, 0, 2},
320+
{0x40, 0xA7, 0x67, 0xA1},
321+
{0, 0, 0, 0x10}, // Length of third bundleelement
322322
ToBytes(BundleTag),
323-
[]byte{0, 0, 0, 0, 0, 0, 0, 0x28}, // Timetag
323+
{0, 0, 0, 0, 0, 0, 0, 0x28}, // Timetag
324324
}, []byte{}),
325325
Expected: Output{
326326
bundle: Bundle{
@@ -353,14 +353,14 @@ func TestParseBundle(t *testing.T) {
353353
{
354354
Input: bytes.Join([][]byte{
355355
ToBytes(BundleTag),
356-
[]byte{0, 0, 0, 0, 0, 0, 0, 0x0A}, // Timetag
357-
[]byte{0, 0, 0, 0x24}, // Length of first bundle element
356+
{0, 0, 0, 0, 0, 0, 0, 0x0A}, // Timetag
357+
{0, 0, 0, 0x24}, // Length of first bundle element
358358
ToBytes(BundleTag),
359-
[]byte{0, 0, 0, 0, 0, 0, 0, 0x14}, // Timetag
360-
[]byte{0, 0, 0, 0x10}, // Length of first element of bundle within bundle.
361-
[]byte{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
362-
[]byte{TypetagPrefix, 'Q', 0, 0},
363-
[]byte{0x3F, 0x80, 0x00, 0x00},
359+
{0, 0, 0, 0, 0, 0, 0, 0x14}, // Timetag
360+
{0, 0, 0, 0x10}, // Length of first element of bundle within bundle.
361+
{'/', 'f', 'o', 'o', 'b', 'a', 'r', 0},
362+
{TypetagPrefix, 'Q', 0, 0},
363+
{0x3F, 0x80, 0x00, 0x00},
364364
}, []byte{}),
365365
Expected: Output{
366366
err: errors.New(`read packets: read packet: parse bundle from packet: read packets: read packet: parse message from packet: parse message: read argument 0: typetag "Q": invalid type tag`),

0 commit comments

Comments
 (0)