Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func runRun(cmd *Command, rawArgs []string) {
// FIXME: Timeout
}
ctx := cmd.GetContext(rawArgs)
err := commands.RunRun(ctx, args)
err := commands.Run(ctx, args)
if err != nil {
logrus.Fatalf("Cannot execute 'run': %v", err)
}
Expand Down
39 changes: 39 additions & 0 deletions pkg/commands/command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2015 Scaleway. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE.md file.

// Golang structs for scw commands
package commands

import (
"os"
"testing"

"github.com/scaleway/scaleway-cli/pkg/api"
"github.com/scaleway/scaleway-cli/vendor/github.com/stretchr/testify/assert"
)

func ExampleCommandContext() CommandContext {
apiClient, err := api.NewScalewayAPI("https://example.org/", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
if err != nil {
panic(err)
}

ctx := CommandContext{
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Env: []string{
"HOME" + os.Getenv("HOME"),
},
RawArgs: []string{},
API: apiClient,
}
return ctx
}

func TestCommandContext_Getenv(t *testing.T) {
ctx := ExampleCommandContext()
assert.Equal(t, ctx.Getenv("HOME"), os.Getenv("HOME"))
assert.Equal(t, ctx.Getenv("DONTEXISTS"), "")
}
6 changes: 3 additions & 3 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
)

// RunArgs are flags for the `RunRun` function
// RunArgs are flags for the `Run` function
type RunArgs struct {
Attach bool
Bootscript string
Expand All @@ -28,8 +28,8 @@ type RunArgs struct {
// Timeout
}

// RunRun is the handler for 'scw run'
func RunRun(ctx CommandContext, args RunArgs) error {
// Run is the handler for 'scw run'
func Run(ctx CommandContext, args RunArgs) error {
if args.Gateway == "" {
args.Gateway = ctx.Getenv("SCW_GATEWAY")
}
Expand Down
29 changes: 29 additions & 0 deletions pkg/commands/run_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2015 Scaleway. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE.md file.

package commands

func ExampleRun() {
ctx := ExampleCommandContext()
args := RunArgs{
Image: "ubuntu-trusuty",
}
Run(ctx, args)
}

func ExampleRun_complex() {
ctx := ExampleCommandContext()
args := RunArgs{
Attach: false,
Bootscript: "rescue",
Command: []string{"ls", "-la"},
Detach: false,
Gateway: "my-gateway",
Image: "ubuntu-trusty",
Name: "my-test-server",
Tags: []string{"testing", "fake"},
Volumes: []string{"50G", "1G"},
}
Run(ctx, args)
}
19 changes: 0 additions & 19 deletions pkg/commands/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,11 @@ package commands

import (
"bytes"
"os"
"testing"

"github.com/scaleway/scaleway-cli/pkg/api"
"github.com/scaleway/scaleway-cli/vendor/github.com/stretchr/testify/assert"
)

func ExampleCommandContext() CommandContext {
apiClient, err := api.NewScalewayAPI("https://example.org/", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
if err != nil {
panic(err)
}

ctx := CommandContext{
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Env: []string{},
RawArgs: []string{},
API: apiClient,
}
return ctx
}

func TestToto(t *testing.T) {
ctx := ExampleCommandContext()
var buf bytes.Buffer
Expand Down