-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathversion_checker_test.go
More file actions
111 lines (101 loc) · 2.95 KB
/
Copy pathversion_checker_test.go
File metadata and controls
111 lines (101 loc) · 2.95 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package headers
import (
"context"
"strings"
"testing"
"go.temporal.io/api/serviceerror"
"go.temporal.io/server/common/testing/parallelsuite"
)
type (
VersionCheckerSuite struct {
parallelsuite.Suite[*VersionCheckerSuite]
}
)
func TestVersionCheckerSuite(t *testing.T) {
parallelsuite.Run(t, new(VersionCheckerSuite))
}
func (s *VersionCheckerSuite) TestClientSupported() {
serverVersion := "22.8.78"
myFeature := "my-new-feature-flag"
testCases := []struct {
callContext context.Context
expectErr bool
supportsMyFeature bool
}{
{
callContext: context.Background(),
expectErr: false,
},
{
callContext: s.constructCallContext("", "unknown-client", "", ""),
expectErr: false,
},
{
callContext: s.constructCallContext("0.0.0", "", "", ""),
expectErr: false,
},
{
callContext: s.constructCallContext("0.0.0", "unknown-client", "", ""),
expectErr: false,
},
{
callContext: s.constructCallContext("malformed-version", ClientNameGoSDK, "", ""),
expectErr: true,
},
{
callContext: s.constructCallContext("3.0.1", ClientNameGoSDK, "", ""),
expectErr: true,
},
{
callContext: s.constructCallContext("2.4.5", ClientNameGoSDK, "", ""),
expectErr: false,
},
{
callContext: s.constructCallContext("2.4.5", ClientNameGoSDK, "<23.1.0", ""),
expectErr: false,
},
{
callContext: s.constructCallContext("2.4.5", ClientNameGoSDK, ">23.1.0", ""),
expectErr: true,
},
{
callContext: s.constructCallContext("2.4.5", ClientNameGoSDK, "<1.0.0 >=3.5.6 || >22.0.0", ""),
expectErr: false,
},
{
callContext: s.constructCallContext("", ClientNameGoSDK, "<1.0.0 >=3.5.6 || >22.0.0", ""),
expectErr: false,
},
{
callContext: s.constructCallContext("2.4.5", ClientNameGoSDK, "", myFeature),
supportsMyFeature: true,
},
{
callContext: s.constructCallContext("2.4.5", ClientNameGoSDK, "",
strings.Join([]string{"another-feature", myFeature, "third-feature"}, SupportedFeaturesHeaderDelim)),
supportsMyFeature: true,
},
}
versionChecker := NewVersionChecker(map[string]string{
ClientNameGoSDK: "<3.0.0",
}, serverVersion)
for caseIndex, tc := range testCases {
err := versionChecker.ClientSupported(tc.callContext)
if tc.expectErr {
s.Errorf(err, "Case #%d", caseIndex)
switch err.(type) {
case *serviceerror.InvalidArgument, *serviceerror.ClientVersionNotSupported, *serviceerror.ServerVersionNotSupported:
default:
s.Fail("error has wrong type: %T", err)
}
} else {
s.NoErrorf(err, "Case #%d", caseIndex)
}
if tc.callContext != nil {
s.Equal(tc.supportsMyFeature, versionChecker.ClientSupportsFeature(tc.callContext, myFeature))
}
}
}
func (s *VersionCheckerSuite) constructCallContext(clientVersion, clientName, supportedServerVersions, supportedFeatures string) context.Context {
return SetVersionsForTests(context.Background(), clientVersion, clientName, supportedServerVersions, supportedFeatures)
}