Skip to content

Commit c08e41a

Browse files
rohanKanojiapraveenkumar
authored andcommitted
test (config) : Add some unit tests for config settings
Extracted some unit tests out of #4451 as I was need them while working on #3832 These unit tests verify these scenarios for config: - when we try to set invalid key, throw error - whether default key values are as expected - whether we're able to override default values by providing new value Signed-off-by: Rohan Kumar <[email protected]>
1 parent d89df4c commit c08e41a

File tree

1 file changed

+180
-0
lines changed

1 file changed

+180
-0
lines changed

pkg/crc/config/settings_test.go

+180
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,183 @@ func TestPath(t *testing.T) {
182182
IsSecret: false,
183183
}, cfg.Get(ProxyCAFile))
184184
}
185+
186+
func TestWhenInvalidKeySetThenErrorIsThrown(t *testing.T) {
187+
// Given
188+
cfg, err := newInMemoryConfig()
189+
require.NoError(t, err)
190+
191+
// When + Then
192+
_, err = cfg.Set("i-dont-exist", "i-should-not-be-set")
193+
assert.Error(t, err, "Configuration property 'i-dont-exist' does not exist")
194+
}
195+
196+
var configDefaultValuesTestArguments = []struct {
197+
key string
198+
defaultValue interface{}
199+
}{
200+
{
201+
KubeAdminPassword, "",
202+
},
203+
{
204+
CPUs, uint(4),
205+
},
206+
{
207+
Memory, uint(10752),
208+
},
209+
{
210+
DiskSize, 31,
211+
},
212+
{
213+
NameServer, "",
214+
},
215+
{
216+
PullSecretFile, "",
217+
},
218+
{
219+
DisableUpdateCheck, false,
220+
},
221+
{
222+
ExperimentalFeatures, false,
223+
},
224+
{
225+
EmergencyLogin, false,
226+
},
227+
{
228+
PersistentVolumeSize, 15,
229+
},
230+
{
231+
HostNetworkAccess, false,
232+
},
233+
{
234+
HTTPProxy, "",
235+
},
236+
{
237+
HTTPSProxy, "",
238+
},
239+
{
240+
NoProxy, "",
241+
},
242+
{
243+
ProxyCAFile, Path(""),
244+
},
245+
{
246+
EnableClusterMonitoring, false,
247+
},
248+
{
249+
ConsentTelemetry, "",
250+
},
251+
{
252+
IngressHTTPPort, 80,
253+
},
254+
{
255+
IngressHTTPSPort, 443,
256+
},
257+
{
258+
EnableBundleQuayFallback, false,
259+
},
260+
{
261+
Preset, "openshift",
262+
},
263+
}
264+
265+
func TestDefaultKeyValuesSetInConfig(t *testing.T) {
266+
for _, tt := range configDefaultValuesTestArguments {
267+
t.Run(tt.key, func(t *testing.T) {
268+
// Given
269+
cfg, err := newInMemoryConfig()
270+
require.NoError(t, err)
271+
272+
// When + Then
273+
assert.Equal(t, SettingValue{
274+
Value: tt.defaultValue,
275+
Invalid: false,
276+
IsDefault: true,
277+
}, cfg.Get(tt.key))
278+
})
279+
}
280+
}
281+
282+
var configProvidedValuesTestArguments = []struct {
283+
key string
284+
providedValue interface{}
285+
}{
286+
{
287+
KubeAdminPassword, "kubeadmin-secret-password",
288+
},
289+
{
290+
CPUs, uint(8),
291+
},
292+
{
293+
Memory, uint(21504),
294+
},
295+
{
296+
DiskSize, 62,
297+
},
298+
{
299+
NameServer, "127.0.0.1",
300+
},
301+
{
302+
DisableUpdateCheck, true,
303+
},
304+
{
305+
ExperimentalFeatures, true,
306+
},
307+
{
308+
EmergencyLogin, true,
309+
},
310+
{
311+
PersistentVolumeSize, 20,
312+
},
313+
{
314+
HTTPProxy, "http://proxy-via-http-proxy-property:3128",
315+
},
316+
{
317+
HTTPSProxy, "https://proxy-via-http-proxy-property:3128",
318+
},
319+
{
320+
NoProxy, "http://no-proxy-property:3128",
321+
},
322+
{
323+
EnableClusterMonitoring, true,
324+
},
325+
{
326+
ConsentTelemetry, "yes",
327+
},
328+
{
329+
IngressHTTPPort, 8080,
330+
},
331+
{
332+
IngressHTTPSPort, 6443,
333+
},
334+
{
335+
EnableBundleQuayFallback, true,
336+
},
337+
{
338+
Preset, "microshift",
339+
},
340+
}
341+
342+
func TestSetProvidedValuesOverrideDefaultValuesInConfig(t *testing.T) {
343+
for _, tt := range configProvidedValuesTestArguments {
344+
t.Run(tt.key, func(t *testing.T) {
345+
346+
// When + Then
347+
348+
// Given
349+
cfg, err := newInMemoryConfig()
350+
require.NoError(t, err)
351+
352+
// When
353+
_, err = cfg.Set(tt.key, tt.providedValue)
354+
require.NoError(t, err)
355+
356+
// Then
357+
assert.Equal(t, SettingValue{
358+
Value: tt.providedValue,
359+
Invalid: false,
360+
IsDefault: false,
361+
}, cfg.Get(tt.key))
362+
})
363+
}
364+
}

0 commit comments

Comments
 (0)