-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlimits_test.go
More file actions
90 lines (80 loc) · 1.9 KB
/
limits_test.go
File metadata and controls
90 lines (80 loc) · 1.9 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
package parser
import (
"bytes"
"errors"
"testing"
"github.com/arschles/assert"
"github.com/drycc/workflow-cli/pkg/testutil"
)
// 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) LimitsList(string) error {
return errors.New("limits:list")
}
func (d FakeDryccCmd) LimitsSet(string, []string, string) error {
return errors.New("limits:set")
}
func (d FakeDryccCmd) LimitsUnset(string, []string, string) error {
return errors.New("limits:unset")
}
func TestLimits(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{"limits:list"},
expected: "",
},
{
args: []string{"limits:set", "web=1G"},
expected: "",
},
{
args: []string{"limits:set", "web=1G worker=2G"},
expected: "",
},
{
args: []string{"limits:set", "web=1G/2G worker=2G/4G"},
expected: "",
},
{
args: []string{"limits:set", "--cpu", "web=1"},
expected: "",
},
{
args: []string{"limits:unset", "web"},
expected: "",
},
{
args: []string{"limits:unset", "--cpu", "web"},
expected: "",
},
{
args: []string{"limits"},
expected: "limits: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 = Limits(c.args, cmdr)
assert.Err(t, errors.New(expected), err)
}
}