@@ -14,16 +14,16 @@ func TestAccConnection_create(t *testing.T) {
1414 connectionType := "WebhookConnection"
1515 name := acctest .RandomWithPrefix ("tf-connection-test-name" )
1616 description := acctest .RandomWithPrefix ("tf-connection-test-description" )
17- url := acctest . RandomWithPrefix ( "https://" )
18- defaultPayload := `{ "eventType" : "{{SearchName}}"}`
17+ url := "https://example.com"
18+ defaultPayload := "{ \ " eventType\ " : \ " {{SearchName}}\" }"
1919 webhookType := "Webhook"
2020
2121 var connection Connection
2222
2323 resource .Test (t , resource.TestCase {
2424 PreCheck : func () { testAccPreCheck (t ) },
2525 Providers : testAccProviders ,
26- CheckDestroy : testAccCheckConnectionDestroy ( connection ) ,
26+ CheckDestroy : testAccCheckConnectionDestroy ,
2727 Steps : []resource.TestStep {
2828 {
2929 Config : createConnectionConfig (name , connectionType , description , url , webhookType , defaultPayload ),
@@ -34,7 +34,7 @@ func TestAccConnection_create(t *testing.T) {
3434 resource .TestCheckResourceAttr ("sumologic_connection.test" , "name" , name ),
3535 resource .TestCheckResourceAttr ("sumologic_connection.test" , "description" , description ),
3636 resource .TestCheckResourceAttr ("sumologic_connection.test" , "url" , url ),
37- resource .TestCheckResourceAttr ("sumologic_connection.test" , "default_payload" , defaultPayload ),
37+ resource .TestCheckResourceAttr ("sumologic_connection.test" , "default_payload" , defaultPayload + " \n " ),
3838 resource .TestCheckResourceAttr ("sumologic_connection.test" , "webhook_type" , webhookType ),
3939 ),
4040 },
@@ -55,7 +55,7 @@ func TestAccConnection_update(t *testing.T) {
5555 resource .Test (t , resource.TestCase {
5656 PreCheck : func () { testAccPreCheck (t ) },
5757 Providers : testAccProviders ,
58- CheckDestroy : testAccCheckConnectionDestroy ( connection ) ,
58+ CheckDestroy : testAccCheckConnectionDestroy ,
5959 Steps : []resource.TestStep {
6060 {
6161 Config : createConnectionConfig (name , connectionType , fDescription , url , webhookType , defaultPayload ),
@@ -66,7 +66,7 @@ func TestAccConnection_update(t *testing.T) {
6666 resource .TestCheckResourceAttr ("sumologic_connection.test" , "name" , name ),
6767 resource .TestCheckResourceAttr ("sumologic_connection.test" , "description" , fDescription ),
6868 resource .TestCheckResourceAttr ("sumologic_connection.test" , "url" , url ),
69- resource .TestCheckResourceAttr ("sumologic_connection.test" , "default_payload" , defaultPayload ),
69+ resource .TestCheckResourceAttr ("sumologic_connection.test" , "default_payload" , defaultPayload + " \n " ),
7070 resource .TestCheckResourceAttr ("sumologic_connection.test" , "webhook_type" , webhookType ),
7171 ),
7272 }, {
@@ -78,7 +78,7 @@ func TestAccConnection_update(t *testing.T) {
7878 resource .TestCheckResourceAttr ("sumologic_connection.test" , "name" , name ),
7979 resource .TestCheckResourceAttr ("sumologic_connection.test" , "description" , sDescription ),
8080 resource .TestCheckResourceAttr ("sumologic_connection.test" , "url" , url ),
81- resource .TestCheckResourceAttr ("sumologic_connection.test" , "default_payload" , defaultPayload ),
81+ resource .TestCheckResourceAttr ("sumologic_connection.test" , "default_payload" , defaultPayload + " \n " ),
8282 resource .TestCheckResourceAttr ("sumologic_connection.test" , "webhook_type" , webhookType ),
8383 ),
8484 },
@@ -117,15 +117,24 @@ func testAccCheckConnectionAttributes(name string) resource.TestCheckFunc {
117117 }
118118}
119119
120- func testAccCheckConnectionDestroy (connection Connection ) resource.TestCheckFunc {
121- return func (s * terraform.State ) error {
122- client := testAccProvider .Meta ().(* Client )
123- conn , err := client .GetConnection (connection .ID )
124- if err == nil && conn == nil {
125- return nil
120+ func testAccCheckConnectionDestroy (s * terraform.State ) error {
121+ client := testAccProvider .Meta ().(* Client )
122+
123+ for _ , rs := range s .RootModule ().Resources {
124+ if rs .Type != "sumologic_connection" {
125+ continue
126+ }
127+
128+ id := rs .Primary .ID
129+ c , err := client .GetConnection (id )
130+ if err != nil {
131+ return fmt .Errorf ("Encountered an error: " + err .Error ())
132+ }
133+ if c != nil {
134+ return fmt .Errorf ("Connection still exists" )
126135 }
127- return fmt .Errorf ("Connection still exists" )
128136 }
137+ return nil
129138}
130139
131140func createConnectionConfig (name , connectionType , desc , url , webhookType , defaultPayload string ) string {
0 commit comments