Skip to content

Commit

Permalink
test(integration): add failing case for rules with no distributions (#…
Browse files Browse the repository at this point in the history
…3078)

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

Signed-off-by: George MacRorie <[email protected]>

* test(storage/fs): add failing case around no rule distributions

Signed-off-by: George MacRorie <[email protected]>

* fix(storage/fs): return empty slice instead of rule not found

Signed-off-by: George MacRorie <[email protected]>

* fix(testing/integration): update assertion to account for new flag cases

Signed-off-by: George MacRorie <[email protected]>

* fix(testing/integration): update assertion to account for new flag cases

Signed-off-by: George MacRorie <[email protected]>

---------

Signed-off-by: George MacRorie <[email protected]>
  • Loading branch information
GeorgeMac authored and markphelps committed May 13, 2024
1 parent dd9f68a commit 1c70110
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 20 deletions.
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
10 changes: 10 additions & 0 deletions build/testing/integration/readonly/testdata/main/production.yaml
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

0 comments on commit 1c70110

Please sign in to comment.