From 251d167c134e70a2f58ce5420b88064bc7daaae3 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Tue, 19 Dec 2023 11:23:03 +0100 Subject: [PATCH] fix: don't change the "FeatureEnabled" state of the fallback variant --- client.go | 7 +------ client_test.go | 5 +---- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index 314e414..8abe334 100644 --- a/client.go +++ b/client.go @@ -418,13 +418,8 @@ func (uc *Client) getVariantWithoutMetrics(feature string, options ...VariantOpt getFallbackVariant := func(featureEnabled bool) *api.Variant { if opts.variantFallbackFunc != nil { - variant := opts.variantFallbackFunc(feature, ctx) - if variant != nil { - variant.FeatureEnabled = featureEnabled - } - return variant + return opts.variantFallbackFunc(feature, ctx) } else if opts.variantFallback != nil { - opts.variantFallback.FeatureEnabled = featureEnabled return opts.variantFallback } diff --git a/client_test.go b/client_test.go index 03c6201..87575d0 100644 --- a/client_test.go +++ b/client_test.go @@ -1192,7 +1192,6 @@ func TestGetVariantWithFallbackVariantWhenFeatureDisabled(t *testing.T) { fallbackVariant := api.Variant{ Name: "fallback-variant", - FeatureEnabled: true, } variant := client.GetVariant(feature, WithVariantFallback(&fallbackVariant)) @@ -1261,14 +1260,13 @@ func TestGetVariantWithFallbackVariantWhenFeatureEnabledButNoVariants(t *testing fallbackVariant := api.Variant{ Name: "fallback-variant", - FeatureEnabled: false, } variant := client.GetVariant(feature, WithVariantFallback(&fallbackVariant)) assert.False(variant.Enabled) - assert.True(variant.FeatureEnabled) + assert.False(variant.FeatureEnabled) assert.Equal(fallbackVariant, *variant) @@ -1318,7 +1316,6 @@ func TestGetVariantWithFallbackVariantWhenFeatureDoesntExist(t *testing.T) { fallbackVariant := api.Variant{ Name: "fallback-variant", - FeatureEnabled: true, } variant := client.GetVariant(feature, WithVariantFallback(&fallbackVariant))