-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathresources_test.go
More file actions
122 lines (106 loc) · 2.78 KB
/
resources_test.go
File metadata and controls
122 lines (106 loc) · 2.78 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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package parser
import (
"bytes"
"errors"
"testing"
"github.com/drycc/workflow-cli/pkg/testutil"
"github.com/stretchr/testify/assert"
)
// Create fake implementations of each method that return the argument
// we expect to have called the function (as an error to satisfy the interface).
func (d FakeDryccCmd) ResourcesServices(int) error {
return errors.New("resources:services")
}
func (d FakeDryccCmd) ResourcesPlans(string, int) error {
return errors.New("resources:plans")
}
func (d FakeDryccCmd) ResourcesCreate(string, string, string, []string, string) error {
return errors.New("resources:create")
}
func (d FakeDryccCmd) ResourcesList(string, int) error {
return errors.New("resources:list")
}
func (d FakeDryccCmd) ResourceGet(string, string, bool) error {
return errors.New("resources:describe")
}
func (d FakeDryccCmd) ResourcePut(string, string, string, []string, string) error {
return errors.New("resources:update")
}
func (d FakeDryccCmd) ResourceDelete(string, string, string) error {
return errors.New("resources:destroy")
}
func (d FakeDryccCmd) ResourceBind(string, string) error {
return errors.New("resources:bind")
}
func (d FakeDryccCmd) ResourceUnbind(string, string) error {
return errors.New("resources:unbind")
}
func TestResources(t *testing.T) {
t.Parallel()
cf, server, err := testutil.NewTestServerAndClient()
if err != nil {
t.Fatal(err)
}
defer server.Close()
var b bytes.Buffer
cmdr := FakeDryccCmd{WOut: &b, ConfigFile: cf}
// cases defines the arguments and expected return of the call.
// if expected is "", it defaults to args[0].
cases := []struct {
args []string
expected string
}{
{
args: []string{"resources:services"},
expected: "",
},
{
args: []string{"resources:plans", "mysql"},
expected: "",
},
{
args: []string{"resources:create", "mysql:5.6", "mysql", "key1=value1"},
expected: "",
},
{
args: []string{"resources:list"},
expected: "",
},
{
args: []string{"resources:describe", "mysql"},
expected: "",
},
{
args: []string{"resources:update", "mysql:5.7", "mysql", "key1=value2"},
expected: "",
},
{
args: []string{"resources:destroy", "mysql"},
expected: "",
},
{
args: []string{"resources:bind", "mysql"},
expected: "",
},
{
args: []string{"resources:unbind", "mysql"},
expected: "",
},
{
args: []string{"resources"},
expected: "resources:list",
},
}
// For each case, check that calling the route with the arguments
// returns the expected error, which is args[0] if not provided.
for _, c := range cases {
var expected string
if c.expected == "" {
expected = c.args[0]
} else {
expected = c.expected
}
err = Resources(c.args, cmdr)
assert.Error(t, errors.New(expected), err)
}
}