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

chore: use run tasks url for notification configuration acc tests #1467

Merged
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
6 changes: 5 additions & 1 deletion .github/actions/test-provider-tfe/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ inputs:
description: Accepts regex rules to either include or exclude specific tests from running in either CI or nightly workflows.
required: false
default: "."
run_tasks_url:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

description: The mock run tasks URL to use for testing.
required: false
default: "http://testing-mocks.tfe:22180/runtasks/pass"

runs:
using: composite
Expand Down Expand Up @@ -102,7 +106,7 @@ runs:
TFE_USER2: tfe-provider-user2
TF_ACC: "1"
ENABLE_TFE: "${{ inputs.enterprise }}"
RUN_TASKS_URL: "http://testing-mocks.tfe:22180/runtasks/pass"
RUN_TASKS_URL: "${{ inputs.run_tasks_url }}"
GITHUB_POLICY_SET_IDENTIFIER: "hashicorp/test-policy-set"
GITHUB_REGISTRY_MODULE_IDENTIFIER: "hashicorp/terraform-random-module"
GITHUB_WORKSPACE_IDENTIFIER: "hashicorp/terraform-random-module"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
matrix_index: ${{ matrix.index }}
matrix_total: ${{ matrix.total }}
hostname: ${{ fromJSON(steps.tflocal.outputs.workspace-outputs-json).ngrok_domain }}
run_tasks_url: 'https://httpstat.us/200'
token: ${{ fromJSON(steps.tflocal.outputs.workspace-outputs-json).tfe_token }}
testing-github-token: ${{ secrets.TESTING_GITHUB_TOKEN }}
admin_configuration_token: ${{ fromJSON(steps.tflocal.outputs.workspace-outputs-json).tfe_admin_token_by_role.configuration }}
Expand Down
94 changes: 51 additions & 43 deletions internal/provider/resource_tfe_notification_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccTFENotificationConfiguration_basic(t *testing.T) {
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand All @@ -40,7 +40,7 @@ func TestAccTFENotificationConfiguration_basic(t *testing.T) {
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "triggers.#", "0"),
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "url", "http://example.com"),
"tfe_notification_configuration.foobar", "url", runTasksURL()),
),
},
},
Expand All @@ -52,7 +52,7 @@ func TestAccTFENotificationConfiguration_emailUserIDs(t *testing.T) {
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestAccTFENotificationConfiguration_update(t *testing.T) {
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand All @@ -102,7 +102,7 @@ func TestAccTFENotificationConfiguration_update(t *testing.T) {
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "triggers.#", "0"),
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "url", "http://example.com"),
"tfe_notification_configuration.foobar", "url", runTasksURL()),
),
},
{
Expand All @@ -124,7 +124,7 @@ func TestAccTFENotificationConfiguration_update(t *testing.T) {
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "triggers.#", "2"),
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "url", "http://example.com/?update=true"),
"tfe_notification_configuration.foobar", "url", fmt.Sprintf("%s/?update=true", runTasksURL())),
),
},
},
Expand All @@ -136,7 +136,7 @@ func TestAccTFENotificationConfiguration_updateEmailUserIDs(t *testing.T) {
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestAccTFENotificationConfiguration_validateSchemaAttributesEmail(t *testin
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Expand All @@ -205,7 +205,7 @@ func TestAccTFENotificationConfiguration_validateSchemaAttributesGeneric(t *test
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Expand All @@ -228,7 +228,7 @@ func TestAccTFENotificationConfiguration_validateSchemaAttributesSlack(t *testin
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Expand All @@ -255,7 +255,7 @@ func TestAccTFENotificationConfiguration_validateSchemaAttributesMicrosoftTeams(
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesEmail(t *
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesGeneric(t
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand All @@ -341,7 +341,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesGeneric(t
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "triggers.#", "0"),
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "url", "http://example.com"),
"tfe_notification_configuration.foobar", "url", runTasksURL()),
),
},
{
Expand All @@ -365,7 +365,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesSlack(t *
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand All @@ -384,7 +384,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesSlack(t *
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "triggers.#", "0"),
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "url", "http://example.com"),
"tfe_notification_configuration.foobar", "url", runTasksURL()),
),
},
{
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesMicrosoft
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand All @@ -427,7 +427,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesMicrosoft
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "name", "notification_msteams"),
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "url", "http://example.com"),
"tfe_notification_configuration.foobar", "url", runTasksURL()),
),
},
{
Expand Down Expand Up @@ -455,7 +455,7 @@ func TestAccTFENotificationConfiguration_duplicateTriggers(t *testing.T) {
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand All @@ -474,7 +474,7 @@ func TestAccTFENotificationConfiguration_duplicateTriggers(t *testing.T) {
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "triggers.#", "1"),
resource.TestCheckResourceAttr(
"tfe_notification_configuration.foobar", "url", "http://example.com"),
"tfe_notification_configuration.foobar", "url", runTasksURL()),
),
},
},
Expand All @@ -485,7 +485,7 @@ func TestAccTFENotificationConfigurationImport_basic(t *testing.T) {
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand All @@ -507,7 +507,7 @@ func TestAccTFENotificationConfigurationImport_emailUserIDs(t *testing.T) {
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand All @@ -529,7 +529,7 @@ func TestAccTFENotificationConfigurationImport_emptyEmailUserIDs(t *testing.T) {
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -591,7 +591,7 @@ func testAccCheckTFENotificationConfigurationAttributes(notificationConfiguratio
return fmt.Errorf("Bad triggers: %v", notificationConfiguration.Triggers)
}

if notificationConfiguration.URL != "http://example.com" {
if notificationConfiguration.URL != runTasksURL() {
return fmt.Errorf("Bad URL: %s", notificationConfiguration.URL)
}

Expand Down Expand Up @@ -619,7 +619,7 @@ func testAccCheckTFENotificationConfigurationAttributesUpdate(notificationConfig
return fmt.Errorf("Bad triggers: %v", notificationConfiguration.Triggers)
}

if notificationConfiguration.URL != "http://example.com/?update=true" {
if notificationConfiguration.URL != fmt.Sprintf("%s/?update=true", runTasksURL()) {
return fmt.Errorf("Bad URL: %s", notificationConfiguration.URL)
}

Expand Down Expand Up @@ -725,7 +725,7 @@ func testAccCheckTFENotificationConfigurationAttributesMicrosoftTeams(notificati
return fmt.Errorf("Bad triggers: %v", notificationConfiguration.Triggers)
}

if notificationConfiguration.URL != "http://example.com" {
if notificationConfiguration.URL != runTasksURL() {
return fmt.Errorf("Bad URL: %s", notificationConfiguration.URL)
}

Expand Down Expand Up @@ -753,7 +753,7 @@ func testAccCheckTFENotificationConfigurationAttributesDuplicateTriggers(notific
return fmt.Errorf("Bad triggers: %v", notificationConfiguration.Triggers)
}

if notificationConfiguration.URL != "http://example.com" {
if notificationConfiguration.URL != runTasksURL() {
return fmt.Errorf("Bad URL: %s", notificationConfiguration.URL)
}

Expand Down Expand Up @@ -797,9 +797,9 @@ resource "tfe_workspace" "foobar" {
resource "tfe_notification_configuration" "foobar" {
name = "notification_basic"
destination_type = "generic"
url = "http://example.com"
url = "%s"
workspace_id = tfe_workspace.foobar.id
}`, rInt)
}`, rInt, runTasksURL())
}

func testAccTFENotificationConfiguration_emailUserIDs(rInt int) string {
Expand Down Expand Up @@ -841,9 +841,9 @@ resource "tfe_workspace" "foobar" {
resource "tfe_notification_configuration" "foobar" {
name = "notification_slack"
destination_type = "slack"
url = "http://example.com"
url = "%s"
workspace_id = tfe_workspace.foobar.id
}`, rInt)
}`, rInt, runTasksURL())
}

func testAccTFENotificationConfiguration_microsoftTeams(rInt int) string {
Expand All @@ -861,9 +861,9 @@ resource "tfe_workspace" "foobar" {
resource "tfe_notification_configuration" "foobar" {
name = "notification_msteams"
destination_type = "microsoft-teams"
url = "http://example.com"
url = "%s"
workspace_id = tfe_workspace.foobar.id
}`, rInt)
}`, rInt, runTasksURL())
}

func testAccTFENotificationConfiguration_update(rInt int) string {
Expand All @@ -884,9 +884,9 @@ resource "tfe_notification_configuration" "foobar" {
enabled = true
token = "1234567890_update"
triggers = ["run:created", "run:needs_attention"]
url = "http://example.com/?update=true"
url = "%s/?update=true"
workspace_id = tfe_workspace.foobar.id
}`, rInt)
}`, rInt, runTasksURL())
}

func testAccTFENotificationConfiguration_updateEmailUserIDs(rInt int) string {
Expand Down Expand Up @@ -930,9 +930,9 @@ resource "tfe_workspace" "foobar" {
resource "tfe_notification_configuration" "foobar" {
name = "notification_email_with_url"
destination_type = "email"
url = "http://example.com"
url = "%s"
workspace_id = tfe_workspace.foobar.id
}`, rInt)
}`, rInt, runTasksURL())
}

func testAccTFENotificationConfiguration_emailWithToken(rInt int) string {
Expand Down Expand Up @@ -1080,9 +1080,9 @@ resource "tfe_notification_configuration" "foobar" {
name = "notification_slack_with_token"
destination_type = "slack"
token = "1234567890"
url = "http://example.com"
url = "%s"
workspace_id = tfe_workspace.foobar.id
}`, rInt)
}`, rInt, runTasksURL())
}

func testAccTFENotificationConfiguration_slackWithoutURL(rInt int) string {
Expand Down Expand Up @@ -1165,9 +1165,9 @@ resource "tfe_notification_configuration" "foobar" {
name = "notification_msteams_with_token"
destination_type = "microsoft-teams"
token = "1234567890"
url = "http://example.com"
url = "%s"
workspace_id = tfe_workspace.foobar.id
}`, rInt)
}`, rInt, runTasksURL())
}

func testAccTFENotificationConfiguration_microsoftTeamsWithoutURL(rInt int) string {
Expand Down Expand Up @@ -1205,7 +1205,15 @@ resource "tfe_notification_configuration" "foobar" {
name = "notification_duplicate_triggers"
destination_type = "generic"
triggers = ["run:created", "run:created", "run:created"]
url = "http://example.com"
url = "%s"
workspace_id = tfe_workspace.foobar.id
}`, rInt)
}`, rInt, runTasksURL())
}

func preCheckTFENotificationConfiguration(t *testing.T) {
testAccPreCheck(t)

if runTasksURL() == "" {
t.Skip("RUN_TASKS_URL must be set for notification configuration acceptance tests")
}
}
Loading