solusvm 1.0.0.beta3 → 1.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +10 -4
  3. data/LICENSE +1 -1
  4. data/README.markdown +1 -1
  5. data/lib/solusvm.rb +2 -2
  6. data/lib/solusvm/base.rb +10 -32
  7. data/lib/solusvm/cli/base_cli.rb +30 -5
  8. data/lib/solusvm/cli/client_cli.rb +9 -9
  9. data/lib/solusvm/cli/general_cli.rb +5 -5
  10. data/lib/solusvm/cli/node_cli.rb +8 -8
  11. data/lib/solusvm/cli/reseller_cli.rb +7 -7
  12. data/lib/solusvm/cli/server_cli.rb +31 -31
  13. data/lib/solusvm/solusvm_errors.rb +22 -0
  14. data/lib/solusvm/version.rb +1 -1
  15. data/solusvm.gemspec +2 -0
  16. data/test/cli/test_base_cli.rb +32 -0
  17. data/test/cli/test_client_cli.rb +38 -21
  18. data/test/cli/test_general_cli.rb +13 -4
  19. data/test/cli/test_node_cli.rb +28 -14
  20. data/test/cli/test_reseller_cli.rb +69 -58
  21. data/test/cli/test_server_cli.rb +128 -39
  22. data/test/solusvm/test_base.rb +103 -0
  23. data/test/{test_cli.rb → solusvm/test_cli.rb} +1 -1
  24. data/test/solusvm/test_client.rb +109 -0
  25. data/test/solusvm/test_general.rb +69 -0
  26. data/test/{test_hash.rb → solusvm/test_hash.rb} +1 -1
  27. data/test/solusvm/test_node.rb +120 -0
  28. data/test/solusvm/test_reseller.rb +93 -0
  29. data/test/solusvm/test_server.rb +253 -0
  30. data/test/{helper.rb → test_helper.rb} +19 -4
  31. data/test/test_solusvm.rb +1 -1
  32. data/test/vcr_cassettes/base/invalid_key.yml +19 -0
  33. data/test/vcr_cassettes/base/invalid_status.yml +19 -0
  34. data/test/vcr_cassettes/base/nonexistent_node.yml +19 -0
  35. data/test/vcr_cassettes/base/parse_response.yml +28 -0
  36. data/test/vcr_cassettes/base/statusmsg.yml +28 -0
  37. data/test/vcr_cassettes/base/successful.yml +45 -0
  38. data/test/vcr_cassettes/base/unauthorized_ip.yml +19 -0
  39. data/test/vcr_cassettes/client/authenticate.yml +37 -0
  40. data/test/vcr_cassettes/client/change_password.yml +39 -0
  41. data/test/vcr_cassettes/client/create.yml +42 -0
  42. data/test/vcr_cassettes/client/delete.yml +37 -0
  43. data/test/vcr_cassettes/client/exists.yml +20 -0
  44. data/test/vcr_cassettes/client/list.yml +66 -0
  45. data/test/vcr_cassettes/general/isos.yml +38 -0
  46. data/test/vcr_cassettes/general/plans.yml +38 -0
  47. data/test/vcr_cassettes/general/templates.yml +38 -0
  48. data/test/vcr_cassettes/node/available_ips.yml +41 -0
  49. data/test/vcr_cassettes/node/ids.yml +21 -0
  50. data/test/vcr_cassettes/node/list.yml +38 -0
  51. data/test/vcr_cassettes/node/statistics.yml +32 -0
  52. data/test/vcr_cassettes/node/virtualservers.yml +67 -0
  53. data/test/vcr_cassettes/node/xenresources.yml +22 -0
  54. data/test/vcr_cassettes/reseller/change_resources.yml +27 -0
  55. data/test/vcr_cassettes/reseller/create.yml +27 -0
  56. data/test/vcr_cassettes/reseller/delete.yml +15 -0
  57. data/test/vcr_cassettes/reseller/info.yml +27 -0
  58. data/test/vcr_cassettes/reseller/list.yml +27 -0
  59. data/test/vcr_cassettes/server/.yml +1017 -0
  60. data/test/vcr_cassettes/server/boot.yml +15 -0
  61. data/test/vcr_cassettes/server/change_bootorder.yml +15 -0
  62. data/test/vcr_cassettes/server/change_consolepass.yml +16 -0
  63. data/test/vcr_cassettes/server/change_hostname.yml +15 -0
  64. data/test/vcr_cassettes/server/change_owner.yml +15 -0
  65. data/test/vcr_cassettes/server/change_plan.yml +15 -0
  66. data/test/vcr_cassettes/server/change_rootpassword.yml +15 -0
  67. data/test/vcr_cassettes/server/change_vncpass.yml +15 -0
  68. data/test/vcr_cassettes/server/console.yml +15 -0
  69. data/test/vcr_cassettes/server/create.yml +27 -0
  70. data/test/vcr_cassettes/server/exists.yml +15 -0
  71. data/test/vcr_cassettes/server/info.yml +27 -0
  72. data/test/vcr_cassettes/server/info_all.yml +15 -0
  73. data/test/vcr_cassettes/server/mountiso.yml +15 -0
  74. data/test/vcr_cassettes/server/network_disable.yml +15 -0
  75. data/test/vcr_cassettes/server/network_enable.yml +15 -0
  76. data/test/vcr_cassettes/server/pae_disable.yml +15 -0
  77. data/test/vcr_cassettes/server/pae_enable.yml +15 -0
  78. data/test/vcr_cassettes/server/reboot.yml +15 -0
  79. data/test/vcr_cassettes/server/rebuild.yml +15 -0
  80. data/test/vcr_cassettes/server/resume.yml +15 -0
  81. data/test/vcr_cassettes/server/shutdown.yml +15 -0
  82. data/test/vcr_cassettes/server/status.yml +15 -0
  83. data/test/vcr_cassettes/server/suspend.yml +15 -0
  84. data/test/vcr_cassettes/server/terminate.yml +27 -0
  85. data/test/vcr_cassettes/server/tun_disable.yml +15 -0
  86. data/test/vcr_cassettes/server/tun_enable.yml +15 -0
  87. data/test/vcr_cassettes/server/unmountiso.yml +15 -0
  88. data/test/vcr_cassettes/server/vnc.yml +15 -0
  89. metadata +220 -156
  90. data/.rbenv-version +0 -1
  91. data/.rvmrc +0 -47
  92. data/test/fixtures/base_bad_key.txt +0 -1
  93. data/test/fixtures/base_node_does_not_exist.txt +0 -1
  94. data/test/fixtures/base_unauthorized_ip.txt +0 -1
  95. data/test/fixtures/client_authenticate_error.txt +0 -2
  96. data/test/fixtures/client_authenticate_success.txt +0 -2
  97. data/test/fixtures/client_change_password_error.txt +0 -2
  98. data/test/fixtures/client_change_password_success.txt +0 -4
  99. data/test/fixtures/client_create_error.txt +0 -2
  100. data/test/fixtures/client_create_success.txt +0 -7
  101. data/test/fixtures/client_delete_success.txt +0 -2
  102. data/test/fixtures/client_exists_success.txt +0 -2
  103. data/test/fixtures/client_list_success.txt +0 -14
  104. data/test/fixtures/client_list_success_empty.txt +0 -2
  105. data/test/fixtures/error.txt +0 -2
  106. data/test/fixtures/general_isos_success.txt +0 -3
  107. data/test/fixtures/general_plans_success.txt +0 -3
  108. data/test/fixtures/general_templates_success.txt +0 -3
  109. data/test/fixtures/node_list_all_ips_available.txt +0 -4
  110. data/test/fixtures/node_list_all_ips_not_available.txt +0 -4
  111. data/test/fixtures/node_statistics_success.txt +0 -14
  112. data/test/fixtures/node_virtualservers_success.txt +0 -15
  113. data/test/fixtures/node_virtualservers_success_empty.txt +0 -2
  114. data/test/fixtures/node_xenresources_success.txt +0 -4
  115. data/test/fixtures/nodes_ids_success.txt +0 -3
  116. data/test/fixtures/nodes_list_success.txt +0 -3
  117. data/test/fixtures/reseller_change_resources_success.txt +0 -16
  118. data/test/fixtures/reseller_create_success.txt +0 -23
  119. data/test/fixtures/reseller_delete_success.txt +0 -2
  120. data/test/fixtures/reseller_info_success.txt +0 -23
  121. data/test/fixtures/reseller_list_success.txt +0 -3
  122. data/test/fixtures/server_boot_success.txt +0 -2
  123. data/test/fixtures/server_bootorder_success.txt +0 -2
  124. data/test/fixtures/server_change_consolepass_success.txt +0 -3
  125. data/test/fixtures/server_change_owner_success.txt +0 -2
  126. data/test/fixtures/server_change_success.txt +0 -2
  127. data/test/fixtures/server_change_vncpass_success.txt +0 -3
  128. data/test/fixtures/server_console_success.txt +0 -7
  129. data/test/fixtures/server_create_success.txt +0 -10
  130. data/test/fixtures/server_exists_success.txt +0 -2
  131. data/test/fixtures/server_hostname_success.txt +0 -3
  132. data/test/fixtures/server_info_success.txt +0 -10
  133. data/test/fixtures/server_infoall_success.txt +0 -13
  134. data/test/fixtures/server_mountiso_success.txt +0 -2
  135. data/test/fixtures/server_network_disable_success.txt +0 -2
  136. data/test/fixtures/server_network_enable_success.txt +0 -2
  137. data/test/fixtures/server_pae_success.txt +0 -2
  138. data/test/fixtures/server_reboot_success.txt +0 -2
  139. data/test/fixtures/server_rebuild_success.txt +0 -2
  140. data/test/fixtures/server_resume_success.txt +0 -2
  141. data/test/fixtures/server_rootpassword_success.txt +0 -3
  142. data/test/fixtures/server_shutdown_success.txt +0 -2
  143. data/test/fixtures/server_status_success.txt +0 -2
  144. data/test/fixtures/server_suspend_success.txt +0 -2
  145. data/test/fixtures/server_terminate_success.txt +0 -2
  146. data/test/fixtures/server_tun_disable_success.txt +0 -2
  147. data/test/fixtures/server_tun_enable_success.txt +0 -2
  148. data/test/fixtures/server_unmountiso_success.txt +0 -2
  149. data/test/fixtures/server_vnc_success.txt +0 -6
  150. data/test/test_base.rb +0 -115
  151. data/test/test_client.rb +0 -98
  152. data/test/test_general.rb +0 -70
  153. data/test/test_node.rb +0 -112
  154. data/test/test_reseller.rb +0 -80
  155. data/test/test_server.rb +0 -227
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'test_helper'
2
2
  require 'solusvm/cli'
