github.com/scaleway/scaleway-cli@v1.11.1/pkg/commands/inspect_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  	"encoding/json"
     9  	"fmt"
    10  	"strings"
    11  	"testing"
    12  
    13  	"github.com/scaleway/scaleway-cli/pkg/api"
    14  	. "github.com/smartystreets/goconvey/convey"
    15  )
    16  
    17  func ExampleRunInspect() {
    18  	ctx := testCommandContext()
    19  	args := InspectArgs{}
    20  	RunInspect(ctx, args)
    21  }
    22  
    23  func ExampleRunInspect_complex() {
    24  	ctx := testCommandContext()
    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-wily", func() {
    40  			args := InspectArgs{
    41  				Format:      "",
    42  				Browser:     false,
    43  				Identifiers: []string{"image:ubuntu-wily"},
    44  				Arch:        "arm",
    45  			}
    46  
    47  			scopedCtx, scopedStdout, scopedStderr := getScopedCtx(ctx)
    48  			err := RunInspect(*scopedCtx, args)
    49  			So(err, ShouldBeNil)
    50  			So(scopedStderr.String(), ShouldBeEmpty)
    51  			fmt.Println(scopedStdout)
    52  			var results []api.ScalewayImage
    53  			err = json.Unmarshal(scopedStdout.Bytes(), &results)
    54  			So(err, ShouldBeNil)
    55  			So(len(results), ShouldEqual, 1)
    56  			So(strings.ToLower(results[0].Name), ShouldContainSubstring, "ubuntu")
    57  			So(strings.ToLower(results[0].Name), ShouldContainSubstring, "wily")
    58  
    59  			Convey("-f \"{{.Identifier}}\" image:ubuntu-wily", func() {
    60  				args := InspectArgs{
    61  					Format:      "{{.Identifier}}",
    62  					Browser:     false,
    63  					Identifiers: []string{"image:ubuntu-wily"},
    64  					Arch:        "arm",
    65  				}
    66  
    67  				scopedCtx, scopedStdout, scopedStderr := getScopedCtx(ctx)
    68  				err := RunInspect(*scopedCtx, args)
    69  				So(err, ShouldBeNil)
    70  				So(scopedStderr.String(), ShouldBeEmpty)
    71  				uuid := strings.TrimSpace(scopedStdout.String())
    72  				So(results[0].Identifier, ShouldEqual, uuid)
    73  			})
    74  		})
    75  	})
    76  }