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
@@ -0,0 +1,22 @@
1
+ module Solusvm
2
+ class SolusvmErrors < Faraday::Response::Middleware
3
+
4
+ def on_complete(env)
5
+ if (200..299).include? env[:status]
6
+ # Checks for application errors
7
+ case env[:body].downcase
8
+ when /invalid ipaddress/i
9
+ raise "This IP is not authorized to use the API"
10
+ when /Invalid id or key/i
11
+ raise "Invalid ID or key"
12
+ when /Node not found/i
13
+ raise "Node does not exist"
14
+ end
15
+ else
16
+ raise SolusvmError, "Bad HTTP Status: #{env[:status]}"
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Solusvm
2
- VERSION = "1.0.0.beta3"
2
+ VERSION = "1.1.0.beta1"
3
3
  end
data/solusvm.gemspec CHANGED
@@ -20,10 +20,12 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_runtime_dependency 'xml-simple', '~> 1.1.1'
22
22
  s.add_runtime_dependency 'thor', '~> 0.14.6'
23
+ s.add_runtime_dependency 'faraday', '~> 0.8.0rc2'
23
24
  s.add_runtime_dependency 'jruby-openssl' if RUBY_PLATFORM == 'java'
24
25
 
25
26
  s.add_development_dependency 'redgreen', '~> 1.2.2'
26
27
  s.add_development_dependency 'fakeweb', '~> 1.3.0'
28
+ s.add_development_dependency 'vcr', '~> 2.0.0'
27
29
  s.add_development_dependency 'mocha', '~> 0.10.3'
28
30
  s.add_development_dependency 'rdoc', '~> 3.12'
29
31
  s.add_development_dependency 'rake', '~> 0.9.2.2'
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+ require 'solusvm/cli'
3
+
4
+ class TestBaseCli < Test::Unit::TestCase
5
+
6
+ def setup
7
+ # Prevents mocha from stubbing non existent methods so that we now if the CLI is failing because
8
+ # something was moved around.
9
+ Mocha::Configuration.prevent(:stubbing_non_existent_method)
10
+
11
+ @base_cli = Solusvm::BaseCli.new
12
+ @api = Solusvm::Base.new
13
+
14
+ @base_cli.stubs(:api).returns(@api)
15
+ end
16
+
17
+ def test_should_print_multiple_lines_if_enumerable
18
+ @api.stubs(:successful?).returns(true)
19
+ @base_cli.expects(:say).with("val1", nil, true)
20
+ @base_cli.expects(:say).with("val2", nil, true)
21
+
22
+ @base_cli.output(["val1", "val2"])
23
+ end
24
+
25
+ def test_should_print_error_if_not_successful
26
+ @api.stubs(:successful?).returns(false)
27
+ @api.stubs(:statusmsg).returns("the message")
28
+ @base_cli.expects(:say).with("Request failed: the message", nil, true)
29
+
30
+ @base_cli.output("result")
31
+ end
32
+ end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'test_helper'
2
2
  require 'solusvm/cli'
3
3
 
4
4
  class TestClientCli < Test::Unit::TestCase
@@ -11,24 +11,26 @@ class TestClientCli < Test::Unit::TestCase
11
11
 
12
12
  def test_should_delegate_client_create_to_client
13
13
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
14
- Solusvm::Client.stubs(:new => mock{ expects(:create).with() do |options|
15
- expected = {
16
- :username => "theusername",
17
- :password => "thepassword",
18
- :email => "theemail",
19
- :firstname => "thefirstname",
20
- :lastname => "thelastname",
21
- :company => "thecompany"
22
- }
23
-
24
- expected.all? { |k,v| options[k] == v }
25
-
26
- end.returns("theresult")
27
- })
14
+ api = mock do
15
+ expects(:successful?).returns(true)
16
+ expects(:create).with() do |options|
17
+ expected = {
18
+ :username => "theusername",
19
+ :password => "thepassword",
20
+ :email => "theemail",
21
+ :firstname => "thefirstname",
22
+ :lastname => "thelastname",
23
+ :company => "thecompany"
24
+ }
25
+
26
+ expected.all? { |k,v| options[k] == v }
27
+ end.returns("theresult")
28
+ end
29
+ Solusvm::Client.stubs(:new => api)
28
30
 
29
31
  $stdout.expects(:puts).with("theresult")
