Skip to content

Commit 574f42f

Browse files
committed
Testing inspect
1 parent 06b542b commit 574f42f

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

pkg/commands/inspect_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
"encoding/json"
9+
"fmt"
10+
"strings"
11+
"testing"
12+
13+
"github.com/scaleway/scaleway-cli/pkg/api"
14+
. "github.com/scaleway/scaleway-cli/vendor/github.com/smartystreets/goconvey/convey"
15+
)
16+
17+
func ExampleRunInspect() {
18+
ctx := ExampleCommandContext()
19+
args := InspectArgs{}
20+
RunInspect(ctx, args)
21+
}
22+
23+
func ExampleRunInspect_complex() {
24+
ctx := ExampleCommandContext()
25+
args := InspectArgs{
26+
Format: "",
27+
Browser: false,
28+
Identifiers: []string{},
29+
}
30+
RunInspect(ctx, args)
31+
}
32+
33+
func TestRunInspect_realAPI(t *testing.T) {
34+
ctx := RealAPIContext()
35+
if ctx == nil {
36+
t.Skip()
37+
}
38+
Convey("Testing RunInspect() on real API", t, func() {
39+
Convey("image:ubuntu-vivid", func() {
40+
args := InspectArgs{
41+
Format: "",
42+
Browser: false,
43+
Identifiers: []string{"image:ubuntu-vivid"},
44+
}
45+
46+
scopedCtx, scopedStdout, scopedStderr := getScopedCtx(ctx)
47+
err := RunInspect(*scopedCtx, args)
48+
So(err, ShouldBeNil)
49+
So(scopedStderr.String(), ShouldBeEmpty)
50+
fmt.Println(scopedStdout)
51+
var results []api.ScalewayImage
52+
err = json.Unmarshal(scopedStdout.Bytes(), &results)
53+
So(err, ShouldBeNil)
54+
So(len(results), ShouldEqual, 1)
55+
So(strings.ToLower(results[0].Name), ShouldContainSubstring, "ubuntu")
56+
So(strings.ToLower(results[0].Name), ShouldContainSubstring, "vivid")
57+
58+
Convey("-f \"{{.Identifier}}\" image:ubuntu-vivid", func() {
59+
args := InspectArgs{
60+
Format: "{{.Identifier}}",
61+
Browser: false,
62+
Identifiers: []string{"image:ubuntu-vivid"},
63+
}
64+
65+
scopedCtx, scopedStdout, scopedStderr := getScopedCtx(ctx)
66+
err := RunInspect(*scopedCtx, args)
67+
So(err, ShouldBeNil)
68+
So(scopedStderr.String(), ShouldBeEmpty)
69+
uuid := strings.TrimSpace(scopedStdout.String())
70+
So(results[0].Identifier, ShouldEqual, uuid)
71+
})
72+
})
73+
})
74+
}

0 commit comments

Comments
 (0)