Skip to content

Commit 179a16f

Browse files
committed
Testing commands.Images()
1 parent b94a0a0 commit 179a16f

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

pkg/commands/images_test.go

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// Copyright (C) 2015 Scaleway. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE.md file.
4+
5+
package commands
6+
7+
import (
8+
"bytes"
9+
"strings"
10+
"testing"
11+
12+
. "github.com/smartystreets/goconvey/convey"
13+
)
14+
15+
func ExampleRunImages() {
16+
ctx := ExampleCommandContext()
17+
args := ImagesArgs{}
18+
RunImages(ctx, args)
19+
}
20+
21+
func ExampleRunImages_complex() {
22+
ctx := ExampleCommandContext()
23+
args := ImagesArgs{
24+
All: false,
25+
NoTrunc: false,
26+
Quiet: false,
27+
}
28+
RunImages(ctx, args)
29+
}
30+
31+
func ExampleRunImages_quiet() {
32+
ctx := ExampleCommandContext()
33+
args := ImagesArgs{
34+
All: false,
35+
NoTrunc: false,
36+
Quiet: true,
37+
}
38+
RunImages(ctx, args)
39+
}
40+
41+
func ExampleRunImages_all() {
42+
ctx := ExampleCommandContext()
43+
args := ImagesArgs{
44+
All: true,
45+
NoTrunc: false,
46+
Quiet: false,
47+
}
48+
RunImages(ctx, args)
49+
}
50+
51+
func ExampleRunImages_notrunc() {
52+
ctx := ExampleCommandContext()
53+
args := ImagesArgs{
54+
All: false,
55+
NoTrunc: true,
56+
Quiet: false,
57+
}
58+
RunImages(ctx, args)
59+
}
60+
61+
func TestRunImages_realAPI(t *testing.T) {
62+
ctx := RealAPIContext()
63+
if ctx == nil {
64+
t.Skip()
65+
}
66+
Convey("Testing RunImages() on real API", t, func() {
67+
Convey("no options", func() {
68+
args := ImagesArgs{
69+
All: false,
70+
NoTrunc: false,
71+
Quiet: false,
72+
}
73+
err := RunImages(*ctx, args)
74+
So(err, ShouldBeNil)
75+
76+
stderr := ctx.Stderr.(*bytes.Buffer).String()
77+
So(stderr, ShouldBeEmpty)
78+
79+
stdout := ctx.Stdout.(*bytes.Buffer).String()
80+
lines := strings.Split(stdout, "\n")
81+
So(len(lines), ShouldBeGreaterThan, 0)
82+
83+
firstLine := lines[0]
84+
colNames := strings.Fields(firstLine)
85+
So(colNames, ShouldResemble, []string{"REPOSITORY", "TAG", "IMAGE", "ID", "CREATED", "VIRTUAL", "SIZE"})
86+
87+
// FIXME: test public images
88+
})
89+
Convey("--all", func() {
90+
args := ImagesArgs{
91+
All: true,
92+
NoTrunc: false,
93+
Quiet: false,
94+
}
95+
err := RunImages(*ctx, args)
96+
So(err, ShouldBeNil)
97+
98+
stderr := ctx.Stderr.(*bytes.Buffer).String()
99+
So(stderr, ShouldBeEmpty)
100+
101+
stdout := ctx.Stdout.(*bytes.Buffer).String()
102+
lines := strings.Split(stdout, "\n")
103+
So(len(lines), ShouldBeGreaterThan, 0)
104+
105+
firstLine := lines[0]
106+
colNames := strings.Fields(firstLine)
107+
So(colNames, ShouldResemble, []string{"REPOSITORY", "TAG", "IMAGE", "ID", "CREATED", "VIRTUAL", "SIZE"})
108+
109+
// FIXME: test public images
110+
// FIXME: test bootscripts
111+
// FIXME: test snapshots
112+
})
113+
Convey("--quiet", func() {
114+
args := ImagesArgs{
115+
All: false,
116+
NoTrunc: false,
117+
Quiet: true,
118+
}
119+
err := RunImages(*ctx, args)
120+
So(err, ShouldBeNil)
121+
122+
stderr := ctx.Stderr.(*bytes.Buffer).String()
123+
So(stderr, ShouldBeEmpty)
124+
125+
stdout := ctx.Stdout.(*bytes.Buffer).String()
126+
lines := strings.Split(stdout, "\n")
127+
// So(len(lines), ShouldBeGreaterThan, 0)
128+
129+
if len(lines) > 0 {
130+
firstLine := lines[0]
131+
colNames := strings.Fields(firstLine)
132+
So(colNames, ShouldNotResemble, []string{"REPOSITORY", "TAG", "IMAGE", "ID", "CREATED", "VIRTUAL", "SIZE"})
133+
134+
// FIXME: test public images
135+
// FIXME: test bootscripts
136+
// FIXME: test snapshots
137+
}
138+
})
139+
Reset(func() {
140+
ctx.Stdout.(*bytes.Buffer).Reset()
141+
ctx.Stderr.(*bytes.Buffer).Reset()
142+
})
143+
})
144+
}

0 commit comments

Comments
 (0)