Skip to content

Commit 2ce3327

Browse files
committed
test(dashboards): merge test cases for options
1 parent 2e5282a commit 2ce3327

File tree

1 file changed

+26
-134
lines changed

1 file changed

+26
-134
lines changed

newrelic/resource_newrelic_one_dashboard_test.go

Lines changed: 26 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,11 @@ func TestAccNewRelicOneDashboard_VariablesNRQL(t *testing.T) {
582582
testAccCheckNewRelicOneDashboardExists("newrelic_one_dashboard.bar", 0),
583583
),
584584
},
585+
// Test: Invalid show_apply_action configuration (expects error)
586+
{
587+
Config: testAccCheckNewRelicOneDashboardConfig_OnePageFullVariablesNRQLShowApplyActionInvalid(rName),
588+
ExpectError: regexp.MustCompile("`show_apply_action` can only be set to true when `is_multi_selection` is true"),
589+
},
585590
// Import
586591
{
587592
ResourceName: "newrelic_one_dashboard.bar",
@@ -642,53 +647,6 @@ func TestAccNewRelicOneDashboard_VariableAccountIDsValidation(t *testing.T) {
642647
})
643648
}
644649

645-
// TestAccNewRelicOneDashboard_VariablesNRQL_ShowApplyAction tests create/update of variable options including show_apply_action
646-
func TestAccNewRelicOneDashboard_VariablesNRQL_ShowApplyAction(t *testing.T) {
647-
rName := fmt.Sprintf("tf-test-%s", acctest.RandString(5))
648-
resource.ParallelTest(t, resource.TestCase{
649-
PreCheck: func() { testAccPreCheck(t) },
650-
Providers: testAccProviders,
651-
CheckDestroy: testAccCheckNewRelicOneDashboardDestroy,
652-
Steps: []resource.TestStep{
653-
{
654-
Config: testAccCheckNewRelicOneDashboardConfig_OnePageFullVariablesNRQLShowApplyAction(rName),
655-
Check: resource.ComposeTestCheckFunc(
656-
testAccCheckNewRelicOneDashboardExists("newrelic_one_dashboard.bar", 0),
657-
),
658-
},
659-
{
660-
Config: testAccCheckNewRelicOneDashboardConfig_OnePageFullVariablesNRQLShowApplyActionUpdated(rName),
661-
Check: resource.ComposeTestCheckFunc(
662-
testAccCheckNewRelicOneDashboardExists("newrelic_one_dashboard.bar", 0),
663-
),
664-
},
665-
{
666-
ResourceName: "newrelic_one_dashboard.bar",
667-
ImportState: true,
668-
ImportStateVerify: true,
669-
ImportStateVerifyIgnore: []string{
670-
"variable.0.options",
671-
},
672-
},
673-
},
674-
})
675-
}
676-
677-
// TestAccNewRelicOneDashboard_VariablesNRQL_ShowApplyActionInvalid ensures validation triggers when show_apply_action is true while is_multi_selection is false
678-
func TestAccNewRelicOneDashboard_VariablesNRQL_ShowApplyActionInvalid(t *testing.T) {
679-
rName := fmt.Sprintf("tf-test-%s", acctest.RandString(5))
680-
resource.ParallelTest(t, resource.TestCase{
681-
PreCheck: func() { testAccPreCheck(t) },
682-
Providers: testAccProviders,
683-
Steps: []resource.TestStep{
684-
{
685-
Config: testAccCheckNewRelicOneDashboardConfig_OnePageFullVariablesNRQLShowApplyActionInvalid(rName),
686-
ExpectError: regexp.MustCompile("`show_apply_action` can only be set to true when `is_multi_selection` is true"),
687-
},
688-
},
689-
})
690-
}
691-
692650
// testAccCheckNewRelicOneDashboardConfig_TwoPageBasic generates a TF config snippet for a simple
693651
// two page dashboard.
694652
func testAccCheckNewRelicOneDashboardConfig_TwoPageBasic(dashboardName string, accountID string) string {
@@ -1031,6 +989,7 @@ func testAccCheckNewRelicOneDashboardConfig_VariableNRQL() string {
1031989
options {
1032990
excluded = true
1033991
ignore_time_range = true
992+
show_apply_action = true
1034993
}
1035994
}
1036995
`
@@ -1056,33 +1015,12 @@ func testAccCheckNewRelicOneDashboardConfig_VariableNRQLUpdated() string {
10561015
options {
10571016
excluded = false
10581017
ignore_time_range = false
1018+
show_apply_action = false
10591019
}
10601020
}
10611021
`
10621022
}
10631023