30
32
  Solusvm::Cli.start(cli_expand_base_arguments([
31
- "client", "create",
33
+ "client", "create",
32
34
  "--username", "theusername",
33
35
  "--password", "thepassword",
34
36
  "--email", "theemail",
@@ -40,7 +42,10 @@ class TestClientCli < Test::Unit::TestCase
40
42
 
41
43
  def test_should_delegate_client_change_password_to_client
42
44
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
43
- Solusvm::Client.stubs(:new => mock{ expects(:change_password).with("theusername", "thepassword").returns("theresult") })
45
+ Solusvm::Client.stubs(:new => mock do
46
+ expects(:successful?).returns(true)
47
+ expects(:change_password).with("theusername", "thepassword").returns("theresult")
48
+ end)
44
49
 
45
50
  $stdout.expects(:puts).with("theresult")
46
51
  Solusvm::Cli.start(cli_expand_base_arguments(["client", "change-password", "theusername", "thepassword"]))
@@ -48,7 +53,10 @@ class TestClientCli < Test::Unit::TestCase
48
53
 
49
54
  def test_should_delegate_client_authenticate_to_client
50
55
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
51
- Solusvm::Client.stubs(:new => mock{ expects(:authenticate).with("theusername", "thepassword").returns("theresult") })
56
+ Solusvm::Client.stubs(:new => mock do
57
+ expects(:successful?).returns(true)
58
+ expects(:authenticate).with("theusername", "thepassword").returns("theresult")
59
+ end)
52
60
 
53
61
  $stdout.expects(:puts).with("theresult")
54
62
  Solusvm::Cli.start(cli_expand_base_arguments(["client", "authenticate", "theusername", "thepassword"]))
@@ -56,7 +64,10 @@ class TestClientCli < Test::Unit::TestCase
56
64
 
57
65
  def test_should_delegate_client_check_exists_to_client
58
66
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
59
- Solusvm::Client.stubs(:new => mock{ expects(:exists?).with("theusername").returns("theresult") })
67
+ Solusvm::Client.stubs(:new => mock do
68
+ expects(:successful?).returns(true)
69
+ expects(:exists?).with("theusername").returns("theresult")
70
+ end)
60
71
 
61
72
  $stdout.expects(:puts).with("theresult")
62
73
  Solusvm::Cli.start(cli_expand_base_arguments(["client", "check-exists", "theusername"]))
@@ -64,7 +75,10 @@ class TestClientCli < Test::Unit::TestCase
64
75
 
65
76
  def test_should_delegate_client_delete_to_client
66
77
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
67
- Solusvm::Client.stubs(:new => mock{ expects(:delete).with("theusername").returns("theresult") })
78
+ Solusvm::Client.stubs(:new => mock do
79
+ expects(:successful?).returns(true)
80
+ expects(:delete).with("theusername").returns("theresult")
81
+ end)
68
82
 
69
83
  $stdout.expects(:puts).with("theresult")
70
84
  Solusvm::Cli.start(cli_expand_base_arguments(["client", "delete", "theusername"]))
@@ -72,7 +86,10 @@ class TestClientCli < Test::Unit::TestCase
72
86
 
73
87
  def test_should_delegate_client_list_to_client
74
88
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
75
- Solusvm::Client.stubs(:new => mock{ expects(:list).returns("theresult") })
89
+ Solusvm::Client.stubs(:new => mock do
90
+ expects(:successful?).returns(true)
91
+ expects(:list).returns("theresult")
92
+ end)
76
93
 
77
94
  $stdout.expects(:puts).with("theresult")
78
95
  Solusvm::Cli.start(cli_expand_base_arguments(["client", "list"]))
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'test_helper'
2
2
  require 'solusvm/cli'
3
3
 
4
4
  class TestGeneralCli < Test::Unit::TestCase
@@ -11,7 +11,10 @@ class TestGeneralCli < Test::Unit::TestCase
11
11
 
12
12
  def test_should_delegate_templates_to_general
13
13
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
14
- Solusvm::General.stubs(:new => mock{ expects(:templates).with("type").returns("thetemplates")})
14
+ Solusvm::General.stubs(:new => mock do
15
+ expects(:successful?).returns(true)
16
+ expects(:templates).with("type").returns("thetemplates")
17
+ end)
15
18
 
16
19
  $stdout.expects(:puts).with("thetemplates")
17
20
  Solusvm::Cli.start(cli_expand_base_arguments(["general", "templates", "type"]))
@@ -19,7 +22,10 @@ class TestGeneralCli < Test::Unit::TestCase
19
22
 
20
23
  def test_should_delegate_plans_to_general
21
24
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
22
- Solusvm::General.stubs(:new => mock{ expects(:plans).with("type").returns("theplans")})
25
+ Solusvm::General.stubs(:new => mock do
26
+ expects(:successful?).returns(true)
27
+ expects(:plans).with("type").returns("theplans")
28
+ end)
23
29
 
24
30
  $stdout.expects(:puts).with("theplans")
25
31
  Solusvm::Cli.start(cli_expand_base_arguments(["general", "plans", "type"]))
@@ -27,7 +33,10 @@ class TestGeneralCli < Test::Unit::TestCase
27
33
 
28
34
  def test_should_delegate_isos_to_general
29
35
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
30
- Solusvm::General.stubs(:new => mock{ expects(:isos).with("type").returns("theisos")})
36
+ Solusvm::General.stubs(:new => mock do
37
+ expects(:successful?).returns(true)
38
+ expects(:isos).with("type").returns("theisos")
39
+ end)
31
40
 
32
41
  $stdout.expects(:puts).with("theisos")
33
42
  Solusvm::Cli.start(cli_expand_base_arguments(["general", "isos", "type"]))
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'test_helper'
2
2
  require 'solusvm/cli'
3
3
 
4
4
  class TestNodeCli < Test::Unit::TestCase
@@ -11,35 +11,43 @@ class TestNodeCli < Test::Unit::TestCase
11
11
 
12
12
  def test_should_delegate_node_available_ips_to_node
13
13
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
14
- Solusvm::Node.stubs(:new => mock{ expects(:available_ips).with("thevserverid").returns(["ip1", "ip2"]) })
14
+ Solusvm::Node.stubs(:new => mock do
15
+ expects(:successful?).returns(true)
16
+ expects(:available_ips).with("thevserverid").returns("theips")
17
+ end)
15
18
 
16
- $stdout.expects(:puts).with("ip1\nip2")
19
+ $stdout.expects(:puts).with("theips")
17
20
  Solusvm::Cli.start(cli_expand_base_arguments(["node", "available-ips", "thevserverid"]))
18
21
  end
19
22
 
20
23
  def test_should_delegate_node_stats_to_node
21
24
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
22
- Solusvm::Node.stubs(:new => mock{ expects(:statistics).with("thevserverid").returns({
23
- :stat1 => "val1", :stat2 => "val2"
24
- })})
25
+ Solusvm::Node.stubs(:new => mock do
26
+ expects(:successful?).returns(true)
27
+ expects(:statistics).with("thevserverid").returns("thestats")
28
+ end)
25
29
 
26
- $stdout.expects(:puts).with("stat1 => val1\nstat2 => val2")
30
+ $stdout.expects(:puts).with("thestats")
27
31
  Solusvm::Cli.start(cli_expand_base_arguments(["node", "stats", "thevserverid"]))
28
32
  end
29
33
 
30
34
  def test_should_delegate_node_xenresources_to_node
31
35
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
32
- Solusvm::Node.stubs(:new => mock{ expects(:xenresources).with("thevserverid").returns({
33
- :stat1 => "val1", :stat2 => "val2"
34
- })})
36
+ Solusvm::Node.stubs(:new => mock do
37
+ expects(:successful?).returns(true)
38
+ expects(:xenresources).with("thevserverid").returns("theresources")
39
+ end)
35
40
 
36
- $stdout.expects(:puts).with("stat1 => val1\nstat2 => val2")
41
+ $stdout.expects(:puts).with("theresources")
37
42
  Solusvm::Cli.start(cli_expand_base_arguments(["node", "xenresources", "thevserverid"]))
38
43
  end
39
44
 
40
45
  def test_should_delegate_node_virtualservers_to_node
41
46
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
42
- Solusvm::Node.stubs(:new => mock{ expects(:virtualservers).with("thevserverid").returns("thedata")})
47
+ Solusvm::Node.stubs(:new => mock do
48
+ expects(:successful?).returns(true)
49
+ expects(:virtualservers).with("thevserverid").returns("thedata")
50
+ end)
43
51
 
44
52
  $stdout.expects(:puts).with("thedata")
45
53
  Solusvm::Cli.start(cli_expand_base_arguments(["node", "virtualservers", "thevserverid"]))
@@ -47,7 +55,10 @@ class TestNodeCli < Test::Unit::TestCase
47
55
 
48
56
  def test_should_delegate_nodes_list_to_node
49
57
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
50
- Solusvm::Node.stubs(:new => mock{ expects(:list).with("type").returns("thenodes")})
58
+ Solusvm::Node.stubs(:new => mock do
59
+ expects(:successful?).returns(true)
60
+ expects(:list).with("type").returns("thenodes")
61
+ end)
51
62
 
52
63
  $stdout.expects(:puts).with("thenodes")
53
64
  Solusvm::Cli.start(cli_expand_base_arguments(["node", "list", "type"]))
@@ -55,7 +66,10 @@ class TestNodeCli < Test::Unit::TestCase
55
66
 
56
67
  def test_should_delegate_nodes_ids_to_node
57
68
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
58
- Solusvm::Node.stubs(:new => mock{ expects(:ids).with("type").returns("thenodes")})
69
+ Solusvm::Node.stubs(:new => mock do
70
+ expects(:successful?).returns(true)
71
+ expects(:ids).with("type").returns("thenodes")
72
+ end)
59
73
 
60
74
  $stdout.expects(:puts).with("thenodes")
61
75
  Solusvm::Cli.start(cli_expand_base_arguments(["node", "list-ids", "type"]))
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'test_helper'
2
2
  require 'solusvm/cli'
3
3
 
4
4
  class TestResellerCli < Test::Unit::TestCase
@@ -11,39 +11,40 @@ class TestResellerCli < Test::Unit::TestCase
11
11
 
12
12
  def test_should_delegate_reseller_create_to_reseller
13
13
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
14
- Solusvm::Reseller.stubs(:new => mock{ expects(:create).with() do |options|
15
- expected = {
16
- :username => "theusername",
17
- :password => "thepassword",
18
- :email => "theemail",
19
- :firstname => "thefirstname",
20
- :lastname => "thelastname",
21
- :company => "thecompany",
22
- :usernameprefix => "theusernameprefix",
23
- :maxvps => "themaxvps",
24
- :maxusers => "themaxusers",
25
- :maxmem => "themaxmem",
26
- :maxburst => "themaxburst",
27
- :maxdisk => "themaxdisk",
28
- :maxbw => "themaxbw",
29
- :maxipv4 => "themaxipv4",
30
- :maxipv6 => "themaxipv6",
31
- :nodegroups => "thenodegroups",
32
- :mediagroups => "themediagroups",
33
- :openvz => "theopenvz",
34
- :xenpv => "thexenpv",
35
- :xenhvm => "thexenhvm",
36
- :kvm => "thekvm"
37
- }
38
-
39
- expected.all? { |k,v| options[k] == v }
40
-
41
- end.returns("theresult")
42
- })
14
+ Solusvm::Reseller.stubs(:new => mock do
15
+ expects(:successful?).returns(true)
16
+ expects(:create).with() do |options|
17
+ expected = {
18
+ :username => "theusername",
19
+ :password => "thepassword",
20
+ :email => "theemail",
21
+ :firstname => "thefirstname",
22
+ :lastname => "thelastname",
23
+ :company => "thecompany",
24
+ :usernameprefix => "theusernameprefix",
25
+ :maxvps => "themaxvps",
26
+ :maxusers => "themaxusers",
27
+ :maxmem => "themaxmem",
28
+ :maxburst => "themaxburst",
29
+ :maxdisk => "themaxdisk",
30
+ :maxbw => "themaxbw",
31
+ :maxipv4 => "themaxipv4",
32
+ :maxipv6 => "themaxipv6",
33
+ :nodegroups => "thenodegroups",
34
+ :mediagroups => "themediagroups",
35
+ :openvz => "theopenvz",
36
+ :xenpv => "thexenpv",
37
+ :xenhvm => "thexenhvm",
38
+ :kvm => "thekvm"
39
+ }
40
+
41
+ expected.all? { |k,v| options[k] == v }
42
+ end.returns("theresult")
43
+ end)
43
44
 
44
45
  $stdout.expects(:puts).with("theresult")
45
46
  Solusvm::Cli.start(cli_expand_base_arguments([
46
- "reseller", "create",
47
+ "reseller", "create",
47
48
  "--username", "theusername",
48
49
  "--password", "thepassword",
49
50
  "--email", "theemail",
@@ -70,32 +71,33 @@ class TestResellerCli < Test::Unit::TestCase
70
71
 
71
72
  def test_should_delegate_reseller_change_resources_to_reseller
72
73
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
73
- Solusvm::Reseller.stubs(:new => mock{ expects(:change_resources).with() do |options|
74
- expected = {
75
- :maxvps => "themaxvps",
76
- :maxusers => "themaxusers",
77
- :maxmem => "themaxmem",
78
- :maxburst => "themaxburst",
79
- :maxdisk => "themaxdisk",
80
- :maxbw => "themaxbw",
81
- :maxipv4 => "themaxipv4",
82
- :maxipv6 => "themaxipv6",
83
- :nodegroups => "thenodegroups",
84
- :mediagroups => "themediagroups",
85
- :openvz => "theopenvz",
86
- :xenpv => "thexenpv",
87
- :xenhvm => "thexenhvm",
88
- :kvm => "thekvm"
89
- }
90
-
91
- expected.all? { |k,v| options[k] == v }
92
-
93
- end.returns("theresult")
94
- })
74
+ Solusvm::Reseller.stubs(:new => mock do
75
+ expects(:successful?).returns(true)
76
+ expects(:change_resources).with() do |options|
77
+ expected = {
78
+ :maxvps => "themaxvps",
79
+ :maxusers => "themaxusers",
80
+ :maxmem => "themaxmem",
81
+ :maxburst => "themaxburst",
82
+ :maxdisk => "themaxdisk",
83
+ :maxbw => "themaxbw",
84
+ :maxipv4 => "themaxipv4",
85
+ :maxipv6 => "themaxipv6",
86
+ :nodegroups => "thenodegroups",
87
+ :mediagroups => "themediagroups",
88
+ :openvz => "theopenvz",
89
+ :xenpv => "thexenpv",
90
+ :xenhvm => "thexenhvm",
91
+ :kvm => "thekvm"
92
+ }
93
+
94
+ expected.all? { |k,v| options[k] == v }
95
+ end.returns("theresult")
96
+ end)
95
97
 
96
98
  $stdout.expects(:puts).with("theresult")
97
99
  Solusvm::Cli.start(cli_expand_base_arguments([
98
- "reseller", "change-resources",
100
+ "reseller", "change-resources",
99
101
  "--maxvps", "themaxvps",
100
102
  "--maxusers", "themaxusers",
101
103
  "--maxmem", "themaxmem",
@@ -115,7 +117,10 @@ class TestResellerCli < Test::Unit::TestCase
115
117
 
116
118
  def test_should_delegate_reseller_info_to_reseller
117
119
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
118
- Solusvm::Reseller.stubs(:new => mock{ expects(:info).with("theusername").returns("theresult") })
120
+ Solusvm::Reseller.stubs(:new => mock do
121
+ expects(:successful?).returns(true)
122
+ expects(:info).with("theusername").returns("theresult")
123
+ end)
119
124
 
120
125
  $stdout.expects(:puts).with("theresult")
121
126
  Solusvm::Cli.start(cli_expand_base_arguments(["reseller", "info", "theusername"]))
@@ -123,7 +128,10 @@ class TestResellerCli < Test::Unit::TestCase
123
128
 
124
129
  def test_should_delegate_reseller_delete_to_reseller
125
130
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
126
- Solusvm::Reseller.stubs(:new => mock{ expects(:delete).with("theusername").returns("theresult") })
131
+ Solusvm::Reseller.stubs(:new => mock do
132
+ expects(:successful?).returns(true)
133
+ expects(:delete).with("theusername").returns("theresult")
134
+ end)
127
135
 
128
136
  $stdout.expects(:puts).with("theresult")
129
137
  Solusvm::Cli.start(cli_expand_base_arguments(["reseller", "delete", "theusername"]))
@@ -131,9 +139,12 @@ class TestResellerCli < Test::Unit::TestCase
131
139
 
132
140
  def test_should_delegate_reseller_list_to_reseller
133
141
  Solusvm.expects(:config).with("thelogin", "thekey", { :url => "theurl" })
134
- Solusvm::Reseller.stubs(:new => mock{ expects(:list).returns("theresult") })
142
+ Solusvm::Reseller.stubs(:new => mock do
143
+ expects(:successful?).returns(true)
144
+ expects(:list).returns("theresult")
145
+ end)
135
146
 
136
147
  $stdout.expects(:puts).with("theresult")
137
148
  Solusvm::Cli.start(cli_expand_base_arguments(["reseller", "list"]))
138
- end
149
+ end
139
150
  end