-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add label and user label to MonitoringNotificationChannel data source…
…, fix tests
- Loading branch information
Showing
3 changed files
with
158 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,25 +18,42 @@ func TestAccDataSourceGoogleMonitoringNotificationChannel_byDisplayName(t *testi | |
Config: testAccDataSourceGoogleMonitoringNotificationChannel_byDisplayName(acctest.RandomWithPrefix("tf-test")), | ||
Check: resource.ComposeTestCheckFunc( | ||
checkDataSourceStateMatchesResourceState( | ||
"data.google_monitoring_notification_channel.my", | ||
"google_monitoring_notification_channel.my"), | ||
"data.google_monitoring_notification_channel.default", | ||
"google_monitoring_notification_channel.default"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceGoogleMonitoringNotificationChannel_byType(t *testing.T) { | ||
func TestAccDataSourceGoogleMonitoringNotificationChannel_byTypeAndLabel(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleMonitoringNotificationChannel_byType(acctest.RandomWithPrefix("tf-test")), | ||
Config: testAccDataSourceGoogleMonitoringNotificationChannel_byTypeAndLabel(acctest.RandomWithPrefix("tf-test")), | ||
Check: resource.ComposeTestCheckFunc( | ||
checkDataSourceStateMatchesResourceState( | ||
"data.google_monitoring_notification_channel.my", | ||
"google_monitoring_notification_channel.my"), | ||
"data.google_monitoring_notification_channel.default", | ||
"google_monitoring_notification_channel.default"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceGoogleMonitoringNotificationChannel_UserLabel(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleMonitoringNotificationChannel_byTypeAndUserLabel(acctest.RandomWithPrefix("tf-test")), | ||
Check: resource.ComposeTestCheckFunc( | ||
checkDataSourceStateMatchesResourceState( | ||
"data.google_monitoring_notification_channel.default", | ||
"google_monitoring_notification_channel.default"), | ||
), | ||
}, | ||
}, | ||
|
@@ -52,141 +69,189 @@ func TestAccDataSourceGoogleMonitoringNotificationChannel_byDisplayNameAndType(t | |
Config: testAccDataSourceGoogleMonitoringNotificationChannel_byDisplayNameAndType(acctest.RandomWithPrefix("tf-test")), | ||
Check: resource.ComposeTestCheckFunc( | ||
checkDataSourceStateMatchesResourceState( | ||
"data.google_monitoring_notification_channel.my", | ||
"google_monitoring_notification_channel.myemail"), | ||
"data.google_monitoring_notification_channel.email", | ||
"google_monitoring_notification_channel.email"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceGoogleMonitoringNotificationChannel_NotFound(t *testing.T) { | ||
func TestAccDataSourceGoogleMonitoringNotificationChannel_ErrorNoDisplayNameOrType(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleMonitoringNotificationChannel_NoDisplayNameOrType(), | ||
ExpectError: regexp.MustCompile("At least one of display_name or type must be provided"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceGoogleMonitoringNotificationChannel_ErrorNotFound(t *testing.T) { | ||
displayName := acctest.RandomWithPrefix("tf-test") | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleMonitoringNotificationChannel_NotFound(displayName), | ||
ExpectError: regexp.MustCompile(fmt.Sprintf("No NotificationChannel found using filter=display_name=\"%s\"", displayName)), | ||
ExpectError: regexp.MustCompile(fmt.Sprintf(`No NotificationChannel found using filter: display_name="%s"`, displayName)), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceGoogleMonitoringNotificationChannel_NotUnique(t *testing.T) { | ||
func TestAccDataSourceGoogleMonitoringNotificationChannel_ErrorNotUnique(t *testing.T) { | ||
displayName := acctest.RandomWithPrefix("tf-test") | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
PreventPostDestroyRefresh: true, | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleMonitoringNotificationChannel_NotUnique(displayName), | ||
}, | ||
{ | ||
Config: testAccDataSourceGoogleMonitoringNotificationChannel_NotUniqueDS(displayName), | ||
ExpectError: regexp.MustCompile(fmt.Sprintf("More than one matching NotificationChannel found using filter=display_name=\"%s\"", displayName)), | ||
Config: testAccDataSourceGoogleMonitoringNotificationChannel_NotUniqueWithData(displayName), | ||
ExpectError: regexp.MustCompile(fmt.Sprintf( | ||
`Found more than one 1 NotificationChannel matching specified filter: display_name="%s"`, displayName)), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceGoogleMonitoringNotificationChannel_byDisplayName(displayName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_monitoring_notification_channel" "my" { | ||
resource "google_monitoring_notification_channel" "default" { | ||
display_name = "%s" | ||
type = "webhook_tokenauth" | ||
labels = { | ||
url = "http://www.acme.org" | ||
url = "http://www.google.com" | ||
} | ||
} | ||
data "google_monitoring_notification_channel" "my" { | ||
display_name = google_monitoring_notification_channel.my.display_name | ||
data "google_monitoring_notification_channel" "default" { | ||
display_name = google_monitoring_notification_channel.default.display_name | ||
} | ||
`, displayName) | ||
} | ||
|
||
func testAccDataSourceGoogleMonitoringNotificationChannel_byType(displayName string) string { | ||
// Include label so we don't fail on dangling resources | ||
func testAccDataSourceGoogleMonitoringNotificationChannel_byTypeAndLabel(displayName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_monitoring_notification_channel" "my" { | ||
resource "google_monitoring_notification_channel" "default" { | ||
display_name = "%s" | ||
type = "sms" | ||
type = "email" | ||
labels = { | ||
number = "+1555" | ||
email_address = "%[email protected]" | ||
} | ||
} | ||
data "google_monitoring_notification_channel" "my" { | ||
type = google_monitoring_notification_channel.my.type | ||
data "google_monitoring_notification_channel" "default" { | ||
type = google_monitoring_notification_channel.default.type | ||
labels = google_monitoring_notification_channel.default.labels | ||
} | ||
`, displayName) | ||
`, displayName, displayName) | ||
} | ||
|
||
func testAccDataSourceGoogleMonitoringNotificationChannel_byTypeAndUserLabel(displayName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_monitoring_notification_channel" "default" { | ||
display_name = "%s" | ||
type = "email" | ||
user_labels = { | ||
testname = "%s" | ||
} | ||
} | ||
data "google_monitoring_notification_channel" "default" { | ||
type = google_monitoring_notification_channel.default.type | ||
user_labels = google_monitoring_notification_channel.default.user_labels | ||
} | ||
`, displayName, displayName) | ||
} | ||
|
||
func testAccDataSourceGoogleMonitoringNotificationChannel_byDisplayNameAndType(displayName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_monitoring_notification_channel" "mywebhook" { | ||
resource "google_monitoring_notification_channel" "webhook" { | ||
display_name = "%s" | ||
type = "webhook_tokenauth" | ||
labels = { | ||
url = "http://www.acme.org" | ||
url = "http://www.google.com" | ||
} | ||
} | ||
resource "google_monitoring_notification_channel" "myemail" { | ||
display_name = google_monitoring_notification_channel.mywebhook.display_name | ||
resource "google_monitoring_notification_channel" "email" { | ||
display_name = "%s" | ||
type = "email" | ||
labels = { | ||
email_address = "[email protected]" | ||
email_address = "%[email protected]" | ||
} | ||
} | ||
data "google_monitoring_notification_channel" "my" { | ||
display_name = google_monitoring_notification_channel.myemail.display_name | ||
type = google_monitoring_notification_channel.myemail.type | ||
data "google_monitoring_notification_channel" "email" { | ||
display_name = google_monitoring_notification_channel.email.display_name | ||
type = google_monitoring_notification_channel.email.type | ||
} | ||
`, displayName) | ||
`, displayName, displayName, displayName) | ||
} | ||
|
||
func testAccDataSourceGoogleMonitoringNotificationChannel_NotFound(displayName string) string { | ||
return fmt.Sprintf(` | ||
data "google_monitoring_notification_channel" "my" { | ||
data "google_monitoring_notification_channel" "default" { | ||
display_name = "%s" | ||
} | ||
`, displayName) | ||
} | ||
|
||
func testAccDataSourceGoogleMonitoringNotificationChannel_NoDisplayNameOrType() string { | ||
return ` | ||
data "google_monitoring_notification_channel" "default" { | ||
labels = { | ||
email = "[email protected]'" | ||
} | ||
user_labels = { | ||
foo = "bar" | ||
} | ||
} | ||
` | ||
} | ||
|
||
func testAccDataSourceGoogleMonitoringNotificationChannel_NotUnique(displayName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_monitoring_notification_channel" "default" { | ||
display_name = "%s" | ||
resource "google_monitoring_notification_channel" "channel-1" { | ||
display_name = "%[1]s" | ||
type = "webhook_tokenauth" | ||
labels = { | ||
url = "http://www.acme1.org" | ||
url = "http://%[1]s.google.com" | ||
} | ||
} | ||
resource "google_monitoring_notification_channel" "default2" { | ||
display_name = google_monitoring_notification_channel.default.display_name | ||
resource "google_monitoring_notification_channel" "channel-2" { | ||
display_name = google_monitoring_notification_channel.channel-1.display_name | ||
type = "webhook_tokenauth" | ||
labels = { | ||
url = "http://www.acme2.org" | ||
url = "http://%[1]s-copy.google.org" | ||
} | ||
} | ||
`, displayName) | ||
} | ||
|
||
func testAccDataSourceGoogleMonitoringNotificationChannel_NotUniqueDS(displayName string) string { | ||
return fmt.Sprintf(` | ||
data "google_monitoring_notification_channel" "my" { | ||
display_name = "%s" | ||
func testAccDataSourceGoogleMonitoringNotificationChannel_NotUniqueWithData(displayName string) string { | ||
return testAccDataSourceGoogleMonitoringNotificationChannel_NotUnique(displayName) + ` | ||
data "google_monitoring_notification_channel" "ds" { | ||
display_name = google_monitoring_notification_channel.channel-2.display_name | ||
} | ||
`, displayName) | ||
` | ||
} |
Oops, something went wrong.