3
3
 
4
4
  class TestServerCli < Test::Unit::TestCase
@@ -11,7 +11,10 @@ class TestServerCli < Test::Unit::TestCase
11
11
 
12
12
  def test_should_delegate_server_status_to_server
13
13
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
14
- Solusvm::Server.stubs(:new => mock{ expects(:status).with("thevserverid").returns("theresult") })
14
+ Solusvm::Server.stubs(:new => mock do
15
+ expects(:successful?).returns(true)
16
+ expects(:status).with("thevserverid").returns("theresult")
17
+ end)
15
18
 
16
19
  $stdout.expects(:puts).with("theresult")
17
20
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "status", "thevserverid"]))
@@ -19,7 +22,10 @@ class TestServerCli < Test::Unit::TestCase
19
22
 
20
23
  def test_should_delegate_server_change_plan_to_server
21
24
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
22
- Solusvm::Server.stubs(:new => mock{ expects(:change_plan).with("thevserverid", "thenewplan").returns("theresult") })
25
+ Solusvm::Server.stubs(:new => mock do
26
+ expects(:successful?).returns(true)
27
+ expects(:change_plan).with("thevserverid", "thenewplan").returns("theresult")
28
+ end)
23
29
 
24
30
  $stdout.expects(:puts).with("theresult")
