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: add test for segments with anonymous clauses #249

Merged
merged 2 commits into from
Dec 10, 2024
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
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
Loading