1064-
func testAccCheckNewRelicOneDashboardConfig_OnePageFullVariablesNRQLShowApplyAction(dashboardName string) string {
1065-
return `
1066-
resource "newrelic_one_dashboard" "bar" {
1067-
name = "` + dashboardName + `"
1068-
permissions = "private"
1069-
1070-
` + testAccCheckNewRelicOneDashboardConfig_PageSimple(dashboardName) + `
1071-
` + testAccCheckNewRelicOneDashboardConfig_VariableNRQLShowApplyAction() + `
1072-
}`
1073-
}
1074-
1075-
func testAccCheckNewRelicOneDashboardConfig_OnePageFullVariablesNRQLShowApplyActionUpdated(dashboardName string) string {
1076-
return `
1077-
resource "newrelic_one_dashboard" "bar" {
1078-
name = "` + dashboardName + `"
1079-
permissions = "private"
1080-
1081-
` + testAccCheckNewRelicOneDashboardConfig_PageSimple(dashboardName) + `
1082-
` + testAccCheckNewRelicOneDashboardConfig_VariableNRQLShowApplyActionUpdated() + `
1083-
}`
1084-
}
1085-
10861024
func testAccCheckNewRelicOneDashboardConfig_OnePageFullVariablesNRQLShowApplyActionInvalid(dashboardName string) string {
10871025
return `
10881026
resource "newrelic_one_dashboard" "bar" {
@@ -1094,75 +1032,29 @@ resource "newrelic_one_dashboard" "bar" {
10941032
}`
10951033
}
10961034

1097-
// Helper configs for NRQL variable with show_apply_action
1098-
func testAccCheckNewRelicOneDashboardConfig_VariableNRQLShowApplyAction() string {
1035+
func testAccCheckNewRelicOneDashboardConfig_VariableNRQLShowApplyActionInvalid() string {
10991036
return `
1100-
variable {
1101-
default_values = ["value"]
1102-
is_multi_selection = true
1103-
item {
1104-
title = "item"
1105-
value = "ITEM"
1106-
}
1107-
name = "variable_show_apply"
1108-
nrql_query {
1109-
account_ids = [3806526]
1110-
query = "FROM Transaction SELECT average(duration) FACET appName"
1111-
}
1112-
replacement_strategy = "default"
1113-
title = "title"
1114-
type = "nrql"
1115-
options {
1116-
show_apply_action = true
1117-
}
1037+
variable {
1038+
default_values = ["value"]
1039+
is_multi_selection = false
1040+
item {
1041+
title = "item"
1042+
value = "ITEM"
11181043
}
1119-
`
1120-
}
1121-
1122-
func testAccCheckNewRelicOneDashboardConfig_VariableNRQLShowApplyActionUpdated() string {
1123-
return `
1124-
variable {
1125-
default_values = ["value"]
1126-
is_multi_selection = true
1127-
item {
1128-
title = "item"
1129-
value = "ITEM"
1130-
}
1131-
name = "variable_show_apply_updated"
1132-
nrql_query {
1133-
account_ids = [3806526]
1134-
query = "FROM Transaction SELECT average(duration) FACET appName"
1135-
}
1136-
replacement_strategy = "default"
1137-
title = "title"
1138-
type = "nrql"
1139-
options {
1140-
show_apply_action = false
1141-
}
1044+
name = "variableUpdated"
1045+
nrql_query {
1046+
account_ids = [3806526, 3814156]
1047+
query = "FROM Transaction SELECT average(duration) FACET appName"
11421048
}
1143-
`
1144-
}
1145-
1146-
func testAccCheckNewRelicOneDashboardConfig_VariableNRQLShowApplyActionInvalid() string {
1147-
return `
1148-
variable {
1149-
is_multi_selection = false
1150-
item {
1151-
title = "item"
1152-
value = "ITEM"
1153-
}
1154-
name = "variable_show_apply_invalid"
1155-
replacement_strategy = "default"
1156-
title = "title"
1157-
type = "nrql"
1158-
nrql_query {
1159-
account_ids = [3806526]
1160-
query = "FROM Transaction SELECT average(duration) FACET appName"
1161-
}
1162-
options {
1163-
show_apply_action = true
1164-
}
1049+
replacement_strategy = "default"
1050+
title = "title"
1051+
type = "nrql"
1052+
options {
1053+
excluded = false
1054+
ignore_time_range = false
1055+
show_apply_action = true
11651056
}
1057+
}
11661058
`
11671059
}
11681060

0 commit comments

Comments
 (0)