25
31
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "change-plan", "thevserverid", "thenewplan"]))
@@ -27,7 +33,10 @@ class TestServerCli < Test::Unit::TestCase
27
33
 
28
34
  def test_should_delegate_server_change_owner_to_server
29
35
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
30
- Solusvm::Server.stubs(:new => mock{ expects(:change_owner).with("thevserverid", "thenewowner").returns("theresult") })
36
+ Solusvm::Server.stubs(:new => mock do
37
+ expects(:successful?).returns(true)
38
+ expects(:change_owner).with("thevserverid", "thenewowner").returns("theresult")
39
+ end)
31
40
 
32
41
  $stdout.expects(:puts).with("theresult")
33
42
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "change-owner", "thevserverid", "thenewowner"]))
@@ -35,7 +44,10 @@ class TestServerCli < Test::Unit::TestCase
35
44
 
36
45
  def test_should_delegate_server_change_consolepass_to_server
37
46
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
38
- Solusvm::Server.stubs(:new => mock{ expects(:change_consolepass).with("thevserverid", "thenewpass").returns("theresult") })
47
+ Solusvm::Server.stubs(:new => mock do
48
+ expects(:successful?).returns(true)
49
+ expects(:change_consolepass).with("thevserverid", "thenewpass").returns("theresult")
50
+ end)
39
51
 
