-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
684 lines (606 loc) · 19.7 KB
/
main_test.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
package main
import (
"bytes"
"io/ioutil"
"path/filepath"
"regexp"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestBip39ChecksumWords(t *testing.T) {
t.Parallel()
var tests = []struct {
input string
want []string
}{
// 11-word mnemonics
{"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon",
[]string{"about", "actual", "age", "alpha", "angle", "argue", "artwork", "attract", "bachelor", "bean", "behind", "blind", "bomb", "brand", "broken", "burger", "cactus", "carbon", "cereal", "cheese", "city", "click", "coach", "cool", "coyote", "cricket", "cruise", "cute", "degree", "describe", "diesel", "disagree", "donor", "drama", "dune", "edit", "enemy", "energy", "escape", "exhaust", "express", "fashion", "field", "fiscal", "flavor", "food", "fringe", "furnace", "genius", "glue", "goddess", "grocery", "hand", "high", "holiday", "huge", "illness", "inform", "insect", "jacket", "kangaroo", "knock", "lamp", "lemon", "length", "lobster", "lyrics", "marble", "mass", "member", "metal", "moment", "mouse", "near", "noise", "obey", "offer", "once", "organ", "own", "parent", "phrase", "pill", "pole", "position", "process", "project", "question", "rail", "record", "remind", "render", "return", "ritual", "rubber", "sand", "scout", "sell", "share", "shoot", "simple", "slice", "soap", "solid", "speed", "square", "stereo", "street", "sugar", "surprise", "tank", "tent", "they", "toddler", "tongue", "trade", "truly", "turtle", "umbrella", "urge", "vast", "vendor", "void", "voyage", "wear", "wife", "world", "wrap"}},
{"legal winner thank year wave sausage worth useful legal winner thank",
[]string{"about", "admit", "age", "amazing", "analyst", "apple", "ask", "author", "awkward", "basket", "beyond", "blame", "boring", "brave", "broom", "busy", "call", "casual", "celery", "check", "churn", "clever", "code", "cool", "cost", "crime", "cross", "daughter", "debate", "derive", "differ", "display", "domain", "drill", "dynamic", "either", "employ", "ensure", "essay", "exchange", "express", "father", "feature", "fine", "flip", "forget", "frequent", "funny", "general", "give", "gold", "grid", "habit", "help", "holiday", "huge", "identify", "impulse", "into", "jealous", "joy", "kind", "latin", "leisure", "library", "lizard", "lunar", "manage", "marriage", "melt", "method", "mix", "much", "nature", "noise", "nut", "object", "open", "output", "panic", "path", "phrase", "pizza", "pole", "prepare", "process", "pudding", "quarter", "radar", "record", "reform", "result", "retreat", "ring", "saddle", "sand", "science", "sell", "setup", "shrug", "six", "slide", "soccer", "solve", "speed", "stadium", "staff", "stuff", "sun", "swift", "tail", "test", "thrive", "tobacco", "tomato", "trade", "truth", "twenty", "under", "upper", "valid", "version", "virtual", "want", "wedding", "wife", "worry", "yellow"}},
{"letter advice cage absurd amount doctor acoustic avoid letter advice cage",
[]string{"above", "add", "afford", "among", "anchor", "any", "army", "attack", "ball", "become", "bicycle", "blind", "bone", "brave", "buffalo", "busy", "candy", "castle", "cereal", "champion", "civil", "close", "code", "comic", "cousin", "creek", "cruel", "daring", "defense", "depth", "device", "dish", "doll", "draw", "earth", "ecology", "end", "envelope", "eternal", "exact", "explain", "fatigue", "federal", "fire", "fly", "forum", "frequent", "future", "genuine", "glass", "grape", "grief", "hat", "heart", "holiday", "hover", "illness", "include", "inspire", "involve", "keep", "kid", "ladder", "lawn", "letter", "logic", "loud", "marble", "match", "media", "milk", "monster", "motion", "myself", "news", "nuclear", "observe", "onion", "orphan", "oyster", "peace", "physical", "piece", "plastic", "potato", "primary", "pull", "quit", "ramp", "rebuild", "reform", "response", "rich", "room", "saddle", "sail", "scheme", "seek", "shaft", "shiver", "size", "skin", "smart", "solve", "spare", "split", "stereo", "style", "suit", "sweet", "talk", "that", "thing", "time", "tongue", "trade", "trigger", "twice", "undo", "update", "vacant", "venture", "village", "wave", "way", "win", "world", "zero"}},
// 23-word mnemonics
{"all hour make first leader extend hole alien behind guard gospel lava path output census museum junior mass reopen famous sing advance salt",
[]string{"alcohol", "diamond", "during", "gym", "noise", "reform", "staff", "valid"}},
{"beyond stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away",
[]string{"aware", "coconut", "feature", "keen", "option", "peasant", "seed", "wheel"}},
{"letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic",
[]string{"bless", "deer", "door", "hub", "mesh", "pledge", "sting", "wild"}},
}
for _, tc := range tests {
got, err := bip39ChecksumWords(strings.Fields(tc.input))
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("record mismatch (-want +got):\n%s", diff)
}
}
}
func TestBipCheckword(t *testing.T) {
t.Parallel()
var tests = []struct {
cmd BipCheckwordCmd
want string
wantFile string
}{
// 11 words
// Test no flags (except required Deterministic)
{BipCheckwordCmd{
Deterministic: true,
PartialMnemonic: []string{
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon"},
}, "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about\n", ""},
// Test Word: true
{BipCheckwordCmd{
Word: true,
Deterministic: true,
PartialMnemonic: []string{
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon"},
}, "about\n", ""},
// Test Multi: true
{BipCheckwordCmd{
Multi: true,
PartialMnemonic: []string{
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon"},
}, "", "bipCheckwordsMnemonics1.txt"},
// Test Multi: true, Word: true
{BipCheckwordCmd{
Multi: true,
Word: true,
PartialMnemonic: []string{
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon"},
}, "", "bipCheckwordsWords1.txt"},
// 23 words
// Test no flags (except required Deterministic)
{BipCheckwordCmd{
Deterministic: true,
PartialMnemonic: []string{
"all hour make first leader extend hole alien behind guard gospel lava path output census museum junior mass reopen famous sing advance salt"},
}, "all hour make first leader extend hole alien behind guard gospel lava path output census museum junior mass reopen famous sing advance salt alcohol\n", ""},
// Test Word: true
{BipCheckwordCmd{
Word: true,
Deterministic: true,
PartialMnemonic: []string{
"all hour make first leader extend hole alien behind guard gospel lava path output census museum junior mass reopen famous sing advance salt"},
}, "alcohol\n", ""},
// Test Multi: true
{BipCheckwordCmd{
Multi: true,
PartialMnemonic: []string{
"all hour make first leader extend hole alien behind guard gospel lava path output census museum junior mass reopen famous sing advance salt"},
}, "", "bipCheckwordsMnemonics2.txt"},
// Test Multi: true, Word: true
{BipCheckwordCmd{
Multi: true,
Word: true,
PartialMnemonic: []string{
"all hour make first leader extend hole alien behind guard gospel lava path output census museum junior mass reopen famous sing advance salt"},
}, "", "bipCheckwordsWords2.txt"},
}
for _, tc := range tests {
var buf bytes.Buffer
ctx := Context{
writer: &buf,
verbose: 0,
}
err := tc.cmd.Run(&ctx)
if err != nil {
t.Fatal(err)
}
got := buf.String()
want := tc.want
if tc.wantFile != "" {
data, err := ioutil.ReadFile("testdata/" + tc.wantFile)
if err != nil {
t.Fatal(err)
}
want = string(data)
}
if got != want {
t.Errorf("want %q, got %q", want, got)
}
}
}
func TestBipValidate_Success(t *testing.T) {
t.Parallel()
// Load all testdata `bipNs.txt` files (good mnemonics)
tests := make(map[string]string)
testfiles, err := filepath.Glob("testdata/bip?s*.txt")
if err != nil {
t.Fatal(err)
}
for _, tf := range testfiles {
data, err := ioutil.ReadFile(tf)
if err != nil {
t.Fatal(err)
}
tests[tf] = standardiseMnemonicBytes(data)
}
for _, quiet := range []bool{true, false} {
for tf, mnemonic := range tests {
cmd := BipValCmd{
Quiet: quiet,
Seed: strings.Fields(strings.TrimSpace(mnemonic)),
}
var buf bytes.Buffer
ctx := Context{
writer: &buf,
verbose: 0,
}
err := cmd.Run(&ctx)
if err != nil {
t.Errorf("mnemonic %q reported as invalid", tf)
}
got := buf.String()
if quiet {
if got != "" {
t.Errorf("mnemonic %q returned output in quiet mode: %s",
tf, got)
}
continue
}
if !strings.Contains(got, "good") {
t.Errorf("mnemonic %q returned no error but outputs invalid", tf)
}
}
}
}
func TestBipValidate_Failure(t *testing.T) {
t.Parallel()
// Load all testdata `bipMfN.txt` files (bad mnemonics)
tests := make(map[string]string)
testfiles, err := filepath.Glob("testdata/bip?f?.txt")
if err != nil {
t.Fatal(err)
}
for _, tf := range testfiles {
data, err := ioutil.ReadFile(tf)
if err != nil {
t.Fatal(err)
}
tests[tf] = string(data)
}
for _, quiet := range []bool{false, true} {
for tf, mnemonic := range tests {
cmd := BipValCmd{
Quiet: quiet,
Seed: strings.Fields(strings.TrimSpace(mnemonic)),
}
var buf bytes.Buffer
ctx := Context{
writer: &buf,
verbose: 0,
}
err := cmd.Run(&ctx)
if err == nil {
t.Errorf("mnemonic %q reported as valid", tf)
}
got := buf.String()
if got != "" {
t.Errorf("mnemonic %q invalid but returned output: %s",
tf, got)
}
}
}
}
// Test validating random BIP-39 mnemonics
func TestBipValidate_Random(t *testing.T) {
t.Parallel()
wordlen := []int{12, 15, 18, 21, 24}
randomCount := 200
for _, n := range wordlen {
for _ = range randomCount {
// Generate a random BIP-39 mnemonic
cmd := BipRandomCmd{
Num: n,
}
var buf bytes.Buffer
ctx := Context{
writer: &buf,
verbose: 0,
}
err := cmd.Run(&ctx)
if err != nil {
t.Errorf("generating random BIP-39 mnemonic generated error: %s",
err.Error())
continue
}
mnemonic := buf.String()
//t.Logf("n: %d, mnemonic: %s", n, mnemonic)
// Validate mnemonic
for _, quiet := range []bool{true, false} {
cmd := BipValCmd{
Quiet: quiet,
Seed: strings.Fields(strings.TrimSpace(mnemonic)),
}
var buf bytes.Buffer
ctx := Context{
writer: &buf,
verbose: 0,
}
err := cmd.Run(&ctx)
if err != nil {
t.Errorf("mnemonic %q (%d) reported as invalid",
mnemonic, n)
}
got := buf.String()
if quiet {
if got != "" {
t.Errorf("mnemonic %q (%d) returned output in quiet mode: %s",
mnemonic, n, got)
}
continue
}
if !strings.Contains(got, "good") {
t.Errorf("mnemonic %q (%d) returned no error but outputs invalid",
mnemonic, n)
}
}
}
}
}
// Test round-tripping between BIP-39 mnemonics and SLIP-39 shares
func TestBipSlip(t *testing.T) {
t.Parallel()
// Load all testdata `bipNs.txt` files (good mnemonics)
tests := make(map[string]string)
testfiles, err := filepath.Glob("testdata/bip?s*.txt")
if err != nil {
t.Fatal(err)
}
for _, tf := range testfiles {
data, err := ioutil.ReadFile(tf)
if err != nil {
t.Fatal(err)
}
tests[tf] = standardiseMnemonicBytes(data)
}
for _, passphrase := range []string{"", "TREZOR"} {
for tf, mnemonic := range tests {
//t.Logf("testing %s with passphrase %q", tf, passphrase)
cmd := BipSlipCmd{
GroupThreshold: 1,
Groups: []string{"2of3"},
Passphrase: passphrase,
Seed: strings.Fields(strings.TrimSpace(mnemonic)),
}
var buf bytes.Buffer
ctx := Context{
writer: &buf,
}
err := cmd.Run(&ctx)
if err != nil {
t.Errorf("mnemonic %q reported as invalid: %s", tf, err.Error())
continue
}
got := buf.String()
//t.Logf("mnemonic %q converted to SLIP-39 shares:\n%s", tf, got)
shares := strings.Split(strings.TrimSpace(got), "\n")
cmd2 := SlipBipCmd{
Passphrase: passphrase,
Shares: shares[:2],
}
buf.Reset()
err = cmd2.Run(&ctx)
if err != nil {
t.Errorf("mnemonic %q reported as invalid: %s", tf, err.Error())
break
continue
}
got = standardiseMnemonicBytes(buf.Bytes())
//t.Logf("mnemonic %q converted back to BIP-39 seed:\n%s", tf, got)
if got != mnemonic {
t.Errorf("round-trip mismatch on %q - got:\n%qexpected:\n%q",
tf, got, mnemonic)
}
}
}
}
// Test converting BIP-39 seeds to labelled words
func TestBipLabel_Success(t *testing.T) {
t.Parallel()
// Load all testdata `bipMs.txt` files (good seeds)
tests := make(map[string]string)
testfiles, err := filepath.Glob("testdata/bip?s*.txt")
if err != nil {
t.Fatal(err)
}
for _, tf := range testfiles {
data, err := ioutil.ReadFile(tf)
if err != nil {
t.Fatal(err)
}
tests[tf] = standardiseMnemonicBytes(data)
}
reTestfile := regexp.MustCompile(`^testdata/bip`)
for tf, seeds := range tests {
lf := reTestfile.ReplaceAllString(tf, "testdata/blabels")
ldata, err := ioutil.ReadFile(lf)
if err != nil {
t.Fatal(err)
}
//t.Logf("checking tf %q vs lf %q", tf, lf)
// Convert bip seeds to labelled words
buf1 := bytes.NewBufferString(seeds)
var buf2 bytes.Buffer
// Test with uppercase flag on
cmd := BipLabelCmd{Upper: true}
ctx := Context{
reader: buf1,
writer: &buf2,
}
err = cmd.Run(&ctx)
if err != nil {
t.Errorf("BipLabel error on %q: %s", tf, err.Error())
continue
}
words := buf2.String()
if words != string(ldata) {
t.Errorf("test file %q mismatch - got:\n%qexpected:\n%q",
tf, words, string(ldata))
}
}
}
// Test validation of good SLIP-39 shares
func TestSlipVal_Success(t *testing.T) {
t.Parallel()
skipTests := make(map[string]bool)
skipTests["testdata/slip5s.txt"] = true
skipTests["testdata/slip6s.txt"] = true
// Load all testdata `slipMs*.txt` files (good shares)
tests := make(map[string]string)
testfiles, err := filepath.Glob("testdata/slip?s*.txt")
if err != nil {
t.Fatal(err)
}
for _, tf := range testfiles {
if skipTests[tf] {
continue
}
data, err := ioutil.ReadFile(tf)
if err != nil {
t.Fatal(err)
}
tests[tf] = string(data)
}
for tf, shares := range tests {
buf1 := bytes.NewBufferString(shares)
var buf2 bytes.Buffer
cmd := SlipValCmd{}
ctx := Context{
reader: buf1,
writer: &buf2,
}
err := cmd.Run(&ctx)
if err != nil {
t.Errorf("SlipVal error on %q: %s", tf, err.Error())
continue
}
got := buf2.String()
if !strings.Contains(got, "good") {
t.Errorf("unexpected output on successful sv for %q: %s", tf, got)
}
}
}
// Test validation of good SLIP-39 shares with CheckFile
func TestSlipVal_CheckFile(t *testing.T) {
t.Parallel()
var tests = []struct {
slipfile string
checkfile string
}{
{"slip1s.txt", "bip1s.txt"},
{"slip1sn.txt", "bip1s.txt"},
{"slip1s.txt", "bip1sn.txt"},
{"slip1sn.txt", "bip1sn.txt"},
}
for _, tc := range tests {
data, err := ioutil.ReadFile("testdata/" + tc.slipfile)
if err != nil {
t.Fatal(err)
}
buf1 := bytes.NewBufferString(string(data))
var buf2 bytes.Buffer
cmd := SlipValCmd{
CheckFile: "testdata/" + tc.checkfile,
}
ctx := Context{
reader: buf1,
writer: &buf2,
}
err = cmd.Run(&ctx)
if err != nil {
t.Errorf("SlipVal error on %q / %q:\n%s",
tc.slipfile, tc.checkfile, err.Error())
continue
}
got := buf2.String()
if !strings.Contains(got, "good") {
t.Errorf("unexpected output on successful sv for %q / %q:\n%s",
tc.slipfile, tc.checkfile, got)
}
}
}
// Test validation of bad SLIP-39 shares
func TestSlipVal_Failure(t *testing.T) {
t.Parallel()
// Load all testdata `slipNf.txt` files (bad shares)
tests := make(map[string]string)
testfiles, err := filepath.Glob("testdata/slip?f*.txt")
if err != nil {
t.Fatal(err)
}
for _, tf := range testfiles {
if strings.Contains(tf, "todo") {
continue
}
data, err := ioutil.ReadFile(tf)
if err != nil {
t.Fatal(err)
}
tests[tf] = string(data)
}
for tf, shares := range tests {
buf1 := bytes.NewBufferString(shares)
var buf2 bytes.Buffer
cmd := SlipValCmd{}
ctx := Context{
reader: buf1,
writer: &buf2,
}
err := cmd.Run(&ctx)
if err == nil {
t.Errorf("%q unexpectedly succeeded!", tf)
continue
}
//t.Logf("%q produced an error, as expected: %s", tf, err.Error())
}
}
// Test round-tripping between SLIP-39 shares and labelled words
func TestSlipLabel_Success(t *testing.T) {
t.Parallel()
// Load all testdata `slipMs.txt` files (good shares)
tests := make(map[string]string)
testfiles, err := filepath.Glob("testdata/slip?s.txt")
if err != nil {
t.Fatal(err)
}
for _, tf := range testfiles {
data, err := ioutil.ReadFile(tf)
if err != nil {
t.Fatal(err)
}
tests[tf] = string(data)
}
reWords := regexp.MustCompile(`(?m)^\d{3,6} [A-Z]+$`)
for tf, shares := range tests {
// Convert slip shares to labelled words
buf1 := bytes.NewBufferString(shares)
var buf2 bytes.Buffer
// Test with uppercase flag on
cmd := SlipLabelCmd{Upper: true}
ctx := Context{
reader: buf1,
writer: &buf2,
}
err := cmd.Run(&ctx)
if err != nil {
t.Errorf("SlipLabel error on %q: %s", tf, err.Error())
continue
}
words := buf2.String()
if !reWords.MatchString(words) {
t.Errorf("test file %q returned invalid words: %s", tf, words)
}
// Convert labelled words back to slip shares
cmd2 := LabelSlipCmd{}
ctx = Context{
reader: &buf2,
writer: buf1,
}
err = cmd2.Run(&ctx)
if err != nil {
t.Errorf("LabelSlip error on %q: %s", tf, err.Error())
continue
}
out := buf1.String()
if out != shares {
t.Errorf("round-trip mismatch on %q - got:\n%sexpected:\n%s",
tf, out, shares)
}
}
}
// Test trying to convert bad sets labelled words
func TestSlipLabel_Failure(t *testing.T) {
t.Parallel()
// Load all testdata `slabelsMf.txt` files (bad labelled words)
tests := make(map[string]string)
testfiles, err := filepath.Glob("testdata/slabels?f.txt")
if err != nil {
t.Fatal(err)
}
for _, tf := range testfiles {
data, err := ioutil.ReadFile(tf)
if err != nil {
t.Fatal(err)
}
tests[tf] = string(data)
}
for tf, shares := range tests {
// Convert labelled words to slip shares
buf1 := bytes.NewBufferString(shares)
var buf2 bytes.Buffer
cmd := LabelSlipCmd{}
ctx := Context{
reader: buf1,
writer: &buf2,
}
err = cmd.Run(&ctx)
if err == nil {
t.Errorf("LabelSlip on %q unexpectedly suceeded!", tf)
continue
}
t.Logf("LabelSlip on %q produced an error, as expected: %s", tf, err.Error())
}
}
// Test validation of good SLIP-39 shares with CheckFile
func TestSlipParse(t *testing.T) {
t.Parallel()
var tests = []struct {
slipfile string
jsonfile string
}{
{"slip1s.txt", "slip1s.json"},
{"slip1sn.txt", "slip1s.json"},
{"slip1su.txt", "slip1s.json"},
}
for _, tc := range tests {
data, err := ioutil.ReadFile("testdata/" + tc.slipfile)
if err != nil {
t.Fatal(err)
}
buf1 := bytes.NewBufferString(string(data))
var buf2 bytes.Buffer
cmd := SlipParseCmd{}
ctx := Context{
reader: buf1,
writer: &buf2,
}
err = cmd.Run(&ctx)
if err != nil {
t.Errorf("SlipParse error on %q:\n%s", tc.slipfile, err.Error())
continue
}
data, err = ioutil.ReadFile("testdata/" + tc.jsonfile)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(string(data), buf2.String()); diff != "" {
t.Errorf("record mismatch (-want +got):\n%s", diff)
}
}
}