Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2020-11-02 18:14:34 +0300
committerPaul Okstad <pokstad@gitlab.com>2020-11-04 08:14:04 +0300
commite371ba9264ca2e6bece62a4445654c8e12e68b70 (patch)
treecc537cd97229842963057ccf8e4b4b0c3d2c3279
parentcf97ec5f7778d80d5d61333dd1cb99afc345b2f5 (diff)
featureset: Add tests for feature sets
The featureset helper currently doesn't have any tests, but it has grown to be a widely used helper which did have bugs. This commit adds a few tests to verify it behaves as expected.
-rw-r--r--internal/testhelper/featureset_test.go154
1 files changed, 154 insertions, 0 deletions
diff --git a/internal/testhelper/featureset_test.go b/internal/testhelper/featureset_test.go
new file mode 100644
index 000000000..fc6fa0f60
--- /dev/null
+++ b/internal/testhelper/featureset_test.go
@@ -0,0 +1,154 @@
+package testhelper
+
+import (
+ "context"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/helper"
+ ff "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
+)
+
+func features(flag ...ff.FeatureFlag) map[ff.FeatureFlag]struct{} {
+ features := make(map[ff.FeatureFlag]struct{}, len(flag))
+ for _, f := range flag {
+ features[f] = struct{}{}
+ }
+ return features
+}
+
+func TestNewFeatureSets(t *testing.T) {
+ testcases := []struct {
+ desc string
+ features []ff.FeatureFlag
+ rubyFeatures []ff.FeatureFlag
+ expected FeatureSets
+ }{
+ {
+ desc: "single Go feature flag",
+ features: []ff.FeatureFlag{ff.GoFetchSourceBranch},
+ expected: FeatureSets{
+ FeatureSet{
+ features: features(),
+ rubyFeatures: features(),
+ },
+ FeatureSet{
+ features: features(ff.GoFetchSourceBranch),
+ rubyFeatures: features(),
+ },
+ },
+ },
+ {
+ desc: "two Go feature flags",
+ features: []ff.FeatureFlag{ff.GoFetchSourceBranch, ff.DistributedReads},
+ expected: FeatureSets{
+ FeatureSet{
+ features: features(),
+ rubyFeatures: features(),
+ },
+ FeatureSet{
+ features: features(ff.DistributedReads),
+ rubyFeatures: features(),
+ },
+ FeatureSet{
+ features: features(ff.GoFetchSourceBranch),
+ rubyFeatures: features(),
+ },
+ FeatureSet{
+ features: features(ff.DistributedReads, ff.GoFetchSourceBranch),
+ rubyFeatures: features(),
+ },
+ },
+ },
+ {
+ desc: "single Ruby feature flag",
+ rubyFeatures: []ff.FeatureFlag{ff.GoFetchSourceBranch},
+ expected: FeatureSets{
+ FeatureSet{
+ features: features(),
+ rubyFeatures: features(),
+ },
+ FeatureSet{
+ features: features(),
+ rubyFeatures: features(ff.GoFetchSourceBranch),
+ },
+ },
+ },
+ {
+ desc: "two Ruby feature flags",
+ rubyFeatures: []ff.FeatureFlag{ff.GoFetchSourceBranch, ff.DistributedReads},
+ expected: FeatureSets{
+ FeatureSet{
+ features: features(),
+ rubyFeatures: features(),
+ },
+ FeatureSet{
+ features: features(),
+ rubyFeatures: features(ff.DistributedReads),
+ },
+ FeatureSet{
+ features: features(),
+ rubyFeatures: features(ff.GoFetchSourceBranch),
+ },
+ FeatureSet{
+ features: features(),
+ rubyFeatures: features(ff.DistributedReads, ff.GoFetchSourceBranch),
+ },
+ },
+ },
+ {
+ desc: "Go and Ruby feature flag",
+ features: []ff.FeatureFlag{ff.DistributedReads},
+ rubyFeatures: []ff.FeatureFlag{ff.GoFetchSourceBranch},
+ expected: FeatureSets{
+ FeatureSet{
+ features: features(),
+ rubyFeatures: features(),
+ },
+ FeatureSet{
+ features: features(ff.DistributedReads),
+ rubyFeatures: features(),
+ },
+ FeatureSet{
+ features: features(),
+ rubyFeatures: features(ff.GoFetchSourceBranch),
+ },
+ FeatureSet{
+ features: features(ff.DistributedReads),
+ rubyFeatures: features(ff.GoFetchSourceBranch),
+ },
+ },
+ },
+ }
+
+ for _, tc := range testcases {
+ t.Run(tc.desc, func(t *testing.T) {
+ featureSets := NewFeatureSets(tc.features, tc.rubyFeatures...)
+ require.Len(t, featureSets, len(tc.expected))
+ for _, expected := range tc.expected {
+ require.Contains(t, featureSets, expected)
+ }
+ })
+ }
+}
+
+func TestFeatureSets_Run(t *testing.T) {
+ var flags [][2]bool
+
+ NewFeatureSets([]ff.FeatureFlag{
+ ff.DistributedReads, ff.GoFetchSourceBranch,
+ }).Run(t, func(t *testing.T, ctx context.Context) {
+ ctx = helper.OutgoingToIncoming(ctx)
+ flags = append(flags, [2]bool{
+ ff.IsDisabled(ctx, ff.DistributedReads),
+ ff.IsDisabled(ctx, ff.GoFetchSourceBranch),
+ })
+ })
+
+ require.Equal(t, flags, [][2]bool{
+ {false, false},
+ {true, false},
+ {false, true},
+ {true, true},
+ })
+}