40
52
  $stdout.expects(:puts).with("theresult")
41
53
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "change-consolepass", "thevserverid", "thenewpass"]))
@@ -43,7 +55,10 @@ class TestServerCli < Test::Unit::TestCase
43
55
 
44
56
  def test_should_delegate_server_change_vncpass_to_server
45
57
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
46
- Solusvm::Server.stubs(:new => mock{ expects(:change_vncpass).with("thevserverid", "thenewpass").returns("theresult") })
58
+ Solusvm::Server.stubs(:new => mock do
59
+ expects(:successful?).returns(true)
60
+ expects(:change_vncpass).with("thevserverid", "thenewpass").returns("theresult")
61
+ end)
47
62
 
48
63
  $stdout.expects(:puts).with("theresult")
49
64
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "change-vncpass", "thevserverid", "thenewpass"]))
@@ -51,7 +66,10 @@ class TestServerCli < Test::Unit::TestCase
51
66
 
52
67
  def test_should_delegate_server_change_rootpass_to_server
53
68
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
54
- Solusvm::Server.stubs(:new => mock{ expects(:change_rootpassword).with("thevserverid", "thenewpass").returns("theresult") })
69
+ Solusvm::Server.stubs(:new => mock do
70
+ expects(:successful?).returns(true)
71
+ expects(:change_rootpassword).with("thevserverid", "thenewpass").returns("theresult")
72
+ end)
55
73
 
56
74
  $stdout.expects(:puts).with("theresult")
57
75
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "change-rootpass", "thevserverid", "thenewpass"]))
@@ -59,7 +77,10 @@ class TestServerCli < Test::Unit::TestCase
59
77
 
60
78
  def test_should_delegate_server_change_bootorder_to_server
61
79
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
62
- Solusvm::Server.stubs(:new => mock{ expects(:change_bootorder).with("thevserverid", "theneworder").returns("theresult") })
80
+ Solusvm::Server.stubs(:new => mock do
81
+ expects(:successful?).returns(true)
82
+ expects(:change_bootorder).with("thevserverid", "theneworder").returns("theresult")
83
+ end)
63
84
 
64
85
  $stdout.expects(:puts).with("theresult")
65
86
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "change-bootorder", "thevserverid", "theneworder"]))
@@ -67,7 +88,10 @@ class TestServerCli < Test::Unit::TestCase
67
88
 
68
89
  def test_should_delegate_server_change_hostname_to_server
69
90
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
70
- Solusvm::Server.stubs(:new => mock{ expects(:change_hostname).with("thevserverid", "thenewhostname").returns("theresult") })
91
+ Solusvm::Server.stubs(:new => mock do
92
+ expects(:successful?).returns(true)
93
+ expects(:change_hostname).with("thevserverid", "thenewhostname").returns("theresult")
94
+ end)
71
95
 
72
96
  $stdout.expects(:puts).with("theresult")
73
97
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "change-hostname", "thevserverid", "thenewhostname"]))
@@ -75,7 +99,10 @@ class TestServerCli < Test::Unit::TestCase
75
99
 
76
100
  def test_should_delegate_server_add_ip_to_server
77
101
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
78
- Solusvm::Server.stubs(:new => mock{ expects(:add_ip).with("thevserverid").returns("theresult") })
102
+ Solusvm::Server.stubs(:new => mock do
103
+ expects(:successful?).returns(true)
104
+ expects(:add_ip).with("thevserverid").returns("theresult")
105
+ end)
79
106
 
80
107
  $stdout.expects(:puts).with("theresult")
81
108
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "addip", "thevserverid"]))
@@ -83,7 +110,10 @@ class TestServerCli < Test::Unit::TestCase
83
110
 
84
111
  def test_should_delegate_server_boot_to_server
85
112
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
86
- Solusvm::Server.stubs(:new => mock{ expects(:boot).with("thevserverid").returns("theresult") })
113
+ Solusvm::Server.stubs(:new => mock do
114
+ expects(:successful?).returns(true)
115
+ expects(:boot).with("thevserverid").returns("theresult")
116
+ end)
87
117
 
