This repository has been archived by the owner on Jul 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
fugu_test.go
811 lines (708 loc) · 21.2 KB
/
fugu_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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
package fugu
import (
"github.com/mattes/go-collect"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"os/user"
"testing"
fileSource "github.com/mattes/go-collect/source/file"
)
func init() {
collect.RegisterSource(&fileSource.File{})
}
// set to testDesc to only run this test
var RunOnly = ""
type DockerCommandTest struct {
testDesc string
command string
// dataIn *data.Data
argsIn []string
strOut string
errOut error
}
func (dct *DockerCommandTest) Test(t *testing.T) {
if RunOnly != "" && RunOnly != dct.testDesc {
return
}
c := collect.New()
data, remainingArgs, err := c.Parse(dct.argsIn, FuguFlags[dct.command], DockerFlags[dct.command])
assert.NoError(t, err, dct.testDesc)
if err == nil {
str, err := DockerCommands[dct.command](c, data, remainingArgs)
assert.Equal(t, dct.errOut, err, dct.testDesc)
if err == nil {
assert.Equal(t, dct.strOut, str, dct.testDesc)
}
}
}
type CommandTest struct {
testDesc string
command string
argsIn []string
errOut error
stdoutContains []string
}
func (dct *CommandTest) Test(t *testing.T) {
if RunOnly != "" && RunOnly != dct.testDesc {
return
}
c := collect.New()
data, remainingArgs, err := c.Parse(dct.argsIn, FuguFlags[dct.command], DockerFlags[dct.command])
assert.NoError(t, err, dct.testDesc)
if err == nil {
// capture stdout
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
err = Commands[dct.command](c, data, remainingArgs)
w.Close()
out, _ := ioutil.ReadAll(r)
os.Stdout = rescueStdout
if !assert.Equal(t, dct.errOut, err, dct.testDesc) {
t.Logf("%s", out)
}
if len(dct.stdoutContains) > 0 {
assert.NotEmpty(t, string(out), dct.testDesc)
}
if len(dct.stdoutContains) == 0 {
assert.Empty(t, string(out), dct.testDesc)
}
for _, str := range dct.stdoutContains {
assert.Contains(t, string(out), str, dct.testDesc)
}
}
}
func TestCommandBuild(t *testing.T) {
(&DockerCommandTest{
testDesc: "image is missing",
command: "build",
argsIn: []string{},
strOut: "",
errOut: ErrMissingImage,
}).Test(t)
(&DockerCommandTest{
testDesc: "build with label",
command: "build",
argsIn: []string{"label1", "--source=file://examples/fugu.labels.yml"},
strOut: "docker build --tag=redis .",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "build with unknown label",
command: "build",
argsIn: []string{"label2", "--source=file://examples/fugu.labels.yml"},
strOut: "",
errOut: ErrMissingImage,
}).Test(t)
(&DockerCommandTest{
testDesc: "tag flag",
command: "build",
argsIn: []string{"--image=foo", "--tag=bar"},
strOut: "docker build --tag=foo:bar .",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "no tag given",
command: "build",
argsIn: []string{"--image=foo"},
strOut: "docker build --tag=foo .",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "given path",
command: "build",
argsIn: []string{"--image=foo", "--path=bar"},
strOut: "docker build --tag=foo bar",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "given url",
command: "build",
argsIn: []string{"--image=foo", "--url=bar"},
strOut: "docker build --tag=foo bar",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "both given path and url",
command: "build",
argsIn: []string{"--image=foo", "--url=url", "--path=path"},
strOut: "docker build --tag=foo url",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "path or url given via args (no label)",
command: "build",
argsIn: []string{"--image=foo", "pathOrUrl"},
strOut: "docker build --tag=foo pathOrUrl",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "path or url given via args (with label)",
command: "build",
argsIn: []string{"label1", "--image=foo", "--source=file://examples/fugu.labels.yml", "pathOrUrl"},
strOut: "docker build --tag=foo pathOrUrl",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "build: invalid number of args (no label)",
command: "build",
argsIn: []string{"--image=foo", "pathOrUrl", "bogus"},
strOut: "",
errOut: ErrTooManyArgs,
}).Test(t)
(&DockerCommandTest{
testDesc: "build: invalid number of args (with label label)",
command: "build",
argsIn: []string{"label1", "--image=foo", "--source=file://examples/fugu.labels.yml", "pathOrUrl", "bogus"},
strOut: "",
errOut: ErrTooManyArgs,
}).Test(t)
(&DockerCommandTest{
testDesc: "tag-git-branch",
command: "build",
argsIn: []string{"--image=foo", "--tag-git-branch"},
strOut: "docker build --tag=foo:current-branch .",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "tag-git-branch overwrites given tag flag",
command: "build",
argsIn: []string{"--image=foo", "--tag=bar", "--tag-git-branch"},
strOut: "docker build --tag=foo:current-branch .",
errOut: nil,
}).Test(t)
}
func TestCommandRun(t *testing.T) {
(&DockerCommandTest{
testDesc: "image is missing",
command: "run",
argsIn: []string{},
strOut: "",
errOut: ErrMissingImage,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain run",
command: "run",
argsIn: []string{"--image=foo"},
strOut: "docker run foo",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain run with label",
command: "run",
argsIn: []string{"label1", "--source=file://examples/fugu.labels.yml"},
strOut: "docker run --name=my-redis redis",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain run without label",
command: "run",
argsIn: []string{"--source=file://examples/fugu.simple.yml"},
strOut: "docker run --name=my-ubuntu ubuntu",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain run with unknown label",
command: "run",
argsIn: []string{"label-unknown", "--source=file://examples/fugu.labels.yml"},
strOut: "docker run --name=my-redis redis label-unknown",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "get docker command from flag",
command: "run",
argsIn: []string{"--image=foo", "--command=cmd"},
strOut: "docker run foo cmd",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "get docker command from args",
command: "run",
argsIn: []string{"--image=foo", "cmd"},
strOut: "docker run foo cmd",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "get docker command from args (with label)",
command: "run",
argsIn: []string{"--image=foo", "--source=file://examples/fugu.labels.yml", "cmd"},
strOut: "docker run --name=my-redis foo cmd",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "get docker command from args (without label)",
command: "run",
argsIn: []string{"--image=foo", "--source=file://examples/fugu.simple.yml", "cmd"},
strOut: "docker run --name=my-ubuntu foo cmd",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "get docker command from args (without label) 2",
command: "run",
argsIn: []string{"--source=file://examples/fugu.simple.yml", "cmd"},
strOut: "docker run --name=my-ubuntu ubuntu cmd",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "docker command is given via args and flags",
command: "run",
argsIn: []string{"--image=foo", "--command=cmdflag", "cmdarg"},
strOut: "docker run foo cmdarg",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "get docker args from flag",
command: "run",
argsIn: []string{"--image=foo", "--arg=a", "--arg=b"},
strOut: "docker run foo a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "get docker args from args",
command: "run",
argsIn: []string{"--image=foo", "cmd", "a", "b"},
strOut: "docker run foo cmd a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "docker args is given via args and flags",
command: "run",
argsIn: []string{"--image=foo", "--arg=c", "--arg=d", "cmd", "a", "b"},
strOut: "docker run foo cmd a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "command given via args, args given via flags",
command: "run",
argsIn: []string{"--image=foo", "--arg=a", "--arg=b", "cmd"},
strOut: "docker run foo cmd a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "command given via flag, args given via args",
command: "run",
argsIn: []string{"--image=foo", "--command=cmd", "a", "b"},
strOut: "docker run foo a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "args given via args and flags",
command: "run",
argsIn: []string{"--image=foo", "--arg=c", "--arg=d", "--arg=e", "a", "b"},
strOut: "docker run foo a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "args given via args and flags (with label)",
command: "run",
argsIn: []string{"--image=foo", "--source=file://examples/fugu.labels.yml", "--arg=c", "--arg=d", "--arg=e", "a", "b"},
strOut: "docker run --name=my-redis foo a b",
errOut: nil,
}).Test(t)
usr, err := user.Current()
if err != nil {
panic(err)
}
(&DockerCommandTest{
testDesc: "command with volume flag",
command: "run",
argsIn: []string{"--image=foo", "--source=file://examples/fugu.volumes.yml"},
strOut: "docker run --name=my-ubuntu --volume=" + usr.HomeDir + "/Go:/root/Go --volume=/tmp foo",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "command with log-driver and log-opt flag",
command: "run",
argsIn: []string{"--image=foo", "--source=file://examples/fugu.log-driver.yml"},
strOut: "docker run --log-driver=syslog --log-opt=syslog-address=tcp://192.168.0.42:123 --name=my-ubuntu foo",
errOut: nil,
}).Test(t)
}
func TestCommandExec(t *testing.T) {
(&DockerCommandTest{
testDesc: "name is missing",
command: "exec",
argsIn: []string{},
strOut: "",
errOut: ErrMissingName,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain exec",
command: "exec",
argsIn: []string{"--name=foo"},
strOut: "docker exec foo",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain exec with label",
command: "exec",
argsIn: []string{"label1", "--source=file://examples/fugu.labels.yml"},
strOut: "docker exec my-redis",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain exec with unknown label",
command: "exec",
argsIn: []string{"label-unknown", "--source=file://examples/fugu.labels.yml"},
strOut: "docker exec my-redis label-unknown",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "get docker command from flag",
command: "exec",
argsIn: []string{"--name=foo", "--command=cmd"},
strOut: "docker exec foo cmd",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "get docker command from args",
command: "exec",
argsIn: []string{"--name=foo", "cmd"},
strOut: "docker exec foo cmd",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "docker command is given via args and flags",
command: "exec",
argsIn: []string{"--name=foo", "--command=cmdflag", "cmdarg"},
strOut: "docker exec foo cmdarg",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "get docker args from flag",
command: "exec",
argsIn: []string{"--name=foo", "--arg=a", "--arg=b"},
strOut: "docker exec foo a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "get docker args from args",
command: "exec",
argsIn: []string{"--name=foo", "cmd", "a", "b"},
strOut: "docker exec foo cmd a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "docker args is given via args and flags",
command: "exec",
argsIn: []string{"--name=foo", "--arg=c", "--arg=d", "cmd", "a", "b"},
strOut: "docker exec foo cmd a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "command given via args, args given via flags",
command: "exec",
argsIn: []string{"--name=foo", "--arg=a", "--arg=b", "cmd"},
strOut: "docker exec foo cmd a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "command given via flag, args given via args",
command: "exec",
argsIn: []string{"--name=foo", "--command=cmd", "a", "b"},
strOut: "docker exec foo a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "args given via args and flags",
command: "exec",
argsIn: []string{"--name=foo", "--arg=c", "--arg=d", "--arg=e", "a", "b"},
strOut: "docker exec foo a b",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "args given via args and flags (with label)",
command: "exec",
argsIn: []string{"label1", "--source=file://examples/fugu.labels.yml", "--arg=c", "--arg=d", "--arg=e", "a", "b"},
strOut: "docker exec my-redis a b",
errOut: nil,
}).Test(t)
}
func TestCommandShell(t *testing.T) {
(&DockerCommandTest{
testDesc: "name is missing",
command: "shell",
argsIn: []string{},
strOut: "",
errOut: ErrMissingName,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain shell",
command: "shell",
argsIn: []string{"--name=foo"},
strOut: "docker exec --detach=false --interactive --tty foo /bin/bash",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "override shell",
command: "shell",
argsIn: []string{"--name=foo", "--shell=/bin/sh"},
strOut: "docker exec --detach=false --interactive --tty foo /bin/sh",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain shell with label",
command: "shell",
argsIn: []string{"label1", "--source=file://examples/fugu.labels.yml"},
strOut: "docker exec --detach=false --interactive --tty my-redis /bin/bash",
errOut: nil,
}).Test(t)
}
func TestCommandDestroy(t *testing.T) {
(&DockerCommandTest{
testDesc: "name is missing",
command: "destroy",
argsIn: []string{},
strOut: "",
errOut: ErrMissingName,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain destroy",
command: "destroy",
argsIn: []string{"--name=foo"},
strOut: "docker rm -f foo",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain destroy with label",
command: "destroy",
argsIn: []string{"label1", "--source=file://examples/fugu.labels.yml"},
strOut: "docker rm -f my-redis",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain destroy with unknown label",
command: "destroy",
argsIn: []string{"label-unknown", "--source=file://examples/fugu.labels.yml"},
strOut: "",
errOut: ErrTooManyArgs,
}).Test(t)
(&DockerCommandTest{
testDesc: "destroy: invalid number of args",
command: "destroy",
argsIn: []string{"--name=foo", "bogus"},
strOut: "",
errOut: ErrTooManyArgs,
}).Test(t)
}
func TestCommandPush(t *testing.T) {
(&DockerCommandTest{
testDesc: "name is missing",
command: "push",
argsIn: []string{},
strOut: "",
errOut: ErrMissingImage,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain push",
command: "push",
argsIn: []string{"--image=foo"},
strOut: "docker push foo",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain push with label",
command: "push",
argsIn: []string{"label1", "--source=file://examples/fugu.labels.yml"},
strOut: "docker push redis",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain push with unknown label",
command: "push",
argsIn: []string{"label-unknown", "--source=file://examples/fugu.labels.yml"},
strOut: "docker push redis:label-unknown",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "push with tag",
command: "push",
argsIn: []string{"--image=foo", "--tag=bar"},
strOut: "docker push foo:bar",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "push with tag when given from args",
command: "push",
argsIn: []string{"--image=foo", "--tag=bar", "rab"},
strOut: "docker push foo:rab",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "push: invalid number of args",
command: "push",
argsIn: []string{"--image=foo", "tag", "bogus"},
strOut: "",
errOut: ErrTooManyArgs,
}).Test(t)
(&DockerCommandTest{
testDesc: "push: invalid number of args with label",
command: "push",
argsIn: []string{"label1", "--source=file://examples/fugu.labels.yml", "tag", "bogus"},
strOut: "",
errOut: ErrTooManyArgs,
}).Test(t)
}
func TestCommandPull(t *testing.T) {
(&DockerCommandTest{
testDesc: "name is missing",
command: "pull",
argsIn: []string{},
strOut: "",
errOut: ErrMissingImage,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain pull",
command: "pull",
argsIn: []string{"--image=foo"},
strOut: "docker pull foo",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain pull with label",
command: "pull",
argsIn: []string{"label1", "--source=file://examples/fugu.labels.yml"},
strOut: "docker pull redis",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "plain pull with unknown label",
command: "pull",
argsIn: []string{"label-unknown", "--source=file://examples/fugu.labels.yml"},
strOut: "docker pull redis:label-unknown",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "pull with tag",
command: "pull",
argsIn: []string{"--image=foo", "--tag=bar"},
strOut: "docker pull foo:bar",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "pull with tag when given from args",
command: "pull",
argsIn: []string{"--image=foo", "--tag=bar", "rab"},
strOut: "docker pull foo:rab",
errOut: nil,
}).Test(t)
(&DockerCommandTest{
testDesc: "pull: invalid number of args",
command: "pull",
argsIn: []string{"--image=foo", "tag", "bogus"},
strOut: "",
errOut: ErrTooManyArgs,
}).Test(t)
}
func TestShowData(t *testing.T) {
(&CommandTest{
testDesc: "plain show-data call",
command: "show-data",
argsIn: []string{"label1", "--source=file://examples/fugu.labels.yml"},
errOut: nil,
stdoutContains: []string{"image: redis", "name: my-redis"},
}).Test(t)
(&CommandTest{
testDesc: "show-data: invalid number of args",
command: "show-data",
argsIn: []string{"label1", "bogus", "--source=file://examples/fugu.labels.yml"},
errOut: ErrTooManyArgs,
stdoutContains: []string{},
}).Test(t)
(&CommandTest{
testDesc: "show-data no output",
command: "show-data",
argsIn: []string{"label3", "--source=file://examples/fugu.labels.yml"},
errOut: nil,
stdoutContains: []string{},
}).Test(t)
}
func TestShowLabels(t *testing.T) {
(&CommandTest{
testDesc: "plain show-labels call",
command: "show-labels",
argsIn: []string{"--source=file://examples/fugu.labels.yml"},
errOut: nil,
stdoutContains: []string{"label1", "label2"},
}).Test(t)
(&CommandTest{
testDesc: "show-labels: invalid number of args",
command: "show-labels",
argsIn: []string{"bogus", "--source=file://examples/fugu.labels.yml"},
errOut: ErrTooManyArgs,
stdoutContains: []string{},
}).Test(t)
(&CommandTest{
testDesc: "show-labels no output",
command: "show-labels",
argsIn: []string{""},
errOut: nil,
stdoutContains: []string{},
}).Test(t)
}
func TestListImages(t *testing.T) {
(&CommandTest{
testDesc: "plain images call",
command: "images",
argsIn: []string{""},
errOut: nil,
stdoutContains: []string{"<local docker images shown>"},
}).Test(t)
(&CommandTest{
testDesc: "images: invalid number of args",
command: "images",
argsIn: []string{"registry", "bogus"},
errOut: ErrTooManyArgs,
stdoutContains: []string{},
}).Test(t)
(&CommandTest{
testDesc: "cannot use user when file given",
command: "images",
argsIn: []string{"registry", "--user=foobar", "--file=file"},
errOut: ErrTooManyArgs,
stdoutContains: []string{},
}).Test(t)
(&CommandTest{
testDesc: "cannot use password when file given",
command: "images",
argsIn: []string{"registry", "--password=foobar", "--file=file"},
errOut: ErrTooManyArgs,
stdoutContains: []string{},
}).Test(t)
(&CommandTest{
testDesc: "cannot use user or password when file given",
command: "images",
argsIn: []string{"registry", "--user=foobar", "--password=foobar", "--file=file"},
errOut: ErrTooManyArgs,
stdoutContains: []string{},
}).Test(t)
(&CommandTest{
testDesc: "cannot use password-stdin when file given",
command: "images",
argsIn: []string{"registry", "--password-stdin", "--file=file"},
errOut: ErrTooManyArgs,
stdoutContains: []string{},
}).Test(t)
(&CommandTest{
testDesc: "need user, too when password given",
command: "images",
argsIn: []string{"registry", "--password=foobar"},
errOut: ErrMissingFlag,
stdoutContains: []string{},
}).Test(t)
(&CommandTest{
testDesc: "need user, too when password-stin given",
command: "images",
argsIn: []string{"registry", "--password-stdin"},
errOut: ErrMissingFlag,
stdoutContains: []string{},
}).Test(t)
(&CommandTest{
testDesc: "user and password empty",
command: "images",
argsIn: []string{"registry", "--password=''", "--user=''"},
errOut: ErrNoCredentials,
stdoutContains: []string{},
}).Test(t)
}