epc 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +1 -0
- data/Gemfile +22 -0
- data/Rakefile +67 -0
- data/Rakefile.gem +1 -0
- data/bin/epc +10 -0
- data/lib/epc.rb +126 -0
- data/lib/epc/client/base_client.rb +80 -0
- data/lib/epc/client/http_client.rb +19 -0
- data/lib/epc/client/json_client.rb +48 -0
- data/lib/epc/command/archive_project_command.rb +24 -0
- data/lib/epc/command/archive_solution_command.rb +21 -0
- data/lib/epc/command/attach_library_command.rb +82 -0
- data/lib/epc/command/attach_libraryset_command.rb +32 -0
- data/lib/epc/command/attach_runtime_command.rb +27 -0
- data/lib/epc/command/base_command.rb +451 -0
- data/lib/epc/command/bind_service_command.rb +35 -0
- data/lib/epc/command/build_command.rb +83 -0
- data/lib/epc/command/config/create_config_command.rb +55 -0
- data/lib/epc/command/copy_deployment_command.rb +21 -0
- data/lib/epc/command/create_command.rb +13 -0
- data/lib/epc/command/create_dependency_command.rb +43 -0
- data/lib/epc/command/define_service_command.rb +37 -0
- data/lib/epc/command/delete_config_command.rb +63 -0
- data/lib/epc/command/delete_dependency_command.rb +40 -0
- data/lib/epc/command/delete_group_command.rb +40 -0
- data/lib/epc/command/delete_library_command.rb +30 -0
- data/lib/epc/command/delete_librarylanguage_command.rb +40 -0
- data/lib/epc/command/delete_libraryset_command.rb +40 -0
- data/lib/epc/command/delete_project_command.rb +54 -0
- data/lib/epc/command/delete_role_command.rb +25 -0
- data/lib/epc/command/delete_serviceversion_command.rb +52 -0
- data/lib/epc/command/delete_solution_command.rb +39 -0
- data/lib/epc/command/delete_user_command.rb +31 -0
- data/lib/epc/command/deploy_command.rb +142 -0
- data/lib/epc/command/deployment/create_deployment_command.rb +82 -0
- data/lib/epc/command/detach_library_command.rb +35 -0
- data/lib/epc/command/detach_libraryset_command.rb +8 -0
- data/lib/epc/command/group/create_group_command.rb +21 -0
- data/lib/epc/command/info_command.rb +11 -0
- data/lib/epc/command/library/create_library_command.rb +45 -0
- data/lib/epc/command/librarylanguage/create_librarylanguage_command.rb +24 -0
- data/lib/epc/command/libraryset/create_libraryset_command.rb +54 -0
- data/lib/epc/command/list_approvals_command.rb +27 -0
- data/lib/epc/command/list_attachedlibraries_command.rb +42 -0
- data/lib/epc/command/list_boundservices_command.rb +40 -0
- data/lib/epc/command/list_config_command.rb +60 -0
- data/lib/epc/command/list_dependencies_command.rb +43 -0
- data/lib/epc/command/list_deployments_command.rb +68 -0
- data/lib/epc/command/list_groups_command.rb +19 -0
- data/lib/epc/command/list_libraries_command.rb +19 -0
- data/lib/epc/command/list_librarylanguages_command.rb +19 -0
- data/lib/epc/command/list_librarysets_command.rb +26 -0
- data/lib/epc/command/list_objectroles_command.rb +25 -0
- data/lib/epc/command/list_objecttypes_command.rb +20 -0
- data/lib/epc/command/list_permissiongroups_command.rb +20 -0
- data/lib/epc/command/list_projects_command.rb +36 -0
- data/lib/epc/command/list_projecttypes_command.rb +20 -0
- data/lib/epc/command/list_rolepermissions_command.rb +21 -0
- data/lib/epc/command/list_roles_command.rb +26 -0
- data/lib/epc/command/list_runtimes_command.rb +16 -0
- data/lib/epc/command/list_service_types_command.rb +19 -0
- data/lib/epc/command/list_servicedefinitions_command.rb +19 -0
- data/lib/epc/command/list_serviceversions_command.rb +21 -0
- data/lib/epc/command/list_solutions_command.rb +25 -0
- data/lib/epc/command/list_stages_command.rb +21 -0
- data/lib/epc/command/list_users_command.rb +26 -0
- data/lib/epc/command/list_versions_command.rb +39 -0
- data/lib/epc/command/login_command.rb +32 -0
- data/lib/epc/command/logout_command.rb +20 -0
- data/lib/epc/command/objectrole/create_objectrole_command.rb +19 -0
- data/lib/epc/command/project/create_project_command.rb +78 -0
- data/lib/epc/command/pull_command.rb +209 -0
- data/lib/epc/command/push_command.rb +194 -0
- data/lib/epc/command/refresh_solution_command.rb +71 -0
- data/lib/epc/command/renew_command.rb +19 -0
- data/lib/epc/command/request_passwordchange_command.rb +23 -0
- data/lib/epc/command/role/create_role_command.rb +17 -0
- data/lib/epc/command/serviceversion/create_serviceversion_command.rb +33 -0
- data/lib/epc/command/show_deployment_command.rb +57 -0
- data/lib/epc/command/show_group_command.rb +35 -0
- data/lib/epc/command/show_libraryset_command.rb +54 -0
- data/lib/epc/command/show_project_command.rb +74 -0
- data/lib/epc/command/show_projecttype_command.rb +18 -0
- data/lib/epc/command/show_role_command.rb +46 -0
- data/lib/epc/command/show_solution_command.rb +54 -0
- data/lib/epc/command/show_user_command.rb +42 -0
- data/lib/epc/command/solution/create_solution_command.rb +34 -0
- data/lib/epc/command/solution/list_solutions_command.rb +25 -0
- data/lib/epc/command/solution/update_solution_command.rb +43 -0
- data/lib/epc/command/submit_deployment_command.rb +19 -0
- data/lib/epc/command/target_command.rb +26 -0
- data/lib/epc/command/unarchive_project_command.rb +23 -0
- data/lib/epc/command/unarchive_solution_command.rb +21 -0
- data/lib/epc/command/unbind_service_command.rb +42 -0
- data/lib/epc/command/undefine_service_command.rb +33 -0
- data/lib/epc/command/undeploy_command.rb +106 -0
- data/lib/epc/command/update_config_command.rb +62 -0
- data/lib/epc/command/update_deploymentproject_command.rb +54 -0
- data/lib/epc/command/update_group_command.rb +43 -0
- data/lib/epc/command/update_librarylanguage_command.rb +28 -0
- data/lib/epc/command/update_libraryset_command.rb +80 -0
- data/lib/epc/command/update_project_command.rb +49 -0
- data/lib/epc/command/update_role_command.rb +47 -0
- data/lib/epc/command/update_rolepermissions_command.rb +83 -0
- data/lib/epc/command/update_solution_command.rb +45 -0
- data/lib/epc/command/update_user_command.rb +57 -0
- data/lib/epc/command/user/create_user_command.rb +27 -0
- data/lib/epc/command/vote_deployment_command.rb +29 -0
- data/lib/epc/config.rb +245 -0
- data/lib/epc/error/basic_error.rb +6 -0
- data/lib/epc/error/fatal_error.rb +6 -0
- data/lib/epc/error/input_error.rb +6 -0
- data/lib/epc/error/internal_error.rb +6 -0
- data/lib/epc/help.rb +292 -0
- data/lib/epc/persistent_attributes.rb +18 -0
- data/lib/epc/runner.rb +177 -0
- data/lib/epc/tabular_outputter.rb +161 -0
- data/lib/epc/version.rb +3 -0
- data/lib/fixnum.rb +9 -0
- data/lib/object.rb +13 -0
- data/test/command/archive_project_command_test.rb +41 -0
- data/test/command/archive_solution_command_test.rb +40 -0
- data/test/command/attach_library_command_test.rb +124 -0
- data/test/command/attach_libraryset_command_test.rb +49 -0
- data/test/command/attach_runtime_command_test.rb +44 -0
- data/test/command/base_command_test.rb +276 -0
- data/test/command/bind_service_command_test.rb +46 -0
- data/test/command/build_command_test.rb +103 -0
- data/test/command/copy_deployment_command_test.rb +38 -0
- data/test/command/create_config_command_test.rb +124 -0
- data/test/command/create_dependency_command_test.rb +55 -0
- data/test/command/create_deployment_command_test.rb +136 -0
- data/test/command/create_group_command_test.rb +34 -0
- data/test/command/create_library_command_test.rb +61 -0
- data/test/command/create_librarylanguage_command_test.rb +51 -0
- data/test/command/create_libraryset_command_test.rb +81 -0
- data/test/command/create_objectrole_command_test.rb +37 -0
- data/test/command/create_project_command_test.rb +102 -0
- data/test/command/create_role_command_test.rb +31 -0
- data/test/command/create_serviceversion_command_test.rb +60 -0
- data/test/command/create_solution_command_test.rb +70 -0
- data/test/command/create_user_command_test.rb +54 -0
- data/test/command/define_service_command_test.rb +55 -0
- data/test/command/delete_config_command_test.rb +82 -0
- data/test/command/delete_dependency_command_test.rb +50 -0
- data/test/command/delete_group_command_test.rb +56 -0
- data/test/command/delete_library_command_test.rb +43 -0
- data/test/command/delete_librarylanguage_command_test.rb +55 -0
- data/test/command/delete_libraryset_command_test.rb +55 -0
- data/test/command/delete_project_command_test.rb +76 -0
- data/test/command/delete_role_command_test.rb +41 -0
- data/test/command/delete_serviceversion_command_test.rb +53 -0
- data/test/command/delete_solution_command_test.rb +79 -0
- data/test/command/delete_user_command_test.rb +56 -0
- data/test/command/deploy_command_test.rb +185 -0
- data/test/command/detach_library_command_test.rb +53 -0
- data/test/command/info_command_test.rb +17 -0
- data/test/command/list_approvals_command_test.rb +41 -0
- data/test/command/list_boundservices_command_test.rb +46 -0
- data/test/command/list_config_command_test.rb +72 -0
- data/test/command/list_dependencies_command_test.rb +46 -0
- data/test/command/list_deployments_command_test.rb +112 -0
- data/test/command/list_deploymentstages_command_test.rb +44 -0
- data/test/command/list_libraries_command_test.rb +42 -0
- data/test/command/list_librarylanguages_command_test.rb +34 -0
- data/test/command/list_librarysets_command_test.rb +33 -0
- data/test/command/list_objectroles_command_test.rb +41 -0
- data/test/command/list_objecttypes_command_test.rb +25 -0
- data/test/command/list_permissiongroups_command_test.rb +25 -0
- data/test/command/list_projects_command_test.rb +63 -0
- data/test/command/list_projecttypes_command_test.rb +39 -0
- data/test/command/list_rolepermissions_command_test.rb +39 -0
- data/test/command/list_roles_command_test.rb +46 -0
- data/test/command/list_runtimes_command_test.rb +30 -0
- data/test/command/list_service_types_command_test.rb +44 -0
- data/test/command/list_servicedefinitions_command_test.rb +44 -0
- data/test/command/list_serviceversions_command_test.rb +47 -0
- data/test/command/list_solutions_command_test.rb +48 -0
- data/test/command/list_users_command_test.rb +33 -0
- data/test/command/login_command_test.rb +83 -0
- data/test/command/logout_command_test.rb +30 -0
- data/test/command/pull_command_test.rb +229 -0
- data/test/command/push_command_test.rb +246 -0
- data/test/command/refresh_solution_command_test.rb +35 -0
- data/test/command/renew_command_test.rb +43 -0
- data/test/command/request_passwordchange_command_test.rb +31 -0
- data/test/command/show_group_command_test.rb +50 -0
- data/test/command/show_libraryset_command_test.rb +51 -0
- data/test/command/show_project_command_test.rb +57 -0
- data/test/command/show_projecttype_command_test.rb +46 -0
- data/test/command/show_role_command_test.rb +37 -0
- data/test/command/show_solution_command_test.rb +59 -0
- data/test/command/show_user_command_test.rb +50 -0
- data/test/command/submit_deployment_command_test.rb +37 -0
- data/test/command/target_command_test.rb +58 -0
- data/test/command/unarchive_project_command_test.rb +45 -0
- data/test/command/unarchive_solution_command_test.rb +43 -0
- data/test/command/unbind_service_command_test.rb +48 -0
- data/test/command/undefine_service_command_test.rb +49 -0
- data/test/command/update_config_command_test.rb +74 -0
- data/test/command/update_deploymentproject_command_test.rb +77 -0
- data/test/command/update_group_command_test.rb +69 -0
- data/test/command/update_librarylanguage_command_test.rb +43 -0
- data/test/command/update_libraryset_command_test.rb +113 -0
- data/test/command/update_project_command_test.rb +56 -0
- data/test/command/update_role_command_test.rb +42 -0
- data/test/command/update_rolepermissions_command_test.rb +54 -0
- data/test/command/update_solution_command_test.rb +58 -0
- data/test/command/update_user_command_test.rb +76 -0
- data/test/command/vote_deployment_command_test.rb +33 -0
- data/test/config_test.rb +70 -0
- data/test/successful_test.rb +21 -0
- data/test/test_files/pom.xml +273 -0
- data/test/test_helper.rb +25 -0
- metadata +470 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ListServiceversionsCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "list service versions" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
|
10
|
+
@command = EPC::Command::ListServiceversionsCommand.new(@mock_client)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "show exception message status is not 201" do
|
14
|
+
@mock_client.expects(:get).with(EPC::Config::SERVICE_VERSIONS_PATH).
|
15
|
+
returns([400, {:message => "Not Found"}, {}])
|
16
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
17
|
+
|
18
|
+
assert_equal(@command.execute, 400)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "show a message if there are no service versions" do
|
22
|
+
|
23
|
+
@mock_client.expects(:get).with(EPC::Config::SERVICE_VERSIONS_PATH).
|
24
|
+
returns([200, {}, {}])
|
25
|
+
|
26
|
+
@command.expects(:say).returns("No service-versions have been defined.")
|
27
|
+
@command.expects(:say).returns("You can define one with epc create service-version.")
|
28
|
+
|
29
|
+
assert_equal(@command.execute, 200)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "list available service versions" do
|
33
|
+
@mock_client.expects(:get).with(EPC::Config::SERVICE_VERSIONS_PATH).
|
34
|
+
returns([200,
|
35
|
+
[
|
36
|
+
{:id => 1, :label => "main_db"},
|
37
|
+
{:id => 2, :label => "main_redis"}],
|
38
|
+
{}])
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
@command.expects(:say).at_least_once
|
43
|
+
assert_equal(@command.execute, 200)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ListSolutionsCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "list solutions" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
|
10
|
+
@command = EPC::Command::ListSolutionsCommand.new(@mock_client)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "show exception message status is not 201" do
|
14
|
+
@mock_client.expects(:get).with(EPC::Config::SOLUTIONS_PATH).
|
15
|
+
returns([400, {:message => "Not Found"}, {}])
|
16
|
+
@command.expects(:say).with("Solutions retrieval failed with [Not Found]")
|
17
|
+
|
18
|
+
assert_equal(@command.execute, 400)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "show a message if there are no solutions" do
|
22
|
+
|
23
|
+
@mock_client.expects(:get).with(EPC::Config::SOLUTIONS_PATH).
|
24
|
+
returns([200, {}, {}])
|
25
|
+
|
26
|
+
@command.expects(:say).returns("You have no solutions created.You can create them with epc create solution.")
|
27
|
+
|
28
|
+
assert_equal(@command.execute, 200)
|
29
|
+
end
|
30
|
+
|
31
|
+
should "list available solutions" do
|
32
|
+
time1 = (Time.now - 5).to_s
|
33
|
+
time2 = Time.now.to_s
|
34
|
+
@mock_client.expects(:get).with(EPC::Config::SOLUTIONS_PATH).
|
35
|
+
returns([200,
|
36
|
+
[
|
37
|
+
{:id => 1, :name => "Solution1", :created_at => time1 },
|
38
|
+
{:id => 2, :name => "Solution2", :created_at => time2 }],
|
39
|
+
{}])
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
@command.expects(:say).at_least_once
|
44
|
+
assert_equal(@command.execute, 200)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ListUsersCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
|
7
|
+
context "execution" do
|
8
|
+
setup do
|
9
|
+
@mock_client = mock("Client")
|
10
|
+
@command = EPC::Command::ListUsersCommand.new(@mock_client)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "fail if status is not 200(ok)" do
|
14
|
+
@mock_client.expects(:get).with(EPC::Config::USERS_PATH).returns([500, {:message => "System exception encountered"}, {}])
|
15
|
+
@command.expects(:say).with("Request failed: [System exception encountered]")
|
16
|
+
assert_equal 500, @command.execute
|
17
|
+
end
|
18
|
+
|
19
|
+
should "show a message if no users are defined" do
|
20
|
+
@mock_client.expects(:get).with(EPC::Config::USERS_PATH).returns([200, {}, {}])
|
21
|
+
@command.expects(:say).with("No users defined")
|
22
|
+
assert_equal 200, @command.execute
|
23
|
+
end
|
24
|
+
|
25
|
+
should "list users" do
|
26
|
+
|
27
|
+
@mock_client.expects(:get).with(EPC::Config::USERS_PATH).returns([200, [ {:id => 1, :name => "user1", :email => "user1@epaas.com", :created_at => Time.now.to_s}], {}])
|
28
|
+
@command.expects(:say)
|
29
|
+
assert_equal 200, @command.execute
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LoginCommandTest < Test::Unit::TestCase
|
4
|
+
context "execute" do
|
5
|
+
setup do
|
6
|
+
@mock_client = mock("Client")
|
7
|
+
@mock_config = mock("Config")
|
8
|
+
|
9
|
+
EPC::Config.target_file = '~/.epc_test_target'
|
10
|
+
end
|
11
|
+
|
12
|
+
should "prompt for password" do
|
13
|
+
command = EPC::Command::LoginCommand.new(@mock_client)
|
14
|
+
command.expects(:ask).with("Password: ").returns("testpass")
|
15
|
+
|
16
|
+
@mock_client.expects(:post).with("/api/v1/tokens/retrieve", { :email => 'me@there.com', :password => 'testpass' }, true).returns(201, {}, {})
|
17
|
+
|
18
|
+
assert_equal(command.execute("me@there.com"), 201)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "use the password passed to initialize" do
|
22
|
+
command = EPC::Command::LoginCommand.new(@mock_client, :password => 'testpass')
|
23
|
+
command.expects(:ask).with("Password: ").never
|
24
|
+
|
25
|
+
@mock_client.expects(:post).with("/api/v1/tokens/retrieve", { :email => 'me@there.com', :password => 'testpass' }, true).returns(201, {}, {})
|
26
|
+
|
27
|
+
assert_equal(command.execute("me@there.com"), 201)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "report failure if email was not provided" do
|
31
|
+
command = EPC::Command::LoginCommand.new(@mock_client, :password => 'testpass')
|
32
|
+
command.expects(:ask).with("Password: ").never
|
33
|
+
|
34
|
+
@mock_client.expects(:post).never
|
35
|
+
command.expects(:say).with("You must supply an email address")
|
36
|
+
|
37
|
+
assert_equal(command.execute, 1)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "store caller_id and auth_token and email if the status is 201" do
|
41
|
+
command = EPC::Command::LoginCommand.new(@mock_client, :password => 'testpass')
|
42
|
+
command.expects(:ask).with("Password: ").never
|
43
|
+
|
44
|
+
@mock_client.expects(:post).
|
45
|
+
with("/api/v1/tokens/retrieve", { :email => 'me@there.com', :password => 'testpass' }, true).
|
46
|
+
returns([201, { :caller_id => '123', :authentication_token => 'abcdef' }, {}])
|
47
|
+
command.expects(:say).with("Successfully logged into [http://localhost:3000]")
|
48
|
+
|
49
|
+
EPC::Config.expects(:store_caller_id).with('123')
|
50
|
+
EPC::Config.expects(:store_auth_token).with('abcdef')
|
51
|
+
EPC::Config.expects(:store_username).with('me@there.com')
|
52
|
+
|
53
|
+
assert_equal(command.execute("me@there.com"), 201)
|
54
|
+
end
|
55
|
+
|
56
|
+
should "not store caller_id and auth_token and email if the status is not 201" do
|
57
|
+
command = EPC::Command::LoginCommand.new(@mock_client, :password => 'testpass')
|
58
|
+
command.expects(:ask).with("Password: ").never
|
59
|
+
|
60
|
+
@mock_client.expects(:post).
|
61
|
+
with("/api/v1/tokens/retrieve", { :email => 'me@there.com', :password => 'testpass' }, true).
|
62
|
+
returns([403, { :message => "login failed" }, {}])
|
63
|
+
command.expects(:say).with("Login failed [login failed]. Please make sure you entered the correct email and password.")
|
64
|
+
|
65
|
+
EPC::Config.expects(:store_caller_id).never
|
66
|
+
EPC::Config.expects(:store_auth_token).never
|
67
|
+
EPC::Config.expects(:store_username).never
|
68
|
+
|
69
|
+
assert_equal(command.execute("me@there.com"), 403)
|
70
|
+
end
|
71
|
+
|
72
|
+
should "report error if the call throws an exception" do
|
73
|
+
command = EPC::Command::LoginCommand.new(@mock_client, :password => 'testpass')
|
74
|
+
|
75
|
+
@mock_client.expects(:post).
|
76
|
+
with("/api/v1/tokens/retrieve", { :email => 'me@there.com', :password => 'testpass' }, true).
|
77
|
+
raises(StandardError.new("failed"))
|
78
|
+
command.expects(:say).with("Login failed [failed].")
|
79
|
+
|
80
|
+
assert_equal(command.execute("me@there.com"), 1)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LogoutCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "execute" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
@mock_config = mock("Config")
|
10
|
+
end
|
11
|
+
|
12
|
+
should "remove the auth_token and user if the status is 200" do
|
13
|
+
command = EPC::Command::LogoutCommand.new(@mock_client)
|
14
|
+
|
15
|
+
EPC::Config.expects(:remove_auth_token).returns(true)
|
16
|
+
EPC::Config.expects(:remove_username)
|
17
|
+
command.expects(:say)
|
18
|
+
assert_equal(command.execute, 0)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "notify when logout fails" do
|
22
|
+
command = EPC::Command::LogoutCommand.new(@mock_client)
|
23
|
+
|
24
|
+
EPC::Config.expects(:remove_auth_token).returns(false)
|
25
|
+
command.expects(:say)
|
26
|
+
assert_equal(command.execute, 1)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PullCommandTest < Test::Unit::TestCase
|
4
|
+
context "execute" do
|
5
|
+
setup do
|
6
|
+
@mock_client = mock("Client")
|
7
|
+
@command = EPC::Command::PullCommand.new(@mock_client)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "fail if solution name can't be inferred" do
|
11
|
+
@command.expects(:get_resource_name).returns(nil)
|
12
|
+
EPC::Config.expects(:is_solution_dir?).returns(false)
|
13
|
+
EPC::Config.expects(:is_project_dir?).returns(false)
|
14
|
+
assert_raise EPC::Error::FatalError do
|
15
|
+
assert_equal(@command.execute(1), 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "prompt the user before pulling" do
|
20
|
+
@command.expects(:ask_yn).returns("N")
|
21
|
+
assert_equal(@command.execute("FirstSolution"), 1)
|
22
|
+
end
|
23
|
+
|
24
|
+
should "create a directory for new solutions" do
|
25
|
+
@command.expects(:get_resource_name).returns("FirstSolution")
|
26
|
+
# EPC::Config.expects(:is_solution_dir?).returns(false)
|
27
|
+
EPC::Config.expects(:is_project_dir?).returns(false)
|
28
|
+
@command.expects(:ask_yn).returns("Y")
|
29
|
+
@command.expects(:create_pull).returns([200, 1])
|
30
|
+
@command.expects(:prep_solution_directory).returns(true)
|
31
|
+
@command.expects(:say)
|
32
|
+
@command.expects(:poll_for_pull_url).returns([true, "url_to_zip"])
|
33
|
+
Dir.expects(:tmpdir).returns("tmp_dir")
|
34
|
+
@command.expects(:pull_zip).with("url_to_zip", "tmp_dir").returns([true, "path_to_zip"])
|
35
|
+
@command.expects(:unzip_solution)
|
36
|
+
@command.expects(:confirm_pull)
|
37
|
+
refresh_command = EPC::Command::RefreshSolutionCommand.new(@mock_client)
|
38
|
+
EPC::Command::RefreshSolutionCommand.expects(:new).returns(refresh_command)
|
39
|
+
refresh_command.expects(:execute).returns(0)
|
40
|
+
assert_equal(@command.execute(1), 0)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
context "create_pull" do
|
46
|
+
setup do
|
47
|
+
@mock_client = mock("Client")
|
48
|
+
EPC::Config.target_file = '~/.epc_test_target'
|
49
|
+
end
|
50
|
+
|
51
|
+
should "return true and id if the status is 201" do
|
52
|
+
command = EPC::Command::PullCommand.new(@mock_client)
|
53
|
+
|
54
|
+
@mock_client.expects(:post).with("/api/v1/pulls", { :solution_name => "Test Solution" }).
|
55
|
+
returns([202, { :id => 1 }, {}])
|
56
|
+
command.expects(:say).with("Successfully created a pull with [http://localhost:3000]")
|
57
|
+
|
58
|
+
status, id = command.send(:create_pull, "Test Solution")
|
59
|
+
|
60
|
+
assert_equal 202, status
|
61
|
+
assert_equal(1, id)
|
62
|
+
end
|
63
|
+
|
64
|
+
should "return false if the status is not 202" do
|
65
|
+
command = EPC::Command::PullCommand.new(@mock_client)
|
66
|
+
|
67
|
+
@mock_client.expects(:post).with("/api/v1/pulls", { :solution_name => "Test Solution" }).
|
68
|
+
returns([404, { :message => "Not Found" }, {}])
|
69
|
+
command.expects(:raise).with(Exception, "Not Found")
|
70
|
+
|
71
|
+
status, id = command.send(:create_pull, "Test Solution")
|
72
|
+
|
73
|
+
assert_equal 404, status
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "confirm_pull" do
|
78
|
+
setup do
|
79
|
+
@mock_client = mock("Client")
|
80
|
+
|
81
|
+
EPC::Config.target_file = '~/.epc_test_target'
|
82
|
+
end
|
83
|
+
|
84
|
+
should "return true if the status is 200" do
|
85
|
+
command = EPC::Command::PullCommand.new(@mock_client)
|
86
|
+
|
87
|
+
@mock_client.expects(:put).with("/api/v1/pulls/1/confirm", { :pulled => 'yes' }).
|
88
|
+
returns([200, { :id => 1 }, {}])
|
89
|
+
command.expects(:say).with("Successfully confirmed the pull with [http://localhost:3000]")
|
90
|
+
|
91
|
+
confirmed = command.send(:confirm_pull, 1)
|
92
|
+
|
93
|
+
assert(confirmed)
|
94
|
+
end
|
95
|
+
|
96
|
+
should "return false if the status is not 200" do
|
97
|
+
command = EPC::Command::PullCommand.new(@mock_client)
|
98
|
+
|
99
|
+
@mock_client.expects(:put).with("/api/v1/pulls/1/confirm", { :pulled => 'yes' }).
|
100
|
+
returns([400, { :message => "bad request" }, {}])
|
101
|
+
command.expects(:say).with("Pull confirmation failed [bad request].")
|
102
|
+
|
103
|
+
confirmed = command.send(:confirm_pull, 1)
|
104
|
+
|
105
|
+
assert(!confirmed)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "sign_pull" do
|
110
|
+
setup do
|
111
|
+
@mock_client = mock("Client")
|
112
|
+
end
|
113
|
+
|
114
|
+
should "return true if the status is 200" do
|
115
|
+
command = EPC::Command::PullCommand.new(@mock_client)
|
116
|
+
|
117
|
+
@mock_client.expects(:put).with("/api/v1/pulls/1/sign").
|
118
|
+
returns([200, { :signed_url => "http://download/from/here" }, {}])
|
119
|
+
|
120
|
+
status, code, url = command.send(:sign_pull, 1)
|
121
|
+
|
122
|
+
assert_equal(200, status)
|
123
|
+
assert_nil(code)
|
124
|
+
assert_equal("http://download/from/here", url)
|
125
|
+
end
|
126
|
+
|
127
|
+
should "return false if the status is not 200" do
|
128
|
+
command = EPC::Command::PullCommand.new(@mock_client)
|
129
|
+
|
130
|
+
@mock_client.expects(:put).with("/api/v1/pulls/1/sign").
|
131
|
+
returns([404, { :message => "not found", :error_code => 801 }, {}])
|
132
|
+
|
133
|
+
status, code, url = command.send(:sign_pull, 1)
|
134
|
+
|
135
|
+
assert_equal(404, status)
|
136
|
+
assert_equal(801, code)
|
137
|
+
assert_nil(url)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "prep_solution_directory" do
|
142
|
+
setup do
|
143
|
+
@mock_client = mock("Client")
|
144
|
+
@command = EPC::Command::PullCommand.new(@mock_client)
|
145
|
+
end
|
146
|
+
|
147
|
+
should "notify if solutions wasn't found" do
|
148
|
+
@command.expects(:get_resource_id).returns(nil)
|
149
|
+
@command.expects(:say).returns("Solution not found")
|
150
|
+
assert_equal(@command.send(:prep_solution_directory, "path_to_dir", "FirstSolution"), false)
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
should "notify if directory creation fails" do
|
155
|
+
@command.expects(:get_resource_id).returns(1)
|
156
|
+
Dir.expects(:mkdir).raises(Exception)
|
157
|
+
@command.expects(:say)
|
158
|
+
assert_equal(@command.send(:prep_solution_directory, "path_to_dir", "FirstSolution"), false)
|
159
|
+
end
|
160
|
+
|
161
|
+
should "notify if metadata file can't be created" do
|
162
|
+
@command.expects(:get_resource_id).returns(1)
|
163
|
+
Dir.expects(:mkdir)
|
164
|
+
File.expects(:open).raises(Exception)
|
165
|
+
@command.expects(:say)
|
166
|
+
assert_equal(@command.send(:prep_solution_directory, "path_to_dir", "FirstSolution"), false)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context "poll for pull url" do
|
171
|
+
setup do
|
172
|
+
@mock_client = mock("Client")
|
173
|
+
@command = EPC::Command::PullCommand.new(@mock_client)
|
174
|
+
end
|
175
|
+
|
176
|
+
should "poll untill if receives and url" do
|
177
|
+
@command.expects(:sign_pull).returns([200, 1, "url_to_zip"])
|
178
|
+
assert_equal(@command.send(:poll_for_pull_url, 1), [true, "url_to_zip"])
|
179
|
+
end
|
180
|
+
|
181
|
+
should "notify when there's an error in polling" do
|
182
|
+
@command.expects(:sign_pull).returns([500, 1, nil])
|
183
|
+
@command.expects(:say).with("Poller failed to get the pull URL. Aborting.")
|
184
|
+
assert_equal(@command.send(:poll_for_pull_url, 1), [false, nil])
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
context "check pull" do
|
190
|
+
setup do
|
191
|
+
@mock_client = mock("Client")
|
192
|
+
@command = EPC::Command::PullCommand.new(@mock_client)
|
193
|
+
end
|
194
|
+
|
195
|
+
should "fail if path doesn't exists" do
|
196
|
+
File.expects(:exists?).returns(false)
|
197
|
+
@command.expects(:say).with("Pull path does not exist")
|
198
|
+
@command.send(:check_pull_directory, "path")
|
199
|
+
end
|
200
|
+
|
201
|
+
should "fail if path isn't a directory" do
|
202
|
+
File.expects(:exists?).returns(true)
|
203
|
+
File.expects(:directory?).returns(false)
|
204
|
+
@command.expects(:say).with("Pull path is not a directory")
|
205
|
+
@command.send(:check_pull_directory, "path")
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context "pull zip" do
|
210
|
+
setup do
|
211
|
+
@mock_client = mock("Client")
|
212
|
+
@command = EPC::Command::PullCommand.new(@mock_client)
|
213
|
+
end
|
214
|
+
|
215
|
+
should "pull the zip" do
|
216
|
+
@command.send(:http_client).expects(:get).returns([200, "response", {}])
|
217
|
+
@command.expects(:say).with("Successfully pulled the zip file from the build repository")
|
218
|
+
@command.expects(:open)
|
219
|
+
|
220
|
+
@command.send(:pull_zip, "url", "path_to_zip")
|
221
|
+
end
|
222
|
+
|
223
|
+
should "notify if pull fails" do
|
224
|
+
@command.send(:http_client).expects(:get).returns([500, "response", {}])
|
225
|
+
@command.expects(:say).with("Failed to pull the zip file from the build repository [status = 500]. Aborting pull command.")
|
226
|
+
@command.send(:pull_zip, "url", "path_to_zip")
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|