Skip to content

Commit 3fbeb1d

Browse files
Break up the tests to make it easier to debug (#570)
1 parent 205e6c5 commit 3fbeb1d

File tree

1 file changed

+273
-85
lines changed

1 file changed

+273
-85
lines changed

sysdig/resource_sysdig_secure_rule_falco_test.go

Lines changed: 273 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,279 @@ import (
1515
"github.com/draios/terraform-provider-sysdig/sysdig"
1616
)
1717

18-
func TestAccRuleFalco(t *testing.T) {
19-
rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) }
18+
//func TestAccRuleFalco(t *testing.T) {
19+
// rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) }
20+
//
21+
// ruleRandomImmutableText := rText()
22+
//
23+
// randomText := rText()
24+
// resource.Test(t, resource.TestCase{
25+
// PreCheck: func() {
26+
// if v := os.Getenv("SYSDIG_SECURE_API_TOKEN"); v == "" {
27+
// t.Fatal("SYSDIG_SECURE_API_TOKEN must be set for acceptance tests")
28+
// }
29+
// },
30+
// ProviderFactories: map[string]func() (*schema.Provider, error){
31+
// "sysdig": func() (*schema.Provider, error) {
32+
// return sysdig.Provider(), nil
33+
// },
34+
// },
35+
// Steps: []resource.TestStep{
36+
// //{
37+
// Config: ruleFalcoTerminalShell(ruleRandomImmutableText),
38+
//},
39+
//{
40+
// Config: ruleFalcoUpdatedTerminalShell(ruleRandomImmutableText),
41+
//},
42+
//{
43+
// Config: ruleFalcoTerminalShellWithMinimumEngineVersion(rText()),
44+
//},
45+
//{
46+
// ResourceName: "sysdig_secure_rule_falco.terminal_shell",
47+
// ImportState: true,
48+
// ImportStateVerify: true,
49+
//},
50+
//{
51+
// Config: ruleFalcoTerminalShellWithAppend(),
52+
//},
53+
//{
54+
// ResourceName: "sysdig_secure_rule_falco.terminal_shell_append",
55+
// ImportState: true,
56+
// ImportStateVerify: true,
57+
//},
58+
//{
59+
// Config: ruleFalcoGcpAuditlog(rText()),
60+
//},
61+
//{
62+
// Config: ruleFalcoAzureAuditlog(rText()),
63+
//},
64+
//{
65+
// Config: ruleFalcoKubeAudit(rText()),
66+
//},
67+
//{
68+
// ResourceName: "sysdig_secure_rule_falco.kube_audit",
69+
// ImportState: true,
70+
// ImportStateVerify: true,
71+
//},
72+
// Incorrect configurations
73+
//{
74+
// Config: ruleFalcoTerminalShellWithMissingOuput(rText()),
75+
// ExpectError: regexp.MustCompile("output must be set when append = false"),
76+
//},
77+
//{
78+
// Config: ruleFalcoTerminalShellWithMissingSource(rText()),
79+
// ExpectError: regexp.MustCompile("source must be set when append = false"),
80+
//},
81+
//{
82+
// Config: ruleFalcoWithExceptions(randomText),
83+
//},
84+
//{
85+
// ResourceName: "sysdig_secure_rule_falco.falco_rule_with_exceptions",
86+
// ImportState: true,
87+
// ImportStateVerify: true,
88+
//},
89+
//{
90+
// Config: existingFalcoRuleWithExceptions(randomText),
91+
//},
92+
//{
93+
// ResourceName: "sysdig_secure_rule_falco.attach_to_cluster_admin_role_exceptions",
94+
// ImportState: true,
95+
// ImportStateVerify: true,
96+
//},
97+
//{
98+
// Config: ruleFalcoCloudAWSCloudtrail(randomText),
99+
//},
100+
//{
101+
// Config: ruleFalcoCloudAWSCloudtrailWithAppend(),
102+
//},
103+
//{
104+
// Config: ruleOkta(randomText),
105+
//},
106+
//{
107+
// Config: ruleOktaWithAppend(),
108+
//},
109+
//{
110+
// Config: ruleGithub(randomText),
111+
//},
112+
//{
113+
// Config: ruleGithubWithAppend(),
114+
//},
115+
// },
116+
// })
117+
//}
118+
119+
func TestAccRuleFalcoTerminalShell(t *testing.T) {
120+
ruleRandomImmutableText := randomString()
121+
steps := []resource.TestStep{
122+
{
123+
Config: ruleFalcoTerminalShell(ruleRandomImmutableText),
124+
},
125+
{
126+
Config: ruleFalcoUpdatedTerminalShell(ruleRandomImmutableText),
127+
},
128+
{
129+
ResourceName: "sysdig_secure_rule_falco.terminal_shell",
130+
ImportState: true,
131+
ImportStateVerify: true,
132+
},
133+
}
134+
runTest(steps, t)
135+
}
136+
137+
func TestAccRuleFalcoTerminalShellWithMinimumEngineVersion(t *testing.T) {
138+
steps := []resource.TestStep{
139+
{Config: ruleFalcoTerminalShellWithMinimumEngineVersion(randomString())},
140+
}
141+
runTest(steps, t)
142+
}
143+
144+
func TestRuleFalcoTerminalShellWithAppend(t *testing.T) {
145+
steps := []resource.TestStep{
146+
{
147+
Config: ruleFalcoTerminalShellWithAppend(),
148+
},
149+
{
150+
ResourceName: "sysdig_secure_rule_falco.terminal_shell_append",
151+
ImportState: true,
152+
ImportStateVerify: true,
153+
},
154+
}
155+
runTest(steps, t)
156+
}
157+
158+
func TestRuleFalcoGcpAuditlog(t *testing.T) {
159+
steps := []resource.TestStep{
160+
{
161+
Config: ruleFalcoGcpAuditlog(randomString()),
162+
},
163+
}
164+
runTest(steps, t)
165+
}
166+
167+
func TestRuleFalcoAzureAuditlog(t *testing.T) {
168+
steps := []resource.TestStep{
169+
{
170+
Config: ruleFalcoAzureAuditlog(randomString()),
171+
},
172+
}
173+
runTest(steps, t)
174+
}
175+
176+
func TestRuleFalcoKubeAudit(t *testing.T) {
177+
178+
steps := []resource.TestStep{
179+
{
180+
Config: ruleFalcoKubeAudit(randomString()),
181+
},
182+
{
183+
ResourceName: "sysdig_secure_rule_falco.kube_audit",
184+
ImportState: true,
185+
ImportStateVerify: true,
186+
},
187+
}
188+
runTest(steps, t)
189+
}
190+
191+
func TestIncorrectErrors(t *testing.T) {
192+
steps := []resource.TestStep{
193+
// Incorrect configurations
194+
{
195+
Config: ruleFalcoTerminalShellWithMissingOuput(randomString()),
196+
ExpectError: regexp.MustCompile("output must be set when append = false"),
197+
},
198+
{
199+
Config: ruleFalcoTerminalShellWithMissingSource(randomString()),
200+
ExpectError: regexp.MustCompile("source must be set when append = false"),
201+
},
202+
}
203+
runTest(steps, t)
204+
}
205+
206+
func TestRuleFalcoWithExceptions(t *testing.T) {
207+
steps := []resource.TestStep{
208+
{
209+
Config: ruleFalcoWithExceptions(randomString()),
210+
},
211+
{
212+
ResourceName: "sysdig_secure_rule_falco.falco_rule_with_exceptions",
213+
ImportState: true,
214+
ImportStateVerify: true,
215+
},
216+
}
217+
runTest(steps, t)
218+
}
20219

