-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathdata_source_sysdig_secure_rule_stateful_count_test.go
More file actions
75 lines (66 loc) · 2.04 KB
/
data_source_sysdig_secure_rule_stateful_count_test.go
File metadata and controls
75 lines (66 loc) · 2.04 KB
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
//go:build tf_acc_sysdig || tf_acc_sysdig_secure || tf_acc_policies || tf_acc_onprem_secure
package sysdig_test
import (
"fmt"
"os"
"strconv"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/draios/terraform-provider-sysdig/sysdig"
)
func TestAccRuleStatefulCountDataSource(t *testing.T) {
if strings.HasSuffix(os.Getenv("SYSDIG_SECURE_URL"), "ibm.com") {
t.Skip("Skipping stateful tests for IBM Cloud")
return
}
resource.Test(t, resource.TestCase{
PreCheck: func() {
if v := os.Getenv("SYSDIG_SECURE_API_TOKEN"); v == "" {
t.Fatal("SYSDIG_SECURE_API_TOKEN must be set for acceptance tests")
}
},
ProviderFactories: map[string]func() (*schema.Provider, error){
"sysdig": func() (*schema.Provider, error) {
return sysdig.Provider(), nil
},
},
Steps: []resource.TestStep{
{
Config: ruleStatefulCountDataSource(),
Check: resource.ComposeTestCheckFunc(
testCheckRuleCountAtLeast("data.sysdig_secure_rule_stateful_count.data_stateful_rule_append", 2),
),
},
},
})
}
func testCheckRuleCountAtLeast(resourceName string, minCount int) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("resource not found: %s", resourceName)
}
countStr := rs.Primary.Attributes["rule_count"]
count, err := strconv.Atoi(countStr)
if err != nil {
return fmt.Errorf("rule_count is not a valid integer: %s", countStr)
}
if count < minCount {
return fmt.Errorf("rule_count expected >= %d, got %d", minCount, count)
}
return nil
}
}
func ruleStatefulCountDataSource() string {
return fmt.Sprintf(`
%s
data "sysdig_secure_rule_stateful_count" "data_stateful_rule_append" {
name = "API Gateway Enumeration Detected"
source = "awscloudtrail_stateful"
depends_on = [ sysdig_secure_rule_stateful.stateful_rule_append ]
}
`, ruleStatefulAppend())
}