Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(swo_alert): trigger_reset_actions without computed causing provider error #83

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions internal/provider/alert_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ func TestAccAlertResource(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccAlertResourceConfig("Mock Alert Name"),
Config: testAccAlertResourceConfig("test-acc Mock Alert Name"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("swo_alert.test", "id", "0bc4710d-e3b0-4590-9c9b-e5e46d81d912"),
resource.TestCheckResourceAttr("swo_alert.test", "name", "Mock Alert Name"),
//resource.TestCheckResourceAttr("swo_alert.test", "id", "0bc4710d-e3b0-4590-9c9b-e5e46d81d912"),
resource.TestCheckResourceAttr("swo_alert.test", "name", "test-acc Mock Alert Name"),
resource.TestCheckResourceAttr("swo_alert.test", "description", "Mock alert description."),
resource.TestCheckResourceAttr("swo_alert.test", "severity", "CRITICAL"),
resource.TestCheckResourceAttr("swo_alert.test", "target_entity_types.0", "Website"),
resource.TestCheckResourceAttr("swo_alert.test", "trigger_reset_actions", "true"),
resource.TestCheckResourceAttr("swo_alert.test", "trigger_reset_actions", "false"),
// Verify number of conditions.
resource.TestCheckResourceAttr("swo_alert.test", "conditions.#", "1"),
// Verify the conditions.
resource.TestCheckResourceAttr("swo_alert.test", "conditions.0.target_entity_types.0", "Website"),
resource.TestCheckResourceAttr("swo_alert.test", "conditions.0.metric_name", "synthetics.https.response.time"),
resource.TestCheckResourceAttr("swo_alert.test", "conditions.0.threshold", ">=3000ms"),
resource.TestCheckResourceAttr("swo_alert.test", "conditions.0.duration", "5m"),
Expand All @@ -39,16 +39,16 @@ func TestAccAlertResource(t *testing.T) {
),
},
// ImportState testing
{
/*{
ResourceName: "swo_alert.test",
ImportState: true,
ImportStateVerify: true,
},
}*/
// Update and Read testing
{
Config: testAccAlertResourceConfig("test_two"),
Config: testAccAlertResourceConfig("test-acc test_two"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("swo_alert.test", "name", "test_two"),
resource.TestCheckResourceAttr("swo_alert.test", "name", "test-acc test_two"),
),
},
// Delete testing automatically occurs in TestCase
Expand All @@ -57,14 +57,13 @@ func TestAccAlertResource(t *testing.T) {
}

func testAccAlertResourceConfig(name string) string {
return providerConfig + fmt.Sprintf(`
return providerConfig() + fmt.Sprintf(`

resource "swo_alert" "test" {
name = %[1]q
description = "Mock alert description."
severity = "CRITICAL"
enabled = true
trigger_reset_actions = true
conditions = [
{
metric_name = "synthetics.https.response.time"
Expand Down
1 change: 1 addition & 0 deletions internal/provider/alert_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (r *alertResource) Schema(ctx context.Context, req resource.SchemaRequest,
"trigger_reset_actions": schema.BoolAttribute{
Description: "True if a notification should be sent when an active alert returns to normal. Default is false.",
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
},
"conditions": schema.SetNestedAttribute{
Expand Down
10 changes: 5 additions & 5 deletions internal/provider/api_token_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func TestAccApiTokenResource(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccApiTokenResourceConfig("test one"),
Config: testAccApiTokenResourceConfig("test-acc test one"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("swo_apitoken.test", "id"),
resource.TestCheckResourceAttr("swo_apitoken.test", "name", "test one"),
resource.TestCheckResourceAttr("swo_apitoken.test", "name", "test-acc test one"),
),
},
// ImportState testing
Expand All @@ -29,9 +29,9 @@ func TestAccApiTokenResource(t *testing.T) {
},
// Update and Read testing
{
Config: testAccApiTokenResourceConfig("test two"),
Config: testAccApiTokenResourceConfig("test-acc test two"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("swo_apitoken.test", "name", "test two"),
resource.TestCheckResourceAttr("swo_apitoken.test", "name", "test-acc test two"),
),
},
// Delete testing automatically occurs in TestCase
Expand All @@ -40,7 +40,7 @@ func TestAccApiTokenResource(t *testing.T) {
}

func testAccApiTokenResourceConfig(name string) string {
return providerConfig + fmt.Sprintf(`
return providerConfig() + fmt.Sprintf(`
resource "swo_apitoken" "test_uri" {
name = %[1]q
access_level = "READ"
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/dashboard_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func TestAccDashboardResource(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccDashboardResourceConfig("swo-terraform-provider [CREATE_TEST]"),
Config: testAccDashboardResourceConfig("test-acc swo-terraform-provider [CREATE_TEST]"),
ExpectNonEmptyPlan: true,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("swo_dashboard.test", "id"),
resource.TestCheckResourceAttr("swo_dashboard.test", "name", "swo-terraform-provider [CREATE_TEST]"),
resource.TestCheckResourceAttr("swo_dashboard.test", "name", "test-acc swo-terraform-provider [CREATE_TEST]"),
resource.TestCheckResourceAttr("swo_dashboard.test", "widgets.#", "2"),
resource.TestCheckResourceAttr("swo_dashboard.test", "widgets.0.type", "TimeSeries"),
resource.TestCheckResourceAttr("swo_dashboard.test", "widgets.1.width", "4"),
Expand All @@ -33,7 +33,7 @@ func TestAccDashboardResource(t *testing.T) {
},
// Update and Read testing
{
Config: testAccDashboardResourceConfig("swo-terraform-provider [UPDATE_TEST]"),
Config: testAccDashboardResourceConfig("test-acc swo-terraform-provider [UPDATE_TEST]"),
ExpectNonEmptyPlan: true,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("swo_dashboard.test", "name", "swo-terraform-provider [UPDATE_TEST]"),
Expand All @@ -45,7 +45,7 @@ func TestAccDashboardResource(t *testing.T) {
}

func testAccDashboardResourceConfig(name string) string {
return providerConfig + fmt.Sprintf(`
return providerConfig() + fmt.Sprintf(`
resource "swo_dashboard" "test" {
name = %[1]q
is_private = true
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/log_filter_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccLogFilterResource(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccLogFilterResourceConfig("test one"),
Config: testAccLogFilterResourceConfig("test-acc test one"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("swo_logfilter.test", "id"),
resource.TestCheckResourceAttr("swo_logfilter.test", "name", "test one"),
Expand All @@ -41,7 +41,7 @@ func TestAccLogFilterResource(t *testing.T) {
}

func testAccLogFilterResourceConfig(name string) string {
return providerConfig + fmt.Sprintf(`
return providerConfig() + fmt.Sprintf(`
resource "swo_logfilter" "test_logfilter" {
name = %[1]q
description = "test description"
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/notification_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccNotificationResource(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccNotificationResourceConfig("test one"),
Config: testAccNotificationResourceConfig("test-acc test one"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("swo_notification.test", "id"),
resource.TestCheckResourceAttr("swo_notification.test", "title", "test one"),
Expand All @@ -35,7 +35,7 @@ func TestAccNotificationResource(t *testing.T) {
},
// Update and Read testing
{
Config: testAccNotificationResourceConfig("test two"),
Config: testAccNotificationResourceConfig("test-acc test two"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("swo_notification.test", "title", "test two"),
),
Expand All @@ -46,7 +46,7 @@ func TestAccNotificationResource(t *testing.T) {
}

func testAccNotificationResourceConfig(title string) string {
return providerConfig + fmt.Sprintf(`
return providerConfig() + fmt.Sprintf(`
resource "swo_notification" "test" {
title = %[1]q
description = "testing..."
Expand Down
18 changes: 8 additions & 10 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package provider

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
)

const (
// providerConfig is a shared configuration to combine with the actual
// test configuration so the SWO client is properly configured.
// It is also possible to use environment variables instead,
// such as updating the Makefile and running the testing through that tool.
providerConfig = `
provider "swo" {
api_token = "123xyz"
func providerConfig() string {
return fmt.Sprintf(`provider "swo" {
api_token = "%s"
request_timeout = 10
base_url = "%s"
debug_mode = true
}`, os.Getenv("SWO_API_TOKEN"), os.Getenv("SWO_BASE_URL"))
}
`
)

// testAccProtoV6ProviderFactories are used to instantiate a provider during
// acceptance testing. The factory function will be invoked for every Terraform
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/uri_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestAccUriResource(t *testing.T) {
}

func testAccUriResourceConfig(name string) string {
return providerConfig + fmt.Sprintf(`
return providerConfig() + fmt.Sprintf(`
resource "swo_uri" "test_uri" {
name = %[1]q
host = "https://example.com"
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/website_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccWebsiteResource(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccWebsiteResourceConfig("test one"),
Config: testAccWebsiteResourceConfig("test-acc test one"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("swo_website.test", "id"),
resource.TestCheckResourceAttr("swo_website.test", "name", "test one"),
Expand All @@ -38,7 +38,7 @@ func TestAccWebsiteResource(t *testing.T) {
},
// Update and Read testing
{
Config: testAccWebsiteResourceConfig("test two"),
Config: testAccWebsiteResourceConfig("test-acc test two"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("swo_website.test", "name", "test two"),
),
Expand All @@ -55,7 +55,7 @@ func TestAccWebsiteResource(t *testing.T) {
}

func testAccWebsiteResourceConfig(name string) string {
return providerConfig + fmt.Sprintf(`
return providerConfig() + fmt.Sprintf(`
resource "swo_website" "test_website" {
name = %[1]q
url = "https://example.com"
Expand Down Expand Up @@ -127,7 +127,7 @@ func testAccWebsiteResourceConfig(name string) string {
}

func testAccWebsiteResourceConfigWithoutOptionals(name string) string {
return providerConfig + fmt.Sprintf(`
return providerConfig() + fmt.Sprintf(`
resource "swo_website" "test_website" {
name = %[1]q
url = "https://example.com"
Expand Down
Loading