|
1 | 1 | package sumologic |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | | - "os" |
6 | | - "strconv" |
7 | | - "testing" |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "strconv" |
| 7 | + "testing" |
8 | 8 |
|
9 | | - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
10 | | - "github.com/hashicorp/terraform-plugin-sdk/terraform" |
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 10 | + "github.com/hashicorp/terraform-plugin-sdk/terraform" |
11 | 11 | ) |
12 | 12 |
|
13 | 13 | func TestAccSumologicKinesisLogSource_create(t *testing.T) { |
14 | | - var kinesisLogSource KinesisLogSource |
15 | | - var collector Collector |
16 | | - cName, cDescription, cCategory := getRandomizedParams() |
17 | | - sName, sDescription, sCategory := getRandomizedParams() |
18 | | - kinesisLogResourceName := "sumologic_kinesis_log_source.kinesisLog" |
19 | | - testAwsRoleArn := os.Getenv("SUMOLOGIC_TEST_ROLE_ARN") |
20 | | - testAwsBucket := os.Getenv("SUMOLOGIC_TEST_BUCKET_NAME") |
21 | | - resource.Test(t, resource.TestCase{ |
22 | | - PreCheck: func() { testAccPreCheckWithAWS(t) }, |
23 | | - Providers: testAccProviders, |
24 | | - CheckDestroy: testAccCheckKinesisLogSourceDestroy, |
25 | | - Steps: []resource.TestStep{ |
26 | | - { |
27 | | - Config: testAccSumologicKinesisLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket), |
28 | | - Check: resource.ComposeTestCheckFunc( |
29 | | - testAccCheckKinesisLogSourceExists(kinesisLogResourceName, &kinesisLogSource), |
30 | | - testAccCheckKinesisLogSourceValues(&kinesisLogSource, sName, sDescription, sCategory), |
31 | | - testAccCheckCollectorExists("sumologic_collector.test", &collector), |
32 | | - testAccCheckCollectorValues(&collector, cName, cDescription, cCategory, "Etc/UTC", ""), |
33 | | - resource.TestCheckResourceAttrSet(kinesisLogResourceName, "id"), |
34 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "name", sName), |
35 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "description", sDescription), |
36 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "category", sCategory), |
37 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "content_type", "KinesisLog"), |
38 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "path.0.type", "KinesisLogPath"), |
39 | | - ), |
40 | | - }, |
41 | | - }, |
42 | | - }) |
| 14 | + var kinesisLogSource KinesisLogSource |
| 15 | + var collector Collector |
| 16 | + cName, cDescription, cCategory := getRandomizedParams() |
| 17 | + sName, sDescription, sCategory := getRandomizedParams() |
| 18 | + kinesisLogResourceName := "sumologic_kinesis_log_source.kinesisLog" |
| 19 | + testAwsRoleArn := os.Getenv("SUMOLOGIC_TEST_ROLE_ARN") |
| 20 | + testAwsBucket := os.Getenv("SUMOLOGIC_TEST_BUCKET_NAME") |
| 21 | + resource.Test(t, resource.TestCase{ |
| 22 | + PreCheck: func() { testAccPreCheckWithAWS(t) }, |
| 23 | + Providers: testAccProviders, |
| 24 | + CheckDestroy: testAccCheckKinesisLogSourceDestroy, |
| 25 | + Steps: []resource.TestStep{ |
| 26 | + { |
| 27 | + Config: testAccSumologicKinesisLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket), |
| 28 | + Check: resource.ComposeTestCheckFunc( |
| 29 | + testAccCheckKinesisLogSourceExists(kinesisLogResourceName, &kinesisLogSource), |
| 30 | + testAccCheckKinesisLogSourceValues(&kinesisLogSource, sName, sDescription, sCategory), |
| 31 | + testAccCheckCollectorExists("sumologic_collector.test", &collector), |
| 32 | + testAccCheckCollectorValues(&collector, cName, cDescription, cCategory, "Etc/UTC", ""), |
| 33 | + resource.TestCheckResourceAttrSet(kinesisLogResourceName, "id"), |
| 34 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "name", sName), |
| 35 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "description", sDescription), |
| 36 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "category", sCategory), |
| 37 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "content_type", "KinesisLog"), |
| 38 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "path.0.type", "KinesisLogPath"), |
| 39 | + ), |
| 40 | + }, |
| 41 | + }, |
| 42 | + }) |
43 | 43 | } |
44 | 44 | func TestAccSumologicKinesisLogSource_update(t *testing.T) { |
45 | | - var kinesisLogSource KinesisLogSource |
46 | | - cName, cDescription, cCategory := getRandomizedParams() |
47 | | - sName, sDescription, sCategory := getRandomizedParams() |
48 | | - sNameUpdated, sDescriptionUpdated, sCategoryUpdated := getRandomizedParams() |
49 | | - kinesisLogResourceName := "sumologic_kinesis_log_source.kinesisLog" |
50 | | - testAwsRoleArn := os.Getenv("SUMOLOGIC_TEST_ROLE_ARN") |
51 | | - testAwsBucket := os.Getenv("SUMOLOGIC_TEST_BUCKET_NAME") |
52 | | - resource.Test(t, resource.TestCase{ |
53 | | - PreCheck: func() { testAccPreCheckWithAWS(t) }, |
54 | | - Providers: testAccProviders, |
55 | | - CheckDestroy: testAccCheckHTTPSourceDestroy, |
56 | | - Steps: []resource.TestStep{ |
57 | | - { |
58 | | - Config: testAccSumologicKinesisLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket), |
59 | | - Check: resource.ComposeTestCheckFunc( |
60 | | - testAccCheckKinesisLogSourceExists(kinesisLogResourceName, &kinesisLogSource), |
61 | | - testAccCheckKinesisLogSourceValues(&kinesisLogSource, sName, sDescription, sCategory), |
62 | | - resource.TestCheckResourceAttrSet(kinesisLogResourceName, "id"), |
63 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "name", sName), |
64 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "description", sDescription), |
65 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "category", sCategory), |
66 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "content_type", "KinesisLog"), |
67 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "path.0.type", "KinesisLogPath"), |
68 | | - ), |
69 | | - }, |
70 | | - { |
71 | | - Config: testAccSumologicKinesisLogSourceConfig(cName, cDescription, cCategory, sNameUpdated, sDescriptionUpdated, sCategoryUpdated, testAwsRoleArn, testAwsBucket), |
72 | | - Check: resource.ComposeTestCheckFunc( |
73 | | - testAccCheckKinesisLogSourceExists(kinesisLogResourceName, &kinesisLogSource), |
74 | | - testAccCheckKinesisLogSourceValues(&kinesisLogSource, sNameUpdated, sDescriptionUpdated, sCategoryUpdated), |
75 | | - resource.TestCheckResourceAttrSet(kinesisLogResourceName, "id"), |
76 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "name", sNameUpdated), |
77 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "description", sDescriptionUpdated), |
78 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "category", sCategoryUpdated), |
79 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "content_type", "KinesisLog"), |
80 | | - resource.TestCheckResourceAttr(kinesisLogResourceName, "path.0.type", "KinesisLogPath"), |
81 | | - ), |
82 | | - }, |
83 | | - }, |
84 | | - }) |
| 45 | + var kinesisLogSource KinesisLogSource |
| 46 | + cName, cDescription, cCategory := getRandomizedParams() |
| 47 | + sName, sDescription, sCategory := getRandomizedParams() |
| 48 | + sNameUpdated, sDescriptionUpdated, sCategoryUpdated := getRandomizedParams() |
| 49 | + kinesisLogResourceName := "sumologic_kinesis_log_source.kinesisLog" |
| 50 | + testAwsRoleArn := os.Getenv("SUMOLOGIC_TEST_ROLE_ARN") |
| 51 | + testAwsBucket := os.Getenv("SUMOLOGIC_TEST_BUCKET_NAME") |
| 52 | + resource.Test(t, resource.TestCase{ |
| 53 | + PreCheck: func() { testAccPreCheckWithAWS(t) }, |
| 54 | + Providers: testAccProviders, |
| 55 | + CheckDestroy: testAccCheckHTTPSourceDestroy, |
| 56 | + Steps: []resource.TestStep{ |
| 57 | + { |
| 58 | + Config: testAccSumologicKinesisLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket), |
| 59 | + Check: resource.ComposeTestCheckFunc( |
| 60 | + testAccCheckKinesisLogSourceExists(kinesisLogResourceName, &kinesisLogSource), |
| 61 | + testAccCheckKinesisLogSourceValues(&kinesisLogSource, sName, sDescription, sCategory), |
| 62 | + resource.TestCheckResourceAttrSet(kinesisLogResourceName, "id"), |
| 63 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "name", sName), |
| 64 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "description", sDescription), |
| 65 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "category", sCategory), |
| 66 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "content_type", "KinesisLog"), |
| 67 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "path.0.type", "KinesisLogPath"), |
| 68 | + ), |
| 69 | + }, |
| 70 | + { |
| 71 | + Config: testAccSumologicKinesisLogSourceConfig(cName, cDescription, cCategory, sNameUpdated, sDescriptionUpdated, sCategoryUpdated, testAwsRoleArn, testAwsBucket), |
| 72 | + Check: resource.ComposeTestCheckFunc( |
| 73 | + testAccCheckKinesisLogSourceExists(kinesisLogResourceName, &kinesisLogSource), |
| 74 | + testAccCheckKinesisLogSourceValues(&kinesisLogSource, sNameUpdated, sDescriptionUpdated, sCategoryUpdated), |
| 75 | + resource.TestCheckResourceAttrSet(kinesisLogResourceName, "id"), |
| 76 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "name", sNameUpdated), |
| 77 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "description", sDescriptionUpdated), |
| 78 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "category", sCategoryUpdated), |
| 79 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "content_type", "KinesisLog"), |
| 80 | + resource.TestCheckResourceAttr(kinesisLogResourceName, "path.0.type", "KinesisLogPath"), |
| 81 | + ), |
| 82 | + }, |
| 83 | + }, |
| 84 | + }) |
85 | 85 | } |
86 | 86 | func testAccCheckKinesisLogSourceDestroy(s *terraform.State) error { |
87 | | - client := testAccProvider.Meta().(*Client) |
88 | | - for _, rs := range s.RootModule().Resources { |
89 | | - if rs.Type != "sumologic_kinesis_log_source" { |
90 | | - continue |
91 | | - } |
92 | | - if rs.Primary.ID == "" { |
93 | | - return fmt.Errorf("HTTP Source destruction check: HTTP Source ID is not set") |
94 | | - } |
95 | | - id, err := strconv.Atoi(rs.Primary.ID) |
96 | | - if err != nil { |
97 | | - return fmt.Errorf("Encountered an error: " + err.Error()) |
98 | | - } |
99 | | - collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"]) |
100 | | - if err != nil { |
101 | | - return fmt.Errorf("Encountered an error: " + err.Error()) |
102 | | - } |
103 | | - s, err := client.GetKinesisLogSource(collectorID, id) |
104 | | - if err != nil { |
105 | | - return fmt.Errorf("Encountered an error: " + err.Error()) |
106 | | - } |
107 | | - if s != nil { |
108 | | - return fmt.Errorf("KinesisLog Source still exists") |
109 | | - } |
110 | | - } |
111 | | - return nil |
| 87 | + client := testAccProvider.Meta().(*Client) |
| 88 | + for _, rs := range s.RootModule().Resources { |
| 89 | + if rs.Type != "sumologic_kinesis_log_source" { |
| 90 | + continue |
| 91 | + } |
| 92 | + if rs.Primary.ID == "" { |
| 93 | + return fmt.Errorf("HTTP Source destruction check: HTTP Source ID is not set") |
| 94 | + } |
| 95 | + id, err := strconv.Atoi(rs.Primary.ID) |
| 96 | + if err != nil { |
| 97 | + return fmt.Errorf("Encountered an error: " + err.Error()) |
| 98 | + } |
| 99 | + collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"]) |
| 100 | + if err != nil { |
| 101 | + return fmt.Errorf("Encountered an error: " + err.Error()) |
| 102 | + } |
| 103 | + s, err := client.GetKinesisLogSource(collectorID, id) |
| 104 | + if err != nil { |
| 105 | + return fmt.Errorf("Encountered an error: " + err.Error()) |
| 106 | + } |
| 107 | + if s != nil { |
| 108 | + return fmt.Errorf("KinesisLog Source still exists") |
| 109 | + } |
| 110 | + } |
| 111 | + return nil |
112 | 112 | } |
113 | 113 | func testAccCheckKinesisLogSourceExists(n string, kinesisLogSource *KinesisLogSource) resource.TestCheckFunc { |
114 | | - return func(s *terraform.State) error { |
115 | | - rs, ok := s.RootModule().Resources[n] |
116 | | - if !ok { |
117 | | - return fmt.Errorf("not found: %s", n) |
118 | | - } |
119 | | - if rs.Primary.ID == "" { |
120 | | - return fmt.Errorf("KinesisLog Source ID is not set") |
121 | | - } |
122 | | - id, err := strconv.Atoi(rs.Primary.ID) |
123 | | - if err != nil { |
124 | | - return fmt.Errorf("KinesisLog Source id should be int; got %s", rs.Primary.ID) |
125 | | - } |
126 | | - collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"]) |
127 | | - if err != nil { |
128 | | - return fmt.Errorf("Encountered an error: " + err.Error()) |
129 | | - } |
130 | | - c := testAccProvider.Meta().(*Client) |
131 | | - kinesisLogSourceResp, err := c.GetKinesisLogSource(collectorID, id) |
132 | | - if err != nil { |
133 | | - return err |
134 | | - } |
135 | | - *kinesisLogSource = *kinesisLogSourceResp |
136 | | - return nil |
137 | | - } |
| 114 | + return func(s *terraform.State) error { |
| 115 | + rs, ok := s.RootModule().Resources[n] |
| 116 | + if !ok { |
| 117 | + return fmt.Errorf("not found: %s", n) |
| 118 | + } |
| 119 | + if rs.Primary.ID == "" { |
| 120 | + return fmt.Errorf("KinesisLog Source ID is not set") |
| 121 | + } |
| 122 | + id, err := strconv.Atoi(rs.Primary.ID) |
| 123 | + if err != nil { |
| 124 | + return fmt.Errorf("KinesisLog Source id should be int; got %s", rs.Primary.ID) |
| 125 | + } |
| 126 | + collectorID, err := strconv.Atoi(rs.Primary.Attributes["collector_id"]) |
| 127 | + if err != nil { |
| 128 | + return fmt.Errorf("Encountered an error: " + err.Error()) |
| 129 | + } |
| 130 | + c := testAccProvider.Meta().(*Client) |
| 131 | + kinesisLogSourceResp, err := c.GetKinesisLogSource(collectorID, id) |
| 132 | + if err != nil { |
| 133 | + return err |
| 134 | + } |
| 135 | + *kinesisLogSource = *kinesisLogSourceResp |
| 136 | + return nil |
| 137 | + } |
138 | 138 | } |
139 | 139 | func testAccCheckKinesisLogSourceValues(kinesisLogSource *KinesisLogSource, name, description, category string) resource.TestCheckFunc { |
140 | | - return func(s *terraform.State) error { |
141 | | - if kinesisLogSource.Name != name { |
142 | | - return fmt.Errorf("bad name, expected \"%s\", got: %#v", name, kinesisLogSource.Name) |
143 | | - } |
144 | | - if kinesisLogSource.Description != description { |
145 | | - return fmt.Errorf("bad description, expected \"%s\", got: %#v", description, kinesisLogSource.Description) |
146 | | - } |
147 | | - if kinesisLogSource.Category != category { |
148 | | - return fmt.Errorf("bad category, expected \"%s\", got: %#v", category, kinesisLogSource.Category) |
149 | | - } |
150 | | - return nil |
151 | | - } |
| 140 | + return func(s *terraform.State) error { |
| 141 | + if kinesisLogSource.Name != name { |
| 142 | + return fmt.Errorf("bad name, expected \"%s\", got: %#v", name, kinesisLogSource.Name) |
| 143 | + } |
| 144 | + if kinesisLogSource.Description != description { |
| 145 | + return fmt.Errorf("bad description, expected \"%s\", got: %#v", description, kinesisLogSource.Description) |
| 146 | + } |
| 147 | + if kinesisLogSource.Category != category { |
| 148 | + return fmt.Errorf("bad category, expected \"%s\", got: %#v", category, kinesisLogSource.Category) |
| 149 | + } |
| 150 | + return nil |
| 151 | + } |
152 | 152 | } |
153 | 153 | func testAccSumologicKinesisLogSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory, testAwsRoleArn, testAwsBucket string) string { |
154 | | - return fmt.Sprintf(` |
| 154 | + return fmt.Sprintf(` |
155 | 155 | resource "sumologic_collector" "test" { |
156 | 156 | name = "%s" |
157 | 157 | description = "%s" |
|
0 commit comments