diff --git a/pkg/experiment/local/client_eu_test.go b/pkg/experiment/local/client_eu_test.go index ea21bc9..c0805e0 100644 --- a/pkg/experiment/local/client_eu_test.go +++ b/pkg/experiment/local/client_eu_test.go @@ -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) } @@ -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) + } } diff --git a/pkg/experiment/local/client_test.go b/pkg/experiment/local/client_test.go index ee32125..bada72a 100644 --- a/pkg/experiment/local/client_test.go +++ b/pkg/experiment/local/client_test.go @@ -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) } @@ -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) } @@ -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) + } }