-
Notifications
You must be signed in to change notification settings - Fork 400
/
Copy pathactions_test.go
70 lines (60 loc) · 1.49 KB
/
actions_test.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package commands
import (
"io/ioutil"
"strconv"
"testing"
"github.com/bryanl/doit"
"github.com/digitalocean/godo"
"github.com/stretchr/testify/assert"
)
var (
testAction = godo.Action{ID: 1, Region: &godo.Region{Slug: "dev0"}}
testActionList = []godo.Action{
testAction,
}
)
func TestActionsCommand(t *testing.T) {
cmd := Actions()
assert.NotNil(t, cmd)
assertCommandNames(t, cmd, "get", "list")
}
func TestActionList(t *testing.T) {
actionDidList := false
client := &godo.Client{
Actions: &doit.ActionsServiceMock{
ListFn: func(opts *godo.ListOptions) ([]godo.Action, *godo.Response, error) {
actionDidList = true
resp := &godo.Response{
Links: &godo.Links{
Pages: &godo.Pages{},
},
}
return testActionList, resp, nil
},
},
}
withTestClient(client, func(c *TestConfig) {
ns := "test"
err := RunCmdActionList(ns, c, ioutil.Discard, []string{})
assert.NoError(t, err)
if !actionDidList {
t.Errorf("Action() did not run")
}
})
}
func TestActionGet(t *testing.T) {
client := &godo.Client{
Actions: &doit.ActionsServiceMock{
GetFn: func(id int) (*godo.Action, *godo.Response, error) {
if got, expected := id, testAction.ID; got != expected {
t.Errorf("GetFn() called with %d; expected %d", got, expected)
}
return &testAction, nil, nil
},
},
}
withTestClient(client, func(c *TestConfig) {
err := RunCmdActionGet("test", c, ioutil.Discard, []string{strconv.Itoa(testAction.ID)})
assert.NoError(t, err)
})
}