Skip to content

Commit

Permalink
fix: add test for segments with anonymous clauses (#249)
Browse files Browse the repository at this point in the history
* don't run RP on PR

* add test
  • Loading branch information
sloloris authored Dec 10, 2024
1 parent 834a3ac commit 0274906
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 17 deletions.
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
on:
pull_request:
push:
branches: [ main ]
jobs:
Expand Down
86 changes: 70 additions & 16 deletions launchdarkly/resource_launchdarkly_segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 0274906

Please sign in to comment.