43
47
assert_equal(BAD_SECRET_MSG, djinn.remove_role("baz", @secret))
51
def test_set_params_w_bad_params
52
flexmock(Djinn).new_instances { |instance|
53
instance.should_receive(:valid_secret?).and_return(true)
57
# Try passing in params that aren't Arrays, the required type
59
result_1 = djinn.set_parameters(bad_param, [], [], @secret)
60
assert_equal(true, result_1.include?("Error: djinn_locations"))
62
result_2 = djinn.set_parameters([], bad_param, [], @secret)
63
assert_equal(true, result_2.include?("Error: database_credentials"))
65
result_3 = djinn.set_parameters([], [], bad_param, @secret)
66
assert_equal(true, result_3.include?("Error: app_names"))
68
# Since DB credentials will be turned from an Array to a Hash,
69
# it should have an even number of items in it
70
bad_credentials = ['a']
71
result_4 = djinn.set_parameters(bad_credentials, bad_credentials,
72
bad_credentials, @secret)
73
expected_1 = "Error: DB Credentials wasn't of even length"
74
assert_equal(true, result_4.include?(expected_1))
76
# Now try credentials with an even number of items, but not all the
78
better_credentials = ['a', 'b']
79
result_5 = djinn.set_parameters(better_credentials, better_credentials,
80
better_credentials, @secret)
81
assert_equal("Error: Credential format wrong", result_5)
83
# Now try good credentials, but with bad node info
84
credentials = ['table', 'cassandra', 'hostname', '127.0.0.1', 'ips', '',
85
'keyname', 'appscale']
87
assert_raises(SystemExit) {
88
djinn.set_parameters(bad_node_info, credentials, better_credentials,
92
# Finally, try credentials with info in the right format, but where it
93
# refers to nodes that aren't in our deployment
94
one_node_info = ['127.0.0.1:127.0.0.1:some_role:instance_id:cloud1']
97
udpsocket = flexmock(UDPSocket)
98
udpsocket.should_receive(:open).and_return("not any ips above")
100
expected_2 = "Error: Couldn't find me in the node map"
101
result_6 = djinn.set_parameters(one_node_info, credentials, app_names,
103
assert_equal(expected_2, result_6)
106
def test_set_params_w_good_params
107
flexmock(Djinn).new_instances { |instance|
108
instance.should_receive(:valid_secret?).and_return(true)
112
credentials = ['table', 'cassandra', 'hostname', '127.0.0.1', 'ips', '',
113
'keyname', 'appscale']
114
one_node_info = ['127.0.0.1:127.0.0.1:some_role:instance_id:cloud1']
117
udpsocket = flexmock(UDPSocket)
118
udpsocket.should_receive(:open).and_return("127.0.0.1")
121
actual = djinn.set_parameters(one_node_info, credentials, app_names,
123
assert_equal(expected, actual)
47
127
flexmock(Djinn).new_instances { |instance|
48
128
instance.should_receive(:valid_secret?).and_return(true)