Skip to content

Commit

Permalink
agent/testdata add a configuration directory for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
langmartin committed Jun 11, 2019
1 parent 4bfbeb6 commit d1ee78a
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 1 deletion.
34 changes: 33 additions & 1 deletion command/agent/config_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
38 changes: 38 additions & 0 deletions command/agent/testdata/sample1/sample0.json
Original file line number Diff line number Diff line change
@@ -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",
}
}
38 changes: 38 additions & 0 deletions command/agent/testdata/sample1/sample1.json
Original file line number Diff line number Diff line change
@@ -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",
}
}
19 changes: 19 additions & 0 deletions command/agent/testdata/sample1/sample2.hcl
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit d1ee78a

Please sign in to comment.