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: integration test 025 is not isolated #735

Merged
merged 3 commits into from
Oct 25, 2023
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
4 changes: 3 additions & 1 deletion tests/integration/025_notifications/expected_outputs.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"notification_1_from_all_notifications": "integration-test-025-notification-1-"
}
34 changes: 28 additions & 6 deletions tests/integration/025_notifications/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,43 @@ resource "random_string" "random" {
min_lower = 20
}

locals {
notification_name_prefix = "integration-test-025-notification"
}

resource "env0_notification" "test_notification_1" {
name = "notification123-${random_string.random.result}-1"
name = "${local.notification_name_prefix}-1-${random_string.random.result}"
type = "Slack"
value = "https://someurl1.com"
}

resource "env0_notification" "test_notification_2" {
name = "notification123-${random_string.random.result}-2"
name = "${local.notification_name_prefix}-2-${random_string.random.result}"
type = "Teams"
value = "https://someurl2.com"
}

data "env0_notifications" "all_notifications" {}
data "env0_notifications" "all_notifications" {
depends_on = [env0_notification.test_notification_1, env0_notification.test_notification_2]
}

data "env0_notification" "test_notification_1" {
Copy link
Contributor

@avnerenv0 avnerenv0 Oct 25, 2023

Choose a reason for hiding this comment

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

why not just use

locals {
  test_notification_1_name = "notification123-${random_string.random.result}-1"
}

data "env0_notification" "my_notification" {
  name = locals.test_notification_1_name
}

here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we wish to see that the all_notifications works as expected too, so I suggest we utilize its data, so if it got broken for some reason the test will fail

Copy link
Contributor

@chpl chpl Oct 25, 2023

Choose a reason for hiding this comment

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

agree with @avnerenv0 .
can be replaced with post condition on the all_notifications data

    postcondition {
      condition     = contains(self.names, local.test_notification_1_name)
      error_message = "One of the notifications not found"
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0c08f76

used the resource name, and used output for the all_notifications verification, that it got one of the notifications

depends_on = [env0_notification.test_notification_1]
name = "${local.notification_name_prefix}-1-${random_string.random.result}"
}

data "env0_notification" "test_notification_2" {
depends_on = [env0_notification.test_notification_2]
name = "${local.notification_name_prefix}-2-${random_string.random.result}"
}

data "env0_notification" "notification" {
for_each = toset(data.env0_notifications.all_notifications.names)
name = each.value
output "notification_1_from_all_notifications" {
value = replace(
data.env0_notifications.all_notifications.names[
index(data.env0_notifications.all_notifications.names,
env0_notification.test_notification_1.name)
]
, random_string.random.result
, ""
)
}
Loading