From 0274906a3a05dd08f1152517b324ef22e1ec6b7b Mon Sep 17 00:00:00 2001 From: Isabelle Miller Date: Tue, 10 Dec 2024 14:03:02 +0100 Subject: [PATCH] fix: add test for segments with anonymous clauses (#249) * don't run RP on PR * add test --- .github/workflows/release.yml | 1 - .../resource_launchdarkly_segment_test.go | 86 +++++++++++++++---- 2 files changed, 70 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2e1c9e6c..35e7e39a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,4 @@ on: - pull_request: push: branches: [ main ] jobs: diff --git a/launchdarkly/resource_launchdarkly_segment_test.go b/launchdarkly/resource_launchdarkly_segment_test.go index e1835ec9..22ee09c7 100644 --- a/launchdarkly/resource_launchdarkly_segment_test.go +++ b/launchdarkly/resource_launchdarkly_segment_test.go @@ -150,27 +150,46 @@ resource "launchdarkly_segment" "test" { testAccSegmentCreateWithUnbounded = ` resource "launchdarkly_segment" "test" { - key = "segmentKey1" - project_key = launchdarkly_project.test.key - env_key = "test" - name = "segment name" - description = "segment description" - tags = ["segmentTag1", "segmentTag2"] - unbounded = true - unbounded_context_kind = "device" + key = "segmentKey1" + project_key = launchdarkly_project.test.key + env_key = "test" + name = "segment name" + description = "segment description" + tags = ["segmentTag1", "segmentTag2"] + unbounded = true + unbounded_context_kind = "device" }` testAccSegmentCreateWithUnboundedUpdate = ` resource "launchdarkly_segment" "test" { - key = "segmentKey1" - project_key = launchdarkly_project.test.key - env_key = "test" - name = "segment name" - description = "segment description" - tags = ["segmentTag1", "segmentTag2"] - unbounded = true - unbounded_context_kind = "account" + key = "segmentKey1" + project_key = launchdarkly_project.test.key + env_key = "test" + name = "segment name" + description = "segment description" + tags = ["segmentTag1", "segmentTag2"] + unbounded = true + unbounded_context_kind = "account" }` + + testAccSegmentWithAnonymousUser = ` +resource "launchdarkly_segment" "anon" { + key = "anonymousSegment" + project_key = launchdarkly_project.test.key + env_key = "test" + name = "anonymous segment" + rules { + clauses { + attribute = "anonymous" + op = "in" + negate = false + values = [ + true + ] + } + } +} +` ) func TestAccSegment_CreateAndUpdate(t *testing.T) { @@ -359,6 +378,41 @@ func TestAccSegment_Unbounded(t *testing.T) { }) } +func TestAccSegment_WithAnonymousClause(t *testing.T) { + projectKey := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) + resourceName := "launchdarkly_segment.anon" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: withRandomProject(projectKey, testAccSegmentWithAnonymousUser), + Check: resource.ComposeTestCheckFunc( + testAccCheckProjectExists("launchdarkly_project.test"), + testAccCheckSegmentExists(resourceName), + resource.TestCheckResourceAttr(resourceName, KEY, "anonymousSegment"), + resource.TestCheckResourceAttr(resourceName, PROJECT_KEY, projectKey), + resource.TestCheckResourceAttr(resourceName, ENV_KEY, "test"), + resource.TestCheckResourceAttr(resourceName, NAME, "anonymous segment"), + resource.TestCheckResourceAttr(resourceName, "rules.#", "1"), + resource.TestCheckResourceAttr(resourceName, "rules.0.clauses.#", "1"), + resource.TestCheckResourceAttr(resourceName, "rules.0.clauses.0.attribute", "anonymous"), + resource.TestCheckResourceAttr(resourceName, "rules.0.clauses.0.op", "in"), + resource.TestCheckResourceAttr(resourceName, "rules.0.clauses.0.negate", "false"), + resource.TestCheckResourceAttr(resourceName, "rules.0.clauses.0.values.0", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccSegment_WithRules(t *testing.T) { projectKey := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resourceName := "launchdarkly_segment.test"