Skip to content

Commit dfc8953

Browse files
authored
Merge pull request #1467 from hashicorp/TF-20376-get-nightly-tests-passing-terraform-provider-tfe
chore: use run tasks url for notification configuration acc tests
2 parents 9ff07e2 + 39c3927 commit dfc8953

File tree

3 files changed

+57
-44
lines changed

3 files changed

+57
-44
lines changed

.github/actions/test-provider-tfe/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ inputs:
4747
description: Accepts regex rules to either include or exclude specific tests from running in either CI or nightly workflows.
4848
required: false
4949
default: "."
50+
run_tasks_url:
51+
description: The mock run tasks URL to use for testing.
52+
required: false
53+
default: "http://testing-mocks.tfe:22180/runtasks/pass"
5054

5155
runs:
5256
using: composite
@@ -102,7 +106,7 @@ runs:
102106
TFE_USER2: tfe-provider-user2
103107
TF_ACC: "1"
104108
ENABLE_TFE: "${{ inputs.enterprise }}"
105-
RUN_TASKS_URL: "http://testing-mocks.tfe:22180/runtasks/pass"
109+
RUN_TASKS_URL: "${{ inputs.run_tasks_url }}"
106110
GITHUB_POLICY_SET_IDENTIFIER: "hashicorp/test-policy-set"
107111
GITHUB_REGISTRY_MODULE_IDENTIFIER: "hashicorp/terraform-random-module"
108112
GITHUB_WORKSPACE_IDENTIFIER: "hashicorp/terraform-random-module"

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
matrix_index: ${{ matrix.index }}
4343
matrix_total: ${{ matrix.total }}
4444
hostname: ${{ fromJSON(steps.tflocal.outputs.workspace-outputs-json).ngrok_domain }}
45+
run_tasks_url: 'https://httpstat.us/200'
4546
token: ${{ fromJSON(steps.tflocal.outputs.workspace-outputs-json).tfe_token }}
4647
testing-github-token: ${{ secrets.TESTING_GITHUB_TOKEN }}
4748
admin_configuration_token: ${{ fromJSON(steps.tflocal.outputs.workspace-outputs-json).tfe_admin_token_by_role.configuration }}

