From 45707f5b7aab4b83a720f77fd326465365dc4339 Mon Sep 17 00:00:00 2001 From: George Date: Mon, 13 May 2024 22:06:30 +0100 Subject: [PATCH] test(integration): add failing case for rules with no distributions (#3078) * test(integration): add failing case for rules with no distributions Signed-off-by: George MacRorie * test(storage/fs): add failing case around no rule distributions Signed-off-by: George MacRorie * fix(storage/fs): return empty slice instead of rule not found Signed-off-by: George MacRorie * fix(testing/integration): update assertion to account for new flag cases Signed-off-by: George MacRorie * fix(testing/integration): update assertion to account for new flag cases Signed-off-by: George MacRorie --------- Signed-off-by: George MacRorie --- .../integration/readonly/readonly_test.go | 23 +++++++++++-- .../readonly/testdata/main/default.yaml | 10 ++++++ .../readonly/testdata/main/production.yaml | 10 ++++++ internal/storage/fs/snapshot.go | 2 +- internal/storage/fs/snapshot_test.go | 32 +++++++++++-------- .../explicit_index/prod/prod.features.yml | 6 ++-- 6 files changed, 63 insertions(+), 20 deletions(-) diff --git a/build/testing/integration/readonly/readonly_test.go b/build/testing/integration/readonly/readonly_test.go index 5933c812dc..ac2457228b 100644 --- a/build/testing/integration/readonly/readonly_test.go +++ b/build/testing/integration/readonly/readonly_test.go @@ -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) @@ -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...) @@ -160,7 +160,7 @@ func TestReadOnly(t *testing.T) { nextPage = flags.NextPageToken } - require.Len(t, found, 56) + require.Len(t, found, 57) }) }) @@ -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) { diff --git a/build/testing/integration/readonly/testdata/main/default.yaml b/build/testing/integration/readonly/testdata/main/default.yaml index 5fb80801ff..064b6c5670 100644 --- a/build/testing/integration/readonly/testdata/main/default.yaml +++ b/build/testing/integration/readonly/testdata/main/default.yaml @@ -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 diff --git a/build/testing/integration/readonly/testdata/main/production.yaml b/build/testing/integration/readonly/testdata/main/production.yaml index 2e2bcc1020..225d63e9f7 100644 --- a/build/testing/integration/readonly/testdata/main/production.yaml +++ b/build/testing/integration/readonly/testdata/main/production.yaml @@ -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 diff --git a/internal/storage/fs/snapshot.go b/internal/storage/fs/snapshot.go index 578fbbe2a3..43570229d0 100644 --- a/internal/storage/fs/snapshot.go +++ b/internal/storage/fs/snapshot.go @@ -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 diff --git a/internal/storage/fs/snapshot_test.go b/internal/storage/fs/snapshot_test.go index 7f9bb0f397..fef8ef22d8 100644 --- a/internal/storage/fs/snapshot_test.go +++ b/internal/storage/fs/snapshot_test.go @@ -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", }, } @@ -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) }) } } diff --git a/internal/storage/fs/testdata/valid/explicit_index/prod/prod.features.yml b/internal/storage/fs/testdata/valid/explicit_index/prod/prod.features.yml index d0363266cb..803634e8aa 100644 --- a/internal/storage/fs/testdata/valid/explicit_index/prod/prod.features.yml +++ b/internal/storage/fs/testdata/valid/explicit_index/prod/prod.features.yml @@ -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