21-
ruleRandomImmutableText := rText()
220+
func TestExistingFalcoRuleWithExceptions(t *testing.T) {
221+
steps := []resource.TestStep{
222+
{
223+
Config: existingFalcoRuleWithExceptions(randomString()),
224+
},
225+
{
226+
ResourceName: "sysdig_secure_rule_falco.attach_to_cluster_admin_role_exceptions",
227+
ImportState: true,
228+
ImportStateVerify: true,
229+
},
230+
}
231+
runTest(steps, t)
232+
}
233+
234+
func TestRuleFalcoCloudAWSCloudtrail(t *testing.T) {
235+
steps := []resource.TestStep{
236+
{
237+
Config: ruleFalcoCloudAWSCloudtrail(randomString()),
238+
},
239+
}
240+
runTest(steps, t)
241+
}
242+
243+
func TestRuleFalcoCloudAWSCloudtrailAppend(t *testing.T) {
244+
steps := []resource.TestStep{
245+
{
246+
Config: ruleFalcoCloudAWSCloudtrailWithAppend(),
247+
},
248+
}
249+
runTest(steps, t)
250+
}
22251

23-
randomText := rText()
252+
func TestRuleOkta(t *testing.T) {
253+
steps := []resource.TestStep{
254+
{
255+
Config: ruleOkta(randomString()),
256+
},
257+
}
258+
runTest(steps, t)
259+
}
260+
261+
func TestRuleOktaAppends(t *testing.T) {
262+
steps := []resource.TestStep{
263+
{
264+
Config: ruleOktaWithAppend(),
265+
},
266+
}
267+
runTest(steps, t)
268+
}
269+
270+
func TestRuleGithub(t *testing.T) {
271+
steps := []resource.TestStep{
272+
{
273+
Config: ruleGithub(randomString()),
274+
},
275+
}
276+
runTest(steps, t)
277+
}
278+
279+
func TestRuleGithubAppends(t *testing.T) {
280+
steps := []resource.TestStep{
281+
{
282+
Config: ruleGithubWithAppend(),
283+
},
284+
}
285+
runTest(steps, t)
286+
}
287+
288+
func randomString() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) }
289+
290+
func runTest(steps []resource.TestStep, t *testing.T) {
24291
resource.Test(t, resource.TestCase{
25292
PreCheck: func() {
26293
if v := os.Getenv("SYSDIG_SECURE_API_TOKEN"); v == "" {
@@ -32,88 +299,9 @@ func TestAccRuleFalco(t *testing.T) {
32299
return sysdig.Provider(), nil
33300
},
34301
},
35-
Steps: []resource.TestStep{
36-
{
37-
Config: ruleFalcoTerminalShell(ruleRandomImmutableText),
38-
},
39-
{
40-
Config: ruleFalcoUpdatedTerminalShell(ruleRandomImmutableText),
41-
},
42-
{
43-
Config: ruleFalcoTerminalShellWithMinimumEngineVersion(rText()),
44-
},
45-
{
46-
ResourceName: "sysdig_secure_rule_falco.terminal_shell",
47-
ImportState: true,
48-
ImportStateVerify: true,
49-
},
50-
{
51-
Config: ruleFalcoTerminalShellWithAppend(),
52-
},
53-
{
54-
ResourceName: "sysdig_secure_rule_falco.terminal_shell_append",
55-
ImportState: true,
56-
ImportStateVerify: true,
57-
},
58-
{
59-
Config: ruleFalcoGcpAuditlog(rText()),
60-
},
61-
{
62-
Config: ruleFalcoAzureAuditlog(rText()),
63-
},
64-
{
65-
Config: ruleFalcoKubeAudit(rText()),
66-
},
67-
{
68-
ResourceName: "sysdig_secure_rule_falco.kube_audit",
69-
ImportState: true,
70-
ImportStateVerify: true,
71-
},
72-
// Incorrect configurations
73-
{
74-
Config: ruleFalcoTerminalShellWithMissingOuput(rText()),
75-
ExpectError: regexp.MustCompile("output must be set when append = false"),
76-
},
77-
{
78-
Config: ruleFalcoTerminalShellWithMissingSource(rText()),
79-
ExpectError: regexp.MustCompile("source must be set when append = false"),
80-
},
81-
{
82-
Config: ruleFalcoWithExceptions(randomText),
83-
},
84-
{
85-
ResourceName: "sysdig_secure_rule_falco.falco_rule_with_exceptions",
86-
ImportState: true,
87-
ImportStateVerify: true,
88-
},
89-
{
90-
Config: existingFalcoRuleWithExceptions(randomText),
91-
},
92-
{
93-
ResourceName: "sysdig_secure_rule_falco.attach_to_cluster_admin_role_exceptions",
94-
ImportState: true,
95-
ImportStateVerify: true,
96-
},
97-
{
98-
Config: ruleFalcoCloudAWSCloudtrail(randomText),
99-
},
100-
{
101-
Config: ruleFalcoCloudAWSCloudtrailWithAppend(),
102-
},
103-
{
104-
Config: ruleOkta(randomText),
105-
},
106-
{
107-
Config: ruleOktaWithAppend(),
108-
},
109-
{
110-
Config: ruleGithub(randomText),
111-
},
112-
{
113-
Config: ruleGithubWithAppend(),
114-
},
115-
},
302+
Steps: steps,
116303
})
304+
117305
}
118306

119307
func ruleFalcoTerminalShell(name string) string {

0 commit comments

Comments
 (0)