-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing synthetics alert condition acceptance tests
- Loading branch information
Showing
2 changed files
with
103 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package newrelic | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
var ( | ||
expectedMonitorName string = fmt.Sprintf("tf-test-synthetic-%s", acctest.RandString(5)) | ||
) | ||
|
||
func TestAccNewRelicSyntheticsMonitorDataSource_Basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckNewRelicSyntheticsDataSourceConfig(expectedMonitorName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccNewRelicSyntheticsDataSource("data.newrelic_synthetics_monitor.bar"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccNewRelicSyntheticsDataSource(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
r := s.RootModule().Resources[n] | ||
a := r.Primary.Attributes | ||
|
||
if a["id"] == "" { | ||
return fmt.Errorf("Expected to read synthetics monitor data from New Relic") | ||
} | ||
|
||
if a["name"] != expectedMonitorName { | ||
return fmt.Errorf("Expected the synthetics monitor name to be: %s, but got: %s", expectedMonitorName, a["name"]) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func testAccCheckNewRelicSyntheticsDataSourceConfig(name string) string { | ||
return fmt.Sprintf(` | ||
resource "newrelic_synthetics_monitor" "foo" { | ||
name = "%[1]s" | ||
type = "SIMPLE" | ||
frequency = 15 | ||
status = "DISABLED" | ||
locations = ["AWS_US_EAST_1"] | ||
uri = "https://google.com" | ||
} | ||
data "newrelic_synthetics_monitor" "bar" { | ||
name = "${newrelic_synthetics_monitor.foo.name}" | ||
} | ||
`, name) | ||
} |
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