-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_test.go
More file actions
43 lines (40 loc) · 1.73 KB
/
Copy pathrun_test.go
File metadata and controls
43 lines (40 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package commands_test
import (
"context"
"fmt"
"strings"
"testing"
"github.com/loilo-inc/canarycage/v6/types"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)
func TestRun(t *testing.T) {
t.Run("basic", func(t *testing.T) {
app, cagecli := setup(t, strings.NewReader(stdinTask))
cagecli.EXPECT().Run(gomock.Any(), gomock.Any()).Return(&types.RunResult{}, nil)
err := app.Run(context.Background(), []string{"cage", "run", "--region", "ap-notheast-1", "../../../fixtures", "container", "exec"})
assert.NoError(t, err)
})
t.Run("basic/ci", func(t *testing.T) {
app, cagecli := setup(t, nil)
cagecli.EXPECT().Run(gomock.Any(), gomock.Any()).Return(&types.RunResult{}, nil)
err := app.Run(context.Background(), []string{"cage", "--ci", "run", "--region", "ap-notheast-1", "../../../fixtures", "container", "exec"})
assert.NoError(t, err)
})
t.Run("missing args", func(t *testing.T) {
app, _ := setup(t, nil)
err := app.Run(context.Background(), []string{"cage", "run", "--region", "ap-notheast-1"})
assert.EqualError(t, err, "invalid number of arguments. expected at least 3")
})
t.Run("reading stdin error", func(t *testing.T) {
app, _ := setup(t, &errorReader{})
err := app.Run(context.Background(), []string{"cage", "run", "--region", "ap-notheast-1", "../../../fixtures", "container", "exec"})
assert.EqualError(t, err, "failed to read from stdin: EOF")
})
t.Run("error", func(t *testing.T) {
app, cagecli := setup(t, strings.NewReader(stdinTask))
cagecli.EXPECT().Run(gomock.Any(), gomock.Any()).Return(nil, fmt.Errorf("error"))
err := app.Run(context.Background(), []string{"cage", "run", "--region", "ap-notheast-1", "../../../fixtures", "container", "exec"})
assert.EqualError(t, err, "error")
})
}