@@ -2,10 +2,12 @@ package sumologic
22
33import (
44 "fmt"
5+ "strings"
56 "testing"
67
78 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
89 "github.com/hashicorp/terraform-plugin-sdk/terraform"
10+ "github.com/stretchr/testify/assert"
911)
1012
1113func TestAccSumologicSCERuleTuningExpression_create (t * testing.T ) {
@@ -18,7 +20,7 @@ func TestAccSumologicSCERuleTuningExpression_create(t *testing.T) {
1820 nEnabled := true
1921 nExclude := true
2022 nIsGlobal := false
21- nRuleIds := []string {"LEGACY-S00084" }
23+ nRuleIds := []string {"LEGACY-S00084" , "THRESHOLD-S00514" , "AGGREGATION-S00002" }
2224 resourceName := "sumologic_cse_rule_tuning_expression.rule_tuning_expression"
2325 resource .Test (t , resource.TestCase {
2426 PreCheck : func () { testAccPreCheck (t ) },
@@ -29,10 +31,15 @@ func TestAccSumologicSCERuleTuningExpression_create(t *testing.T) {
2931 Config : testCreateCSERuleTuningExpressionConfig (nName , nDescription , nExpression , nEnabled , nExclude , nIsGlobal , nRuleIds ),
3032 Check : resource .ComposeTestCheckFunc (
3133 testCheckCSERuleTuningExpressionExists (resourceName , & ruleTuningExpression ),
32- testCheckRuleTuningExpressionValues (& ruleTuningExpression , nName , nDescription , nExpression , nEnabled , nExclude , nIsGlobal ),
34+ testCheckRuleTuningExpressionValues (t , & ruleTuningExpression , nName , nDescription , nExpression , nEnabled , nExclude , nIsGlobal , nRuleIds ),
3335 resource .TestCheckResourceAttrSet (resourceName , "id" ),
3436 ),
3537 },
38+ {
39+ ResourceName : resourceName ,
40+ ImportState : true ,
41+ ImportStateVerify : true ,
42+ },
3643 },
3744 })
3845}
@@ -61,6 +68,11 @@ func testAccCSERuleTuningExpressionDestroy(s *terraform.State) error {
6168}
6269
6370func testCreateCSERuleTuningExpressionConfig (nName string , nDescription string , nExpression string , nEnabled bool , nExclude bool , nIsGlobal bool , nRuleIds []string ) string {
71+ quotedRuleIds := make ([]string , len (nRuleIds ))
72+ for i , id := range nRuleIds {
73+ quotedRuleIds [i ] = fmt .Sprintf (`"%s"` , id )
74+ }
75+
6476 return fmt .Sprintf (`
6577resource "sumologic_cse_rule_tuning_expression" "rule_tuning_expression" {
6678 name = "%s"
@@ -69,9 +81,9 @@ resource "sumologic_cse_rule_tuning_expression" "rule_tuning_expression" {
6981 enabled = "%t"
7082 exclude = "%t"
7183 is_global = "%t"
72- rule_ids = ["%s" ]
84+ rule_ids = [%s ]
7385}
74- ` , nName , nDescription , nExpression , nEnabled , nExclude , nIsGlobal , nRuleIds [ 0 ] )
86+ ` , nName , nDescription , nExpression , nEnabled , nExclude , nIsGlobal , strings . Join ( quotedRuleIds , ", " ) )
7587}
7688
7789func testCheckCSERuleTuningExpressionExists (n string , ruleTuningExpression * CSERuleTuningExpression ) resource.TestCheckFunc {
@@ -97,27 +109,15 @@ func testCheckCSERuleTuningExpressionExists(n string, ruleTuningExpression *CSER
97109 }
98110}
99111
100- func testCheckRuleTuningExpressionValues (ruleTuningExpression * CSERuleTuningExpression , nName string , nDescription string , nExpression string , nEnabled bool , nExclude bool , nIsGlobal bool ) resource.TestCheckFunc {
112+ func testCheckRuleTuningExpressionValues (t * testing. T , ruleTuningExpression * CSERuleTuningExpression , nName string , nDescription string , nExpression string , nEnabled bool , nExclude bool , nIsGlobal bool , nRuleIds [] string ) resource.TestCheckFunc {
101113 return func (s * terraform.State ) error {
102- if ruleTuningExpression .Name != nName {
103- return fmt .Errorf ("bad name, expected \" %s\" , got: %#v" , nName , ruleTuningExpression .Name )
104- }
105- if ruleTuningExpression .Description != nDescription {
106- return fmt .Errorf ("bad description, expected \" %s\" , got: %#v" , nDescription , ruleTuningExpression .Description )
107- }
108- if ruleTuningExpression .Expression != nExpression {
109- return fmt .Errorf ("bad expression, expected \" %s\" , got: %#v" , nExpression , ruleTuningExpression .Expression )
110- }
111- if ruleTuningExpression .Enabled != nEnabled {
112- return fmt .Errorf ("bad enabled flag, expected \" %t\" , got: %#v" , nEnabled , ruleTuningExpression .Enabled )
113- }
114- if ruleTuningExpression .Exclude != nExclude {
115- return fmt .Errorf ("bad exclude flag, expected \" %t\" , got: %#v" , nExclude , ruleTuningExpression .Exclude )
116- }
117- if ruleTuningExpression .IsGlobal != nIsGlobal {
118- return fmt .Errorf ("bad isGlobal flag, expected \" %t\" , got: %#v" , nIsGlobal , ruleTuningExpression .IsGlobal )
119- }
120-
114+ assert .Equal (t , nName , ruleTuningExpression .Name )
115+ assert .Equal (t , nDescription , ruleTuningExpression .Description )
116+ assert .Equal (t , nExpression , ruleTuningExpression .Expression )
117+ assert .Equal (t , nEnabled , ruleTuningExpression .Enabled )
118+ assert .Equal (t , nExclude , ruleTuningExpression .Exclude )
119+ assert .Equal (t , nIsGlobal , ruleTuningExpression .IsGlobal )
120+ assert .ElementsMatch (t , nRuleIds , ruleTuningExpression .RuleIds )
121121 return nil
122122 }
123123}
0 commit comments