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
|
package featureflag
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/metadata"
)
func TestGRPCMetadataFeatureFlag(t *testing.T) {
testCases := []struct {
flag string
headers map[string]string
enabled bool
}{
{"", nil, false},
{"flag", nil, false},
{"flag", map[string]string{"flag": "true"}, false},
{"flag", map[string]string{"gitaly-feature-flag": "TRUE"}, false},
{"flag", map[string]string{"gitaly-feature-flag": "true"}, true},
}
for _, tc := range testCases {
md := metadata.New(tc.headers)
ctx := metadata.NewIncomingContext(context.Background(), md)
assert.Equal(t, tc.enabled, IsEnabled(ctx, tc.flag))
assert.NotEqual(t, tc.enabled, IsDisabled(ctx, tc.flag))
}
}
|