internal/provider/resource_tfe_notification_configuration_test.go

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestAccTFENotificationConfiguration_basic(t *testing.T) {
2121
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
2222

2323
resource.Test(t, resource.TestCase{
24-
PreCheck: func() { testAccPreCheck(t) },
24+
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
2525
Providers: testAccProviders,
2626
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
2727
Steps: []resource.TestStep{
@@ -40,7 +40,7 @@ func TestAccTFENotificationConfiguration_basic(t *testing.T) {
4040
resource.TestCheckResourceAttr(
4141
"tfe_notification_configuration.foobar", "triggers.#", "0"),
4242
resource.TestCheckResourceAttr(
43-
"tfe_notification_configuration.foobar", "url", "http://example.com"),
43+
"tfe_notification_configuration.foobar", "url", runTasksURL()),
4444
),
4545
},
4646
},
@@ -52,7 +52,7 @@ func TestAccTFENotificationConfiguration_emailUserIDs(t *testing.T) {
5252
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
5353

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

8585
resource.Test(t, resource.TestCase{
86-
PreCheck: func() { testAccPreCheck(t) },
86+
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
8787
Providers: testAccProviders,
8888
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
8989
Steps: []resource.TestStep{
@@ -102,7 +102,7 @@ func TestAccTFENotificationConfiguration_update(t *testing.T) {
102102
resource.TestCheckResourceAttr(
103103
"tfe_notification_configuration.foobar", "triggers.#", "0"),
104104
resource.TestCheckResourceAttr(
105-
"tfe_notification_configuration.foobar", "url", "http://example.com"),
105+
"tfe_notification_configuration.foobar", "url", runTasksURL()),
106106
),
107107
},
108108
{
@@ -124,7 +124,7 @@ func TestAccTFENotificationConfiguration_update(t *testing.T) {
124124
resource.TestCheckResourceAttr(
125125
"tfe_notification_configuration.foobar", "triggers.#", "2"),
126126
resource.TestCheckResourceAttr(
127-
"tfe_notification_configuration.foobar", "url", "http://example.com/?update=true"),
127+
"tfe_notification_configuration.foobar", "url", fmt.Sprintf("%s/?update=true", runTasksURL())),
128128
),
129129
},
130130
},
@@ -136,7 +136,7 @@ func TestAccTFENotificationConfiguration_updateEmailUserIDs(t *testing.T) {
136136
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
137137

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

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

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

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

257257
resource.Test(t, resource.TestCase{
258-
PreCheck: func() { testAccPreCheck(t) },
258+
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
259259
Providers: testAccProviders,
260260
Steps: []resource.TestStep{
261261
{
@@ -283,7 +283,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesEmail(t *
283283
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
284284

285285
resource.Test(t, resource.TestCase{
286-
PreCheck: func() { testAccPreCheck(t) },
286+
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
287287
Providers: testAccProviders,
288288
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
289289
Steps: []resource.TestStep{
@@ -322,7 +322,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesGeneric(t
322322
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
323323

324324
resource.Test(t, resource.TestCase{
325-
PreCheck: func() { testAccPreCheck(t) },
325+
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
326326
Providers: testAccProviders,
327327
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
328328
Steps: []resource.TestStep{
@@ -341,7 +341,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesGeneric(t
341341
resource.TestCheckResourceAttr(
342342
"tfe_notification_configuration.foobar", "triggers.#", "0"),
343343
resource.TestCheckResourceAttr(
344-
"tfe_notification_configuration.foobar", "url", "http://example.com"),
344+
"tfe_notification_configuration.foobar", "url", runTasksURL()),
345345
),
346346
},
347347
{
@@ -365,7 +365,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesSlack(t *
365365
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
366366

367367
resource.Test(t, resource.TestCase{
368-
PreCheck: func() { testAccPreCheck(t) },
368+
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
369369
Providers: testAccProviders,
370370
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
371371
Steps: []resource.TestStep{
@@ -384,7 +384,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesSlack(t *
384384
resource.TestCheckResourceAttr(
385385
"tfe_notification_configuration.foobar", "triggers.#", "0"),
386386
resource.TestCheckResourceAttr(
387-
"tfe_notification_configuration.foobar", "url", "http://example.com"),
387+
"tfe_notification_configuration.foobar", "url", runTasksURL()),
388388
),
389389
},
390390
{
@@ -412,7 +412,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesMicrosoft
412412
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
413413

414414
resource.Test(t, resource.TestCase{
415-
PreCheck: func() { testAccPreCheck(t) },
415+
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
416416
Providers: testAccProviders,
417417
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
418418
Steps: []resource.TestStep{
@@ -427,7 +427,7 @@ func TestAccTFENotificationConfiguration_updateValidateSchemaAttributesMicrosoft
427427
resource.TestCheckResourceAttr(
428428
"tfe_notification_configuration.foobar", "name", "notification_msteams"),
429429
resource.TestCheckResourceAttr(
430-
"tfe_notification_configuration.foobar", "url", "http://example.com"),
430+
"tfe_notification_configuration.foobar", "url", runTasksURL()),
431431
),
432432
},
433433
{
@@ -455,7 +455,7 @@ func TestAccTFENotificationConfiguration_duplicateTriggers(t *testing.T) {
455455
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
456456

457457
resource.Test(t, resource.TestCase{
458-
PreCheck: func() { testAccPreCheck(t) },
458+
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
459459
Providers: testAccProviders,
460460
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
461461
Steps: []resource.TestStep{
@@ -474,7 +474,7 @@ func TestAccTFENotificationConfiguration_duplicateTriggers(t *testing.T) {
474474
resource.TestCheckResourceAttr(
475475
"tfe_notification_configuration.foobar", "triggers.#", "1"),
476476
resource.TestCheckResourceAttr(
477-
"tfe_notification_configuration.foobar", "url", "http://example.com"),
477+
"tfe_notification_configuration.foobar", "url", runTasksURL()),
478478
),
479479
},
480480
},
@@ -485,7 +485,7 @@ func TestAccTFENotificationConfigurationImport_basic(t *testing.T) {
485485
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
486486

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

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

531531
resource.Test(t, resource.TestCase{
532-
PreCheck: func() { testAccPreCheck(t) },
532+
PreCheck: func() { preCheckTFENotificationConfiguration(t) },
533533
Providers: testAccProviders,
534534
CheckDestroy: testAccCheckTFENotificationConfigurationDestroy,
535535
Steps: []resource.TestStep{
@@ -591,7 +591,7 @@ func testAccCheckTFENotificationConfigurationAttributes(notificationConfiguratio
591591
return fmt.Errorf("Bad triggers: %v", notificationConfiguration.Triggers)
592592
}
593593

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

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

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

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

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

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

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

@@ -797,9 +797,9 @@ resource "tfe_workspace" "foobar" {
797797
resource "tfe_notification_configuration" "foobar" {
798798
name = "notification_basic"
799799
destination_type = "generic"
800-
url = "http://example.com"
800+
url = "%s"
801801
workspace_id = tfe_workspace.foobar.id
802-
}`, rInt)
802+
}`, rInt, runTasksURL())
803803
}
804804

805805
func testAccTFENotificationConfiguration_emailUserIDs(rInt int) string {
@@ -841,9 +841,9 @@ resource "tfe_workspace" "foobar" {
841841
resource "tfe_notification_configuration" "foobar" {
842842
name = "notification_slack"
843843
destination_type = "slack"
844-
url = "http://example.com"
844+
url = "%s"
845845
workspace_id = tfe_workspace.foobar.id
846-
}`, rInt)
846+
}`, rInt, runTasksURL())
847847
}
848848

849849
func testAccTFENotificationConfiguration_microsoftTeams(rInt int) string {
@@ -861,9 +861,9 @@ resource "tfe_workspace" "foobar" {
861861
resource "tfe_notification_configuration" "foobar" {
862862
name = "notification_msteams"
863863
destination_type = "microsoft-teams"
864-
url = "http://example.com"
864+
url = "%s"
865865
workspace_id = tfe_workspace.foobar.id
866-
}`, rInt)
866+
}`, rInt, runTasksURL())
867867
}
868868

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

892892
func testAccTFENotificationConfiguration_updateEmailUserIDs(rInt int) string {
@@ -930,9 +930,9 @@ resource "tfe_workspace" "foobar" {
930930
resource "tfe_notification_configuration" "foobar" {
931931
name = "notification_email_with_url"
932932
destination_type = "email"
933-
url = "http://example.com"
933+
url = "%s"
934934
workspace_id = tfe_workspace.foobar.id
935-
}`, rInt)
935+
}`, rInt, runTasksURL())
936936
}
937937

938938
func testAccTFENotificationConfiguration_emailWithToken(rInt int) string {
@@ -1080,9 +1080,9 @@ resource "tfe_notification_configuration" "foobar" {
10801080
name = "notification_slack_with_token"
10811081
destination_type = "slack"
10821082
token = "1234567890"
1083-
url = "http://example.com"
1083+
url = "%s"
10841084
workspace_id = tfe_workspace.foobar.id
1085-
}`, rInt)
1085+
}`, rInt, runTasksURL())
10861086
}
10871087

10881088
func testAccTFENotificationConfiguration_slackWithoutURL(rInt int) string {
@@ -1165,9 +1165,9 @@ resource "tfe_notification_configuration" "foobar" {
11651165
name = "notification_msteams_with_token"
11661166
destination_type = "microsoft-teams"
11671167
token = "1234567890"
1168-
url = "http://example.com"
1168+
url = "%s"
11691169
workspace_id = tfe_workspace.foobar.id
1170-
}`, rInt)
1170+
}`, rInt, runTasksURL())
11711171
}
11721172

11731173
func testAccTFENotificationConfiguration_microsoftTeamsWithoutURL(rInt int) string {
@@ -1205,7 +1205,15 @@ resource "tfe_notification_configuration" "foobar" {
12051205
name = "notification_duplicate_triggers"
12061206
destination_type = "generic"
12071207
triggers = ["run:created", "run:created", "run:created"]
1208-
url = "http://example.com"
1208+
url = "%s"
12091209
workspace_id = tfe_workspace.foobar.id
1210-
}`, rInt)
1210+
}`, rInt, runTasksURL())
1211+
}
1212+
1213+
func preCheckTFENotificationConfiguration(t *testing.T) {
1214+
testAccPreCheck(t)
1215+
1216+
if runTasksURL() == "" {
1217+
t.Skip("RUN_TASKS_URL must be set for notification configuration acceptance tests")
1218+
}
12111219
}

0 commit comments

Comments
 (0)