66
77 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
88 "github.com/hashicorp/terraform-plugin-sdk/terraform"
9+ "github.com/stretchr/testify/assert"
910)
1011
1112func TestAccSumologicCSECustomInsight_createAndUpdate (t * testing.T ) {
@@ -17,15 +18,12 @@ func TestAccSumologicCSECustomInsight_createAndUpdate(t *testing.T) {
1718 ordered := true
1819 name := "Test Custom Insight"
1920 severity := "HIGH"
20- minimumSignalSeverity := 5
21- insightSeverity := "CRITICAL"
2221 signalName1 := "Some Signal Name *"
2322 signalName2 := "Some Other Signal Name *"
2423 tag := "foo"
2524
2625 nameUpdated := "Updated Custom Insight"
2726 severityUpdated := "LOW"
28- minimumSignalSeverityUpdated := 8
2927
3028 resourceName := "sumologic_cse_custom_insight.custom_insight"
3129 resource .Test (t , resource.TestCase {
@@ -35,22 +33,22 @@ func TestAccSumologicCSECustomInsight_createAndUpdate(t *testing.T) {
3533 Steps : []resource.TestStep {
3634 {
3735 Config : testCreateCSECustomInsightConfig (description , enabled ,
38- ordered , name , severity , minimumSignalSeverity , insightSeverity , signalName1 , signalName2 , tag ),
36+ ordered , name , severity , signalName1 , signalName2 , tag ),
3937 Check : resource .ComposeTestCheckFunc (
4038 testCheckCSECustomInsightExists (resourceName , & CustomInsight ),
4139 testCheckCustomInsightValues (& CustomInsight , description , enabled ,
42- ordered , name , severity , minimumSignalSeverity , insightSeverity , signalName1 , signalName2 , tag ),
40+ ordered , name , severity , signalName1 , signalName2 , tag ),
4341 resource .TestCheckResourceAttrSet (resourceName , "id" ),
4442 ),
4543 },
4644 {
4745 Config : testCreateCSECustomInsightConfig (description , enabled ,
48- ordered , nameUpdated , severityUpdated , minimumSignalSeverityUpdated , insightSeverity , signalName1 ,
46+ ordered , nameUpdated , severityUpdated , signalName1 ,
4947 signalName2 , tag ),
5048 Check : resource .ComposeTestCheckFunc (
5149 testCheckCSECustomInsightExists (resourceName , & CustomInsight ),
5250 testCheckCustomInsightValues (& CustomInsight , description , enabled ,
53- ordered , nameUpdated , severityUpdated , minimumSignalSeverityUpdated , insightSeverity , signalName1 ,
51+ ordered , nameUpdated , severityUpdated , signalName1 ,
5452 signalName2 , tag ),
5553 resource .TestCheckResourceAttrSet (resourceName , "id" ),
5654 ),
@@ -64,6 +62,51 @@ func TestAccSumologicCSECustomInsight_createAndUpdate(t *testing.T) {
6462 })
6563}
6664
65+ func TestAccSumologicCSECustomInsightWithDynamicSeverity_createAndUpdate (t * testing.T ) {
66+ SkipCseTest (t )
67+
68+ var CustomInsight CSECustomInsight
69+ minimumSignalSeverity1 := 5
70+ dynamicSeverity1 := "MEDIUM"
71+ minimumSignalSeverity2 := 8
72+ dynamicSeverity2 := "HIGH"
73+
74+ updatedMinimumSignalSeverity2 := 9
75+ updatedDynamicSeverity2 := "CRITICAL"
76+
77+ resourceName := "sumologic_cse_custom_insight.custom_insight2"
78+ resource .Test (t , resource.TestCase {
79+ PreCheck : func () { testAccPreCheck (t ) },
80+ Providers : testAccProviders ,
81+ CheckDestroy : testAccCSECustomInsightDestroy ,
82+ Steps : []resource.TestStep {
83+ {
84+ Config : testCreateCSECustomInsightConfigWithDynamicSeverity (minimumSignalSeverity1 , dynamicSeverity1 , minimumSignalSeverity2 , dynamicSeverity2 ),
85+ Check : resource .ComposeTestCheckFunc (
86+ testCheckCSECustomInsightExists (resourceName , & CustomInsight ),
87+ testCheckCustomInsightDynamicSeverity (t , & CustomInsight ,
88+ minimumSignalSeverity1 , dynamicSeverity1 , minimumSignalSeverity2 , dynamicSeverity2 ),
89+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
90+ ),
91+ },
92+ {
93+ Config : testCreateCSECustomInsightConfigWithDynamicSeverity (minimumSignalSeverity1 , dynamicSeverity1 , updatedMinimumSignalSeverity2 , updatedDynamicSeverity2 ),
94+ Check : resource .ComposeTestCheckFunc (
95+ testCheckCSECustomInsightExists (resourceName , & CustomInsight ),
96+ testCheckCustomInsightDynamicSeverity (t , & CustomInsight ,
97+ minimumSignalSeverity1 , dynamicSeverity1 , updatedMinimumSignalSeverity2 , updatedDynamicSeverity2 ),
98+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
99+ ),
100+ },
101+ {
102+ ResourceName : resourceName ,
103+ ImportState : true ,
104+ ImportStateVerify : true ,
105+ },
106+ },
107+ })
108+ }
109+
67110func testAccCSECustomInsightDestroy (s * terraform.State ) error {
68111 client := testAccProvider .Meta ().(* Client )
69112
@@ -89,22 +132,41 @@ func testAccCSECustomInsightDestroy(s *terraform.State) error {
89132
90133func testCreateCSECustomInsightConfig (
91134 description string , enabled bool , ordered bool , name string ,
92- severity string , minimumSignalSeverity int , insightSeverity string , signalName1 string , signalName2 string , tag string ) string {
135+ severity string , signalName1 string , signalName2 string , tag string ) string {
93136 return fmt .Sprintf (`
94137resource "sumologic_cse_custom_insight" "custom_insight" {
95138 description = "%s"
96139 enabled = %t
97140 ordered = %t
98141 name = "%s"
99142 severity = "%s"
100- dynamic_severity {
101- minimum_signal_severity = "%d"
102- insight_severity = "%s"
103- }
104143 signal_names = ["%s", "%s"]
105144 tags = ["%s"]
106145}
107- ` , description , enabled , ordered , name , severity , minimumSignalSeverity , insightSeverity , signalName1 , signalName2 , tag )
146+ ` , description , enabled , ordered , name , severity , signalName1 ,
147+ signalName2 , tag )
148+ }
149+
150+ func testCreateCSECustomInsightConfigWithDynamicSeverity (
151+ minimumSignalSeverity1 int , dynamicSeverity1 string , minimumSignalSeverity2 int , dynamicSeverity2 string ) string {
152+ return fmt .Sprintf (`
153+ resource "sumologic_cse_custom_insight" "custom_insight2" {
154+ description = "Dynamic severity insight"
155+ enabled = true
156+ ordered = true
157+ name = "Dynamic severity insight"
158+ severity = "LOW"
159+ dynamic_severity {
160+ minimum_signal_severity = "%d"
161+ insight_severity = "%s"
162+ }
163+ dynamic_severity {
164+ minimum_signal_severity = "%d"
165+ insight_severity = "%s"
166+ }
167+ tags = ["test tag"]
168+ }
169+ ` , minimumSignalSeverity1 , dynamicSeverity1 , minimumSignalSeverity2 , dynamicSeverity2 )
108170}
109171
110172func testCheckCSECustomInsightExists (n string , CustomInsight * CSECustomInsight ) resource.TestCheckFunc {
@@ -115,7 +177,7 @@ func testCheckCSECustomInsightExists(n string, CustomInsight *CSECustomInsight)
115177 }
116178
117179 if rs .Primary .ID == "" {
118- return fmt .Errorf ("chain rule ID is not set" )
180+ return fmt .Errorf ("CustomInsight ID is not set" )
119181 }
120182
121183 c := testAccProvider .Meta ().(* Client )
@@ -131,7 +193,7 @@ func testCheckCSECustomInsightExists(n string, CustomInsight *CSECustomInsight)
131193}
132194
133195func testCheckCustomInsightValues (CustomInsight * CSECustomInsight , description string ,
134- enabled bool , ordered bool , name string , severity string , minimumSignalSeverity int , insightSeverity string , signalName1 string ,
196+ enabled bool , ordered bool , name string , severity string , signalName1 string ,
135197 signalName2 string , tag string ) resource.TestCheckFunc {
136198 return func (s * terraform.State ) error {
137199 if CustomInsight .Description != description {
@@ -149,14 +211,8 @@ func testCheckCustomInsightValues(CustomInsight *CSECustomInsight, description s
149211 if CustomInsight .Severity != severity {
150212 return fmt .Errorf ("bad severity, expected \" %s\" , got %#v" , severity , CustomInsight .Severity )
151213 }
152- if CustomInsight .Severity != severity {
153- return fmt .Errorf ("bad severity, expected \" %s\" , got %#v" , severity , CustomInsight .Severity )
154- }
155- if CustomInsight .DynamicSeverity [0 ].MinimumSignalSeverity != minimumSignalSeverity {
156- return fmt .Errorf ("bad minimumSignalSeverity, expected \" %d\" , got %#v" , minimumSignalSeverity , CustomInsight .DynamicSeverity [0 ].MinimumSignalSeverity )
157- }
158- if CustomInsight .DynamicSeverity [0 ].InsightSeverity != insightSeverity {
159- return fmt .Errorf ("bad insightSeverity, expected \" %s\" , got %#v" , insightSeverity , CustomInsight .DynamicSeverity [0 ].InsightSeverity )
214+ if CustomInsight .SignalNames [0 ] != signalName1 {
215+ return fmt .Errorf ("bad signalName1, expected \" %s\" , got %#v" , signalName1 , CustomInsight .SignalNames [0 ])
160216 }
161217 if CustomInsight .SignalNames [1 ] != signalName2 {
162218 return fmt .Errorf ("bad signalName2, expected \" %s\" , got %#v" , signalName2 , CustomInsight .SignalNames [1 ])
@@ -168,3 +224,15 @@ func testCheckCustomInsightValues(CustomInsight *CSECustomInsight, description s
168224 return nil
169225 }
170226}
227+
228+ func testCheckCustomInsightDynamicSeverity (t * testing.T , CustomInsight * CSECustomInsight ,
229+ minimumSignalSeverity1 int , dynamicSeverity1 string , minimumSignalSeverity2 int , dynamicSeverity2 string ) resource.TestCheckFunc {
230+
231+ return func (s * terraform.State ) error {
232+ assert .Equal (t , minimumSignalSeverity1 , CustomInsight .DynamicSeverity [0 ].MinimumSignalSeverity )
233+ assert .Equal (t , dynamicSeverity1 , CustomInsight .DynamicSeverity [0 ].InsightSeverity )
234+ assert .Equal (t , minimumSignalSeverity2 , CustomInsight .DynamicSeverity [1 ].MinimumSignalSeverity )
235+ assert .Equal (t , dynamicSeverity2 , CustomInsight .DynamicSeverity [1 ].InsightSeverity )
236+ return nil
237+ }
238+ }
0 commit comments