github.com/scaleway/scaleway-cli@v1.11.1/pkg/commands/create_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 ExampleRunCreate() {
    15  	ctx := testCommandContext()
    16  	args := CreateArgs{}
    17  	RunCreate(ctx, args)
    18  }
    19  
    20  func ExampleRunCreate_complex() {
    21  	ctx := testCommandContext()
    22  	args := CreateArgs{
    23  		Name:       "test",
    24  		Bootscript: "rescue",
    25  		Tags:       []string{"tag1", "tag2"},
    26  		Volumes:    []string{},
    27  		Image:      "ubuntu-wily",
    28  		TmpSSHKey:  false,
    29  	}
    30  	RunCreate(ctx, args)
    31  }
    32  
    33  func TestRunCreate_realAPI(t *testing.T) {
    34  	createdUUIDs := []string{}
    35  	ctx := RealAPIContext()
    36  	if ctx == nil {
    37  		t.Skip()
    38  	}
    39  
    40  	// FIXME: test empty settings
    41  	// FIXME: test cache duplicates
    42  	// FIXME: test TmpSSHKey
    43  	// FIXME: test Volumes
    44  	// FIXME: test Tags
    45  	// FIXME: test Bootscript
    46  
    47  	Convey("Testing RunCreate() on real API", t, func() {
    48  		// Error when image is empty !
    49  		/*
    50  			Convey("no options", func() {
    51  				args := CreateArgs{}
    52  				err := RunCreate(*ctx, args)
    53  				So(err, ShouldBeNil)
    54  
    55  				stderr := ctx.Stderr.(*bytes.Buffer).String()
    56  				stdout := ctx.Stdout.(*bytes.Buffer).String()
    57  				fmt.Println(stderr)
    58  				fmt.Println(stdout)
    59  			})
    60  		*/
    61  
    62  		Convey("--name=unittest-create-standard wily", func() {
    63  			args := CreateArgs{
    64  				Name:           "unittest-create-standard",
    65  				Image:          "wily",
    66  				CommercialType: "VC1S",
    67  				IP:             "dynamic",
    68  			}
    69  
    70  			scopedCtx, scopedStdout, scopedStderr := getScopedCtx(ctx)
    71  			err := RunCreate(*scopedCtx, args)
    72  			So(err, ShouldBeNil)
    73  			So(scopedStderr.String(), ShouldBeEmpty)
    74  
    75  			uuid := strings.TrimSpace(scopedStdout.String())
    76  			So(uuid, shouldBeAnUUID)
    77  
    78  			createdUUIDs = append(createdUUIDs, uuid)
    79  		})
    80  
    81  		Reset(func() {
    82  			if len(createdUUIDs) > 0 {
    83  				rmCtx, rmStdout, rmStderr := getScopedCtx(ctx)
    84  				rmErr := RunRm(*rmCtx, RmArgs{Servers: createdUUIDs})
    85  				So(rmErr, ShouldBeNil)
    86  				So(rmStderr.String(), ShouldBeEmpty)
    87  
    88  				removedUUIDs := strings.Split(strings.TrimSpace(rmStdout.String()), "\n")
    89  				So(removedUUIDs, ShouldResemble, createdUUIDs)
    90  				createdUUIDs = createdUUIDs[:0]
    91  			}
    92  		})
    93  	})
    94  }