Skip to content

Commit b635fbd

Browse files
chore: follow-up PR to add test for bucketing (#2379)
* add BucketingKey to DTO converter functions * Adding test to validate DTO convertion Signed-off-by: Thomas Poignant <[email protected]> --------- Signed-off-by: Thomas Poignant <[email protected]> Co-authored-by: Ricardo Tomasi <[email protected]>
1 parent 3d42409 commit b635fbd

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

feature_flag_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
ffclient "github.com/thomaspoignant/go-feature-flag"
1414
"github.com/thomaspoignant/go-feature-flag/ffcontext"
1515
"github.com/thomaspoignant/go-feature-flag/internal/flag"
16+
"github.com/thomaspoignant/go-feature-flag/model"
1617
"github.com/thomaspoignant/go-feature-flag/retriever"
1718
"github.com/thomaspoignant/go-feature-flag/retriever/fileretriever"
1819
"github.com/thomaspoignant/go-feature-flag/retriever/s3retriever"
@@ -663,3 +664,45 @@ func Test_PersistFlagConfigurationOnDisk(t *testing.T) {
663664
assert.NoError(t, err)
664665
assert.NotEqual(t, contentP2, contentP3)
665666
}
667+
668+
func Test_UseCustomBucketingKey(t *testing.T) {
669+
gffClient, err := ffclient.New(ffclient.Config{
670+
PollingInterval: 1 * time.Second,
671+
Retriever: &fileretriever.Retriever{Path: "testdata/flag-config-custom-bucketingkey.yaml"},
672+
LeveledLogger: slog.Default(),
673+
Offline: false,
674+
})
675+
assert.NoError(t, err)
676+
677+
{
678+
got, err := gffClient.StringVariationDetails("my-flag", ffcontext.NewEvaluationContext("random-key"), "default")
679+
assert.NoError(t, err)
680+
want := model.VariationResult[string]{
681+
Value: "default",
682+
TrackEvents: true,
683+
VariationType: "SdkDefault",
684+
Failed: true,
685+
Reason: flag.ReasonError,
686+
ErrorCode: flag.ErrorCodeTargetingKeyMissing,
687+
ErrorDetails: "invalid bucketing key",
688+
}
689+
assert.Equal(t, want, got)
690+
}
691+
692+
{
693+
got, err := gffClient.StringVariationDetails(
694+
"my-flag",
695+
ffcontext.NewEvaluationContextBuilder("random-key").AddCustom("teamId", "team-123").Build(),
696+
"default")
697+
assert.NoError(t, err)
698+
want := model.VariationResult[string]{
699+
Value: "value_A",
700+
TrackEvents: true,
701+
VariationType: "variation_A",
702+
Failed: false,
703+
Reason: flag.ReasonStatic,
704+
Cacheable: true,
705+
}
706+
assert.Equal(t, want, got)
707+
}
708+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
my-flag:
2+
variations:
3+
variation_A: value_A
4+
variation_B: value_B
5+
variation_C: value_C
6+
bucketingKey: teamId
7+
defaultRule:
8+
variation: variation_A
9+
percentage:
10+
variation_A: 33
11+
variation_B: 67

0 commit comments

Comments
 (0)