Skip to content

Commit e6e7ffc

Browse files
author
Sean Sain
committed
finish up the collector tests
1 parent e147f56 commit e6e7ffc

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

sumologic/resource_sumologic_collector.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ func resourceSumologicCollector() *schema.Resource {
2727
Type: schema.TypeString,
2828
Optional: true,
2929
ForceNew: false,
30-
Default: "",
3130
},
3231
"category": {
3332
Type: schema.TypeString,
3433
Optional: true,
3534
ForceNew: false,
36-
Default: "",
3735
},
3836
"timezone": {
3937
Type: schema.TypeString,
@@ -48,7 +46,6 @@ func resourceSumologicCollector() *schema.Resource {
4846
},
4947
Optional: true,
5048
ForceNew: false,
51-
Default: "",
5249
},
5350
"lookup_by_name": {
5451
Deprecated: "We are deprecating the lookup_by_name attribute as collectors now have data sources.",

sumologic/resource_sumologic_collector_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
func 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

4043
func 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

6372
func 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+
121182
func testAccSumologicCollectorConfigBasic(name string) string {
122183
return fmt.Sprintf(`
123184
resource "sumologic_collector" "test" {

0 commit comments

Comments
 (0)