Skip to content

Commit 06b542b

Browse files
committed
Testing RunSearch
1 parent 4f31090 commit 06b542b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

pkg/commands/search_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
"strings"
9+
"testing"
10+
11+
. "github.com/scaleway/scaleway-cli/vendor/github.com/smartystreets/goconvey/convey"
12+
)
13+
14+
func ExampleRunSearch() {
15+
ctx := ExampleCommandContext()
16+
args := SearchArgs{}
17+
RunSearch(ctx, args)
18+
}
19+
20+
func ExampleRunSearch_complex() {
21+
ctx := ExampleCommandContext()
22+
args := SearchArgs{
23+
Term: "",
24+
NoTrunc: false,
25+
}
26+
RunSearch(ctx, args)
27+
}
28+
29+
func TestRunSearch_realAPI(t *testing.T) {
30+
ctx := RealAPIContext()
31+
if ctx == nil {
32+
t.Skip()
33+
}
34+
Convey("Testing RunSearch() on real API", t, func() {
35+
Convey("ubuntu", func() {
36+
args := SearchArgs{
37+
Term: "ubuntu",
38+
NoTrunc: false,
39+
}
40+
41+
scopedCtx, scopedStdout, scopedStderr := getScopedCtx(ctx)
42+
err := RunSearch(*scopedCtx, args)
43+
So(err, ShouldBeNil)
44+
So(scopedStderr.String(), ShouldBeEmpty)
45+
46+
lines := strings.Split(scopedStdout.String(), "\n")
47+
So(len(lines), ShouldBeGreaterThan, 0)
48+
49+
firstLine := lines[0]
50+
colNames := strings.Fields(firstLine)
51+
So(colNames, ShouldResemble, []string{"NAME", "DESCRIPTION", "STARS", "OFFICIAL", "AUTOMATED"})
52+
})
53+
54+
// FIXME: test invalid word
55+
// FIXME: test no-trunc
56+
})
57+
}

0 commit comments

Comments
 (0)