github.com/scaleway/scaleway-cli@v1.11.1/pkg/commands/images_test.go (about) 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/smartystreets/goconvey/convey" 12 ) 13 14 func ExampleRunImages() { 15 ctx := testCommandContext() 16 args := ImagesArgs{} 17 RunImages(ctx, args) 18 } 19 20 func ExampleRunImages_complex() { 21 ctx := testCommandContext() 22 args := ImagesArgs{ 23 All: false, 24 NoTrunc: false, 25 Quiet: false, 26 } 27 RunImages(ctx, args) 28 } 29 30 func ExampleRunImages_quiet() { 31 ctx := testCommandContext() 32 args := ImagesArgs{ 33 All: false, 34 NoTrunc: false, 35 Quiet: true, 36 } 37 RunImages(ctx, args) 38 } 39 40 func ExampleRunImages_all() { 41 ctx := testCommandContext() 42 args := ImagesArgs{ 43 All: true, 44 NoTrunc: false, 45 Quiet: false, 46 } 47 RunImages(ctx, args) 48 } 49 50 func ExampleRunImages_notrunc() { 51 ctx := testCommandContext() 52 args := ImagesArgs{ 53 All: false, 54 NoTrunc: true, 55 Quiet: false, 56 } 57 RunImages(ctx, args) 58 } 59 60 func TestRunImages_realAPI(t *testing.T) { 61 ctx := RealAPIContext() 62 if ctx == nil { 63 t.Skip() 64 } 65 Convey("Testing RunImages() on real API", t, func() { 66 Convey("no options", func() { 67 args := ImagesArgs{ 68 All: false, 69 NoTrunc: false, 70 Quiet: false, 71 } 72 73 scopedCtx, scopedStdout, scopedStderr := getScopedCtx(ctx) 74 err := RunImages(*scopedCtx, args) 75 So(err, ShouldBeNil) 76 So(scopedStderr.String(), ShouldBeEmpty) 77 78 lines := strings.Split(scopedStdout.String(), "\n") 79 So(len(lines), ShouldBeGreaterThan, 0) 80 81 firstLine := lines[0] 82 colNames := strings.Fields(firstLine) 83 So(colNames, ShouldResemble, []string{"REPOSITORY", "TAG", "IMAGE", "ID", "CREATED", "REGION", "ARCH"}) 84 85 // FIXME: test public images 86 }) 87 Convey("--all", func() { 88 args := ImagesArgs{ 89 All: true, 90 NoTrunc: false, 91 Quiet: false, 92 } 93 94 scopedCtx, scopedStdout, scopedStderr := getScopedCtx(ctx) 95 err := RunImages(*scopedCtx, args) 96 So(err, ShouldBeNil) 97 So(scopedStderr.String(), ShouldBeEmpty) 98 99 lines := strings.Split(scopedStdout.String(), "\n") 100 So(len(lines), ShouldBeGreaterThan, 0) 101 102 firstLine := lines[0] 103 colNames := strings.Fields(firstLine) 104 So(colNames, ShouldResemble, []string{"REPOSITORY", "TAG", "IMAGE", "ID", "CREATED", "REGION", "ARCH"}) 105 106 // FIXME: test public images 107 // FIXME: test bootscripts 108 // FIXME: test snapshots 109 }) 110 Convey("--quiet", func() { 111 args := ImagesArgs{ 112 All: false, 113 NoTrunc: false, 114 Quiet: true, 115 } 116 117 scopedCtx, scopedStdout, scopedStderr := getScopedCtx(ctx) 118 err := RunImages(*scopedCtx, args) 119 So(err, ShouldBeNil) 120 So(scopedStderr.String(), ShouldBeEmpty) 121 122 lines := strings.Split(scopedStdout.String(), "\n") 123 // So(len(lines), ShouldBeGreaterThan, 0) 124 125 if len(lines) > 0 { 126 firstLine := lines[0] 127 colNames := strings.Fields(firstLine) 128 So(colNames, ShouldNotResemble, []string{"REPOSITORY", "TAG", "IMAGE", "ID", "CREATED"}) 129 130 // FIXME: test public images 131 // FIXME: test bootscripts 132 // FIXME: test snapshots 133 } 134 }) 135 }) 136 }