@@ -11,6 +11,7 @@ import (
1111)
1212
1313func TestAccSumologicCollector_basic (t * testing.T ) {
14+ var collector Collector
1415 rname := acctest .RandomWithPrefix ("tf-acc-test" )
1516 resourceName := "sumologic_collector.test"
1617 resource .Test (t , resource.TestCase {
@@ -20,6 +21,8 @@ func TestAccSumologicCollector_basic(t *testing.T) {
2021 {
2122 Config : testAccSumologicCollectorConfigBasic (rname ),
2223 Check : resource .ComposeTestCheckFunc (
24+ testAccCheckCollectorExists (resourceName , & collector ),
25+ testAccCheckCollectorValues (& collector , rname , "" , "" , "Etc/UTC" ),
2326 resource .TestCheckResourceAttrSet (resourceName , "id" ),
2427 resource .TestCheckResourceAttr (resourceName , "name" , rname ),
2528 resource .TestCheckResourceAttr (resourceName , "description" , "" ),
@@ -38,6 +41,7 @@ func TestAccSumologicCollector_basic(t *testing.T) {
3841}
3942
4043func TestAccSumologicCollector_create (t * testing.T ) {
44+ var collector Collector
4145 rname := acctest .RandomWithPrefix ("tf-acc-test" )
4246 rdescription := acctest .RandomWithPrefix ("tf-acc-test" )
4347 rcategory := acctest .RandomWithPrefix ("tf-acc-test" )
@@ -49,6 +53,11 @@ func TestAccSumologicCollector_create(t *testing.T) {
4953 {
5054 Config : testAccSumologicCollectorConfig (rname , rdescription , rcategory ),
5155 Check : resource .ComposeTestCheckFunc (
56+ // query the API to retrieve the collector
57+ testAccCheckCollectorExists (resourceName , & collector ),
58+ // verify remote values
59+ testAccCheckCollectorValues (& collector , rname , rdescription , rcategory , "Etc/UTC" ),
60+ // verify local values
5261 resource .TestCheckResourceAttrSet (resourceName , "id" ),
5362 resource .TestCheckResourceAttr (resourceName , "name" , rname ),
5463 resource .TestCheckResourceAttr (resourceName , "description" , rdescription ),
@@ -61,6 +70,7 @@ func TestAccSumologicCollector_create(t *testing.T) {
6170}
6271
6372func TestAccSumologicCollector_update (t * testing.T ) {
73+ var collector Collector
6474 rname := acctest .RandomWithPrefix ("tf-acc-test" )
6575 rdescription := acctest .RandomWithPrefix ("tf-acc-test" )
6676 rcategory := acctest .RandomWithPrefix ("tf-acc-test" )
@@ -72,6 +82,9 @@ func TestAccSumologicCollector_update(t *testing.T) {
7282 {
7383 Config : testAccSumologicCollectorConfig (rname , rdescription , rcategory ),
7484 Check : resource .ComposeTestCheckFunc (
85+ testAccCheckCollectorExists (resourceName , & collector ),
86+ testAccCheckCollectorValues (& collector , rname , rdescription , rcategory , "Etc/UTC" ),
87+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
7588 resource .TestCheckResourceAttr (resourceName , "name" , rname ),
7689 resource .TestCheckResourceAttr (resourceName , "description" , rdescription ),
7790 resource .TestCheckResourceAttr (resourceName , "category" , rcategory ),
@@ -81,6 +94,9 @@ func TestAccSumologicCollector_update(t *testing.T) {
8194 {
8295 Config : testAccSumologicCollectorConfigUpdate (rname , rdescription , rcategory ),
8396 Check : resource .ComposeTestCheckFunc (
97+ testAccCheckCollectorExists (resourceName , & collector ),
98+ testAccCheckCollectorValues (& collector , rname , rdescription , rcategory , "Europe/Berlin" ),
99+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
84100 resource .TestCheckResourceAttr (resourceName , "name" , rname ),
85101 resource .TestCheckResourceAttr (resourceName , "description" , rdescription ),
86102 resource .TestCheckResourceAttr (resourceName , "category" , rcategory ),
@@ -118,6 +134,51 @@ func testAccCheckCollectorDestroy(s *terraform.State) error {
118134 return nil
119135}
120136
137+ func testAccCheckCollectorExists (n string , collector * Collector ) resource.TestCheckFunc {
138+ return func (s * terraform.State ) error {
139+ rs , ok := s .RootModule ().Resources [n ]
140+ if ! ok {
141+ return fmt .Errorf ("not found: %s" , n )
142+ }
143+
144+ if rs .Primary .ID == "" {
145+ return fmt .Errorf ("collector ID is not set" )
146+ }
147+
148+ id , err := strconv .Atoi (rs .Primary .ID )
149+ if err != nil {
150+ return fmt .Errorf ("collector id should be int; got %s" , rs .Primary .ID )
151+ }
152+ c := testAccProvider .Meta ().(* Client )
153+ collectorResp , err := c .GetCollector (id )
154+ if err != nil {
155+ return err
156+ }
157+
158+ * collector = * collectorResp
159+
160+ return nil
161+ }
162+ }
163+
164+ func testAccCheckCollectorValues (collector * Collector , name , description , category , timezone string ) resource.TestCheckFunc {
165+ return func (s * terraform.State ) error {
166+ if collector .Name != name {
167+ return fmt .Errorf ("bad name, expected \" %s\" , got: %#v" , name , collector .Name )
168+ }
169+ if collector .Description != description {
170+ return fmt .Errorf ("bad name, expected \" %s\" , got: %#v" , description , collector .Description )
171+ }
172+ if collector .Category != category {
173+ return fmt .Errorf ("bad name, expected \" %s\" , got: %#v" , category , collector .Category )
174+ }
175+ if collector .TimeZone != timezone {
176+ return fmt .Errorf ("bad name, expected \" %s\" , got: %#v" , timezone , collector .TimeZone )
177+ }
178+ return nil
179+ }
180+ }
181+
121182func testAccSumologicCollectorConfigBasic (name string ) string {
122183 return fmt .Sprintf (`
123184resource "sumologic_collector" "test" {
0 commit comments