Skip to content

Commit

Permalink
update client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc committed Jul 25, 2024
1 parent 27e0876 commit 40df4cb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
13 changes: 11 additions & 2 deletions pkg/experiment/local/client_eu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ func init() {
}

func TestEvaluateV2CohortEU(t *testing.T) {
user := &experiment.User{UserId: "1", DeviceId: "0"}
targetedUser := &experiment.User{UserId: "1", DeviceId: "0"}
nonTargetedUser := &experiment.User{UserId: "not_targeted", DeviceId: "0"}
flagKeys := []string{"sdk-local-evaluation-user-cohort"}
result, err := clientEU.EvaluateV2(user, flagKeys)
result, err := clientEU.EvaluateV2(targetedUser, flagKeys)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
Expand All @@ -43,4 +44,12 @@ func TestEvaluateV2CohortEU(t *testing.T) {
if variant.Value != "on" {
t.Fatalf("Unexpected variant %v", variant)
}
result, err = clientEU.EvaluateV2(nonTargetedUser, flagKeys)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
variant = result["sdk-local-evaluation-user-cohort"]
if variant.Key != "off" {
t.Fatalf("Unexpected variant %v", variant)
}
}
31 changes: 27 additions & 4 deletions pkg/experiment/local/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ func TestFlagMetadataLocalFlagKey(t *testing.T) {
}

func TestEvaluateV2Cohort(t *testing.T) {
user := &experiment.User{UserId: "12345"}
targetedUser := &experiment.User{UserId: "12345"}
nonTargetedUser := &experiment.User{UserId: "not_targeted"}
flagKeys := []string{"sdk-local-evaluation-user-cohort-ci-test"}
result, err := client.EvaluateV2(user, flagKeys)
result, err := client.EvaluateV2(targetedUser, flagKeys)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
Expand All @@ -185,17 +186,31 @@ func TestEvaluateV2Cohort(t *testing.T) {
if variant.Value != "on" {
t.Fatalf("Unexpected variant %v", variant)
}
result, err = client.EvaluateV2(nonTargetedUser, flagKeys)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
variant = result["sdk-local-evaluation-user-cohort-ci-test"]
if variant.Key != "off" {
t.Fatalf("Unexpected variant %v", variant)
}
}

func TestEvaluateV2GroupCohort(t *testing.T) {
user := &experiment.User{
targetedUser := &experiment.User{
UserId: "12345",
DeviceId: "device_id",
Groups: map[string][]string{
"org id": {"1"},
}}
nonTargetedUser := &experiment.User{
UserId: "12345",
DeviceId: "device_id",
Groups: map[string][]string{
"org id": {"not_targeted"},
}}
flagKeys := []string{"sdk-local-evaluation-group-cohort-ci-test"}
result, err := client.EvaluateV2(user, flagKeys)
result, err := client.EvaluateV2(targetedUser, flagKeys)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
Expand All @@ -206,4 +221,12 @@ func TestEvaluateV2GroupCohort(t *testing.T) {
if variant.Value != "on" {
t.Fatalf("Unexpected variant %v", variant)
}
result, err = client.EvaluateV2(nonTargetedUser, flagKeys)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
variant = result["sdk-local-evaluation-group-cohort-ci-test"]
if variant.Key != "off" {
t.Fatalf("Unexpected variant %v", variant)
}
}

0 comments on commit 40df4cb

Please sign in to comment.