diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 8d407938ee4..aea94556a6c 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -572,6 +572,38 @@ var sample0 = &Config{ func TestConfig_ParseSample0(t *testing.T) { c, err := ParseConfigFile("./testdata/sample0.json") - require.Nil(t, err) + require.NoError(t, err) require.EqualValues(t, sample0, c) } + +func TestConfig_ParseDir(t *testing.T) { + c, err := LoadConfig("./testdata/sample1") + require.NoError(t, err) + + // Defaults + sample1 := ParseConfigDefault().Merge(sample0) + + // Merge makes empty maps & slices rather than nil, so set those for the expected + // value + require.Nil(t, sample1.Client.Options) + sample1.Client.Options = map[string]string{} + require.Nil(t, sample1.Client.Meta) + sample1.Client.Meta = map[string]string{} + require.Nil(t, sample1.Client.ChrootEnv) + sample1.Client.ChrootEnv = map[string]string{} + require.Nil(t, sample1.Server.StartJoin) + sample1.Server.StartJoin = []string{} + + // This value added to the config file + sample1.Consul.EnableSSL = helper.BoolToPtr(true) + + // LoadDir listed the config files + require.Nil(t, sample1.Files) + sample1.Files = []string{ + "testdata/sample1/sample0.json", + "testdata/sample1/sample1.json", + "testdata/sample1/sample2.hcl", + } + + require.EqualValues(t, sample1, c) +} diff --git a/command/agent/testdata/sample1/sample0.json b/command/agent/testdata/sample1/sample0.json new file mode 100644 index 00000000000..07796e913d9 --- /dev/null +++ b/command/agent/testdata/sample1/sample0.json @@ -0,0 +1,38 @@ +{ + "acl": { + "enabled": true + }, + "bind_addr": "0.0.0.0", + "consul": { + "ssl": true, + "server_auto_join": false, + "client_auto_join": false, + "token": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" + }, + "data_dir": "/opt/data/nomad/data", + "datacenter": "dc1", + "enable_syslog": true, + "leave_on_interrupt": true, + "leave_on_terminate": true, + "log_level": "INFO", + "region": "global", + "server": { + "bootstrap_expect": 3, + "enabled": true, + "encrypt": "sHck3WL6cxuhuY7Mso9BHA==", + "retry_join": [ + "10.0.0.101", + "10.0.0.102", + "10.0.0.103" + ] + }, + "syslog_facility": "LOCAL0", + "tls": { + "ca_file": "/opt/data/nomad/certs/nomad-ca.pem", + "cert_file": "/opt/data/nomad/certs/server.pem", + "http": true, + }, + "vault": { + "address": "http://host.example.com:8200", + } +} diff --git a/command/agent/testdata/sample1/sample1.json b/command/agent/testdata/sample1/sample1.json new file mode 100644 index 00000000000..8f83354d45f --- /dev/null +++ b/command/agent/testdata/sample1/sample1.json @@ -0,0 +1,38 @@ +{ + "acl": { + "enabled": true + }, + "advertise": { + "http": "host.example.com", + "rpc": "host.example.com", + "serf": "host.example.com" + }, + "bind_addr": "0.0.0.0", + "data_dir": "/opt/data/nomad/data", + "datacenter": "dc1", + "enable_syslog": true, + "leave_on_interrupt": true, + "leave_on_terminate": true, + "log_level": "INFO", + "region": "global", + "server": { + "bootstrap_expect": 3, + "enabled": true, + }, + "syslog_facility": "LOCAL0", + "telemetry": { + "collection_interval": "60s", + "disable_hostname": true, + "prometheus_metrics": true, + "publish_allocation_metrics": true, + "publish_node_metrics": true + }, + "tls": { + "key_file": "/opt/data/nomad/certs/server-key.pem", + "rpc": true, + "verify_server_hostname": true + }, + "vault": { + "create_from_role": "nomad-cluster", + } +} diff --git a/command/agent/testdata/sample1/sample2.hcl b/command/agent/testdata/sample1/sample2.hcl new file mode 100644 index 00000000000..6ad6055850c --- /dev/null +++ b/command/agent/testdata/sample1/sample2.hcl @@ -0,0 +1,19 @@ +"advertise" = { + "http" = "host.example.com" + "rpc" = "host.example.com" + "serf" = "host.example.com" +} + +"autopilot" = { + "cleanup_dead_servers" = true +} + +"consul" = { + "client_auto_join" = false + "server_auto_join" = false + "token" = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" +} + +vault = { + enabled = true +}