diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-12-09 15:17:40 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-12-14 09:54:12 +0300 |
commit | 96d719812d67df232017eb4dbac800d575d3c88d (patch) | |
tree | 367942903b72e2c489cea5b7dc07735a14391501 | |
parent | da9773ba7ad5c047e3d2346a3d348b95542b84ec (diff) |
testhelper: Simplify feature set test
The test for `FeatureSet`s is needlessly complex, doing a lot of voodoo
with converting contexts. Simplify the test to instead just assert that
incoming and outgoing metadata are exactly the same such that we can
then proceed to only whether feature flags are set in one of both tests.
-rw-r--r-- | internal/testhelper/featureset_test.go | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/internal/testhelper/featureset_test.go b/internal/testhelper/featureset_test.go index c6a4e75a8..fdbbba5ed 100644 --- a/internal/testhelper/featureset_test.go +++ b/internal/testhelper/featureset_test.go @@ -5,9 +5,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/v14/internal/metadata" ff "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag" - grpc_metadata "google.golang.org/grpc/metadata" + "google.golang.org/grpc/metadata" ) var ( @@ -172,9 +171,6 @@ func TestNewFeatureSetsWithRubyFlags(t *testing.T) { } func TestFeatureSets_Run(t *testing.T) { - var incomingFlags [][2]bool - var outgoingFlags [][2]bool - // This test depends on feature flags being default-enabled in the test // context, which requires those flags to exist in the ff.All slice. So // let's just append them here so we do not need to use a "real" @@ -185,40 +181,25 @@ func TestFeatureSets_Run(t *testing.T) { }(ff.All) ff.All = append(ff.All, featureFlagA, featureFlagB) + var featureFlags [][2]bool NewFeatureSets(featureFlagB, featureFlagA).Run(t, func(t *testing.T, ctx context.Context) { - incomingMD, ok := grpc_metadata.FromIncomingContext(ctx) + incomingMD, ok := metadata.FromIncomingContext(ctx) require.True(t, ok) - outgoingMD, ok := grpc_metadata.FromOutgoingContext(ctx) + outgoingMD, ok := metadata.FromOutgoingContext(ctx) require.True(t, ok) - incomingCtx := grpc_metadata.NewIncomingContext(context.Background(), incomingMD) - outgoingCtx := metadata.OutgoingToIncoming(grpc_metadata.NewOutgoingContext(context.Background(), outgoingMD)) + require.Equal(t, incomingMD, outgoingMD) - incomingFlags = append(incomingFlags, [2]bool{ - featureFlagB.IsDisabled(incomingCtx), - featureFlagA.IsDisabled(incomingCtx), - }) - outgoingFlags = append(outgoingFlags, [2]bool{ - featureFlagB.IsDisabled(outgoingCtx), - featureFlagA.IsDisabled(outgoingCtx), + featureFlags = append(featureFlags, [2]bool{ + featureFlagA.IsEnabled(ctx), featureFlagB.IsEnabled(ctx), }) }) - for _, tc := range []struct { - desc string - flags [][2]bool - }{ - {desc: "incoming context", flags: incomingFlags}, - {desc: "outgoing context", flags: outgoingFlags}, - } { - t.Run(tc.desc, func(t *testing.T) { - require.ElementsMatch(t, tc.flags, [][2]bool{ - {false, false}, - {true, false}, - {false, true}, - {true, true}, - }) - }) - } + require.Equal(t, [][2]bool{ + {false, false}, + {false, true}, + {true, false}, + {true, true}, + }, featureFlags) } |