Skip to content

Commit 27b8834

Browse files
author
Quentin Perez
committed
Merge pull request #123 from moul/test-convey
Test convey
2 parents b46f47a + 83fe0ff commit 27b8834

File tree

192 files changed

+28980
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+28980
-329
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,9 @@ golint:
146146

147147
party:
148148
party -c -d=vendor
149+
150+
151+
.PHONY: convey
152+
convey:
153+
go get github.com/smartystreets/goconvey
154+
goconvey -cover -port=9042 -workDir="$(realpath .)/pkg" -depth=-1

cmd/scw/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ func main() {
120120
}
121121
cmd.API = api
122122
}
123-
cmd.Exec(cmd, cmd.Flag.Args())
123+
err = cmd.Exec(cmd, cmd.Flag.Args())
124+
if err != nil {
125+
log.Fatalf("Cannot execute '%s': %v", cmd.Name(), err)
126+
}
124127
if cmd.API != nil {
125128
cmd.API.Sync()
126129
}

pkg/api/api_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package api
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/scaleway/scaleway-cli/vendor/github.com/smartystreets/goconvey/convey"
7+
)
8+
9+
func TestNewScalewayAPI(t *testing.T) {
10+
Convey("Testing NewScalewayAPI()", t, func() {
11+
api, err := NewScalewayAPI("http://api-endpoint.com", "http://account-endpoint.com", "my-organization", "my-token")
12+
So(err, ShouldBeNil)
13+
So(api, ShouldNotBeNil)
14+
So(api.ComputeAPI, ShouldEqual, "http://api-endpoint.com")
15+
So(api.AccountAPI, ShouldEqual, "http://account-endpoint.com")
16+
So(api.Token, ShouldEqual, "my-token")
17+
So(api.Organization, ShouldEqual, "my-organization")
18+
So(api.Cache, ShouldNotBeNil)
19+
So(api.client, ShouldNotBeNil)
20+
So(api.anonuuid, ShouldNotBeNil)
21+
})
22+
}

pkg/api/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ package api
77
import (
88
"encoding/json"
99
"fmt"
10-
"github.com/scaleway/scaleway-cli/pkg/utils"
1110
"os"
11+
12+
"github.com/scaleway/scaleway-cli/pkg/utils"
1213
)
1314

1415
// Config is a Scaleway CLI configuration file

pkg/cli/attach.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44

55
package cli
66

7-
import (
8-
"github.com/scaleway/scaleway-cli/pkg/commands"
9-
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
10-
)
7+
import "github.com/scaleway/scaleway-cli/pkg/commands"
118