88
118
  $stdout.expects(:puts).with("theresult")
89
119
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "boot", "thevserverid"]))
@@ -91,7 +121,10 @@ class TestServerCli < Test::Unit::TestCase
91
121
 
92
122
  def test_should_delegate_server_reboot_to_server
93
123
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
94
- Solusvm::Server.stubs(:new => mock{ expects(:reboot).with("thevserverid").returns("theresult") })
124
+ Solusvm::Server.stubs(:new => mock do
125
+ expects(:successful?).returns(true)
126
+ expects(:reboot).with("thevserverid").returns("theresult")
127
+ end)
95
128
 
96
129
  $stdout.expects(:puts).with("theresult")
97
130
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "reboot", "thevserverid"]))
@@ -99,7 +132,10 @@ class TestServerCli < Test::Unit::TestCase
99
132
 
100
133
  def test_should_delegate_server_shutdown_to_server
101
134
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
102
- Solusvm::Server.stubs(:new => mock{ expects(:shutdown).with("thevserverid").returns("theresult") })
135
+ Solusvm::Server.stubs(:new => mock do
136
+ expects(:successful?).returns(true)
137
+ expects(:shutdown).with("thevserverid").returns("theresult")
138
+ end)
103
139
 
104
140
  $stdout.expects(:puts).with("theresult")
105
141
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "shutdown", "thevserverid"]))
@@ -107,7 +143,10 @@ class TestServerCli < Test::Unit::TestCase
107
143
 
108
144
  def test_should_delegate_server_suspend_to_server
109
145
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
110
- Solusvm::Server.stubs(:new => mock{ expects(:suspend).with("thevserverid").returns("theresult") })
146
+ Solusvm::Server.stubs(:new => mock do
147
+ expects(:successful?).returns(true)
148
+ expects(:suspend).with("thevserverid").returns("theresult")
149
+ end)
111
150
 
112
151
  $stdout.expects(:puts).with("theresult")
113
152
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "suspend", "thevserverid"]))
@@ -115,7 +154,10 @@ class TestServerCli < Test::Unit::TestCase
115
154
 
116
155
  def test_should_delegate_server_resume_to_server
117
156
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
118
- Solusvm::Server.stubs(:new => mock{ expects(:resume).with("thevserverid").returns("theresult") })
157
+ Solusvm::Server.stubs(:new => mock do
158
+ expects(:successful?).returns(true)
159
+ expects(:resume).with("thevserverid").returns("theresult")
160
+ end)
119
161
 
120
162
  $stdout.expects(:puts).with("theresult")
121
163
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "resume", "thevserverid"]))
@@ -123,7 +165,10 @@ class TestServerCli < Test::Unit::TestCase
123
165
 
124
166
  def test_should_delegate_server_check_exists_to_server
125
167
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
126
- Solusvm::Server.stubs(:new => mock{ expects(:check_exists).with("thevserverid").returns("theresult") })
168
+ Solusvm::Server.stubs(:new => mock do
169
+ expects(:successful?).returns(true)
170
+ expects(:exists?).with("thevserverid").returns("theresult")
171
+ end)
127
172
 
128
173
  $stdout.expects(:puts).with("theresult")
129
174
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "check-exists", "thevserverid"]))
@@ -131,7 +176,10 @@ class TestServerCli < Test::Unit::TestCase
131
176
 
132
177
  def test_should_delegate_server_terminate_to_server
133
178
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
134
- Solusvm::Server.stubs(:new => mock{ expects(:terminate).with("thevserverid").returns("theresult") })
179
+ Solusvm::Server.stubs(:new => mock do
180
+ expects(:successful?).returns(true)
181
+ expects(:terminate).with("thevserverid").returns("theresult")
182
+ end)
135
183
 
136
184
  $stdout.expects(:puts).with("theresult")
137
185
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "terminate", "thevserverid"]))
@@ -139,8 +187,10 @@ class TestServerCli < Test::Unit::TestCase
139
187
 
140
188
  def test_should_delegate_server_rebuild_to_server
141
189
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
142
- Solusvm::Server.stubs(:new => mock{ expects(:rebuild).with(
143
- "thevserverid", :template => "thetemplate").returns("theresult") })
190
+ Solusvm::Server.stubs(:new => mock do
191
+ expects(:successful?).returns(true)
192
+ expects(:rebuild).with("thevserverid", :template => "thetemplate").returns("theresult")
193
+ end)
144
194
 
