1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
//go:build !gitaly_test_sha256
package git2go
import (
"context"
"encoding/gob"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/repository"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v16/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testcfg"
)
func (b *Executor) FeatureFlags(ctx context.Context, repo repository.GitRepo) ([]FeatureFlag, error) {
output, err := b.run(ctx, repo, nil, "feature-flags")
if err != nil {
return nil, err
}
var result FeatureFlags
if err := gob.NewDecoder(output).Decode(&result); err != nil {
return nil, err
}
if result.Err != nil {
return nil, result.Err
}
return result.Flags, err
}
var (
featureA = featureflag.NewFeatureFlag("feature_a", "", "", false)
featureB = featureflag.NewFeatureFlag("feature_b", "", "", true)
)
func TestExecutor_explicitFeatureFlags(t *testing.T) {
testhelper.NewFeatureSets(featureA, featureB).Run(t, testExecutorFeatureFlags)
}
func testExecutorFeatureFlags(t *testing.T, ctx context.Context) {
cfg := testcfg.Build(t)
testcfg.BuildGitalyGit2Go(t, cfg)
repoProto, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
SkipCreationViaService: true,
})
repo := localrepo.NewTestRepo(t, cfg, repoProto)
executor := NewExecutor(cfg, gittest.NewCommandFactory(t, cfg), config.NewLocator(cfg))
flags, err := executor.FeatureFlags(ctx, repo)
require.NoError(t, err)
require.Subset(t, flags, []FeatureFlag{
{
Name: "feature_a",
MetadataKey: "gitaly-feature-feature-a",
Value: featureA.IsEnabled(ctx),
},
{
Name: "feature_b",
MetadataKey: "gitaly-feature-feature-b",
Value: featureB.IsEnabled(ctx),
},
}, flags)
}
|