~nchohan/appscale/zk3.3.4

« back to all changes in this revision

Viewing changes to AppController/test/tc_djinn.rb

  • Committer: Chris Bunch
  • Date: 2012-02-17 07:11:05 UTC
  • Revision ID: cgb@cs.ucsb.edu-20120217071105-0wivvbicrg7zoerd
removed eval from set_parameters, added more tests to test out each parameter we send to it, and added documentation on methods that we've tested so far

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
    kernel = flexmock(Kernel)
15
15
    kernel.should_receive(:puts).and_return()
16
16
 
 
17
    djinn_class = flexmock(Djinn)
 
18
    djinn_class.should_receive(:log_debug).and_return()
 
19
 
17
20
    @app = "app"
18
21
    @secret = "baz"
19
22
  end
20
23
 
 
24
 
21
25
  # Every function that is accessible via SOAP should check for the secret
22
26
  # and return a certain message if a bad secret is given.
23
27
  def test_functions_w_bad_secret
43
47
    assert_equal(BAD_SECRET_MSG, djinn.remove_role("baz", @secret))
44
48
  end
45
49
 
 
50
 
 
51
  def test_set_params_w_bad_params
 
52
    flexmock(Djinn).new_instances { |instance|
 
53
      instance.should_receive(:valid_secret?).and_return(true)
 
54
    }
 
55
    djinn = Djinn.new
 
56
 
 
57
    # Try passing in params that aren't Arrays, the required type
 
58
    bad_param = ""
 
59
    result_1 = djinn.set_parameters(bad_param, [], [], @secret)
 
60
    assert_equal(true, result_1.include?("Error: djinn_locations"))
 
61
 
 
62
    result_2 = djinn.set_parameters([], bad_param, [], @secret)
 
63
    assert_equal(true, result_2.include?("Error: database_credentials"))
 
64
 
 
65
    result_3 = djinn.set_parameters([], [], bad_param, @secret)
 
66
    assert_equal(true, result_3.include?("Error: app_names"))
 
67
 
 
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))
 
75
 
 
76
    # Now try credentials with an even number of items, but not all the
 
77
    # required parameters
 
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)
 
82
 
 
83
    # Now try good credentials, but with bad node info
 
84
    credentials = ['table', 'cassandra', 'hostname', '127.0.0.1', 'ips', '', 
 
85
      'keyname', 'appscale']
 
86
    bad_node_info = [1]
 
87
    assert_raises(SystemExit) {
 
88
      djinn.set_parameters(bad_node_info, credentials, better_credentials,
 
89
        @secret)
 
90
    }
 
91
 
 
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']
 
95
    app_names = []
 
96
 
 
97
    udpsocket = flexmock(UDPSocket)
 
98
    udpsocket.should_receive(:open).and_return("not any ips above")
 
99
 
 
100
    expected_2 = "Error: Couldn't find me in the node map"
 
101
    result_6 = djinn.set_parameters(one_node_info, credentials, app_names,
 
102
      @secret)
 
103
    assert_equal(expected_2, result_6)
 
104
  end
 
105
 
 
106
  def test_set_params_w_good_params
 
107
    flexmock(Djinn).new_instances { |instance|
 
108
      instance.should_receive(:valid_secret?).and_return(true)
 
109
    }
 
110
    djinn = Djinn.new
 
111
 
 
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']
 
115
    app_names = []
 
116
 
 
117
    udpsocket = flexmock(UDPSocket)
 
118
    udpsocket.should_receive(:open).and_return("127.0.0.1")
 
119
 
 
120
    expected = "OK"
 
121
    actual = djinn.set_parameters(one_node_info, credentials, app_names,
 
122
      @secret)
 
123
    assert_equal(expected, actual)
 
124
  end
 
125
 
46
126
  def test_set_apps
47
127
    flexmock(Djinn).new_instances { |instance|
48
128
      instance.should_receive(:valid_secret?).and_return(true)