145
195
  $stdout.expects(:puts).with("theresult")
146
196
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "rebuild", "thevserverid", "--template", "thetemplate"]))
@@ -148,7 +198,10 @@ class TestServerCli < Test::Unit::TestCase
148
198
 
149
199
  def test_should_delegate_server_tun_switcher_on_to_server
150
200
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
151
- Solusvm::Server.stubs(:new => mock{ expects(:tun_enable).with("thevserverid").returns("theresult") })
201
+ Solusvm::Server.stubs(:new => mock do
202
+ expects(:successful?).returns(true)
203
+ expects(:tun_enable).with("thevserverid").returns("theresult")
204
+ end)
152
205
 
153
206
  $stdout.expects(:puts).with("theresult")
154
207
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "tun-switcher", "thevserverid", "on"]))
@@ -156,7 +209,10 @@ class TestServerCli < Test::Unit::TestCase
156
209
 
157
210
  def test_should_delegate_server_tun_switcher_off_to_server
158
211
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
159
- Solusvm::Server.stubs(:new => mock{ expects(:tun_disable).with("thevserverid").returns("theresult") })
212
+ Solusvm::Server.stubs(:new => mock do
213
+ expects(:successful?).returns(true)
214
+ expects(:tun_disable).with("thevserverid").returns("theresult")
215
+ end)
160
216
 
161
217
  $stdout.expects(:puts).with("theresult")
162
218
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "tun-switcher", "thevserverid", "off"]))
@@ -164,7 +220,10 @@ class TestServerCli < Test::Unit::TestCase
164
220
 
165
221
  def test_should_delegate_server_network_switcher_on_to_server
166
222
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
167
- Solusvm::Server.stubs(:new => mock{ expects(:network_enable).with("thevserverid").returns("theresult") })
223
+ Solusvm::Server.stubs(:new => mock do
224
+ expects(:successful?).returns(true)
225
+ expects(:network_enable).with("thevserverid").returns("theresult")
226
+ end)
168
227
 
169
228
  $stdout.expects(:puts).with("theresult")
170
229
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "network-switcher", "thevserverid", "on"]))
@@ -172,7 +231,10 @@ class TestServerCli < Test::Unit::TestCase
172
231
 
173
232
  def test_should_delegate_server_network_switcher_off_to_server
174
233
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
175
- Solusvm::Server.stubs(:new => mock{ expects(:network_disable).with("thevserverid").returns("theresult") })
234
+ Solusvm::Server.stubs(:new => mock do
235
+ expects(:successful?).returns(true)
236
+ expects(:network_disable).with("thevserverid").returns("theresult")
237
+ end)
176
238
 
177
239
  $stdout.expects(:puts).with("theresult")
178
240
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "network-switcher", "thevserverid", "off"]))
@@ -180,7 +242,10 @@ class TestServerCli < Test::Unit::TestCase
180
242
 
181
243
  def test_should_delegate_server_pae_switcher_on_to_server
182
244
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
183
- Solusvm::Server.stubs(:new => mock{ expects(:pae_enable).with("thevserverid").returns("theresult") })
245
+ Solusvm::Server.stubs(:new => mock do
246
+ expects(:successful?).returns(true)
247
+ expects(:pae_enable).with("thevserverid").returns("theresult")
248
+ end)
184
249
 
185
250
  $stdout.expects(:puts).with("theresult")
186
251
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "pae-switcher", "thevserverid", "on"]))
@@ -188,7 +253,10 @@ class TestServerCli < Test::Unit::TestCase
188
253
 
189
254
  def test_should_delegate_server_pae_switcher_off_to_server
190
255
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
191
- Solusvm::Server.stubs(:new => mock{ expects(:pae_disable).with("thevserverid").returns("theresult") })
256
+ Solusvm::Server.stubs(:new => mock do
257
+ expects(:successful?).returns(true)
258
+ expects(:pae_disable).with("thevserverid").returns("theresult")
259
+ end)
192
260
 
193
261
  $stdout.expects(:puts).with("theresult")
194
262
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "pae-switcher", "thevserverid", "off"]))
@@ -196,7 +264,10 @@ class TestServerCli < Test::Unit::TestCase
196
264
 
197
265
  def test_should_delegate_server_info_to_server
