|
| 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 | +} |
0 commit comments