-
Notifications
You must be signed in to change notification settings - Fork 213
Generate JSON in pretty form, and add ip address #360
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,8 @@ def test_generates_a_node_config | |
cmd = command(@host) | ||
cmd.generate_node_config | ||
assert cmd.node_config.exist? | ||
assert_match '{"run_list":[]}', cmd.node_config.read | ||
|
||
assert_config_contains({"run_list" => []}, cmd) | ||
end | ||
end | ||
|
||
|
@@ -72,7 +73,8 @@ def test_generates_a_node_config_with_specified_run_list | |
in_kitchen do | ||
cmd = command(@host, "--run-list=role[base],recipe[foo]") | ||
cmd.generate_node_config | ||
assert_match '{"run_list":["role[base]","recipe[foo]"]}', cmd.node_config.read | ||
|
||
assert_config_contains({"run_list" => ["role[base]","recipe[foo]"]}, cmd) | ||
end | ||
end | ||
|
||
|
@@ -81,7 +83,13 @@ def test_generates_a_node_config_with_specified_attributes | |
foo_json = '"foo":{"bar":[1,2],"baz":"x"}' | ||
cmd = command(@host, "--json-attributes={#{foo_json}}") | ||
cmd.generate_node_config | ||
assert_match "{#{foo_json},\"run_list\":[]}", cmd.node_config.read | ||
|
||
expected_hash = { | ||
"foo" => {"bar" => [1,2], "baz" => "x"}, | ||
"run_list" => [] | ||
} | ||
|
||
assert_config_contains expected_hash, cmd | ||
end | ||
end | ||
|
||
|
@@ -94,17 +102,28 @@ def test_generates_a_node_config_with_specified_json_attributes | |
cmd.config[:json_attributes] = JSON.parse("{#{foo_json}}") | ||
cmd.config[:first_boot_attributes] = JSON.parse("{#{ignored_json}}") | ||
cmd.generate_node_config | ||
assert_match "{#{foo_json},\"run_list\":[]}", cmd.node_config.read | ||
|
||
expected_hash = { | ||
"foo" => 99, | ||
"run_list" => [] | ||
} | ||
|
||
assert_config_contains expected_hash, cmd | ||
end | ||
end | ||
|
||
def test_generates_a_node_config_with_specified_first_boot_attributes | ||
in_kitchen do | ||
foo_json = '"foo":null' | ||
cmd = command(@host) | ||
cmd.config[:first_boot_attributes] = JSON.parse("{#{foo_json}}") | ||
cmd.config[:first_boot_attributes] = {"foo"=>nil} | ||
cmd.generate_node_config | ||
assert_match "{#{foo_json},\"run_list\":[]}", cmd.node_config.read | ||
|
||
expected_hash = { | ||
"foo" => nil, | ||
"run_list" => [] | ||
} | ||
|
||
assert_config_contains expected_hash, cmd | ||
end | ||
end | ||
|
||
|
@@ -114,10 +133,33 @@ def test_generates_a_node_config_with_specified_run_list_and_attributes | |
run_list = 'recipe[baz]' | ||
cmd = command(@host, "--run-list=#{run_list}", "--json-attributes={#{foo_json}}") | ||
cmd.generate_node_config | ||
assert_match "{#{foo_json},\"run_list\":[\"#{run_list}\"]}", cmd.node_config.read | ||
|
||
expected_hash = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This repeated pattern in the test has a bit of smell to it. Thinking we should have some sort of helper here that allows for testing only the part of the json we're interested in for a given test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I felt the same way. I'll refactor this. I was thinking something like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, you can see the updated code below |
||
"foo" => "bar", | ||
"run_list" => [run_list] | ||
} | ||
|
||
assert_config_contains expected_hash, cmd | ||
|
||
end | ||
end | ||
|
||
def test_generates_a_node_config_with_the_ip_address | ||
in_kitchen do | ||
cmd = command(@host) | ||
cmd.generate_node_config | ||
|
||
expected_hash = { | ||
"automatic" => { "ipaddress" => @host } | ||
} | ||
|
||
assert_config_contains expected_hash, cmd | ||
|
||
end | ||
end | ||
|
||
|
||
|
||
def test_creates_the_nodes_directory_if_needed | ||
outside_kitchen do | ||
cmd = command(@host, "--node-name=mynode") | ||
|
@@ -126,7 +168,17 @@ def test_creates_the_nodes_directory_if_needed | |
end | ||
end | ||
|
||
private | ||
|
||
def command(*args) | ||
knife_command(DummyNodeConfigCommand, *args) | ||
end | ||
|
||
def assert_config_contains expected_hash, cmd | ||
config = JSON.parse(cmd.node_config.read) | ||
expected_hash.each do |k, v| | ||
assert_equal v, config[k] | ||
end | ||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, what's the use case for the addition of automatic.ipaddress? I thought ohai would do that for you w/o having to specify anything in the node config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, although you then only have the IP inside of that node's run, and not on the others. We're using this for two purposes: First, to automate connecting to the server to use chef-solo (we don't need to keep track of IPs, they are stored in the node file). Second, to use other servers IP addresses inside a recipe (say, I want my web server to connect to the DB server on it's IP, so it loads the IP from the node file using a search).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... interesting. Sounds worth the feature then.