forked from raystack/frontier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_test.go
89 lines (83 loc) · 2.38 KB
/
group_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package cmd_test
import (
"bytes"
"context"
"errors"
"testing"
"github.com/goto/shield/cmd"
"github.com/stretchr/testify/assert"
)
func TestClientGroup(t *testing.T) {
t.Run("without config file", func(t *testing.T) {
tests := []struct {
name string
cliConfig *cmd.Config
subCommands []string
want string
err error
}{
{
name: "`group` list only should throw error host not found",
want: "",
subCommands: []string{"list"},
err: cmd.ErrClientConfigHostNotFound,
},
{
name: "`group` list with host flag should pass",
want: "",
subCommands: []string{"list", "-h", "test"},
err: context.DeadlineExceeded,
},
{
name: "`group` create only should throw error host not found",
want: "",
subCommands: []string{"create"},
err: cmd.ErrClientConfigHostNotFound,
},
{
name: "`group` create with host flag should throw error missing required flag",
want: "",
subCommands: []string{"create", "-h", "test"},
err: errors.New("required flag(s) \"file\", \"header\" not set"),
},
{
name: "`group` edit without host should throw error host not found",
want: "",
subCommands: []string{"edit", "123"},
err: cmd.ErrClientConfigHostNotFound,
},
{
name: "`group` edit with host flag should throw error missing required flag",
want: "",
subCommands: []string{"edit", "123", "-h", "test"},
err: errors.New("required flag(s) \"file\" not set"),
},
{
name: "`group` view without host should throw error host not found",
want: "",
subCommands: []string{"view", "123"},
err: cmd.ErrClientConfigHostNotFound,
},
{
name: "`group` view with host flag should pass",
want: "",
subCommands: []string{"view", "123", "-h", "test"},
err: context.DeadlineExceeded,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.cliConfig = &cmd.Config{}
cli := cmd.New(tt.cliConfig)
buf := new(bytes.Buffer)
cli.SetOutput(buf)
args := append([]string{"group"}, tt.subCommands...)
cli.SetArgs(args)
err := cli.Execute()
got := buf.String()
assert.Equal(t, tt.err, err)
assert.Equal(t, tt.want, got)
})
}
})
}