cf_script 0.0.1.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +12 -0
- data/LICENSE +22 -0
- data/README.md +84 -0
- data/Rakefile +33 -0
- data/cf_script.gemspec +34 -0
- data/lib/cf_script/callbacks.rb +43 -0
- data/lib/cf_script/command/base.rb +57 -0
- data/lib/cf_script/command/cf/apps/app.rb +19 -0
- data/lib/cf_script/command/cf/apps/apps.rb +44 -0
- data/lib/cf_script/command/cf/apps/env.rb +20 -0
- data/lib/cf_script/command/cf/apps/push.rb +47 -0
- data/lib/cf_script/command/cf/apps/restage.rb +19 -0
- data/lib/cf_script/command/cf/apps/restart.rb +19 -0
- data/lib/cf_script/command/cf/apps/set_env.rb +18 -0
- data/lib/cf_script/command/cf/apps/start.rb +19 -0
- data/lib/cf_script/command/cf/apps/stop.rb +19 -0
- data/lib/cf_script/command/cf/apps/unset_env.rb +18 -0
- data/lib/cf_script/command/cf/apps.rb +55 -0
- data/lib/cf_script/command/cf/general/api.rb +36 -0
- data/lib/cf_script/command/cf/general/auth.rb +28 -0
- data/lib/cf_script/command/cf/general/login.rb +42 -0
- data/lib/cf_script/command/cf/general/logout.rb +15 -0
- data/lib/cf_script/command/cf/general/target.rb +64 -0
- data/lib/cf_script/command/cf/general.rb +15 -0
- data/lib/cf_script/command/cf/routes/check_route.rb +17 -0
- data/lib/cf_script/command/cf/routes/create_route.rb +19 -0
- data/lib/cf_script/command/cf/routes/delete_route.rb +19 -0
- data/lib/cf_script/command/cf/routes/map_route.rb +30 -0
- data/lib/cf_script/command/cf/routes/routes.rb +40 -0
- data/lib/cf_script/command/cf/routes/unmap_route.rb +30 -0
- data/lib/cf_script/command/cf/routes.rb +17 -0
- data/lib/cf_script/command/cf/spaces/space.rb +36 -0
- data/lib/cf_script/command/cf/spaces/spaces.rb +23 -0
- data/lib/cf_script/command/cf/spaces.rb +9 -0
- data/lib/cf_script/command/error.rb +5 -0
- data/lib/cf_script/command/line.rb +105 -0
- data/lib/cf_script/command/registry.rb +50 -0
- data/lib/cf_script/command/runner.rb +97 -0
- data/lib/cf_script/command.rb +44 -0
- data/lib/cf_script/config.rb +60 -0
- data/lib/cf_script/executor/non_blocking.rb +107 -0
- data/lib/cf_script/executor/recorder.rb +16 -0
- data/lib/cf_script/executor/simple.rb +17 -0
- data/lib/cf_script/executor.rb +5 -0
- data/lib/cf_script/manifest.rb +38 -0
- data/lib/cf_script/object/api_endpoint.rb +10 -0
- data/lib/cf_script/object/app_info.rb +69 -0
- data/lib/cf_script/object/app_list.rb +24 -0
- data/lib/cf_script/object/app_spec.rb +55 -0
- data/lib/cf_script/object/attribute.rb +18 -0
- data/lib/cf_script/object/attribute_list.rb +40 -0
- data/lib/cf_script/object/instance_status.rb +29 -0
- data/lib/cf_script/object/route_info.rb +14 -0
- data/lib/cf_script/object/space.rb +17 -0
- data/lib/cf_script/object/target.rb +23 -0
- data/lib/cf_script/object.rb +24 -0
- data/lib/cf_script/output/buffer.rb +74 -0
- data/lib/cf_script/output/parser/attributes.rb +44 -0
- data/lib/cf_script/output/parser/section.rb +15 -0
- data/lib/cf_script/output/parser/table.rb +46 -0
- data/lib/cf_script/output/parser.rb +15 -0
- data/lib/cf_script/output/tests.rb +51 -0
- data/lib/cf_script/output/utils.rb +13 -0
- data/lib/cf_script/output.rb +62 -0
- data/lib/cf_script/scope/app/env.rb +15 -0
- data/lib/cf_script/scope/app/routes.rb +21 -0
- data/lib/cf_script/scope/app/state.rb +33 -0
- data/lib/cf_script/scope/app/utils.rb +32 -0
- data/lib/cf_script/scope/app.rb +94 -0
- data/lib/cf_script/scope/proxy.rb +36 -0
- data/lib/cf_script/scope/script.rb +59 -0
- data/lib/cf_script/scope/space.rb +9 -0
- data/lib/cf_script/scope/target.rb +90 -0
- data/lib/cf_script/scope.rb +68 -0
- data/lib/cf_script/ui.rb +261 -0
- data/lib/cf_script/utils.rb +19 -0
- data/lib/cf_script/version.rb +3 -0
- data/lib/cf_script.rb +105 -0
- data/test/fixtures/commands/apps/app/good.yml +18 -0
- data/test/fixtures/commands/apps/app/not_found.yml +8 -0
- data/test/fixtures/commands/apps/app/running.yml +19 -0
- data/test/fixtures/commands/apps/apps/good.yml +14 -0
- data/test/fixtures/commands/apps/apps/no_apps.yml +10 -0
- data/test/fixtures/commands/apps/env/empty.yml +37 -0
- data/test/fixtures/commands/apps/env/good.yml +41 -0
- data/test/fixtures/commands/apps/push/good.yml +60 -0
- data/test/fixtures/commands/apps/restage/good.yml +48 -0
- data/test/fixtures/commands/apps/restage/not_found.yml +8 -0
- data/test/fixtures/commands/apps/restart/good.yml +35 -0
- data/test/fixtures/commands/apps/restart/not_found.yml +8 -0
- data/test/fixtures/commands/apps/set_env/empty.yml +5 -0
- data/test/fixtures/commands/apps/set_env/good.yml +9 -0
- data/test/fixtures/commands/apps/set_env/not_found.yml +8 -0
- data/test/fixtures/commands/apps/start/good.yml +32 -0
- data/test/fixtures/commands/apps/start/not_found.yml +8 -0
- data/test/fixtures/commands/apps/start/with_container.yml +98 -0
- data/test/fixtures/commands/apps/stop/good.yml +8 -0
- data/test/fixtures/commands/apps/stop/not_found.yml +8 -0
- data/test/fixtures/commands/apps/unset_env/empty.yml +5 -0
- data/test/fixtures/commands/apps/unset_env/good.yml +9 -0
- data/test/fixtures/commands/apps/unset_env/not_found.yml +8 -0
- data/test/fixtures/commands/common/fail.yml +5 -0
- data/test/fixtures/commands/common/no_endpoint.yml +11 -0
- data/test/fixtures/commands/common/no_login.yml +8 -0
- data/test/fixtures/commands/general/api/bad_argument.yml +9 -0
- data/test/fixtures/commands/general/api/bad_endpoint.yml +9 -0
- data/test/fixtures/commands/general/api/good.yml +7 -0
- data/test/fixtures/commands/general/api/not_set.yml +7 -0
- data/test/fixtures/commands/general/api/set.yml +7 -0
- data/test/fixtures/commands/general/auth/empty.yml +5 -0
- data/test/fixtures/commands/general/auth/good.yml +10 -0
- data/test/fixtures/commands/general/auth/rejected.yml +10 -0
- data/test/fixtures/commands/general/login/good.yml +8 -0
- data/test/fixtures/commands/general/login/rejected.yml +23 -0
- data/test/fixtures/commands/general/logout/good.yml +8 -0
- data/test/fixtures/commands/general/target/empty.yml +5 -0
- data/test/fixtures/commands/general/target/good.yml +11 -0
- data/test/fixtures/commands/general/target/no_space.yml +10 -0
- data/test/fixtures/commands/general/target/not_found.yml +9 -0
- data/test/fixtures/commands/general/target/production.yml +11 -0
- data/test/fixtures/commands/general/target/staging.yml +11 -0
- data/test/fixtures/commands/general/target/staging_org.yml +11 -0
- data/test/fixtures/commands/general/target/test.yml +11 -0
- data/test/fixtures/commands/routes/check_route/good.yml +9 -0
- data/test/fixtures/commands/routes/check_route/no_domain.yml +9 -0
- data/test/fixtures/commands/routes/check_route/no_route.yml +9 -0
- data/test/fixtures/commands/routes/create_route/exists.yml +9 -0
- data/test/fixtures/commands/routes/create_route/good.yml +8 -0
- data/test/fixtures/commands/routes/delete_route/good.yml +8 -0
- data/test/fixtures/commands/routes/delete_route/not_exist.yml +8 -0
- data/test/fixtures/commands/routes/map_route/good.yml +10 -0
- data/test/fixtures/commands/routes/map_route/host_taken.yml +10 -0
- data/test/fixtures/commands/routes/map_route/invalid.yml +9 -0
- data/test/fixtures/commands/routes/map_route/no_app.yml +8 -0
- data/test/fixtures/commands/routes/map_route/no_domain.yml +9 -0
- data/test/fixtures/commands/routes/routes/good.yml +14 -0
- data/test/fixtures/commands/routes/unmap_route/good.yml +8 -0
- data/test/fixtures/commands/routes/unmap_route/no_app.yml +8 -0
- data/test/fixtures/commands/routes/unmap_route/no_domain.yml +9 -0
- data/test/fixtures/commands/spaces/space/empty.yml +5 -0
- data/test/fixtures/commands/spaces/space/good.yml +16 -0
- data/test/fixtures/commands/spaces/space/staging.yml +16 -0
- data/test/fixtures/commands/spaces/spaces/empty.yml +5 -0
- data/test/fixtures/commands/spaces/spaces/good.yml +12 -0
- data/test/lib/cf_script/command/base_test.rb +21 -0
- data/test/lib/cf_script/command/cf/apps/app_test.rb +56 -0
- data/test/lib/cf_script/command/cf/apps/apps_test.rb +81 -0
- data/test/lib/cf_script/command/cf/apps/env_test.rb +55 -0
- data/test/lib/cf_script/command/cf/apps/push_test.rb +46 -0
- data/test/lib/cf_script/command/cf/apps/restage_test.rb +47 -0
- data/test/lib/cf_script/command/cf/apps/restart_test.rb +47 -0
- data/test/lib/cf_script/command/cf/apps/set_env_test.rb +38 -0
- data/test/lib/cf_script/command/cf/apps/start_test.rb +55 -0
- data/test/lib/cf_script/command/cf/apps/stop_test.rb +35 -0
- data/test/lib/cf_script/command/cf/apps/unset_env_test.rb +38 -0
- data/test/lib/cf_script/command/cf/general/api_test.rb +55 -0
- data/test/lib/cf_script/command/cf/general/auth_test.rb +76 -0
- data/test/lib/cf_script/command/cf/general/login_test.rb +80 -0
- data/test/lib/cf_script/command/cf/general/logout_test.rb +34 -0
- data/test/lib/cf_script/command/cf/general/target_test.rb +110 -0
- data/test/lib/cf_script/command/cf/routes/check_route_test.rb +31 -0
- data/test/lib/cf_script/command/cf/routes/create_route_test.rb +19 -0
- data/test/lib/cf_script/command/cf/routes/delete_route_test.rb +19 -0
- data/test/lib/cf_script/command/cf/routes/map_route_test.rb +56 -0
- data/test/lib/cf_script/command/cf/routes/routes_test.rb +24 -0
- data/test/lib/cf_script/command/cf/routes/unmap_route_test.rb +36 -0
- data/test/lib/cf_script/command/cf/spaces/space_test.rb +55 -0
- data/test/lib/cf_script/command/cf/spaces/spaces_test.rb +47 -0
- data/test/lib/cf_script/command/line_test.rb +59 -0
- data/test/lib/cf_script/object/api_endpoint_test.rb +19 -0
- data/test/lib/cf_script/object/app_info_test.rb +127 -0
- data/test/lib/cf_script/object/app_list_test.rb +51 -0
- data/test/lib/cf_script/object/attribute_list_test.rb +42 -0
- data/test/lib/cf_script/object/attribute_test.rb +29 -0
- data/test/lib/cf_script/object/instance_status_test.rb +37 -0
- data/test/lib/cf_script/object/space_test.rb +31 -0
- data/test/lib/cf_script/object/target_test.rb +41 -0
- data/test/lib/cf_script/output/buffer_test.rb +73 -0
- data/test/lib/cf_script/output/parser/attributes_test.rb +102 -0
- data/test/lib/cf_script/output/parser/section_test.rb +60 -0
- data/test/lib/cf_script/output/parser/table_test.rb +108 -0
- data/test/lib/cf_script/output/tests_test.rb +91 -0
- data/test/lib/cf_script/output_test.rb +134 -0
- data/test/lib/cf_script/scope/app/state_test.rb +61 -0
- data/test/lib/cf_script/scope/app_test.rb +101 -0
- data/test/lib/cf_script/scope/script_test.rb +88 -0
- data/test/lib/cf_script/scope/space_test.rb +27 -0
- data/test/lib/cf_script/scope/target_test.rb +158 -0
- data/test/lib/cf_script/scope_test.rb +41 -0
- data/test/lib/cf_script/utils_test.rb +20 -0
- data/test/lib/cf_script_test.rb +73 -0
- data/test/support/assertions.rb +14 -0
- data/test/support/helpers/config_context.rb +19 -0
- data/test/support/helpers/fixture_executor.rb +79 -0
- data/test/support/helpers/mock_execution.rb +58 -0
- data/test/support/helpers/object_helpers.rb +29 -0
- data/test/support/helpers/output_sink.rb +25 -0
- data/test/support/helpers.rb +3 -0
- data/test/support/shared_examples/command_object.rb +38 -0
- data/test/support/shared_examples.rb +30 -0
- data/test/test_helper.rb +34 -0
- metadata +321 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
stdout: |
|
3
|
+
Getting routes as user@example.com ...
|
4
|
+
|
5
|
+
space host domain apps
|
6
|
+
development users example.io
|
7
|
+
development api example.io api, users
|
8
|
+
development org-development-frontend-green example.ps
|
9
|
+
development org-development-projects-green example.io
|
10
|
+
development org-projects example.io projects-green
|
11
|
+
|
12
|
+
stderr: ''
|
13
|
+
status:
|
14
|
+
exitstatus: 0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
stdout: |
|
3
|
+
Getting info for space staging in org ACME as user@example.com...
|
4
|
+
OK
|
5
|
+
|
6
|
+
staging
|
7
|
+
Org: ACME
|
8
|
+
Apps: org-frontend-staging, org-backend-staging
|
9
|
+
Domains: cf.io, example.com
|
10
|
+
Services: org-db, org-cache
|
11
|
+
Security Groups: ssh, dns, log
|
12
|
+
Space Quota:
|
13
|
+
|
14
|
+
stderr: ''
|
15
|
+
status:
|
16
|
+
exitstatus: 0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
stdout: |
|
3
|
+
Getting info for space staging in org ACME as user@example.com...
|
4
|
+
OK
|
5
|
+
|
6
|
+
staging
|
7
|
+
Org: ACME
|
8
|
+
Apps: org-frontend-staging, org-backend-staging
|
9
|
+
Domains: cf.io, example.com
|
10
|
+
Services: org-db, org-cache
|
11
|
+
Security Groups: ssh, dns, log
|
12
|
+
Space Quota:
|
13
|
+
|
14
|
+
stderr: ''
|
15
|
+
status:
|
16
|
+
exitstatus: 0
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::Command::Base do
|
4
|
+
class TestCommand < CfScript::Command::Base
|
5
|
+
def initialize
|
6
|
+
super(:test, :dummy)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "defines a line method that returns a Command::Line object" do
|
11
|
+
line = TestCommand.instance.line({}, 'cf', [])
|
12
|
+
|
13
|
+
assert_instance_of CfScript::Command::Line, line
|
14
|
+
end
|
15
|
+
|
16
|
+
it "raises an exception if run is called" do
|
17
|
+
assert_raises(RuntimeError) {
|
18
|
+
TestCommand.instance.run
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'AppCommand' do
|
4
|
+
include MockExecution
|
5
|
+
|
6
|
+
let(:command) { CfScript::Command::Apps::AppCommand.instance }
|
7
|
+
|
8
|
+
it_behaves_like 'a command object that', {
|
9
|
+
has_type: :apps,
|
10
|
+
has_name: :app,
|
11
|
+
fails_with: nil
|
12
|
+
}
|
13
|
+
|
14
|
+
it "returns an App object" do
|
15
|
+
fake_cf do
|
16
|
+
app = command.run(:frontend)
|
17
|
+
|
18
|
+
assert_kind_of CfScript::AppInfo, app
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "yields an App object when a block is given" do
|
23
|
+
fake_cf do
|
24
|
+
called = false
|
25
|
+
|
26
|
+
command.run(:worker) do |app|
|
27
|
+
called = true
|
28
|
+
|
29
|
+
assert_kind_of CfScript::AppInfo, app
|
30
|
+
end
|
31
|
+
|
32
|
+
assert called, "Expected block to have been called"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns nil when the app is not found" do
|
37
|
+
fake_cf app: :not_found do
|
38
|
+
assert_equal nil, command.run(:api)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "includes status line" do
|
43
|
+
fake_cf app: :running do |stdout, srderr|
|
44
|
+
app = command.run(:frontend)
|
45
|
+
|
46
|
+
assert_kind_of CfScript::AppInfo, app
|
47
|
+
|
48
|
+
assert_instance_of Array, app.instance_status
|
49
|
+
assert_equal 1, app.instance_status.length
|
50
|
+
|
51
|
+
app.instance_status.each do |instance_status|
|
52
|
+
assert_instance_of CfScript::InstanceStatus, instance_status
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'AppsCommand' do
|
4
|
+
include MockExecution
|
5
|
+
|
6
|
+
let(:command) { CfScript::Command::Apps::AppsCommand.instance }
|
7
|
+
|
8
|
+
it_behaves_like 'a command object that', {
|
9
|
+
has_type: :apps,
|
10
|
+
has_name: :apps,
|
11
|
+
fails_with: []
|
12
|
+
}
|
13
|
+
|
14
|
+
it "returns an AppList object" do
|
15
|
+
fake_cf do
|
16
|
+
apps = command.run
|
17
|
+
|
18
|
+
assert_instance_of CfScript::AppList, apps
|
19
|
+
apps.each do |app_info|
|
20
|
+
assert_instance_of CfScript::AppInfo, app_info
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "yields an AppList object when a block is given" do
|
26
|
+
fake_cf do
|
27
|
+
called = false
|
28
|
+
|
29
|
+
command.run do |apps|
|
30
|
+
called = true
|
31
|
+
|
32
|
+
assert_instance_of CfScript::AppList, apps
|
33
|
+
apps.each do |app_info|
|
34
|
+
assert_instance_of CfScript::AppInfo, app_info
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
assert called, "Expected block to have been called"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "correctly builds the AppInfo objects" do
|
43
|
+
fake_cf do
|
44
|
+
apps = command.run
|
45
|
+
|
46
|
+
assert_equal [
|
47
|
+
'org-one-api',
|
48
|
+
'org-one-worker',
|
49
|
+
'org-two-api',
|
50
|
+
'org-two-worker'
|
51
|
+
], apps.map(&:name)
|
52
|
+
|
53
|
+
assert_equal [
|
54
|
+
'stopped',
|
55
|
+
'started',
|
56
|
+
'stopped',
|
57
|
+
'started'
|
58
|
+
], apps.map(&:requested_state)
|
59
|
+
|
60
|
+
assert_equal ['0/1', '1/3', '0/2', '1/1'], apps.map(&:instances)
|
61
|
+
assert_equal ['256M', '1G', '256M', '2G'], apps.map(&:memory)
|
62
|
+
assert_equal ['1G', '2G', '3G', '4G'], apps.map(&:disk)
|
63
|
+
|
64
|
+
assert_equal [
|
65
|
+
['example.com', 'example.net'],
|
66
|
+
[],
|
67
|
+
['example.io', 'example.org'],
|
68
|
+
[]
|
69
|
+
], apps.map(&:urls)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "returns an empty Array when no apps are found" do
|
74
|
+
fake_cf apps: :no_apps do
|
75
|
+
apps = command.run
|
76
|
+
|
77
|
+
assert_instance_of Array, apps
|
78
|
+
assert_equal [], apps
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'EnvCommand' do
|
4
|
+
include MockExecution
|
5
|
+
|
6
|
+
let(:command) { CfScript::Command::Apps::EnvCommand.instance }
|
7
|
+
|
8
|
+
it_behaves_like 'a command object that', {
|
9
|
+
has_type: :apps,
|
10
|
+
has_name: :env,
|
11
|
+
fails_with: {}
|
12
|
+
}
|
13
|
+
|
14
|
+
it "returns a Hash" do
|
15
|
+
expected = {
|
16
|
+
'SERVER_HOSTNAME' => 'host.example.com',
|
17
|
+
'SERVER_HOSTPORT' => '1234',
|
18
|
+
'SERVER_USERNAME' => 'name',
|
19
|
+
'SERVER_PASSWORD' => 'word',
|
20
|
+
}
|
21
|
+
|
22
|
+
fake_cf do
|
23
|
+
envs = command.run(:worker)
|
24
|
+
|
25
|
+
assert_instance_of Hash, envs
|
26
|
+
|
27
|
+
assert_equal expected.length, envs.length
|
28
|
+
|
29
|
+
expected.each do |name, value|
|
30
|
+
assert_equal expected[name], envs[name]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "yields a Hash when a block is given" do
|
36
|
+
fake_cf do
|
37
|
+
called = false
|
38
|
+
|
39
|
+
command.run(:worker) do |envs|
|
40
|
+
assert_instance_of Hash, envs
|
41
|
+
assert_equal 4, envs.length
|
42
|
+
|
43
|
+
called = true
|
44
|
+
end
|
45
|
+
|
46
|
+
assert called, "Expected block to have been called"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns an empty Hash when no env variables are found" do
|
51
|
+
fake_cf env: :empty do
|
52
|
+
assert_equal({}, command.run(:worker))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'PushCommand' do
|
4
|
+
include MockExecution
|
5
|
+
|
6
|
+
let(:command) { CfScript::Command::Apps::PushCommand.instance }
|
7
|
+
|
8
|
+
it_behaves_like 'a command object that', {
|
9
|
+
has_type: :apps,
|
10
|
+
has_name: :push,
|
11
|
+
fails_with: nil
|
12
|
+
}
|
13
|
+
|
14
|
+
it "returns an AppInfo object on success" do
|
15
|
+
fake_cf do
|
16
|
+
app_info = command.run(:worker)
|
17
|
+
|
18
|
+
assert_instance_of CfScript::AppInfo, app_info
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "translates long option names to cf's short ones" do
|
23
|
+
fake_cf do
|
24
|
+
assert_equal({ f: 'a' }, command.translate_options({ manifest: 'a' }))
|
25
|
+
assert_equal({ i: 'a' }, command.translate_options({ instances: 'a' }))
|
26
|
+
assert_equal({ m: 'a' }, command.translate_options({ memory: 'a' }))
|
27
|
+
assert_equal({ c: 'a' }, command.translate_options({ command: 'a' }))
|
28
|
+
assert_equal({ b: 'a' }, command.translate_options({ buildpack: 'a' }))
|
29
|
+
assert_equal({ n: 'a' }, command.translate_options({ hostname: 'a' }))
|
30
|
+
assert_equal({ d: 'a' }, command.translate_options({ domain: 'a' }))
|
31
|
+
assert_equal({ k: 'a' }, command.translate_options({ disk: 'a' }))
|
32
|
+
assert_equal({ p: 'a' }, command.translate_options({ path: 'a' }))
|
33
|
+
assert_equal({ s: 'a' }, command.translate_options({ stack: 'a' }))
|
34
|
+
assert_equal({ t: 'a' }, command.translate_options({ timeout: 'a' }))
|
35
|
+
assert_equal({ o: 'a' }, command.translate_options({ docker_image: 'a' }))
|
36
|
+
assert_equal({ u: 'a' }, command.translate_options({ health_check_type: 'a' }))
|
37
|
+
|
38
|
+
assert_equal(
|
39
|
+
{ m: 'b', c: 'a', u: 'd', k: 'c' },
|
40
|
+
command.translate_options(
|
41
|
+
{ command: 'a', memory: 'b', disk: 'c', health_check_type: 'd' }
|
42
|
+
)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'RestageCommand' do
|
4
|
+
include MockExecution
|
5
|
+
|
6
|
+
let(:command) { CfScript::Command::Apps::RestageCommand.instance }
|
7
|
+
|
8
|
+
it_behaves_like 'a command object that', {
|
9
|
+
has_type: :apps,
|
10
|
+
has_name: :restage,
|
11
|
+
fails_with: nil
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:expected_instances) {[
|
15
|
+
{
|
16
|
+
index: '#0',
|
17
|
+
state: 'running',
|
18
|
+
since: '2015-12-25 00:00:00 AM',
|
19
|
+
cpu: '42.0%',
|
20
|
+
memory: '12.3M of 256M',
|
21
|
+
disk: '45.6M of 1G',
|
22
|
+
details: ''
|
23
|
+
}, {
|
24
|
+
index: '#1',
|
25
|
+
state: 'stopped',
|
26
|
+
since: '2015-12-25 00:00:00 AM',
|
27
|
+
cpu: '0.0%',
|
28
|
+
memory: '0M of 256M',
|
29
|
+
disk: '45.6M of 1G',
|
30
|
+
details: ''
|
31
|
+
},
|
32
|
+
]}
|
33
|
+
|
34
|
+
it "returns an AppStaus object with its instance_status set on success" do
|
35
|
+
fake_cf do
|
36
|
+
app_info = command.run(:some_app)
|
37
|
+
|
38
|
+
assert_app_info(app_info, expected_instances)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns nil on failure" do
|
43
|
+
fake_cf restage: :not_found do
|
44
|
+
assert_equal nil, command.run(:some_app)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'RestartCommand' do
|
4
|
+
include MockExecution
|
5
|
+
|
6
|
+
let(:command) { CfScript::Command::Apps::RestartCommand.instance }
|
7
|
+
|
8
|
+
it_behaves_like 'a command object that', {
|
9
|
+
has_type: :apps,
|
10
|
+
has_name: :restart,
|
11
|
+
fails_with: nil
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:expected_instances) {[
|
15
|
+
{
|
16
|
+
index: '#0',
|
17
|
+
state: 'running',
|
18
|
+
since: '2015-12-25 00:00:00 AM',
|
19
|
+
cpu: '42.0%',
|
20
|
+
memory: '12.3M of 256M',
|
21
|
+
disk: '45.6M of 1G',
|
22
|
+
details: ''
|
23
|
+
}, {
|
24
|
+
index: '#1',
|
25
|
+
state: 'stopped',
|
26
|
+
since: '2015-12-25 00:00:00 AM',
|
27
|
+
cpu: '0.0%',
|
28
|
+
memory: '0M of 256M',
|
29
|
+
disk: '45.6M of 1G',
|
30
|
+
details: ''
|
31
|
+
},
|
32
|
+
]}
|
33
|
+
|
34
|
+
it "returns an AppStaus object with its instance_status set on success" do
|
35
|
+
fake_cf do
|
36
|
+
app_info = command.run(:some_app)
|
37
|
+
|
38
|
+
assert_app_info(app_info, expected_instances)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns nil on failure" do
|
43
|
+
fake_cf restart: :not_found do
|
44
|
+
assert_equal nil, command.run(:some_app)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'SetEnvCommand' do
|
4
|
+
include MockExecution
|
5
|
+
|
6
|
+
let(:command) { CfScript::Command::Apps::SetEnvCommand.instance }
|
7
|
+
|
8
|
+
it_behaves_like 'a command object that', {
|
9
|
+
has_type: :apps,
|
10
|
+
has_name: :set_env,
|
11
|
+
fails_with: false
|
12
|
+
}
|
13
|
+
|
14
|
+
it "returns true on success" do
|
15
|
+
fake_cf do |o, e|
|
16
|
+
result = command.run(:worker, 'NAME', 'VALUE')
|
17
|
+
|
18
|
+
assert_equal true, result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns false if the output was empty" do
|
23
|
+
fake_cf set_env: :empty do
|
24
|
+
result = command.run(:app, 'NAME', 'VALUE')
|
25
|
+
|
26
|
+
assert_equal false, result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "prints an error on failure" do
|
31
|
+
fake_cf set_env: :not_found do |stdout, stderr|
|
32
|
+
result = command.run(:api, 'API_PASSWORD', 'password')
|
33
|
+
|
34
|
+
assert_equal false, result
|
35
|
+
assert_match /\{set_env\} FAILED/, stderr.lines.first
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'StartCommand' do
|
4
|
+
include MockExecution
|
5
|
+
|
6
|
+
let(:command) { CfScript::Command::Apps::StartCommand.instance }
|
7
|
+
|
8
|
+
it_behaves_like 'a command object that', {
|
9
|
+
has_type: :apps,
|
10
|
+
has_name: :start,
|
11
|
+
fails_with: nil
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:expected_instances) {[
|
15
|
+
{
|
16
|
+
index: '#0',
|
17
|
+
state: 'running',
|
18
|
+
since: '2015-12-25 00:00:00 AM',
|
19
|
+
cpu: '42.0%',
|
20
|
+
memory: '12.3M of 256M',
|
21
|
+
disk: '45.6M of 1G',
|
22
|
+
details: ''
|
23
|
+
}, {
|
24
|
+
index: '#1',
|
25
|
+
state: 'stopped',
|
26
|
+
since: '2015-12-25 00:00:00 AM',
|
27
|
+
cpu: '0.0%',
|
28
|
+
memory: '0M of 256M',
|
29
|
+
disk: '45.6M of 1G',
|
30
|
+
details: ''
|
31
|
+
},
|
32
|
+
]}
|
33
|
+
|
34
|
+
it "returns an AppStaus object with its instance_status set on success" do
|
35
|
+
fake_cf do
|
36
|
+
app_info = command.run(:some_app)
|
37
|
+
|
38
|
+
assert_app_info(app_info, expected_instances)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "correctly handles container creation output" do
|
43
|
+
fake_cf start: :with_container do
|
44
|
+
app_info = command.run(:frontend)
|
45
|
+
|
46
|
+
assert_app_info(app_info, expected_instances)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns nil on failure" do
|
51
|
+
fake_cf start: :not_found do
|
52
|
+
assert_equal nil, command.run(:some_app)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'StopCommand' do
|
4
|
+
include MockExecution
|
5
|
+
|
6
|
+
let(:command) { CfScript::Command::Apps::StopCommand.instance }
|
7
|
+
|
8
|
+
it_behaves_like 'a command object that', {
|
9
|
+
has_type: :apps,
|
10
|
+
has_name: :stop,
|
11
|
+
fails_with: false
|
12
|
+
}
|
13
|
+
|
14
|
+
it "returns true on success" do
|
15
|
+
fake_cf do
|
16
|
+
assert command.run(:worker)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "prints an error on failure" do
|
21
|
+
fake_cf stop: :not_found do |stdout, stderr|
|
22
|
+
command.run(:bogus)
|
23
|
+
|
24
|
+
assert_match /\{stop\} failed to stop/, stderr.lines.first
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns false when the app is not found" do
|
29
|
+
fake_cf stop: :not_found do |stdout, stderr|
|
30
|
+
refute command.run(:bogus)
|
31
|
+
|
32
|
+
assert_match /\{stop\} failed to stop/, stderr.lines.first
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'UnsetEnvCommand' do
|
4
|
+
include MockExecution
|
5
|
+
|
6
|
+
let(:command) { CfScript::Command::Apps::UnsetEnvCommand.instance }
|
7
|
+
|
8
|
+
it_behaves_like 'a command object that', {
|
9
|
+
has_type: :apps,
|
10
|
+
has_name: :unset_env,
|
11
|
+
fails_with: false
|
12
|
+
}
|
13
|
+
|
14
|
+
it "returns true on success" do
|
15
|
+
fake_cf do |o, e|
|
16
|
+
result = command.run(:worker, 'NAME')
|
17
|
+
|
18
|
+
assert_equal true, result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns false if the output was empty" do
|
23
|
+
fake_cf unset_env: :empty do
|
24
|
+
result = command.run(:app, 'NAME')
|
25
|
+
|
26
|
+
assert_equal false, result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "prints an error on failure" do
|
31
|
+
fake_cf unset_env: :not_found do |stdout, stderr|
|
32
|
+
result = command.run(:bogus, 'VAR_NAME')
|
33
|
+
|
34
|
+
assert_equal false, result
|
35
|
+
assert_match /\{unset_env\} FAILED/, stderr.lines.first
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|