Skip to content

Commit d87c9b1

Browse files
committed
Testing RunHistory
1 parent 9a6a177 commit d87c9b1

File tree

3 files changed

+66
-7
lines changed

3 files changed

+66
-7
lines changed

pkg/commands/history_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
"fmt"
9+
"strings"
10+
"testing"
11+
12+
. "github.com/scaleway/scaleway-cli/vendor/github.com/smartystreets/goconvey/convey"
13+
)
14+
15+
func ExampleRunHistory() {
16+
ctx := ExampleCommandContext()
17+
args := HistoryArgs{}
18+
RunHistory(ctx, args)
19+
}
20+
21+
func ExampleRunHistory_complex() {
22+
ctx := ExampleCommandContext()
23+
args := HistoryArgs{
24+
NoTrunc: false,
25+
Quiet: false,
26+
Image: "",
27+
}
28+
RunHistory(ctx, args)
29+
}
30+
31+
func TestRunHistory_realAPI(t *testing.T) {
32+
ctx := RealAPIContext()
33+
if ctx == nil {
34+
t.Skip()
35+
}
36+
Convey("Testing RunHistory() on real API", t, func() {
37+
Convey("ubuntu-vivid", func() {
38+
args := HistoryArgs{
39+
NoTrunc: false,
40+
Quiet: false,
41+
Image: "ubuntu-vivid",
42+
}
43+
44+
scopedCtx, scopedStdout, scopedStderr := getScopedCtx(ctx)
45+
err := RunHistory(*scopedCtx, args)
46+
So(err, ShouldBeNil)
47+
So(scopedStderr.String(), ShouldBeEmpty)
48+
49+
lines := strings.Split(scopedStdout.String(), "\n")
50+
So(len(lines), ShouldBeGreaterThan, 0)
51+
52+
firstLine := lines[0]
53+
colNames := strings.Fields(firstLine)
54+
So(colNames, ShouldResemble, []string{"IMAGE", "CREATED", "CREATED", "BY", "SIZE"})
55+
56+
fmt.Println(scopedStdout.String())
57+
})
58+
59+
// FIXME: test invalid image
60+
// FIXME: test image with duplicates cache
61+
// FIXME: test quiet
62+
// FIXME: test no-trunc
63+
})
64+
}

pkg/commands/images_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package commands
66

77
import (
8-
"bytes"
98
"strings"
109
"testing"
1110

@@ -133,9 +132,5 @@ func TestRunImages_realAPI(t *testing.T) {
133132
// FIXME: test snapshots
134133
}
135134
})
136-
Reset(func() {
137-
ctx.Stdout.(*bytes.Buffer).Reset()
138-
ctx.Stderr.(*bytes.Buffer).Reset()
139-
})
140135
})
141136
}

pkg/commands/test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"os"
77
"strings"
88

9-
"github.com/Sirupsen/logrus"
10-
"github.com/pborman/uuid"
119
"github.com/scaleway/scaleway-cli/pkg/api"
1210
"github.com/scaleway/scaleway-cli/pkg/config"
11+
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
12+
"github.com/scaleway/scaleway-cli/vendor/github.com/pborman/uuid"
1313
)
1414

1515
func shouldBeAnUUID(actual interface{}, expected ...interface{}) string {

0 commit comments

Comments
 (0)