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.
- data/.gitignore +3 -0
- data/.travis.yml +10 -4
- data/LICENSE +1 -1
- data/README.markdown +1 -1
- data/lib/solusvm.rb +2 -2
- data/lib/solusvm/base.rb +10 -32
- data/lib/solusvm/cli/base_cli.rb +30 -5
- data/lib/solusvm/cli/client_cli.rb +9 -9
- data/lib/solusvm/cli/general_cli.rb +5 -5
- data/lib/solusvm/cli/node_cli.rb +8 -8
- data/lib/solusvm/cli/reseller_cli.rb +7 -7
- data/lib/solusvm/cli/server_cli.rb +31 -31
- data/lib/solusvm/solusvm_errors.rb +22 -0
- data/lib/solusvm/version.rb +1 -1
- data/solusvm.gemspec +2 -0
- data/test/cli/test_base_cli.rb +32 -0
- data/test/cli/test_client_cli.rb +38 -21
- data/test/cli/test_general_cli.rb +13 -4
- data/test/cli/test_node_cli.rb +28 -14
- data/test/cli/test_reseller_cli.rb +69 -58
- data/test/cli/test_server_cli.rb +128 -39
- data/test/solusvm/test_base.rb +103 -0
- data/test/{test_cli.rb → solusvm/test_cli.rb} +1 -1
- data/test/solusvm/test_client.rb +109 -0
- data/test/solusvm/test_general.rb +69 -0
- data/test/{test_hash.rb → solusvm/test_hash.rb} +1 -1
- data/test/solusvm/test_node.rb +120 -0
- data/test/solusvm/test_reseller.rb +93 -0
- data/test/solusvm/test_server.rb +253 -0
- data/test/{helper.rb → test_helper.rb} +19 -4
- data/test/test_solusvm.rb +1 -1
- data/test/vcr_cassettes/base/invalid_key.yml +19 -0
- data/test/vcr_cassettes/base/invalid_status.yml +19 -0
- data/test/vcr_cassettes/base/nonexistent_node.yml +19 -0
- data/test/vcr_cassettes/base/parse_response.yml +28 -0
- data/test/vcr_cassettes/base/statusmsg.yml +28 -0
- data/test/vcr_cassettes/base/successful.yml +45 -0
- data/test/vcr_cassettes/base/unauthorized_ip.yml +19 -0
- data/test/vcr_cassettes/client/authenticate.yml +37 -0
- data/test/vcr_cassettes/client/change_password.yml +39 -0
- data/test/vcr_cassettes/client/create.yml +42 -0
- data/test/vcr_cassettes/client/delete.yml +37 -0
- data/test/vcr_cassettes/client/exists.yml +20 -0
- data/test/vcr_cassettes/client/list.yml +66 -0
- data/test/vcr_cassettes/general/isos.yml +38 -0
- data/test/vcr_cassettes/general/plans.yml +38 -0
- data/test/vcr_cassettes/general/templates.yml +38 -0
- data/test/vcr_cassettes/node/available_ips.yml +41 -0
- data/test/vcr_cassettes/node/ids.yml +21 -0
- data/test/vcr_cassettes/node/list.yml +38 -0
- data/test/vcr_cassettes/node/statistics.yml +32 -0
- data/test/vcr_cassettes/node/virtualservers.yml +67 -0
- data/test/vcr_cassettes/node/xenresources.yml +22 -0
- data/test/vcr_cassettes/reseller/change_resources.yml +27 -0
- data/test/vcr_cassettes/reseller/create.yml +27 -0
- data/test/vcr_cassettes/reseller/delete.yml +15 -0
- data/test/vcr_cassettes/reseller/info.yml +27 -0
- data/test/vcr_cassettes/reseller/list.yml +27 -0
- data/test/vcr_cassettes/server/.yml +1017 -0
- data/test/vcr_cassettes/server/boot.yml +15 -0
- data/test/vcr_cassettes/server/change_bootorder.yml +15 -0
- data/test/vcr_cassettes/server/change_consolepass.yml +16 -0
- data/test/vcr_cassettes/server/change_hostname.yml +15 -0
- data/test/vcr_cassettes/server/change_owner.yml +15 -0
- data/test/vcr_cassettes/server/change_plan.yml +15 -0
- data/test/vcr_cassettes/server/change_rootpassword.yml +15 -0
- data/test/vcr_cassettes/server/change_vncpass.yml +15 -0
- data/test/vcr_cassettes/server/console.yml +15 -0
- data/test/vcr_cassettes/server/create.yml +27 -0
- data/test/vcr_cassettes/server/exists.yml +15 -0
- data/test/vcr_cassettes/server/info.yml +27 -0
- data/test/vcr_cassettes/server/info_all.yml +15 -0
- data/test/vcr_cassettes/server/mountiso.yml +15 -0
- data/test/vcr_cassettes/server/network_disable.yml +15 -0
- data/test/vcr_cassettes/server/network_enable.yml +15 -0
- data/test/vcr_cassettes/server/pae_disable.yml +15 -0
- data/test/vcr_cassettes/server/pae_enable.yml +15 -0
- data/test/vcr_cassettes/server/reboot.yml +15 -0
- data/test/vcr_cassettes/server/rebuild.yml +15 -0
- data/test/vcr_cassettes/server/resume.yml +15 -0
- data/test/vcr_cassettes/server/shutdown.yml +15 -0
- data/test/vcr_cassettes/server/status.yml +15 -0
- data/test/vcr_cassettes/server/suspend.yml +15 -0
- data/test/vcr_cassettes/server/terminate.yml +27 -0
- data/test/vcr_cassettes/server/tun_disable.yml +15 -0
- data/test/vcr_cassettes/server/tun_enable.yml +15 -0
- data/test/vcr_cassettes/server/unmountiso.yml +15 -0
- data/test/vcr_cassettes/server/vnc.yml +15 -0
- metadata +220 -156
- data/.rbenv-version +0 -1
- data/.rvmrc +0 -47
- data/test/fixtures/base_bad_key.txt +0 -1
- data/test/fixtures/base_node_does_not_exist.txt +0 -1
- data/test/fixtures/base_unauthorized_ip.txt +0 -1
- data/test/fixtures/client_authenticate_error.txt +0 -2
- data/test/fixtures/client_authenticate_success.txt +0 -2
- data/test/fixtures/client_change_password_error.txt +0 -2
- data/test/fixtures/client_change_password_success.txt +0 -4
- data/test/fixtures/client_create_error.txt +0 -2
- data/test/fixtures/client_create_success.txt +0 -7
- data/test/fixtures/client_delete_success.txt +0 -2
- data/test/fixtures/client_exists_success.txt +0 -2
- data/test/fixtures/client_list_success.txt +0 -14
- data/test/fixtures/client_list_success_empty.txt +0 -2
- data/test/fixtures/error.txt +0 -2
- data/test/fixtures/general_isos_success.txt +0 -3
- data/test/fixtures/general_plans_success.txt +0 -3
- data/test/fixtures/general_templates_success.txt +0 -3
- data/test/fixtures/node_list_all_ips_available.txt +0 -4
- data/test/fixtures/node_list_all_ips_not_available.txt +0 -4
- data/test/fixtures/node_statistics_success.txt +0 -14
- data/test/fixtures/node_virtualservers_success.txt +0 -15
- data/test/fixtures/node_virtualservers_success_empty.txt +0 -2
- data/test/fixtures/node_xenresources_success.txt +0 -4
- data/test/fixtures/nodes_ids_success.txt +0 -3
- data/test/fixtures/nodes_list_success.txt +0 -3
- data/test/fixtures/reseller_change_resources_success.txt +0 -16
- data/test/fixtures/reseller_create_success.txt +0 -23
- data/test/fixtures/reseller_delete_success.txt +0 -2
- data/test/fixtures/reseller_info_success.txt +0 -23
- data/test/fixtures/reseller_list_success.txt +0 -3
- data/test/fixtures/server_boot_success.txt +0 -2
- data/test/fixtures/server_bootorder_success.txt +0 -2
- data/test/fixtures/server_change_consolepass_success.txt +0 -3
- data/test/fixtures/server_change_owner_success.txt +0 -2
- data/test/fixtures/server_change_success.txt +0 -2
- data/test/fixtures/server_change_vncpass_success.txt +0 -3
- data/test/fixtures/server_console_success.txt +0 -7
- data/test/fixtures/server_create_success.txt +0 -10
- data/test/fixtures/server_exists_success.txt +0 -2
- data/test/fixtures/server_hostname_success.txt +0 -3
- data/test/fixtures/server_info_success.txt +0 -10
- data/test/fixtures/server_infoall_success.txt +0 -13
- data/test/fixtures/server_mountiso_success.txt +0 -2
- data/test/fixtures/server_network_disable_success.txt +0 -2
- data/test/fixtures/server_network_enable_success.txt +0 -2
- data/test/fixtures/server_pae_success.txt +0 -2
- data/test/fixtures/server_reboot_success.txt +0 -2
- data/test/fixtures/server_rebuild_success.txt +0 -2
- data/test/fixtures/server_resume_success.txt +0 -2
- data/test/fixtures/server_rootpassword_success.txt +0 -3
- data/test/fixtures/server_shutdown_success.txt +0 -2
- data/test/fixtures/server_status_success.txt +0 -2
- data/test/fixtures/server_suspend_success.txt +0 -2
- data/test/fixtures/server_terminate_success.txt +0 -2
- data/test/fixtures/server_tun_disable_success.txt +0 -2
- data/test/fixtures/server_tun_enable_success.txt +0 -2
- data/test/fixtures/server_unmountiso_success.txt +0 -2
- data/test/fixtures/server_vnc_success.txt +0 -6
- data/test/test_base.rb +0 -115
- data/test/test_client.rb +0 -98
- data/test/test_general.rb +0 -70
- data/test/test_node.rb +0 -112
- data/test/test_reseller.rb +0 -80
- 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
|
data/lib/solusvm/version.rb
CHANGED
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
|
data/test/cli/test_client_cli.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
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
|
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
|
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
|
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
|
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 '
|
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
|
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
|
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
|
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"]))
|
data/test/cli/test_node_cli.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
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
|
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("
|
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
|
23
|
-
:
|
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("
|
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
|
33
|
-
:
|
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("
|
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
|
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
|
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
|
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 '
|
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
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
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
|
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
|
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
|