Skip to content

Commit 0b2f18b

Browse files
committed
Update acceptance test for topology label
1 parent 4fb65ad commit 0b2f18b

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

sumologic/resource_sumologic_dashboard_test.go

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1212
)
1313

14+
var firstLabelKey = "service"
15+
var secondLabelKey = "env"
16+
var topologyLabel = TopologyLabel{
17+
Data: map[string][]string{
18+
firstLabelKey: {"collection-proxy"},
19+
secondLabelKey: {"dev", "prod"},
20+
},
21+
}
22+
1423
func TestAccSumologicDashboard_basic(t *testing.T) {
1524
testNameSuffix := acctest.RandString(16)
1625
title := "terraform_test_dashboard_" + testNameSuffix
@@ -41,8 +50,7 @@ func TestAccSumologicDashboard_create(t *testing.T) {
4150
description := "Test dashboard description"
4251
theme := "Dark"
4352
refreshInterval := 120
44-
topologyLabel := "service"
45-
topologyLabelValue := "collection-proxy"
53+
4654
literalRangeName := "today"
4755
textPanel := TextPanel{
4856
Key: "text-panel-001",
@@ -77,7 +85,7 @@ func TestAccSumologicDashboard_create(t *testing.T) {
7785
Steps: []resource.TestStep{
7886
{
7987
Config: dashboardCreateConfig(title, description, theme, refreshInterval,
80-
topologyLabel, topologyLabelValue, literalRangeName, textPanel, layout, variable),
88+
topologyLabel, literalRangeName, textPanel, layout, variable),
8189
Check: resource.ComposeTestCheckFunc(
8290
testAccCheckDashboardExists("sumologic_dashboard.tf_crud_test", &dashboard, t),
8391
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
@@ -89,9 +97,7 @@ func TestAccSumologicDashboard_create(t *testing.T) {
8997
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
9098
"theme", theme),
9199
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
92-
"topology_label_map.0.data.0.label", topologyLabel),
93-
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
94-
"topology_label_map.0.data.0.values.0", topologyLabelValue),
100+
"topology_label_map.0.data.#", "2"),
95101
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
96102
"time_range.#", "1"),
97103
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
@@ -124,8 +130,6 @@ func TestAccSumologicDashboard_update(t *testing.T) {
124130
description := "Test dashboard description"
125131
theme := "Dark"
126132
refreshInterval := 120
127-
topologyLabel := "service"
128-
topologyLabelValue := "collection-proxy"
129133
literalRangeName := "today"
130134
textPanel := TextPanel{
131135
Key: "text-panel-001",
@@ -155,7 +159,7 @@ func TestAccSumologicDashboard_update(t *testing.T) {
155159
// updated config
156160
newTheme := "Light"
157161
newRefreshInterval := 300
158-
newTopologyLabelValue := "collection-cluster"
162+
newFirstLabelValue := "collection-cluster"
159163
newLiteralRangeName := "week"
160164
searchPanel := SumoSearchPanel{
161165
Key: "search-panel-001",
@@ -207,7 +211,7 @@ func TestAccSumologicDashboard_update(t *testing.T) {
207211
Steps: []resource.TestStep{
208212
{
209213
Config: dashboardCreateConfig(title, description, theme, refreshInterval,
210-
topologyLabel, topologyLabelValue, literalRangeName, textPanel, layout, csvVariable),
214+
topologyLabel, literalRangeName, textPanel, layout, csvVariable),
211215
Check: resource.ComposeTestCheckFunc(
212216
testAccCheckDashboardExists("sumologic_dashboard.tf_crud_test", &dashboard, t),
213217
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
@@ -217,7 +221,7 @@ func TestAccSumologicDashboard_update(t *testing.T) {
217221
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
218222
"theme", theme),
219223
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
220-
"topology_label_map.0.data.0.values.0", topologyLabelValue),
224+
"topology_label_map.0.data.#", "2"),
221225
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
222226
"time_range.0.begin_bounded_time_range.0.from.0.literal_time_range.0.range_name",
223227
literalRangeName),
@@ -237,7 +241,7 @@ func TestAccSumologicDashboard_update(t *testing.T) {
237241
},
238242
{
239243
Config: dashboardUpdateConfig(title, description, newTheme, newRefreshInterval,
240-
topologyLabel, newTopologyLabelValue, newLiteralRangeName, textPanel, searchPanel,
244+
firstLabelKey, newFirstLabelValue, newLiteralRangeName, textPanel, searchPanel,
241245
newLayout, newVariables),
242246
Check: resource.ComposeTestCheckFunc(
243247
testAccCheckDashboardExists("sumologic_dashboard.tf_crud_test", &dashboard, t),
@@ -248,7 +252,11 @@ func TestAccSumologicDashboard_update(t *testing.T) {
248252
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
249253
"theme", newTheme),
250254
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
251-
"topology_label_map.0.data.0.values.0", newTopologyLabelValue),
255+
"topology_label_map.0.data.#", "1"),
256+
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
257+
"topology_label_map.0.data.0.label", firstLabelKey),
258+
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
259+
"topology_label_map.0.data.0.values.0", newFirstLabelValue),
252260
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
253261
"time_range.0.begin_bounded_time_range.0.from.0.literal_time_range.0.range_name",
254262
newLiteralRangeName),
@@ -391,8 +399,8 @@ func dashboardImportConfig(title string) string {
391399
}
392400

393401
func dashboardCreateConfig(title string, description string, theme string, refreshInterval int,
394-
topologyLabel string, topologyLabelValue string, rangeName string, textPanel TextPanel,
395-
layout GridLayout, variable Variable) string {
402+
topologyLabel TopologyLabel, rangeName string, textPanel TextPanel, layout GridLayout,
403+
variable Variable) string {
396404

397405
return fmt.Sprintf(`
398406
data "sumologic_personal_folder" "personalFolder" {}
@@ -407,6 +415,10 @@ func dashboardCreateConfig(title string, description string, theme string, refre
407415
label = "%s"
408416
values = ["%s"]
409417
}
418+
data {
419+
label = "%s"
420+
values = ["%s", "%s"]
421+
}
410422
}
411423
time_range {
412424
begin_bounded_time_range {
@@ -448,8 +460,9 @@ func dashboardCreateConfig(title string, description string, theme string, refre
448460
hide_from_ui = false
449461
}
450462
}`,
451-
title, description, refreshInterval, theme, topologyLabel, topologyLabelValue, rangeName,
452-
textPanel.Key, textPanel.Title, textPanel.Text,
463+
title, description, refreshInterval, theme, firstLabelKey, topologyLabel.Data[firstLabelKey][0],
464+
secondLabelKey, topologyLabel.Data[secondLabelKey][0], topologyLabel.Data[secondLabelKey][1],
465+
rangeName, textPanel.Key, textPanel.Title, textPanel.Text,
453466
layout.LayoutStructures[0].Key, variable.Name, variable.DisplayName, variable.DefaultValue,
454467
variable.SourceDefinition.(CsvVariableSourceDefinition).Values,
455468
)

0 commit comments

Comments
 (0)