Manually test different types of flags with valid values
(t *testing.T)
| 76 | |
| 77 | // Manually test different types of flags with valid values |
| 78 | func TestFillConfigWithFlagsValidVals(t *testing.T) { |
| 79 | fs := flag.NewFlagSet("test", flag.ContinueOnError) |
| 80 | config := NewEmptyStartupConfig() |
| 81 | |
| 82 | flags := registerConfigFlags(&config, fs) |
| 83 | |
| 84 | err := fs.Parse([]string{ |
| 85 | "-bootstrap.server", "testServer", // String |
| 86 | "-bootstrap.server_tls_skip_verify=true", // *bool |
| 87 | "-bootstrap.config_update_frequency", "2h", // *base.ConfigDuration |
| 88 | "-api.max_connections", "5", // uint |
| 89 | "-api.cors.origin", "*,example.com,test.net", // []string |
| 90 | "-api.cors.max_age", "-5", // int |
| 91 | "-logging.redaction_level", "full", // RedactionLevel |
| 92 | "-logging.console.log_level", "warn", // *LogLevel |
| 93 | "-replicator.max_heartbeat", "5h2m33s", // base.ConfigDuration |
| 94 | "-max_file_descriptors", "12345", // uint64 |
| 95 | "-heap_profile_collection_threshold", "10000", // uint64 |
| 96 | }) |
| 97 | require.NoError(t, err) |
| 98 | |
| 99 | err = fillConfigWithFlags(fs, flags) |
| 100 | assert.NoError(t, err) |
| 101 | |
| 102 | assert.Equal(t, "testServer", config.Bootstrap.Server) |
| 103 | assert.Equal(t, base.Ptr(true), config.Bootstrap.ServerTLSSkipVerify) |
| 104 | assert.Equal(t, uint(5), config.API.MaximumConnections) |
| 105 | require.NotNil(t, config.Bootstrap.ConfigUpdateFrequency) |
| 106 | assert.Equal(t, base.NewConfigDuration(time.Hour*2), config.Bootstrap.ConfigUpdateFrequency) |
| 107 | assert.Equal(t, []string{"*", "example.com", "test.net"}, config.API.CORS.Origin) |
| 108 | assert.Equal(t, -5, config.API.CORS.MaxAge) |
| 109 | assert.Equal(t, "full", config.Logging.RedactionLevel.String()) |
| 110 | assert.Equal(t, "warn", config.Logging.Console.LogLevel.String()) |
| 111 | assert.Equal(t, base.NewConfigDuration(time.Hour*5+time.Minute*2+time.Second*33), config.Replicator.MaxHeartbeat) |
| 112 | assert.Equal(t, uint64(12345), config.MaxFileDescriptors) |
| 113 | assert.Equal(t, uint64(10000), *config.HeapProfileCollectionThreshold) |
| 114 | |
| 115 | // unset values |
| 116 | assert.Equal(t, "", config.Bootstrap.X509CertPath) // String |
| 117 | assert.Nil(t, config.API.CORS.Headers) // []string |
| 118 | assert.Nil(t, config.API.AdminInterfaceAuthentication) // *bool |
| 119 | assert.Nil(t, config.Logging.Warn.Rotation.RotationInterval) // *base.ConfigDuration |
| 120 | } |
| 121 | |
| 122 | // Manually test different types of flags with invalid values |
| 123 | func TestFillConfigWithFlagsInvalidVals(t *testing.T) { |
nothing calls this directly
no test coverage detected