129
var cmdAttach = &Command{
13-
Exec: cmdExecAttach,
10+
Exec: runAttach,
1411
UsageLine: "attach [OPTIONS] SERVER",
1512
Description: "Attach to a server serial console",
1613
Help: "Attach to a running server serial console.",
@@ -30,7 +27,7 @@ func init() {
3027
var attachHelp bool // -h, --help flag
3128
var attachNoStdin bool // --no-stdin flag
3229

33-
func cmdExecAttach(cmd *Command, rawArgs []string) {
30+
func runAttach(cmd *Command, rawArgs []string) error {
3431
if attachHelp {
3532
cmd.PrintUsage()
3633
}
@@ -43,8 +40,5 @@ func cmdExecAttach(cmd *Command, rawArgs []string) {
4340
Server: rawArgs[0],
4441
}
4542
ctx := cmd.GetContext(rawArgs)
46-
err := commands.RunAttach(ctx, args)
47-
if err != nil {
48-
logrus.Fatalf("Cannot execute 'attach': %v", err)
49-
}
43+
return commands.RunAttach(ctx, args)
5044
}

pkg/cli/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
// Command contains everything needed by the cli main loop to calls the workflow, display help and usage, and the context
2323
type Command struct {
2424
// Exec executes the command
25-
Exec func(cmd *Command, args []string)
25+
Exec func(cmd *Command, args []string) error
2626

2727
// Usage is the one-line usage message.
2828
UsageLine string

pkg/cli/command_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cli
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/scaleway/scaleway-cli/vendor/github.com/smartystreets/goconvey/convey"
7+
)
8+
9+
func TestCommand_Name(t *testing.T) {
10+
Convey("Testing Command.Name()", t, func() {
11+
command := Command{
12+
UsageLine: "top [OPTIONS] SERVER",
13+
}
14+
So(command.Name(), ShouldEqual, "top")
15+
16+
command = Command{
17+
UsageLine: "top",
18+
}
19+
So(command.Name(), ShouldEqual, "top")
20+
})
21+
}

pkg/cli/commit.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44

55
package cli
66

7-
import (
8-
"github.com/scaleway/scaleway-cli/pkg/commands"
9-
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
10-
)
7+
import "github.com/scaleway/scaleway-cli/pkg/commands"
118

129
var cmdCommit = &Command{
13-
Exec: cmdExecCommit,
10+
Exec: runCommit,
1411
UsageLine: "commit [OPTIONS] SERVER [NAME]",
1512
Description: "Create a new snapshot from a server's volume",
1613
Help: "Create a new snapshot from a server's volume.",
@@ -29,7 +26,7 @@ func init() {
2926
var commitVolume int // -v, --volume flag
3027
var commitHelp bool // -h, --help flag
3128

32-
func cmdExecCommit(cmd *Command, rawArgs []string) {
29+
func runCommit(cmd *Command, rawArgs []string) error {
3330
if commitHelp {
3431
cmd.PrintUsage()
3532
}
@@ -47,8 +44,5 @@ func cmdExecCommit(cmd *Command, rawArgs []string) {
4744
}
4845

4946
ctx := cmd.GetContext(rawArgs)
50-
err := commands.RunCommit(ctx, args)
51-
if err != nil {
52-
logrus.Fatalf("Cannot execute 'commit': %v", err)
53-
}
47+
return commands.RunCommit(ctx, args)
5448
}

pkg/cli/cp.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
package cli
66

7-
import (
8-
"github.com/scaleway/scaleway-cli/pkg/commands"
9-
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
10-
)
7+
import "github.com/scaleway/scaleway-cli/pkg/commands"
118

129
var cmdCp = &Command{
1310
Exec: runCp,
@@ -40,7 +37,7 @@ func init() {
4037
var cpHelp bool // -h, --help flag
4138
var cpGateway string // -g, --gateway flag
4239

43-
func runCp(cmd *Command, rawArgs []string) {
40+
func runCp(cmd *Command, rawArgs []string) error {
4441
if cpHelp {
4542
cmd.PrintUsage()
4643
}
@@ -54,9 +51,5 @@ func runCp(cmd *Command, rawArgs []string) {
5451
Destination: rawArgs[1],
5552
}
5653
ctx := cmd.GetContext(rawArgs)
57-
err := commands.RunCp(ctx, args)
58-
if err != nil {
59-
logrus.Fatalf("Cannot execute 'cp': %v", err)
60-
}
61-
54+
return commands.RunCp(ctx, args)
6255
}

pkg/cli/create.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99

1010
"github.com/scaleway/scaleway-cli/pkg/commands"
11-
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
1211
)
1312

1413
var cmdCreate = &Command{
@@ -43,7 +42,7 @@ var createVolume string // -v, --volume flag
4342
var createHelp bool // -h, --help flag
4443
var createTmpSSHKey bool // --tmp-ssh-key flag
4544

46-
func runCreate(cmd *Command, rawArgs []string) {
45+
func runCreate(cmd *Command, rawArgs []string) error {
4746
if createHelp {
4847
cmd.PrintUsage()
4948
}
@@ -65,8 +64,5 @@ func runCreate(cmd *Command, rawArgs []string) {
6564
args.Volumes = strings.Split(runCreateVolume, " ")
6665
}
6766
ctx := cmd.GetContext(rawArgs)
68-
err := commands.RunCreate(ctx, args)
69-
if err != nil {
70-
logrus.Fatalf("Cannot execute 'create': %v", err)
71-
}
67+
return commands.RunCreate(ctx, args)
7268
}

0 commit comments

Comments
 (0)