github.com/scaleway/scaleway-cli@v1.11.1/pkg/commands/search_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 ExampleRunSearch() {
    15  	ctx := testCommandContext()
    16  	args := SearchArgs{}
    17  	RunSearch(ctx, args)
    18  }
    19  
    20  func ExampleRunSearch_complex() {
    21  	ctx := testCommandContext()
    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  }