MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestAllConfigFlags

Function TestAllConfigFlags

rest/config_flags_test.go:24–75  ·  view source on GitHub ↗

Test to make sure that filling all the flags correctly causes no errors or panics

(t *testing.T)

Source from the content-addressed store, hash-verified

22
23// Test to make sure that filling all the flags correctly causes no errors or panics
24func TestAllConfigFlags(t *testing.T) {
25 fs := flag.NewFlagSet("test", flag.ContinueOnError)
26 config := NewEmptyStartupConfig()
27
28 flagMap := registerConfigFlags(&config, fs)
29
30 flags := []string{}
31 for name, flagConfig := range flagMap {
32 // Skip disabled flags in this test - they will intentionally error when set
33 if flagConfig.disabled {
34 continue
35 }
36 rFlagVal := reflect.ValueOf(flagConfig.flagValue).Elem()
37 switch rFlagVal.Interface().(type) {
38 case string: // Test different types of strings
39 rConfigVal := reflect.ValueOf(flagConfig.config).Elem()
40 if rConfigVal.Kind() != reflect.Ptr && rConfigVal.CanAddr() {
41 rConfigVal = rConfigVal.Addr()
42 }
43 val := "TestString"
44 switch rConfigVal.Interface().(type) {
45 case *base.ConfigDuration:
46 val = "5h2m33s"
47 case *base.RedactionLevel:
48 val = "partial"
49 case *base.LogLevel:
50 val = "trace"
51 case *[]uint:
52 val = `123,456,789`
53 case *PerDatabaseCredentialsConfig:
54 val = `{"db1":{"x509_cert_path":"cert","x509_key_path":"key"}}`
55 case *base.PerBucketCredentialsConfig:
56 val = `{"bucket":{"x509_cert_path":"cert","x509_key_path":"key"}}`
57 }
58 flags = append(flags, "-"+name, val)
59 case bool:
60 flags = append(flags, "-"+name+"=true")
61 case uint, uint64:
62 flags = append(flags, "-"+name, "1234")
63 case int, int64:
64 flags = append(flags, "-"+name, "-5678")
65 case float64:
66 flags = append(flags, "-"+name, "123.456")
67 default:
68 assert.Failf(t, "Unknown flag type", "value type %v for flag %v", rFlagVal.Interface(), name)
69 }
70 }
71 err := fs.Parse(flags)
72 assert.NoError(t, err)
73 err = fillConfigWithFlags(fs, flagMap)
74 assert.NoError(t, err)
75}
76
77// Manually test different types of flags with valid values
78func TestFillConfigWithFlagsValidVals(t *testing.T) {

Callers

nothing calls this directly

Calls 3

NewEmptyStartupConfigFunction · 0.85
registerConfigFlagsFunction · 0.85
fillConfigWithFlagsFunction · 0.85

Tested by

no test coverage detected