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,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BindServiceCommandTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should_require_login
|
6
|
+
|
7
|
+
context "binding" do
|
8
|
+
setup do
|
9
|
+
@mock_client = mock("Client")
|
10
|
+
@command = EPC::Command::BindServiceCommand.new(@mock_client)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "fail if service version not specified" do
|
14
|
+
assert_raise EPC::Error::FatalError do
|
15
|
+
assert_equal(@command.execute, 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "fail if service version id or project id cannot be determined" do
|
20
|
+
@command.expects(:infer_project_context).returns([nil, nil])
|
21
|
+
@command.expects(:get_resource_id).with(EPC::Config::SERVICE_VERSIONS_PATH, :label, "main_db").returns(nil)
|
22
|
+
|
23
|
+
assert_raise EPC::Error::FatalError do
|
24
|
+
assert_equal(@command.execute("main_db"), 1)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
should "fail if status is not 201" do
|
29
|
+
@command.expects(:infer_project_context).returns([1, "FirstProject"])
|
30
|
+
@mock_client.expects(:post).with(EPC::Config::PROJECTS_PATH + "/1/add_service_version", {:version_id => 1}).
|
31
|
+
returns([404, {:message => "Not Found"}, {}])
|
32
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
33
|
+
|
34
|
+
assert_equal(@command.execute(1), 404)
|
35
|
+
end
|
36
|
+
|
37
|
+
should "bind the service to the project" do
|
38
|
+
@command.expects(:infer_project_context).returns([1, "FirstProject"])
|
39
|
+
@mock_client.expects(:post).with(EPC::Config::PROJECTS_PATH + "/1/add_service_version", {:version_id => 1}).
|
40
|
+
returns([201, {}, {}])
|
41
|
+
@command.expects(:say).with("Service bound.")
|
42
|
+
|
43
|
+
assert_equal(@command.execute(1), 201)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BuildCommandTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should_require_login
|
6
|
+
|
7
|
+
context "execution" do
|
8
|
+
setup do
|
9
|
+
@mock_client = mock("Client")
|
10
|
+
@command = EPC::Command::BuildCommand.new(@mock_client)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "from solution directory" do
|
14
|
+
setup do
|
15
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
16
|
+
EPC::Config.expects(:is_solution_dir?).returns(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "build all projects when no arguments specified" do
|
20
|
+
@command.expects(:ask_yn).returns("Y")
|
21
|
+
Dir.expects(:glob).returns(["p1_dir", "p2_dir"])
|
22
|
+
EPC::Config.expects(:is_project_dir?).with("p1_dir").returns(true)
|
23
|
+
EPC::Config.expects(:get_project_value).with("p1_dir", "id").returns(1)
|
24
|
+
EPC::Config.expects(:is_project_dir?).with("p2_dir").returns(true)
|
25
|
+
EPC::Config.expects(:get_project_value).with("p2_dir", "id").returns(2)
|
26
|
+
@command.expects(:create_build).returns([true, 1])
|
27
|
+
@command.expects(:say)
|
28
|
+
@command.expects(:poll_for_build_status).returns(0)
|
29
|
+
@command.execute
|
30
|
+
end
|
31
|
+
|
32
|
+
should "only build the projects whose ids specified as arguments" do
|
33
|
+
@command.expects(:ask_yn).returns(1)
|
34
|
+
@command.execute("1=11", "2=12")
|
35
|
+
end
|
36
|
+
|
37
|
+
should "only build the projects whose names specified as arguments" do
|
38
|
+
@command.expects(:infer_project_context).with("p1", File.expand_path("."), 1).returns([1, "p1"])
|
39
|
+
@command.expects(:infer_project_context).with("p2", File.expand_path("."), 1).returns([2, "p2"])
|
40
|
+
@command.expects(:ask_yn).returns(1)
|
41
|
+
@command.execute("p1=11", "p2=12")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "from a project directory" do
|
46
|
+
setup do
|
47
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
48
|
+
EPC::Config.expects(:is_solution_dir?).returns(false)
|
49
|
+
EPC::Config.expects(:is_project_dir?).returns(true)
|
50
|
+
end
|
51
|
+
|
52
|
+
should "build the project from the directory" do
|
53
|
+
@command.expects(:infer_project_context).returns([1, "FirstProject"])
|
54
|
+
@command.expects(:ask_yn)
|
55
|
+
@command.execute
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "create_build" do
|
63
|
+
setup do
|
64
|
+
@mock_client = mock("Client")
|
65
|
+
@command = EPC::Command::BuildCommand.new(@mock_client)
|
66
|
+
EPC::Config.target_file = '~/.epc_test_target'
|
67
|
+
end
|
68
|
+
|
69
|
+
should "return true, id, built and message if the status is 201" do
|
70
|
+
@mock_client.expects(:post).with("/api/v1/builds", { :project_ids => [7], :project_versions => [], :note => nil }).
|
71
|
+
returns([201, { :id => 1 }, {}])
|
72
|
+
@command.expects(:say).with("Successfully kicked off a build with [http://localhost:3000]")
|
73
|
+
|
74
|
+
created, id = @command.send(:create_build, { 7 => 4 })
|
75
|
+
|
76
|
+
assert(created)
|
77
|
+
assert_equal(1, id)
|
78
|
+
end
|
79
|
+
|
80
|
+
should "return false if the status is not 200" do
|
81
|
+
@mock_client.expects(:post).with("/api/v1/builds", { :project_ids => [7], :project_versions => [], :note => nil }).
|
82
|
+
returns([404, { :message => "Not Found" }, {}])
|
83
|
+
@command.expects(:say).with("Build kickoff failed [Not Found]. Aborting.")
|
84
|
+
|
85
|
+
created, id, built, message = @command.send(:create_build, { 7 => nil })
|
86
|
+
|
87
|
+
assert(!created)
|
88
|
+
end
|
89
|
+
|
90
|
+
should "notify when a build in progress is found" do
|
91
|
+
@mock_client.expects(:post).with("/api/v1/builds", { :project_ids => [7], :project_versions => [], :note => nil }).
|
92
|
+
returns([202, { :id => 1}, {}])
|
93
|
+
@command.expects(:say).with("Build already in progress. Retrieving build status")
|
94
|
+
|
95
|
+
created, id = @command.send(:create_build, {7 => nil})
|
96
|
+
assert(created)
|
97
|
+
assert_equal(1, id)
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CopyDeploymentCommandTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should_require_login
|
6
|
+
|
7
|
+
context "execute" do
|
8
|
+
setup do
|
9
|
+
@mock_client = mock("Client")
|
10
|
+
@command = EPC::Command::CopyDeploymentCommand.new(@mock_client)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "fail if no deployment id specified" do
|
14
|
+
assert_raise EPC::Error::FatalError do
|
15
|
+
assert_equal(@command.execute, 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "fail if status is not 201" do
|
20
|
+
@mock_client.expects(:post).with(EPC::Config::DEPLOYMENTS_PATH + "/1/copy", :stage_name => "development").
|
21
|
+
returns([404, {:message => "Not Found"}, {}])
|
22
|
+
|
23
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
24
|
+
assert_equal(@command.execute(1, "development"), 404)
|
25
|
+
end
|
26
|
+
|
27
|
+
should "report the succesfull creation of new deployment" do
|
28
|
+
@mock_client.expects(:post).with(EPC::Config::DEPLOYMENTS_PATH + "/1/copy", :stage_name => "development").
|
29
|
+
returns([201, {:id => 2}, {}])
|
30
|
+
|
31
|
+
@command.expects(:say).with("Copied new deployment to the development stage. ID: 2")
|
32
|
+
assert_equal(@command.execute(1, "development"), 201)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CreateConfigCommandTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should_require_login
|
6
|
+
|
7
|
+
context "adding" do
|
8
|
+
setup do
|
9
|
+
@mock_client = mock("Client")
|
10
|
+
@command = EPC::Command::CreateConfigCommand.new(@mock_client)
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
should "fail if no key specified" do
|
15
|
+
assert_raise EPC::Error::FatalError do
|
16
|
+
@command.execute("")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
should "fail if status code is not 201" do
|
22
|
+
EPC::Config.expects(:is_project_dir?).returns(true)
|
23
|
+
|
24
|
+
EPC::Config.expects(:get_project_value).returns(1)
|
25
|
+
|
26
|
+
@mock_client.expects(:post).with(EPC::Config::CONFIGURATIONS_PATH,
|
27
|
+
{:config_values => [{:name => "key1", :value => "value1", :value_type => "text", :configurable_id => 1, :configurable_type => "Project", :required => false, :no_override => nil}]}
|
28
|
+
).returns([400, {:message => "Not Found"}, {}])
|
29
|
+
|
30
|
+
@command.expects("say").with("Request failed with message [Not Found]")
|
31
|
+
assert_equal(@command.execute("", "key1=value1"), 400)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
should "add to specified configuration level when option is specified" do
|
37
|
+
command = EPC::Command::CreateConfigCommand.new(@mock_client, {:user => 2})
|
38
|
+
|
39
|
+
command.expects(:extract_configuration_level).returns(["User", 2])
|
40
|
+
|
41
|
+
@mock_client.expects(:post).with(EPC::Config::CONFIGURATIONS_PATH,
|
42
|
+
{:config_values => [{:name => "key1", :value => "value1", :value_type => "text", :configurable_id => 2, :configurable_type => "User", :required => false, :no_override => nil}]}
|
43
|
+
).returns([201, {:id => 1}, {}])
|
44
|
+
|
45
|
+
command.expects(:say).with("Configuration values saved.")
|
46
|
+
assert_equal(command.execute("", "key1=value1"), 201)
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
should "add keys" do
|
51
|
+
@command.expects(:extract_configuration_level).returns(["Project", 1])
|
52
|
+
|
53
|
+
@mock_client.expects(:post).with(EPC::Config::CONFIGURATIONS_PATH,
|
54
|
+
{:config_values => [{:name => "key1", :value => "value1", :value_type => "text", :configurable_id => 1, :configurable_type => "Project", :required => false, :no_override => nil}]}
|
55
|
+
).returns([201, {:id => 1}, {}])
|
56
|
+
|
57
|
+
@command.expects(:say).with("Configuration values saved.")
|
58
|
+
assert_equal(@command.execute("", "key1=value1"), 201)
|
59
|
+
end
|
60
|
+
|
61
|
+
should "add required key when --required flag is supplied" do
|
62
|
+
command = EPC::Command::CreateConfigCommand.new(@mock_client, {:required => true})
|
63
|
+
|
64
|
+
command.expects(:extract_configuration_level).returns(["Project", 1])
|
65
|
+
|
66
|
+
@mock_client.expects(:post).with(EPC::Config::CONFIGURATIONS_PATH,
|
67
|
+
{:config_values => [{:name => "key1", :value => "value1", :value_type => "text", :configurable_id => 1, :configurable_type => "Project", :required => true, :no_override => nil}]}
|
68
|
+
).returns([201, {:id => 1}, {}])
|
69
|
+
|
70
|
+
command.expects(:say).with("Configuration values saved.")
|
71
|
+
assert_equal(command.execute("", "key1=value1"), 201)
|
72
|
+
end
|
73
|
+
|
74
|
+
should "should accept value-type parameter" do
|
75
|
+
command = EPC::Command::CreateConfigCommand.new(@mock_client, {:value_type => "URL"})
|
76
|
+
|
77
|
+
command.expects(:extract_configuration_level).returns(["Project", 1])
|
78
|
+
|
79
|
+
@mock_client.expects(:post).with(EPC::Config::CONFIGURATIONS_PATH,
|
80
|
+
{:config_values => [{:name => "key1", :value => "value1", :value_type => "URL", :configurable_id => 1, :configurable_type => "Project", :required => false, :no_override => nil}]}
|
81
|
+
).returns([201, {:id => 1}, {}])
|
82
|
+
|
83
|
+
command.expects(:say).with("Configuration values saved.")
|
84
|
+
assert_equal(command.execute("", "key1=value1"), 201)
|
85
|
+
end
|
86
|
+
|
87
|
+
should "should add the stage name parameter" do
|
88
|
+
command = EPC::Command::CreateConfigCommand.new(@mock_client, {:value_type => "URL", :stage => "Development"})
|
89
|
+
|
90
|
+
command.expects(:extract_configuration_level).returns(["Project", 1])
|
91
|
+
|
92
|
+
@mock_client.expects(:post).with(EPC::Config::CONFIGURATIONS_PATH,
|
93
|
+
{:config_values => [{:name => "key1", :value => "value1", :value_type => "URL", :configurable_id => 1, :configurable_type => "Project", :required => false, :no_override => nil, :stage_name => "Development"}]}
|
94
|
+
).returns([201, {:id => 1}, {}])
|
95
|
+
|
96
|
+
command.expects(:say).with("Configuration values saved.")
|
97
|
+
assert_equal(command.execute("", "key1=value1"), 201)
|
98
|
+
end
|
99
|
+
|
100
|
+
should "read data from external file when prompted to" do
|
101
|
+
@command.options[:file] = "path_to_file"
|
102
|
+
@command.expects(:extract_configuration_level).returns(["Project", 1])
|
103
|
+
EPC::Config.expects(:read_content_as_json).returns([{:name => "key1", :value => "value1", :value_type => "text", :required => true, :no_override => nil}])
|
104
|
+
@mock_client.expects(:post).with(EPC::Config::CONFIGURATIONS_PATH,
|
105
|
+
{:config_values => [{:name => "key1", :value => "value1", :value_type => "text", :configurable_id => 1, :configurable_type => "Project", :required => true, :no_override => nil}]}
|
106
|
+
).returns([201, {:id => 1}, {}])
|
107
|
+
|
108
|
+
@command.expects(:say).with("Configuration values saved.")
|
109
|
+
assert_equal(@command.execute("", "key1=value1"), 201)
|
110
|
+
end
|
111
|
+
|
112
|
+
should "fail if no config values were supplied" do
|
113
|
+
assert_raise EPC::Error::FatalError do
|
114
|
+
@command.options[:file] = "path_to_file"
|
115
|
+
EPC::Config.expects(:read_content_as_json).returns([])
|
116
|
+
@command.expects(:extract_configuration_level).returns(["Project", 1])
|
117
|
+
@command.execute("")
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CreateDependencyCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "execute" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@mock_client = mock("Client")
|
10
|
+
@command = EPC::Command::CreateDependencyCommand.new(@mock_client)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "fail if project id can't be determined (no solution)" do
|
14
|
+
@command.expects(:infer_solution_context).returns([ nil, nil ])
|
15
|
+
@command.expects(:infer_project_context).returns([ nil, nil ])
|
16
|
+
@command.expects(:say).with("Project/solution could not be inferred")
|
17
|
+
@command.expects(:say).with(EPC::Help::COMMAND_USAGES[:create_dependency])
|
18
|
+
assert_equal(@command.execute, 1)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "fail if project id can't be determined" do
|
22
|
+
@command.expects(:infer_solution_context).returns([ 1, "FirstSolution" ])
|
23
|
+
@command.expects(:infer_project_context).returns([ 1, "FirstProject" ])
|
24
|
+
@command.expects(:get_resource_id).returns(nil)
|
25
|
+
@command.expects(:say).with("Dependency could not be inferred")
|
26
|
+
@command.expects(:say).with(EPC::Help::COMMAND_USAGES[:create_dependency])
|
27
|
+
assert_equal(@command.execute, 1)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "show a message if status is not 201" do
|
31
|
+
@command.options[:dependency] = "dependency_name"
|
32
|
+
@command.expects(:infer_project_context).returns([1, "FirstProject"])
|
33
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
34
|
+
@command.expects(:get_resource_id).returns(2)
|
35
|
+
@mock_client.expects(:post).with(EPC::Config::PROJECTS_PATH + "/1/add_dependency", {:dependency_id => 2, :dependency_kind => 1}).
|
36
|
+
returns([400, {:message => "Not Found"}, {}])
|
37
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
38
|
+
|
39
|
+
assert_equal(@command.execute, 400)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "do a POST request to core" do
|
43
|
+
@command.options[:dependency_type] = 2
|
44
|
+
@command.options[:dependency] = 2
|
45
|
+
@command.expects(:infer_project_context).returns([1, "FirstProject"])
|
46
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
47
|
+
|
48
|
+
@mock_client.expects(:post).with(EPC::Config::PROJECTS_PATH + "/1/add_dependency", {:dependency_id => 2, :dependency_kind => 2}).returns([201, {}, {}])
|
49
|
+
@command.expects(:say).with("Dependency defined")
|
50
|
+
|
51
|
+
assert_equal(@command.execute, 201)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CreateDeploymentCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "pre-execution checks" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
@command = EPC::Command::CreateDeploymentCommand.new(@mock_client, {:solution_name => "FirstSolution"})
|
10
|
+
end
|
11
|
+
|
12
|
+
should "fail if solution can't be inferred " do
|
13
|
+
assert_raise EPC::Error::FatalError do
|
14
|
+
@command.expects(:infer_solution_context).returns(nil)
|
15
|
+
assert_equal @command.execute, 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "execute" do
|
21
|
+
setup do
|
22
|
+
@mock_client = mock("Client")
|
23
|
+
@mock_config = mock("Config")
|
24
|
+
|
25
|
+
EPC::Config.solutions_projects_file = '~/.epc_test_solutions_projects'
|
26
|
+
@command = EPC::Command::CreateDeploymentCommand.new(@mock_client, {:solution_name => "FirstSolution"})
|
27
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
28
|
+
end
|
29
|
+
|
30
|
+
teardown do
|
31
|
+
file = File.expand_path(EPC::Config.solutions_projects_file)
|
32
|
+
FileUtils.rm(file) if File.exists?(file)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
should "report failure if the status is not 201" do
|
37
|
+
@mock_client.expects(:post).with("/api/v1/deployments",
|
38
|
+
{ :solution_name => "FirstSolution", :stage_name => "Development" }).
|
39
|
+
returns([404, { :message => "Not Found" }, {}])
|
40
|
+
|
41
|
+
|
42
|
+
@command.expects(:ask_yn).returns("Y")
|
43
|
+
@command.expects(:say).with("Deployment creation failed [Not Found]. Aborting.")
|
44
|
+
|
45
|
+
assert_equal(@command.execute("", "Development"), 404)
|
46
|
+
end
|
47
|
+
|
48
|
+
should "report failure if it catches an exception" do
|
49
|
+
@mock_client.expects(:post).with("/api/v1/deployments",
|
50
|
+
{ :solution_name => "FirstSolution", :stage_name => "Development" }).
|
51
|
+
raises(StandardError.new("failed"))
|
52
|
+
|
53
|
+
@command.expects(:ask_yn).returns("Y")
|
54
|
+
@command.expects(:say).with("Create deployment failed [Exception Caught (StandardError): failed].")
|
55
|
+
|
56
|
+
assert_equal(@command.execute("", "Development"), 1)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "deployment replacement" do
|
61
|
+
setup do
|
62
|
+
@mock_client = mock("Client")
|
63
|
+
@command = EPC::Command::CreateDeploymentCommand.new(@mock_client, {:solution_name => "FirstSolution"})
|
64
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
65
|
+
@command.expects(:ask_yn).returns("Y")
|
66
|
+
@command.options[:replaces] = 1
|
67
|
+
@command.expects(:create_deployment).returns([200, 2])
|
68
|
+
end
|
69
|
+
|
70
|
+
should "issue a replacement request to core" do
|
71
|
+
@mock_client.expects(:put).with(EPC::Config::DEPLOYMENTS_PATH + "/2", :stage_name => "no_change", :replaces_id => 1, :versions => "no_change").
|
72
|
+
returns([200, {}, {}])
|
73
|
+
@command.expects(:say).with("Replacement request successful")
|
74
|
+
|
75
|
+
@command.execute
|
76
|
+
end
|
77
|
+
|
78
|
+
should "notify if replacement request fails" do
|
79
|
+
@mock_client.expects(:put).with(EPC::Config::DEPLOYMENTS_PATH + "/2", :stage_name => "no_change", :replaces_id => 1, :versions => "no_change").
|
80
|
+
returns([500, {:message => "System exception"}, {}])
|
81
|
+
@command.expects(:say).with("Replacement request failed: [System exception]")
|
82
|
+
|
83
|
+
@command.execute
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
context "create_deployment" do
|
90
|
+
setup do
|
91
|
+
@mock_client = mock("Client")
|
92
|
+
@command = EPC::Command::CreateDeploymentCommand.new(@mock_client)
|
93
|
+
end
|
94
|
+
|
95
|
+
should "return status and id if the status is 201" do
|
96
|
+
|
97
|
+
@mock_client.expects(:post).with("/api/v1/deployments",
|
98
|
+
{ :solution_name => "Test Solution", :stage_name => "dev" }).
|
99
|
+
returns([201, { :id => 1 }, {}])
|
100
|
+
@command.expects(:say).with("Successfully created deployment [1] with [http://localhost:3000]")
|
101
|
+
|
102
|
+
status, id = @command.send(:create_deployment, "Test Solution", "dev")
|
103
|
+
|
104
|
+
assert_equal 201, status
|
105
|
+
assert_equal(1, id)
|
106
|
+
end
|
107
|
+
|
108
|
+
should "return status if the status is not 200" do
|
109
|
+
|
110
|
+
@mock_client.expects(:post).with("/api/v1/deployments",
|
111
|
+
{ :solution_name => "Test Solution", :stage_name => "dev" }).
|
112
|
+
returns([404, { :message => "Not Found" }, {}])
|
113
|
+
@command.expects(:say).with("Deployment creation failed [Not Found]. Aborting.")
|
114
|
+
|
115
|
+
status, id = @command.send(:create_deployment, "Test Solution", "dev")
|
116
|
+
|
117
|
+
assert_equal 404, status
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "project parsing" do
|
122
|
+
setup do
|
123
|
+
@mock_client = mock("Client")
|
124
|
+
@command = EPC::Command::CreateDeploymentCommand.new(@mock_client)
|
125
|
+
end
|
126
|
+
|
127
|
+
should "return blank results when passed blank data" do
|
128
|
+
assert_equal(@command.send(:parse_projects, []), [[], []])
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
should "parse projects" do
|
133
|
+
assert_equal(@command.send(:parse_projects, "1:2:3"), [[{:project_id => "1", :version => "2"}], [{:project_id => "1", :instances => "3"}]])
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|