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,124 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AttachLibraryCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "checks" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
@command = EPC::Command::AttachLibraryCommand.new(@mock_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "fail if library not specified" do
|
13
|
+
assert_raise EPC::Error::FatalError do
|
14
|
+
assert_equal(@command.execute, 1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
should "fail if project cannot be determined" do
|
19
|
+
assert_raise EPC::Error::FatalError do
|
20
|
+
@command.expects(:infer_project_context).returns(nil)
|
21
|
+
assert_equal(@command.execute("libmath"), 1)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
should "fail if library id cannot be determined" do
|
26
|
+
assert_raise EPC::Error::InputError do
|
27
|
+
@command.expects(:infer_project_context).returns([1, "FirstSolution"])
|
28
|
+
@command.expects(:retrieve_libraries).returns(nil)
|
29
|
+
|
30
|
+
assert_equal(@command.execute("libmath"), 1)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "attaching from json" do
|
36
|
+
setup do
|
37
|
+
@mock_client = mock("Client")
|
38
|
+
@command = EPC::Command::AttachLibraryCommand.new(@mock_client)
|
39
|
+
@command.expects(:infer_project_context).returns([1, "FirstProject"])
|
40
|
+
@command.options[:file] = "path/to/json/file"
|
41
|
+
end
|
42
|
+
|
43
|
+
should "read data and retrieve ids" do
|
44
|
+
EPC::Config.expects(:read_content_as_json).returns([{"id" => 1, "name" => "libmath", "library_version" => "1.0", "group" => "math_libs"}])
|
45
|
+
@command.expects(:retrieve_libraries).returns([1])
|
46
|
+
@mock_client.expects(:post).returns([200, {}, {}])
|
47
|
+
@command.expects(:say).with("Library [1] attached to project.")
|
48
|
+
assert_equal 200, @command.execute
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
context "attaching" do
|
54
|
+
setup do
|
55
|
+
@mock_client = mock("Client")
|
56
|
+
@command = EPC::Command::AttachLibraryCommand.new(@mock_client)
|
57
|
+
@command.expects(:infer_project_context).returns([1, "FirstProject"])
|
58
|
+
end
|
59
|
+
|
60
|
+
should "retrieve libraries by parsing a pom file" do
|
61
|
+
@command.options[:pom] = "path/to/pom/file"
|
62
|
+
@command.expects(:parse_pom).returns([1])
|
63
|
+
@mock_client.expects(:post).returns([200, {}, {}])
|
64
|
+
@command.expects(:say).with("Library [1] attached to project.")
|
65
|
+
assert_equal 200, @command.execute
|
66
|
+
end
|
67
|
+
|
68
|
+
should "fail if status is not 200" do
|
69
|
+
@mock_client.expects(:post).with(EPC::Config::PROJECTS_PATH + "/1/attach_library/1").
|
70
|
+
returns([404, {:message => "Not Found"}, {}])
|
71
|
+
@command.expects(:say).with("Failed to attach library [1]: [Not Found]")
|
72
|
+
|
73
|
+
assert_equal(@command.execute(1), 404)
|
74
|
+
end
|
75
|
+
|
76
|
+
should "attach the library to the project" do
|
77
|
+
@mock_client.expects(:post).with(EPC::Config::PROJECTS_PATH + "/1/attach_library/1").
|
78
|
+
returns([201, {}, {}])
|
79
|
+
@command.expects(:say).with("Library [1] attached to project.")
|
80
|
+
|
81
|
+
assert_equal(@command.execute(1), 201)
|
82
|
+
end
|
83
|
+
|
84
|
+
should "attach library by name, version and group" do
|
85
|
+
@command.expects(:retrieve_libraries).returns([1])
|
86
|
+
@mock_client.expects(:post).with(EPC::Config::PROJECTS_PATH + "/1/attach_library/1").
|
87
|
+
returns([201, {}, {}])
|
88
|
+
@command.expects(:say).with("Library [1] attached to project.")
|
89
|
+
|
90
|
+
assert_equal(@command.execute("math.lib", "2.0.1", "math-libs"), 201)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "parse pom" do
|
95
|
+
setup do
|
96
|
+
@mock_client = mock("Client")
|
97
|
+
@command = EPC::Command::AttachLibraryCommand.new(@mock_client)
|
98
|
+
@file = File.new(File.join(File.expand_path("."), "path_to_pom"), "w+")
|
99
|
+
end
|
100
|
+
|
101
|
+
teardown do
|
102
|
+
File.delete(@file) if FileTest.exist?(@file)
|
103
|
+
end
|
104
|
+
|
105
|
+
should "throw exception if can't read the file" do
|
106
|
+
assert_raise EPC::Error::FatalError do
|
107
|
+
@command.send(:parse_pom, "path/to/pom")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
should "throw exception if it encounters a malformed/invalid xml file" do
|
112
|
+
assert_raise EPC::Error::FatalError do
|
113
|
+
File.expects(:read).with(File.expand_path("path_to_pom")).returns(@file)
|
114
|
+
REXML::Document.expects(:new).with(@file).raises(REXML::ParseException)
|
115
|
+
@command.send(:parse_pom, "path_to_pom")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
should "parse and retrieve library ids" do
|
120
|
+
@command.expects(:retrieve_libraries).returns([1,2,3])
|
121
|
+
assert_equal @command.send(:parse_pom, "test/test_files/pom.xml"), [1,2,3]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AttachLibrarysetCommandTest < 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::AttachLibrarysetCommand.new(@mock_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "fail if can't determine project context" do
|
13
|
+
assert_raise EPC::Error::InputError do
|
14
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
15
|
+
@command.expects(:infer_project_context).returns(nil)
|
16
|
+
assert_equal(@command.execute(1), 1)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "attaching/detaching" do
|
22
|
+
setup do
|
23
|
+
@mock_client = mock("Client")
|
24
|
+
@command = EPC::Command::AttachLibrarysetCommand.new(@mock_client)
|
25
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
26
|
+
@command.expects(:infer_project_context).returns([1, "FirstProject"])
|
27
|
+
end
|
28
|
+
|
29
|
+
should "issue the request to the server" do
|
30
|
+
@mock_client.expects(:post).with(EPC::Config::PROJECTS_PATH + "/1/attach_set/1").returns([201, {}, {}])
|
31
|
+
@command.expects(:say).with("Library set attached")
|
32
|
+
assert_equal(@command.execute(1), 201)
|
33
|
+
end
|
34
|
+
|
35
|
+
should "issue a detach request when detach option is true" do
|
36
|
+
@command.options[:detach] = true
|
37
|
+
@mock_client.expects(:delete).with(EPC::Config::PROJECTS_PATH + "/1/detach_set/1").returns([201, {}, {}])
|
38
|
+
@command.expects(:say).with("Library set detached")
|
39
|
+
assert_equal(@command.execute(1), 201)
|
40
|
+
end
|
41
|
+
|
42
|
+
should "fail if status is not successful" do
|
43
|
+
@mock_client.expects(:post).with(EPC::Config::PROJECTS_PATH + "/1/attach_set/1").returns([404, {:message => "Not Found"}, {}])
|
44
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
45
|
+
assert_equal(@command.execute(1), 404)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AttachRuntimeCommandTest < Test::Unit::TestCase
|
4
|
+
should_require_login
|
5
|
+
|
6
|
+
context "attaching" do
|
7
|
+
setup do
|
8
|
+
@mock_client = mock("Client")
|
9
|
+
@command = EPC::Command::AttachRuntimeCommand.new(@mock_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
should "fail if no project id specified or could not be determined" do
|
14
|
+
@command.options[:stage] = "development"
|
15
|
+
@command.expects(:infer_project_context).returns(nil)
|
16
|
+
|
17
|
+
assert_raise EPC::Error::InputError do
|
18
|
+
assert_equal(@command.execute(1), 1)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
should "fail if status is not 200" do
|
23
|
+
@command.options[:stage] = "development"
|
24
|
+
@command.expects(:infer_project_context).returns([1, "FirstProject"])
|
25
|
+
@mock_client.expects(:put).with(EPC::Config::PROJECTS_PATH + "/1/set_runtime_env",
|
26
|
+
{:runtime_env_id => 1, :stage_name => 'development'}).
|
27
|
+
returns([404, {:message => "Not Found"}, {}])
|
28
|
+
@command.expects(:say).with("Request failed: [Not Found]")
|
29
|
+
|
30
|
+
assert_equal(@command.execute(1), 404)
|
31
|
+
end
|
32
|
+
|
33
|
+
should "attach the runtime from the project" do
|
34
|
+
@command.options[:stage] = "development"
|
35
|
+
@command.expects(:infer_project_context).returns([1, "FirstProject"])
|
36
|
+
@mock_client.expects(:put).with(EPC::Config::PROJECTS_PATH + "/1/set_runtime_env",
|
37
|
+
{:runtime_env_id => 1, :stage_name => 'development'}).
|
38
|
+
returns([201, {}, {}])
|
39
|
+
@command.expects(:say).with("Runtime attached")
|
40
|
+
|
41
|
+
assert_equal(@command.execute(1), 201)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class BaseCommandTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "translate_status_to_exit_code" do
|
7
|
+
setup do
|
8
|
+
mock_client = mock('Client')
|
9
|
+
@command = EPC::Command::BaseCommand.new(mock_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "return 0 for statuses in the 2xx range" do
|
13
|
+
exit_code = @command.send(:translate_status_to_exit_code, 250)
|
14
|
+
assert_equal 0, exit_code
|
15
|
+
end
|
16
|
+
|
17
|
+
should "return the status otherwise" do
|
18
|
+
[0, 1, 404].each do |code|
|
19
|
+
exit_code = @command.send(:translate_status_to_exit_code, code)
|
20
|
+
assert_equal code, exit_code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context "resource id retrieval" do
|
27
|
+
setup do
|
28
|
+
@mock_client = mock('Client')
|
29
|
+
@command = EPC::Command::BaseCommand.new(@mock_client)
|
30
|
+
@url = EPC::Config::SOLUTIONS_PATH
|
31
|
+
end
|
32
|
+
|
33
|
+
should "fail if status != 200" do
|
34
|
+
@mock_client.expects(:get).with(@url).returns([400, {:message => "Not Found"}, {}])
|
35
|
+
|
36
|
+
assert_raise EPC::Error::InputError do
|
37
|
+
@command.send(:get_resource_id, @url, :name, "Sol1")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
should "retrieve id from the response" do
|
42
|
+
@mock_client.expects(:get).with(@url).returns([200, [{:id => 1, :name => "Sol1"}, {:id => 2, :name => "Sol2"}], {}])
|
43
|
+
id = @command.send(:get_resource_id, @url, :name, "Sol1")
|
44
|
+
assert_equal id, 1
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "infer solution context" do
|
50
|
+
setup do
|
51
|
+
@mock_client = mock("Client")
|
52
|
+
@command = EPC::Command::BaseCommand.new(@mock_client)
|
53
|
+
@path = File.expand_path(".")
|
54
|
+
@project_path = File.expand_path("./..")
|
55
|
+
end
|
56
|
+
|
57
|
+
context "s_identifier nil" do
|
58
|
+
should "read it from the solution directory" do
|
59
|
+
EPC::Config.expects(:is_solution_dir?).returns(true)
|
60
|
+
EPC::Config.expects(:get_solution_value).with(@path, "id").returns(1)
|
61
|
+
EPC::Config.expects(:get_solution_value).with(@path, "name").returns("FirstSolution")
|
62
|
+
result = @command.send(:infer_solution_context, nil, @path)
|
63
|
+
assert_equal(result, [1, "FirstSolution"])
|
64
|
+
end
|
65
|
+
|
66
|
+
should "read it from the project directory" do
|
67
|
+
EPC::Config.expects(:is_project_dir?).returns(true)
|
68
|
+
@command.expects(:project_solution_path).returns(@project_path)
|
69
|
+
EPC::Config.expects(:get_solution_value).with(@project_path, "id").returns(1)
|
70
|
+
EPC::Config.expects(:get_solution_value).with(@project_path, "name").returns("FirstSolution")
|
71
|
+
result = @command.send(:infer_solution_context, nil, @path)
|
72
|
+
assert_equal(result, [1, "FirstSolution"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "s_identifier present" do
|
77
|
+
|
78
|
+
context "numeric s_identifier" do
|
79
|
+
should "just return s_identifier" do
|
80
|
+
sol_id = @command.send(:infer_solution_context, 1, @path)
|
81
|
+
assert_equal([1, nil], sol_id)
|
82
|
+
end
|
83
|
+
|
84
|
+
should "query for solution name when option is passed" do
|
85
|
+
@command.expects(:get_resource_name).returns("FirstSolution")
|
86
|
+
sol_id, sol_name = @command.send(:infer_solution_context, 1, @path, :get_solution_name => true)
|
87
|
+
assert_equal(sol_id, 1)
|
88
|
+
assert_equal(sol_name, "FirstSolution")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "alphanumeric s_identifier" do
|
93
|
+
should "read the id from solution metadata if names coincide and directory is a solution directory" do
|
94
|
+
EPC::Config.expects(:is_solution_dir?).returns(true)
|
95
|
+
EPC::Config.expects(:get_solution_value).with(@path, "name").returns("FirstSolution")
|
96
|
+
EPC::Config.expects(:get_solution_value).with(@path, "id").returns(1)
|
97
|
+
EPC::Config.expects(:get_solution_value).with(@path, "name").returns("FirstSolution")
|
98
|
+
results = @command.send(:infer_solution_context, "FirstSolution", @path)
|
99
|
+
assert_equal(results, [1, "FirstSolution"])
|
100
|
+
end
|
101
|
+
|
102
|
+
should "read the id from solution metadata if directory is a project directory" do
|
103
|
+
EPC::Config.expects(:is_solution_dir?).returns(false)
|
104
|
+
EPC::Config.expects(:is_project_dir?).returns(true)
|
105
|
+
@command.expects(:project_solution_path).with(@path).returns("a_new_path")
|
106
|
+
EPC::Config.expects(:get_solution_value).with("a_new_path", "name").returns("FirstSolution")
|
107
|
+
EPC::Config.expects(:get_solution_value).with("a_new_path", "id").returns(1)
|
108
|
+
EPC::Config.expects(:get_solution_value).with("a_new_path", "name").returns("FirstSolution")
|
109
|
+
|
110
|
+
results = @command.send(:infer_solution_context, "FirstSolution", @path)
|
111
|
+
assert_equal(results, [1, "FirstSolution"])
|
112
|
+
end
|
113
|
+
|
114
|
+
should "query for the solution id if it can't determine id from metadata" do
|
115
|
+
EPC::Config.expects(:is_solution_dir?).returns(false)
|
116
|
+
EPC::Config.expects(:is_project_dir?).returns(false)
|
117
|
+
@command.expects(:get_resource_id).returns(1)
|
118
|
+
results = @command.send(:infer_solution_context, "FirstSolution", @path)
|
119
|
+
assert_equal(results, [1, "FirstSolution"])
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "infer project context" do
|
127
|
+
setup do
|
128
|
+
@mock_client = mock("Client")
|
129
|
+
@command = EPC::Command::BaseCommand.new(@mock_client)
|
130
|
+
@path = File.expand_path(".")
|
131
|
+
@solution_path = File.expand_path("./..")
|
132
|
+
end
|
133
|
+
|
134
|
+
context "s_identifier nil" do
|
135
|
+
|
136
|
+
should "read it from the project directory" do
|
137
|
+
EPC::Config.expects(:is_project_dir?).returns(true)
|
138
|
+
EPC::Config.expects(:get_project_value).with(@path, "id").returns(1)
|
139
|
+
EPC::Config.expects(:get_project_value).with(@path, "name").returns("FirstProject")
|
140
|
+
result = @command.send(:infer_project_context, nil, @path)
|
141
|
+
assert_equal(result, [1, "FirstProject"])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "p_identifier present" do
|
146
|
+
|
147
|
+
context "numeric p_identifier" do
|
148
|
+
should "just return p_identifier" do
|
149
|
+
p_id = @command.send(:infer_project_context, 1, @path)
|
150
|
+
assert_equal([1, nil], p_id)
|
151
|
+
end
|
152
|
+
|
153
|
+
should "query for project name when option is passed" do
|
154
|
+
@command.expects(:get_resource_name).returns("FirstProject")
|
155
|
+
p_id, p_name = @command.send(:infer_project_context, 1, @path, 1, :get_project_name => true)
|
156
|
+
assert_equal(p_id, 1)
|
157
|
+
assert_equal(p_name, "FirstProject")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "alphanumeric p_identifier" do
|
162
|
+
should "query for the project id if a solution identifier has been passed" do
|
163
|
+
@command.expects(:get_resource_id).returns(1)
|
164
|
+
results = @command.send(:infer_project_context, "FirstProject", @path, 1)
|
165
|
+
assert_equal(results, [1, "FirstProject"])
|
166
|
+
end
|
167
|
+
|
168
|
+
should "read the id from project metadata if names coincide and directory is the parent solution directory" do
|
169
|
+
EPC::Config.expects(:is_solution_dir?).with(@path).returns(true)
|
170
|
+
File.expects(:join).with(@path, "FirstProject").returns("project_path")
|
171
|
+
File.expects(:exists?).with("project_path").returns(true)
|
172
|
+
EPC::Config.expects(:get_project_value).with("project_path", "id").returns(1)
|
173
|
+
results = @command.send(:infer_project_context, "FirstProject", @path, nil, {})
|
174
|
+
assert_equal(results, [1, "FirstProject"])
|
175
|
+
end
|
176
|
+
|
177
|
+
should "read the id from project metadata if names coincide and directory is a project directory" do
|
178
|
+
EPC::Config.expects(:is_solution_dir?).with(@path).returns(false)
|
179
|
+
EPC::Config.expects(:is_project_dir?).with(@path).returns(true)
|
180
|
+
EPC::Config.expects(:get_project_value).with(@path, "name").returns("FirstProject")
|
181
|
+
EPC::Config.expects(:get_project_value).with(@path, "id").returns(1)
|
182
|
+
results = @command.send(:infer_project_context, "FirstProject", @path, nil, {})
|
183
|
+
assert_equal(results, [1, "FirstProject"])
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "library retrieval" do
|
191
|
+
setup do
|
192
|
+
@mock_client = mock('Client')
|
193
|
+
@command = EPC::Command::BaseCommand.new(@mock_client)
|
194
|
+
end
|
195
|
+
|
196
|
+
should "fail if library retrieval from server fails" do
|
197
|
+
assert_raise EPC::Error::FatalError do
|
198
|
+
@mock_client.expects(:get).with(EPC::Config::LIBRARIES_PATH).returns([500, {:message => "System exception"}, {}])
|
199
|
+
@command.send(:retrieve_libraries, [{}])
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
should "fail if a library can't be found" do
|
204
|
+
assert_raise EPC::Error::FatalError do
|
205
|
+
@mock_client.expects(:get).with(EPC::Config::LIBRARIES_PATH).
|
206
|
+
returns(
|
207
|
+
[200, [{:id => 2, :name => "lib2", :group => "grp", :library_version => "1"}], {}]
|
208
|
+
)
|
209
|
+
@command.send(:retrieve_libraries, [{:name => "lib1", :library_version => "1.2", :group => "grp"}])
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
should "return library ids" do
|
214
|
+
@mock_client.expects(:get).with(EPC::Config::LIBRARIES_PATH).
|
215
|
+
returns(
|
216
|
+
[200, [{:id => 2, :name => "lib1", :group => "grp", :library_version => "1.2"}], {}]
|
217
|
+
)
|
218
|
+
assert_equal @command.send(:retrieve_libraries, [{:name => "lib1", :library_version => "1.2", :group => "grp"}]), [2]
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
|
223
|
+
context "show_build_status" do
|
224
|
+
setup do
|
225
|
+
@mock_client = mock("Client")
|
226
|
+
@command = EPC::Command::BaseCommand.new(@mock_client)
|
227
|
+
end
|
228
|
+
|
229
|
+
should "return true, id, built and message if the status is 200" do
|
230
|
+
@mock_client.expects(:get).with("/api/v1/builds/7/status").
|
231
|
+
returns([200, { :id => 1, :built => true, :message => 'Success' }, {}])
|
232
|
+
|
233
|
+
created, id, built, message = @command.send(:show_build_status, 7)
|
234
|
+
|
235
|
+
assert(created)
|
236
|
+
assert_equal(1, id)
|
237
|
+
assert(built)
|
238
|
+
end
|
239
|
+
|
240
|
+
should "return false if the status is not 200" do
|
241
|
+
@mock_client.expects(:get).with("/api/v1/builds/7/status").
|
242
|
+
returns([404, { :message => "Not Found" }, {}])
|
243
|
+
|
244
|
+
created, id, built, message = @command.send(:show_build_status, 7)
|
245
|
+
|
246
|
+
assert(!created)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context "poll for build status" do
|
251
|
+
setup do
|
252
|
+
@mock_client = mock("Client")
|
253
|
+
@command = EPC::Command::BaseCommand.new(@mock_client)
|
254
|
+
@command.instance_variable_set(:@timeout, 5)
|
255
|
+
end
|
256
|
+
|
257
|
+
should "poll untill built" do
|
258
|
+
@command.expects(:show_build_status).with(1).returns([true, 1, "", "BUILT"])
|
259
|
+
@command.expects(:say).with("\nBuild completed successfully.")
|
260
|
+
assert_equal(@command.send(:poll_for_build_status, 1), 0)
|
261
|
+
end
|
262
|
+
|
263
|
+
should "poll untill failed" do
|
264
|
+
@command.expects(:show_build_status).with(1).returns([true, 1, "there was an error", "FAILED"])
|
265
|
+
@command.expects(:say).with("\nBuild failed: FAILED - there was an error")
|
266
|
+
assert_equal(@command.send(:poll_for_build_status, 1), 1)
|
267
|
+
end
|
268
|
+
|
269
|
+
should "notify when it's unable to get the build status" do
|
270
|
+
@command.expects(:show_build_status).with(1).returns([false, 1, "there was an error", "FAILED"])
|
271
|
+
@command.expects(:say).with("Poller failed to get the build status. Aborting.")
|
272
|
+
assert_equal(@command.send(:poll_for_build_status, 1), 1)
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
end
|