MCPcopy
hub / github.com/crowdsecurity/crowdsec / TestFeatureSet

Function TestFeatureSet

pkg/fflag/features_test.go:157–215  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

155}
156
157func TestFeatureSet(t *testing.T) {
158 tests := []struct {
159 name string // test description
160 feature string // feature name
161 value bool // value for SetFeature
162 expected bool // expected value from IsEnabled
163 expectedSetErr string // error expected from SetFeature
164 expectedGetErr string // error expected from GetFeature
165 }{
166 {
167 name: "enable a feature to try something new",
168 feature: "experimental1",
169 value: true,
170 expected: true,
171 }, {
172 // not useful in practice, unlikely to happen
173 name: "disable the feature that was enabled",
174 feature: "experimental1",
175 value: false,
176 expected: false,
177 }, {
178 name: "enable a feature that will be retired in v2",
179 feature: "new_standard",
180 value: true,
181 expected: true,
182 expectedSetErr: "the flag is deprecated",
183 }, {
184 name: "enable a feature that was retired in v1.5",
185 feature: "was_adopted",
186 value: true,
187 expected: false,
188 expectedSetErr: "the flag is retired",
189 }, {
190 name: "enable a feature that does not exist",
191 feature: "will_never_exist",
192 value: true,
193 expectedSetErr: "unknown feature",
194 expectedGetErr: "unknown feature",
195 },
196 }
197
198 // the tests are not indepedent because we don't instantiate a feature
199 // map for each one, but it simplified the code
200 fr := setUp(t)
201
202 for _, tc := range tests {
203 t.Run(tc.name, func(t *testing.T) {
204 feat, err := fr.GetFeature(tc.feature)
205 cstest.RequireErrorMessage(t, err, tc.expectedGetErr)
206 if tc.expectedGetErr != "" {
207 return
208 }
209
210 err = feat.Set(tc.value)
211 cstest.RequireErrorMessage(t, err, tc.expectedSetErr)
212 require.Equal(t, tc.expected, feat.IsEnabled())
213 })
214 }

Callers

nothing calls this directly

Calls 5

setUpFunction · 0.85
GetFeatureMethod · 0.80
RunMethod · 0.65
SetMethod · 0.45
IsEnabledMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…