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

test(integration): add failing case for rules with no distributions #3078

Merged
merged 6 commits into from
May 13, 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
23 changes: 20 additions & 3 deletions build/testing/integration/readonly/readonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestReadOnly(t *testing.T) {
NamespaceKey: namespace,
})
require.NoError(t, err)
require.Len(t, flags.Flags, 56)
require.Len(t, flags.Flags, 57)

flag := flags.Flags[0]
assert.Equal(t, namespace, flag.NamespaceKey)
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestReadOnly(t *testing.T) {

if flags.NextPageToken == "" {
// ensure last page contains 3 entries (boolean and disabled)
assert.Len(t, flags.Flags, 6)
assert.Len(t, flags.Flags, 7)

found = append(found, flags.Flags...)

Expand All @@ -160,7 +160,7 @@ func TestReadOnly(t *testing.T) {
nextPage = flags.NextPageToken
}

require.Len(t, found, 56)
require.Len(t, found, 57)
})
})

Expand Down Expand Up @@ -540,6 +540,23 @@ func TestReadOnly(t *testing.T) {

require.Nil(t, result)
})

t.Run("match no distributions", func(t *testing.T) {
response, err := sdk.Evaluation().Variant(ctx, &evaluation.EvaluationRequest{
NamespaceKey: namespace,
FlagKey: "flag_no_distributions",
EntityId: "some-fixed-entity-id",
Context: map[string]string{
"in_segment": "segment_001",
},
})
require.NoError(t, err)

assert.Equal(t, true, response.Match)
assert.Equal(t, "flag_no_distributions", response.FlagKey)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, response.Reason)
assert.Contains(t, response.SegmentKeys, "segment_001")
})
})

t.Run("Boolean", func(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions build/testing/integration/readonly/testdata/main/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15636,6 +15636,16 @@ flags:
distributions:
- variant: variant_001
rollout: 100
- key: flag_no_distributions
name: FLAG_NO_DISTRIBUTIONS
type: VARIANT_FLAG_TYPE
description: Flag no distributions
enabled: true
variants:
- key: variant_001
name: VARIANT_001
rules:
- segment: segment_001
segments:
- key: segment_001
name: SEGMENT_001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15637,6 +15637,16 @@ flags:
distributions:
- variant: variant_001
rollout: 100
- key: flag_no_distributions
name: FLAG_NO_DISTRIBUTIONS
type: VARIANT_FLAG_TYPE
description: Flag no distributions
enabled: true
variants:
- key: variant_001
name: VARIANT_001
rules:
- segment: segment_001
segments:
- key: segment_001
name: SEGMENT_001
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/fs/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ func (ss *Snapshot) GetEvaluationRules(ctx context.Context, flag storage.Resourc
func (ss *Snapshot) GetEvaluationDistributions(ctx context.Context, rule storage.IDRequest) ([]*storage.EvaluationDistribution, error) {
dists, ok := ss.evalDists[rule.ID]
if !ok {
return nil, errs.ErrNotFoundf("rule %q", rule.ID)
return []*storage.EvaluationDistribution{}, nil
}

return dists, nil
Expand Down
32 changes: 18 additions & 14 deletions internal/storage/fs/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,22 +603,27 @@ func (fis *FSIndexSuite) TestGetEvaluationDistributions() {
t := fis.T()

testCases := []struct {
name string
namespace string
flagKey string
expectedVariantName string
name string
namespace string
flagKey string
count int
}{
{
name: "Sandbox",
namespace: "sandbox",
flagKey: "sandbox-flag",
expectedVariantName: "sandbox-variant",
name: "Sandbox",
namespace: "sandbox",
flagKey: "sandbox-flag",
count: 1,
},
{
name: "Production",
namespace: "production",
flagKey: "prod-flag",
expectedVariantName: "prod-variant",
name: "Production",
namespace: "production",
flagKey: "prod-flag",
count: 1,
},
{
name: "Production No Distributions",
namespace: "production",
flagKey: "no-distributions",
},
}

Expand All @@ -632,8 +637,7 @@ func (fis *FSIndexSuite) TestGetEvaluationDistributions() {

require.NoError(t, err)

assert.Equal(t, tc.expectedVariantName, dist[0].VariantKey)
assert.Equal(t, float32(100), dist[0].Rollout)
assert.Len(t, dist, tc.count)
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ flags:
threshold:
percentage: 50
value: true
- key: redemptory
name: redemptory
- key: no-distributions
name: No Distributions
description: description
enabled: true
variants:
- key: flipt-flag
rules:
- segment: segment1
- key: animalculine
name: animalculine
description: description
Expand Down
Loading