198
266
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
199
- Solusvm::Server.stubs(:new => mock{ expects(:info).with("thevserverid").returns("theresult") })
267
+ Solusvm::Server.stubs(:new => mock do
268
+ expects(:successful?).returns(true)
269
+ expects(:info).with("thevserverid").returns("theresult")
270
+ end)
200
271
 
201
272
  $stdout.expects(:puts).with("theresult")
202
273
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "info", "thevserverid"]))
@@ -204,7 +275,10 @@ class TestServerCli < Test::Unit::TestCase
204
275
 
205
276
  def test_should_delegate_server_vnc_to_server
206
277
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
207
- Solusvm::Server.stubs(:new => mock{ expects(:vnc).with("thevserverid").returns("theresult") })
278
+ Solusvm::Server.stubs(:new => mock do
279
+ expects(:successful?).returns(true)
280
+ expects(:vnc).with("thevserverid").returns("theresult")
281
+ end)
208
282
 
209
283
  $stdout.expects(:puts).with("theresult")
210
284
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "vnc", "thevserverid"]))
@@ -212,7 +286,10 @@ class TestServerCli < Test::Unit::TestCase
212
286
 
213
287
  def test_should_delegate_server_console_to_server
214
288
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
215
- Solusvm::Server.stubs(:new => mock{ expects(:console).with("thevserverid").returns("theresult") })
289
+ Solusvm::Server.stubs(:new => mock do
290
+ expects(:successful?).returns(true)
291
+ expects(:console).with("thevserverid").returns("theresult")
292
+ end)
216
293
 
217
294
  $stdout.expects(:puts).with("theresult")
218
295
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "console", "thevserverid"]))
@@ -220,7 +297,10 @@ class TestServerCli < Test::Unit::TestCase
220
297
 
221
298
  def test_should_delegate_server_info_all_to_server
222
299
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
223
- Solusvm::Server.stubs(:new => mock{ expects(:info_all).with("thevserverid").returns("theresult") })
300
+ Solusvm::Server.stubs(:new => mock do
301
+ expects(:successful?).returns(true)
302
+ expects(:info_all).with("thevserverid").returns("theresult")
303
+ end)
224
304
 
225
305
  $stdout.expects(:puts).with("theresult")
226
306
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "info-all", "thevserverid"]))
@@ -228,7 +308,10 @@ class TestServerCli < Test::Unit::TestCase
228
308
 
229
309
  def test_should_delegate_server_mountiso_to_server
230
310
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
231
- Solusvm::Server.stubs(:new => mock{ expects(:mountiso).with("thevserverid", "theiso").returns("theresult") })
311
+ Solusvm::Server.stubs(:new => mock do
312
+ expects(:successful?).returns(true)
313
+ expects(:mountiso).with("thevserverid", "theiso").returns("theresult")
314
+ end)
232
315
 
233
316
  $stdout.expects(:puts).with("theresult")
234
317
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "mountiso", "thevserverid", "theiso"]))
@@ -236,7 +319,10 @@ class TestServerCli < Test::Unit::TestCase
236
319
 
237
320
  def test_should_delegate_server_unmountiso_to_server
238
321
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
239
- Solusvm::Server.stubs(:new => mock{ expects(:unmountiso).with("thevserverid").returns("theresult") })
322
+ Solusvm::Server.stubs(:new => mock do
323
+ expects(:successful?).returns(true)
324
+ expects(:unmountiso).with("thevserverid").returns("theresult")
325
+ end)
240
326
 
241
327
  $stdout.expects(:puts).with("theresult")
242
328
  Solusvm::Cli.start(cli_expand_base_arguments(["server", "unmountiso", "thevserverid"]))
@@ -244,17 +330,20 @@ class TestServerCli < Test::Unit::TestCase
244
330
 
245
331
  def test_should_delegate_server_create_to_server
246
332
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
247
- Solusvm::Server.stubs(:new => mock{ expects(:create).with(
248
- "thehostname", "thepassword",
249
- :plan => "theplan", :ips => "theips", :type => "thekind",
250
- :username => "theusername", :template => "thetemplate", :node => "thenode"
251
- ).returns("theresult") })
333
+ Solusvm::Server.stubs(:new => mock do
334
+ expects(:successful?).returns(true)
335
+ expects(:create).with(
336
+ "thehostname", "thepassword",
337
+ :plan => "theplan", :ips => "theips", :type => "thekind",
338
+ :username => "theusername", :template => "thetemplate", :node => "thenode"
339
+ ).returns("theresult")
340
+ end)
252
341
 
