forked from raystack/frontier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
policy_test.go
59 lines (53 loc) · 1.37 KB
/
policy_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
package cmd_test
import (
"bytes"
"context"
"errors"
"testing"
"github.com/goto/shield/cmd"
"github.com/stretchr/testify/assert"
)
func TestClientPolicy(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: "`policy` list only should throw error host not found",
want: "",
subCommands: []string{"list"},
err: cmd.ErrClientConfigHostNotFound,
},
{
name: "`policy` list with host flag should pass",
want: "",
subCommands: []string{"list", "-h", "test"},
err: context.DeadlineExceeded,
},
{
name: "`policy` 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"),
},
}
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{"policy"}, tt.subCommands...)
cli.SetArgs(args)
err := cli.Execute()
got := buf.String()
assert.Equal(t, tt.err, err)
assert.Equal(t, tt.want, got)
})
}
})
}