From 4d3e86648e8f5e384034a7f84f0332f7e997a648 Mon Sep 17 00:00:00 2001 From: Lang Martin Date: Tue, 30 Apr 2019 09:22:12 -0400 Subject: [PATCH] config_parse_test additional config confirmation w/ sample json --- command/agent/config_parse_test.go | 82 +++++++++++++++++++++++++++++ command/agent/testdata/sample0.json | 57 ++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 command/agent/testdata/sample0.json diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 7ec2e89e7..7a2f0f809 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -502,3 +502,85 @@ func TestConfig_ParseSliceExtra(t *testing.T) { t.Fatalf("parse error: %s\n", err) } } + +var sample0 = &Config{ + Region: "global", + Datacenter: "dc1", + DataDir: "/opt/data/nomad/data", + LogLevel: "INFO", + BindAddr: "0.0.0.0", + AdvertiseAddrs: &AdvertiseAddrs{ + HTTP: "host.example.com", + RPC: "host.example.com", + Serf: "host.example.com", + }, + Client: &ClientConfig{ServerJoin: &ServerJoin{}}, + Server: &ServerConfig{ + Enabled: true, + BootstrapExpect: 3, + RetryJoin: []string{"10.0.0.101", "10.0.0.102", "10.0.0.103"}, + EncryptKey: "sHck3WL6cxuhuY7Mso9BHA==", + ServerJoin: &ServerJoin{}, + }, + ACL: &ACLConfig{ + Enabled: true, + }, + Telemetry: &Telemetry{ + PrometheusMetrics: true, + DisableHostname: true, + CollectionInterval: "", + collectionInterval: 60 * time.Second, + PublishAllocationMetrics: true, + PublishNodeMetrics: true, + }, + LeaveOnInt: true, + LeaveOnTerm: true, + EnableSyslog: true, + SyslogFacility: "LOCAL0", + Consul: &config.ConsulConfig{ + Token: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", + ServerAutoJoin: helper.BoolToPtr(false), + ClientAutoJoin: helper.BoolToPtr(false), + // Defaults + ServerServiceName: "nomad", + ServerHTTPCheckName: "Nomad Server HTTP Check", + ServerSerfCheckName: "Nomad Server Serf Check", + ServerRPCCheckName: "Nomad Server RPC Check", + ClientServiceName: "nomad-client", + ClientHTTPCheckName: "Nomad Client HTTP Check", + AutoAdvertise: helper.BoolToPtr(true), + ChecksUseAdvertise: helper.BoolToPtr(false), + Timeout: 5 * time.Second, + EnableSSL: helper.BoolToPtr(false), + VerifySSL: helper.BoolToPtr(true), + }, + Vault: &config.VaultConfig{ + Enabled: helper.BoolToPtr(true), + Role: "nomad-cluster", + Addr: "http://host.example.com:8200", + // Defaults + AllowUnauthenticated: helper.BoolToPtr(true), + ConnectionRetryIntv: 30 * time.Second, + }, + TLSConfig: &config.TLSConfig{ + EnableHTTP: true, + EnableRPC: true, + VerifyServerHostname: true, + CAFile: "/opt/data/nomad/certs/nomad-ca.pem", + CertFile: "/opt/data/nomad/certs/server.pem", + KeyFile: "/opt/data/nomad/certs/server-key.pem", + }, + Autopilot: &config.AutopilotConfig{ + CleanupDeadServers: helper.BoolToPtr(true), + // Defaults + ServerStabilizationTime: 10 * time.Second, + LastContactThreshold: 200 * time.Millisecond, + MaxTrailingLogs: 250, + }, +} + +func TestConfig_ParseSample0(t *testing.T) { + c, err := ParseConfigFile("./testdata/sample0.json") + require.Nil(t, err) + require.EqualValues(t, sample0, c) +} diff --git a/command/agent/testdata/sample0.json b/command/agent/testdata/sample0.json new file mode 100644 index 000000000..c9f9a8bd9 --- /dev/null +++ b/command/agent/testdata/sample0.json @@ -0,0 +1,57 @@ +{ + "autopilot": { + "cleanup_dead_servers": true + }, + "acl": { + "enabled": true + }, + "advertise": { + "http": "host.example.com", + "rpc": "host.example.com", + "serf": "host.example.com" + }, + "bind_addr": "0.0.0.0", + "consul": { + "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", + "telemetry": { + "collection_interval": "60s", + "disable_hostname": true, + "prometheus_metrics": true, + "publish_allocation_metrics": true, + "publish_node_metrics": true + }, + "tls": { + "ca_file": "/opt/data/nomad/certs/nomad-ca.pem", + "cert_file": "/opt/data/nomad/certs/server.pem", + "http": true, + "key_file": "/opt/data/nomad/certs/server-key.pem", + "rpc": true, + "verify_server_hostname": true + }, + "vault": { + "address": "http://host.example.com:8200", + "create_from_role": "nomad-cluster", + "enabled": true + } +}