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