-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathexperiment_test.go
More file actions
97 lines (88 loc) · 2.63 KB
/
experiment_test.go
File metadata and controls
97 lines (88 loc) · 2.63 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
// Copyright 2022-2026 Salesforce, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package experiment
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_Includes(t *testing.T) {
// Test valid experiment
require.Equal(t, true, Includes(Experiment(Placeholder)))
// Test expected experiments
require.Equal(t, true, Includes(Experiment("lipgloss")))
// Test invalid experiment
require.Equal(t, false, Includes(Experiment("should-fail")))
}
func Test_AllExperimentsListedAreValid(t *testing.T) {
for _, exp := range AllExperiments {
require.Equal(t, true, isValid(string(exp)))
}
}
func Test_EnabledExperimentsListedAreValid(t *testing.T) {
for _, exp := range EnabledExperiments {
require.Equal(t, true, isValid(string(exp)))
}
}
func Test_IsValid(t *testing.T) {
tableTests := map[string]struct {
experiment string
expectedRes bool
}{
"accepts valid experiment format: no hyphen": {
experiment: "match",
expectedRes: true,
},
"accepts valid experiment format: kebab-case": {
experiment: "should-match",
expectedRes: true,
},
"accepts valid experiment format: kebab-case-multi": {
experiment: "should-also-match",
expectedRes: true,
},
"accepts valid experiment format: kebab-case-numerical": {
experiment: "should-also-match3",
expectedRes: true,
},
"rejects invalid experiment format: capitalized": {
experiment: "Nomatch",
expectedRes: false,
},
"rejects invalid experiment format: capitalized-with-hyphen": {
experiment: "No-match",
expectedRes: false,
},
"rejects invalid experiment format: hyphen-prefix-or-suffix": {
experiment: "-no-match-",
expectedRes: false,
},
"rejects invalid experiment format: mixed-case-capital": {
experiment: "NoMatch",
expectedRes: false,
},
"rejects invalid experiment format: mixed-case-lower": {
experiment: "noMatch",
expectedRes: false,
},
"rejects invalid experiment format: snake_case": {
experiment: "no_match",
expectedRes: false,
},
}
for name, tc := range tableTests {
t.Run(name, func(t *testing.T) {
require.Equal(t, tc.expectedRes, isValid(tc.experiment))
})
}
}