-
Notifications
You must be signed in to change notification settings - Fork 21
/
config_test.go
115 lines (89 loc) · 2.72 KB
/
config_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
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
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestSwampConfig_ValidateSessionProfileOnly(t *testing.T) {
c := NewSwampConfig()
c.targetAccount = ""
c.targetRole = ""
c.targetProfile = ""
c.tokenSerialNumber = "someSerialNumber"
assert.NoError(t, c.Validate())
}
func TestSwampConfig_ValidateSessionProfileOnlyMissingMfaDevice(t *testing.T) {
c := NewSwampConfig()
c.targetAccount = ""
c.targetRole = ""
c.targetProfile = ""
c.tokenSerialNumber = ""
assert.Error(t, c.Validate())
}
func TestSwampConfig_ValidateAccountAndRoleName(t *testing.T) {
c := NewSwampConfig()
c.targetAccount = "1234567890"
c.targetRole = "some-role"
assert.NoError(t, c.Validate())
}
func TestSwampConfig_ValidateRoleArn(t *testing.T) {
c := NewSwampConfig()
c.targetAccount = ""
c.targetRole = "arn:aws:iam::1234567890:role/some-role"
assert.NoError(t, c.Validate())
}
func TestSwampConfig_ValidateAccountAndRoleArn(t *testing.T) {
c := NewSwampConfig()
c.targetAccount = "1234567890"
c.targetRole = "arn:aws:iam::1234567890:role/some-role"
assert.Error(t, c.Validate())
}
func TestSwampConfig_NotDefaults(t *testing.T) {
c := NewSwampConfig()
c.targetAccount = "1234567890"
c.targetRole = "arn:aws:iam::1234567890:role/some-role"
c.aliasConfig = "CHANGELOG.md"
assert.NoError(t, c.Validate())
}
func TestSwampConfig_ValidateMFADeviceAndTokenCommand(t *testing.T) {
c := NewSwampConfig()
c.targetRole = "arn:aws:iam::1234567890:role/some-role"
c.tokenSerialNumber = "someSerialNumber"
c.mfaExec = "some command"
assert.NoError(t, c.Validate())
}
func TestSwampConfig_ValidateNoMFADeviceButTokenCommand(t *testing.T) {
c := NewSwampConfig()
c.targetRole = "arn:aws:iam::1234567890:role/some-role"
c.mfaExec = "some command"
assert.Error(t, c.Validate())
}
func TestSwampConfig_GetRoleArnWithArn(t *testing.T) {
c := NewSwampConfig()
c.targetRole = "arn:aws:iam::1234567890:role/some-role"
c.targetAccount = "does-not-matter-at-all"
arn := c.GetRoleArn()
assert.Equal(t, *arn, "arn:aws:iam::1234567890:role/some-role")
}
func TestSwampConfig_GetRoleArnWithAccountAndRole(t *testing.T) {
c := NewSwampConfig()
c.targetRole = "some-role"
c.targetAccount = "1234567890"
arn := c.GetRoleArn()
assert.Equal(t, *arn, "arn:aws:iam::1234567890:role/some-role")
}
func TestSwampConfig_DefaultQuietIsFalse(t *testing.T) {
c := NewSwampConfig()
c.targetRole = "some-role"
c.targetAccount = "1234567890"
assert.Equal(t, false, c.quiet)
}
func TestSwampConfig_Aliases(t *testing.T) {
c := NewSwampConfig()
c.aliasConfig = "does-not-exists"
assert.Error(t, c.Validate())
}
func TestSwampConfig_AliasesMissing(t *testing.T) {
c := NewSwampConfig()
c.aliasConfig = "CHANGELOG.md"
assert.NoError(t, c.Validate())
}