-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
iamserviceaccount_test.go
61 lines (55 loc) · 2.48 KB
/
iamserviceaccount_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
package create
import (
"fmt"
"github.com/weaveworks/eksctl/pkg/ctl/cmdutils"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("create iamserviceaccount", func() {
DescribeTable("create service account successfully",
func(args ...string) {
commandArgs := append([]string{"iamserviceaccount"}, args...)
cmd := newMockEmptyCmd(commandArgs...)
count := 0
cmdutils.AddResourceCmd(cmdutils.NewGrouping(), cmd.parentCmd, func(cmd *cmdutils.Cmd) {
createIAMServiceAccountCmdWithRunFunc(cmd, func(cmd *cmdutils.Cmd, overrideExistingServiceAccounts bool) error {
Expect(cmd.ClusterConfig.Metadata.Name).To(Equal("clusterName"))
Expect(cmd.ClusterConfig.IAM.ServiceAccounts[0].Name).To(Equal("serviceAccountName"))
Expect(cmd.ClusterConfig.IAM.ServiceAccounts[0].AttachPolicyARNs).To(ContainElement("dummyPolicyArn"))
count++
return nil
})
})
_, err := cmd.execute()
Expect(err).To(Not(HaveOccurred()))
Expect(count).To(Equal(1))
},
Entry("with all required flags", "--cluster", "clusterName", "--name", "serviceAccountName", "--attach-policy-arn", "dummyPolicyArn"),
Entry("with override flags", "--cluster", "clusterName", "--name", "serviceAccountName", "--attach-policy-arn", "dummyPolicyArn", "--override-existing-serviceaccounts"),
)
DescribeTable("invalid flags or arguments",
func(c invalidParamsCase) {
cmd := newDefaultCmd(c.args...)
_, err := cmd.execute()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring(c.error.Error()))
},
Entry("without cluster name", invalidParamsCase{
args: []string{"iamserviceaccount", "--name", "serviceAccountName"},
error: fmt.Errorf("Error: --cluster must be set"),
}),
Entry("with iamserviceaccount name as argument and flag", invalidParamsCase{
args: []string{"iamserviceaccount", "--cluster", "clusterName", "--name", "serviceAccountName", "serviceAccountName"},
error: fmt.Errorf("Error: --name=serviceAccountName and argument serviceAccountName cannot be used at the same time"),
}),
Entry("without required flag --attach-policy-arn", invalidParamsCase{
args: []string{"iamserviceaccount", "--cluster", "clusterName", "serviceAccountName"},
error: fmt.Errorf("Error: --attach-policy-arn must be set"),
}),
Entry("with invalid flags", invalidParamsCase{
args: []string{"iamserviceaccount", "--invalid", "dummy"},
error: fmt.Errorf("Error: unknown flag: --invalid"),
}),
)
})