253
342
  $stdout.expects(:puts).with("theresult")
254
343
  Solusvm::Cli.start(cli_expand_base_arguments([
255
- "server", "create",
256
- "thehostname",
257
- "thepassword",
344
+ "server", "create",
345
+ "thehostname",
346
+ "thepassword",
258
347
  "--plan", "theplan",
259
348
  "--ips", "theips",
260
349
  "--kind", "thekind",
@@ -0,0 +1,103 @@
1
+ require 'test_helper'
2
+
3
+ class TestBase < Test::Unit::TestCase
4
+
5
+ def setup
6
+ setup_solusvm
7
+ @base = Solusvm::Base.new
8
+ end
9
+
10
+ def test_valid_server_types
11
+ assert_equal 3, Solusvm::Base::VALID_SERVER_TYPES.size
12
+ assert_equal ['openvz', 'xen', 'xen hvm'].sort, Solusvm::Base::VALID_SERVER_TYPES.sort
13
+ end
14
+
15
+ def test_parse_response
16
+ assert_nil @base.returned_parameters
17
+ VCR.use_cassette "base/parse_response" do
18
+ @base.perform_request(:action => 'test', :vserverid => 1)
19
+ end
20
+ params = @base.returned_parameters
21
+
22
+ assert_equal 10, params.size
23
+ assert_equal '123.123.123.123', params['mainipaddress']
24
+ assert_equal 'console-123', params['consoleuser']
25
+ assert_equal '100', params['vserverid']
26
+ assert_equal 'Virtual server created', params['statusmsg']
27
+ assert_equal 'vm101|101', params['virtid']
28
+ assert_equal '123456', params['consolepassword']
29
+ assert_equal '122.122.122.122,111.111.111.111', params['extraipaddress']
30
+ assert_equal 'server.hostname.com', params['hostname']
31
+ assert_equal '123456', params['rootpassword']
32
+ assert_equal 'success', params['status']
33
+ end
34
+
35
+ def test_successful
36
+ VCR.use_cassette "base/successful" do
37
+ @base.perform_request(:action => 'testsuccess', :vserverid => 1)
38
+ assert @base.successful?
39
+
40
+ @base.perform_request(:action => 'testfail', :vserverid => 1)
41
+ assert_equal "error message", @base.statusmsg
42
+ end
43
+ end
44
+
45
+ def test_api_login
46
+ assert_equal api_login, @base.api_login
47
+ end
48
+
49
+ def test_statusmsg
50
+ VCR.use_cassette "base/statusmsg" do
51
+ @base.perform_request(:action => 'testsuccess', :vserverid => 1)
52
+ end
53
+ assert_equal 'Virtual server created', @base.statusmsg
54
+ end
55
+
56
+ def test_validate_server_type
57
+ Solusvm::Base::VALID_SERVER_TYPES.each do |type|
58
+ assert_nothing_raised do
59
+ @base.validate_server_type!(type)
60
+ end
61
+ end
62
+
63
+ begin
64
+ @base.validate_server_type!('bob')
65
+ flunk "Shouldn't get here"
66
+ rescue Solusvm::SolusvmError => e
67
+ assert_equal 'Invalid Virtual Server type: bob', e.message
68
+ end
69
+ end
70
+
71
+ def test_unautorized_ip
72
+ VCR.use_cassette "base/unauthorized_ip" do
73
+ assert_raise RuntimeError do
74
+ @base.perform_request(:action => 'unauthorized')
75
+ end
76
+ end
77
+ end
78
+
79
+ def test_invalid_key_or_id
80
+ VCR.use_cassette "base/invalid_key" do
81
+ assert_raise RuntimeError do
82
+ @base.perform_request(:action => 'badkey')
83
+ end
84
+ end
85
+ end
86
+
87
+ def test_node_does_not_exist
88
+ VCR.use_cassette "base/nonexistent_node" do
89
+ assert_raise RuntimeError do
90
+ @base.perform_request(:action => 'nodeexist')
91
+ end
92
+ end
93
+ end
94
+
95
+ def test_invalid_http_status
96
+ VCR.use_cassette "base/invalid_status" do
97
+ assert_raise Solusvm::SolusvmError do
98
+ @base.perform_request(:action => 'httperror')
99
+ end
100
+ end
101
+
102
+ end
103
+ end