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,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::Command::Line do
|
4
|
+
subject { CfScript::Command::Line }
|
5
|
+
|
6
|
+
it "initializes bin, name, args, options, and flags" do
|
7
|
+
line = subject.new({ foo: :bar}, 'bin', :test, :dummy, [:arg1, :arg2, { i: 1, o: 2, flags: [:s] }])
|
8
|
+
|
9
|
+
assert_equal 'bin', line.bin
|
10
|
+
assert_equal :dummy, line.name
|
11
|
+
assert_equal [:arg1, :arg2], line.args
|
12
|
+
assert_equal({ i: 1, o: 2 }, line.options)
|
13
|
+
assert_equal [:s], line.flags
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "line" do
|
17
|
+
it "returns a formatted command line" do
|
18
|
+
line = subject.new({}, 'cf', :test, :dummy, [:arg1, :arg2, { i: 1, o: 2, flags: [:s] }])
|
19
|
+
|
20
|
+
assert_equal 'cf dummy arg1 arg2 -i 1 -o 2 -s', line.line
|
21
|
+
end
|
22
|
+
|
23
|
+
it "formats long flag names" do
|
24
|
+
line = subject.new({}, 'cf', :test, :dummy, [:arg1, { i: 1, flags: [:some_thing] }])
|
25
|
+
|
26
|
+
assert_equal 'cf dummy arg1 -i 1 --some-thing', line.line
|
27
|
+
end
|
28
|
+
|
29
|
+
it "pass preformatted flags as is" do
|
30
|
+
line = subject.new({}, 'cf', :test, :dummy, [:arg1, { i: 1, flags: ['--one', '--foo-bar'] }])
|
31
|
+
|
32
|
+
assert_equal 'cf dummy arg1 -i 1 --one --foo-bar', line.line
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "hides password for auth command" do
|
37
|
+
line = subject.new({}, 'cf', :test, :auth, ['username', 'password'])
|
38
|
+
|
39
|
+
assert_equal 'cf auth username [PASSWORD HIDDEN]', line.hide_sensitive
|
40
|
+
end
|
41
|
+
|
42
|
+
it "hides password for login command" do
|
43
|
+
options = [
|
44
|
+
{ p: 'word', u: 'name', a: 'work' },
|
45
|
+
{ u: 'name', p: 'word', a: 'work' },
|
46
|
+
{ u: 'name', a: 'work', p: 'word' },
|
47
|
+
]
|
48
|
+
|
49
|
+
options.each do |test|
|
50
|
+
line = subject.new({}, 'cf', :test, :login, [test])
|
51
|
+
text = line.hide_sensitive
|
52
|
+
|
53
|
+
assert_match /cf login /, text
|
54
|
+
assert_match /-p \[PASSWORD HIDDEN\]/, text
|
55
|
+
assert_match /-u name/, text
|
56
|
+
assert_match /-a work/, text
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::ApiEndpoint do
|
4
|
+
subject { CfScript::ApiEndpoint }
|
5
|
+
|
6
|
+
it "initializes all attributes to sensible defaults" do
|
7
|
+
api_endpoint = subject.new
|
8
|
+
|
9
|
+
assert_equal nil, api_endpoint.url
|
10
|
+
assert_equal nil, api_endpoint.version
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets all given attributes" do
|
14
|
+
api_endpoint = subject.new('URL', '123')
|
15
|
+
|
16
|
+
assert_equal 'URL', api_endpoint.url
|
17
|
+
assert_equal '123', api_endpoint.version
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::AppInfo do
|
4
|
+
include ObjectHelpers
|
5
|
+
|
6
|
+
attr_reader :urls
|
7
|
+
attr_reader :last_uploaded
|
8
|
+
attr_reader :buildpack
|
9
|
+
|
10
|
+
attr_accessor :empty_attrs
|
11
|
+
attr_accessor :apps_attrs
|
12
|
+
attr_accessor :app_attrs
|
13
|
+
attr_accessor :instance_attrs
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@urls = 'projects.example.com, projects.example.io'
|
17
|
+
@last_uploaded = 'Fri Dec 25 00:00:00 UTC 2015'
|
18
|
+
@buildpack = 'https://github.com/cloudfoundry/binary-buildpack.git'
|
19
|
+
|
20
|
+
@empty_attrs = CfScript::AttributeList.new
|
21
|
+
|
22
|
+
@apps_attrs = build_attribute_list(
|
23
|
+
requested_state: 'started',
|
24
|
+
instances: '1/2',
|
25
|
+
memory: '1G',
|
26
|
+
disk: '2G',
|
27
|
+
urls: @urls,
|
28
|
+
)
|
29
|
+
|
30
|
+
@app_attrs = build_attribute_list(
|
31
|
+
requested_state: 'started',
|
32
|
+
instances: '1/2',
|
33
|
+
usage: '1G x 1 instances',
|
34
|
+
urls: @urls,
|
35
|
+
last_uploaded: @last_uploaded,
|
36
|
+
stack: 'cflinuxfs2',
|
37
|
+
buildpack: @buildpack,
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "initializes missing attributes to sensible defaults" do
|
42
|
+
info = CfScript::AppInfo.new('name', empty_attrs)
|
43
|
+
|
44
|
+
assert_equal 'name', info.name
|
45
|
+
assert_equal nil, info.requested_state
|
46
|
+
assert_equal nil, info.instances
|
47
|
+
assert_equal [], info.urls
|
48
|
+
assert_equal nil, info.usage
|
49
|
+
assert_equal nil, info.last_uploaded
|
50
|
+
assert_equal nil, info.stack
|
51
|
+
assert_equal nil, info.buildpack
|
52
|
+
assert_equal nil, info.memory
|
53
|
+
assert_equal nil, info.disk
|
54
|
+
end
|
55
|
+
|
56
|
+
it "sets apps command attributes when given" do
|
57
|
+
info = CfScript::AppInfo.new('projects', apps_attrs)
|
58
|
+
|
59
|
+
assert_equal 'projects', info.name
|
60
|
+
assert_equal 'started', info.requested_state
|
61
|
+
assert_equal '1/2', info.instances
|
62
|
+
assert_equal 2, info.urls.length
|
63
|
+
assert_equal 'projects.example.com', info.urls.first
|
64
|
+
assert_equal 'projects.example.io', info.urls.last
|
65
|
+
assert_equal nil, info.usage
|
66
|
+
assert_equal nil, info.last_uploaded
|
67
|
+
assert_equal nil, info.stack
|
68
|
+
assert_equal nil, info.buildpack
|
69
|
+
assert_equal '1G', info.memory
|
70
|
+
assert_equal '2G', info.disk
|
71
|
+
end
|
72
|
+
|
73
|
+
it "sets app command attributes when given" do
|
74
|
+
info = CfScript::AppInfo.new('projects', app_attrs)
|
75
|
+
|
76
|
+
assert_equal 'projects', info.name
|
77
|
+
assert_equal 'started', info.requested_state
|
78
|
+
assert_equal '1/2', info.instances
|
79
|
+
assert_equal 2, info.urls.length
|
80
|
+
assert_equal 'projects.example.com', info.urls.first
|
81
|
+
assert_equal 'projects.example.io', info.urls.last
|
82
|
+
assert_equal '1G x 1 instances', info.usage
|
83
|
+
assert_equal last_uploaded, info.last_uploaded
|
84
|
+
assert_equal 'cflinuxfs2', info.stack
|
85
|
+
assert_equal buildpack, info.buildpack
|
86
|
+
assert_equal '1G', info.memory # Extracted from usage
|
87
|
+
assert_equal nil, info.disk
|
88
|
+
end
|
89
|
+
|
90
|
+
it "defines state method that return value of requested_state" do
|
91
|
+
info = CfScript::AppInfo.new('projects', app_attrs)
|
92
|
+
|
93
|
+
assert_respond_to info, :state
|
94
|
+
assert_equal 'started', info.state
|
95
|
+
end
|
96
|
+
|
97
|
+
it "defines started? and stopped? methods and hot?, cold? aliases" do
|
98
|
+
info = CfScript::AppInfo.new('projects', app_attrs)
|
99
|
+
|
100
|
+
assert_respond_to info, :started?
|
101
|
+
assert_respond_to info, :hot?
|
102
|
+
|
103
|
+
assert_respond_to info, :stopped?
|
104
|
+
assert_respond_to info, :cold?
|
105
|
+
|
106
|
+
assert info.started?
|
107
|
+
assert info.hot?
|
108
|
+
|
109
|
+
refute info.stopped?
|
110
|
+
refute info.cold?
|
111
|
+
end
|
112
|
+
|
113
|
+
it "defines set_intance_status method that takes attribute lists and builds InstanceStatus objects" do
|
114
|
+
info = CfScript::AppInfo.new('projects', app_attrs)
|
115
|
+
|
116
|
+
info.set_instance_status [
|
117
|
+
build_instance_status_attrs(index: '0'),
|
118
|
+
build_instance_status_attrs(index: '1'),
|
119
|
+
build_instance_status_attrs(index: '2'),
|
120
|
+
]
|
121
|
+
|
122
|
+
assert_equal 3, info.instance_status.length
|
123
|
+
assert_equal '0', info.instance_status[0].index
|
124
|
+
assert_equal '1', info.instance_status[1].index
|
125
|
+
assert_equal '2', info.instance_status[2].index
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::AppList do
|
4
|
+
include ObjectHelpers
|
5
|
+
|
6
|
+
attr_accessor :list
|
7
|
+
|
8
|
+
def setup
|
9
|
+
one_attrs = build_attribute_list(
|
10
|
+
requested_state: 'started',
|
11
|
+
urls: 'example.com',
|
12
|
+
)
|
13
|
+
|
14
|
+
two_attrs = build_attribute_list(
|
15
|
+
requested_state: 'stopped',
|
16
|
+
urls: 'example.com',
|
17
|
+
)
|
18
|
+
|
19
|
+
@list = CfScript::AppList.new([
|
20
|
+
CfScript::AppInfo.new('one-worker', one_attrs),
|
21
|
+
CfScript::AppInfo.new('two-engine', two_attrs),
|
22
|
+
])
|
23
|
+
end
|
24
|
+
|
25
|
+
it "initializes list to an empty Array" do
|
26
|
+
app_list = CfScript::AppList.new
|
27
|
+
|
28
|
+
assert_equal 0, app_list.length
|
29
|
+
end
|
30
|
+
|
31
|
+
it "selects by prefix" do
|
32
|
+
list.select!(ending_with: 'worker')
|
33
|
+
|
34
|
+
assert_equal 1, list.length
|
35
|
+
assert_equal 'one-worker', list.first.name
|
36
|
+
end
|
37
|
+
|
38
|
+
it "selects by suffix" do
|
39
|
+
list.select!(starting_with: 'two')
|
40
|
+
|
41
|
+
assert_equal 1, list.length
|
42
|
+
assert_equal 'two-engine', list.first.name
|
43
|
+
end
|
44
|
+
|
45
|
+
it "selects by state" do
|
46
|
+
list.select!(state: 'stopped')
|
47
|
+
|
48
|
+
assert_equal 1, list.length
|
49
|
+
assert_equal 'two-engine', list.first.name
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::AttributeList do
|
4
|
+
subject {
|
5
|
+
CfScript::AttributeList.new([
|
6
|
+
CfScript::Attribute.new('one', 'UNO'),
|
7
|
+
CfScript::Attribute.new('two', 'DUE'),
|
8
|
+
])
|
9
|
+
}
|
10
|
+
|
11
|
+
it "defines << method that adds attributes to the list" do
|
12
|
+
subject << CfScript::Attribute.new('six', 'SEI')
|
13
|
+
|
14
|
+
assert_equal 3, subject.length
|
15
|
+
end
|
16
|
+
|
17
|
+
it "raises an exception when duplicate attributes are added" do
|
18
|
+
e = assert_raises(RuntimeError) {
|
19
|
+
subject << CfScript::Attribute.new('one', 'DUPLICATE')
|
20
|
+
}
|
21
|
+
|
22
|
+
assert_equal "Duplicate attribute 'one'", e.message
|
23
|
+
end
|
24
|
+
|
25
|
+
it "delegates [] method to the underlying Hash" do
|
26
|
+
assert_equal 'UNO', subject['one'].value
|
27
|
+
end
|
28
|
+
|
29
|
+
it "defines a names method that returns an Array of attribute names" do
|
30
|
+
assert_equal ['one', 'two'], subject.names
|
31
|
+
end
|
32
|
+
|
33
|
+
it "defines a values method that returns an Array of attribute values" do
|
34
|
+
assert_equal ['UNO', 'DUE'], subject.values
|
35
|
+
end
|
36
|
+
|
37
|
+
it "defines a to_h method that returns a Hash representation of the attributes" do
|
38
|
+
expected = { 'one' => 'UNO', 'two' => 'DUE' }
|
39
|
+
|
40
|
+
assert_equal expected, subject.to_h
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::Attribute do
|
4
|
+
subject { CfScript::Attribute }
|
5
|
+
|
6
|
+
it "preserves the name and value as given" do
|
7
|
+
{ :foo => :bar,
|
8
|
+
'foo' => 'bar'
|
9
|
+
}.each do |name, value|
|
10
|
+
var = subject.new(name, value)
|
11
|
+
|
12
|
+
assert_equal name, var.name
|
13
|
+
assert_equal value, var.value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "defines to_a methods that splits the value on commas + zero or more space" do
|
18
|
+
var = subject.new('list', 'a, b, c,d')
|
19
|
+
|
20
|
+
assert_equal ['a', 'b', 'c', 'd'], var.to_a
|
21
|
+
end
|
22
|
+
|
23
|
+
it "defines a to_s that returns a formatted string representation" do
|
24
|
+
var = subject.new(:foo, :bar)
|
25
|
+
|
26
|
+
assert_equal "foo: bar", var.to_s
|
27
|
+
assert_equal "foo: bar", var.inspect
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::InstanceStatus do
|
4
|
+
include ObjectHelpers
|
5
|
+
|
6
|
+
attr_accessor :instance_status
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@instance_status = build_instance_status
|
10
|
+
end
|
11
|
+
|
12
|
+
it "initializes all attributes to sensible defaults" do
|
13
|
+
status = CfScript::InstanceStatus.new
|
14
|
+
|
15
|
+
assert_equal nil, status.index
|
16
|
+
assert_equal nil, status.state
|
17
|
+
assert_equal nil, status.since
|
18
|
+
assert_equal nil, status.cpu
|
19
|
+
assert_equal nil, status.memory
|
20
|
+
assert_equal nil, status.disk
|
21
|
+
assert_equal nil, status.details
|
22
|
+
end
|
23
|
+
|
24
|
+
it "initializes given attributes" do
|
25
|
+
assert_equal '0', @instance_status.index
|
26
|
+
assert_equal '1', @instance_status.state
|
27
|
+
assert_equal '2', @instance_status.since
|
28
|
+
assert_equal '3', @instance_status.cpu
|
29
|
+
assert_equal '4', @instance_status.memory
|
30
|
+
assert_equal '5', @instance_status.disk
|
31
|
+
assert_equal '6', @instance_status.details
|
32
|
+
end
|
33
|
+
|
34
|
+
it "shows requested attributes" do
|
35
|
+
assert_equal 'since: 2, memory: 4', @instance_status.show(:since, :memory)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::Space do
|
4
|
+
subject { CfScript::Space }
|
5
|
+
|
6
|
+
it "initializes all attributes to sensible defaults" do
|
7
|
+
space = subject.new('outer-space')
|
8
|
+
|
9
|
+
assert_equal 'outer-space', space.name
|
10
|
+
|
11
|
+
assert_equal nil, space.org
|
12
|
+
|
13
|
+
assert_equal [], space.apps
|
14
|
+
assert_equal [], space.domains
|
15
|
+
assert_equal [], space.services
|
16
|
+
assert_equal [], space.security_groups
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets all given attributes" do
|
20
|
+
space = subject.new('space', 'ORG', [:app], [:domain], [:service], [:security])
|
21
|
+
|
22
|
+
assert_equal 'space', space.name
|
23
|
+
|
24
|
+
assert_equal 'ORG', space.org
|
25
|
+
|
26
|
+
assert_equal [:app], space.apps
|
27
|
+
assert_equal [:domain], space.domains
|
28
|
+
assert_equal [:service], space.services
|
29
|
+
assert_equal [:security], space.security_groups
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::Target do
|
4
|
+
subject { CfScript::Target }
|
5
|
+
|
6
|
+
it "initializes all attributes to sensible defaults" do
|
7
|
+
target = subject.new
|
8
|
+
|
9
|
+
assert_equal '', target.api_endpoint
|
10
|
+
assert_equal '', target.org
|
11
|
+
assert_equal '', target.space
|
12
|
+
assert_equal nil, target.user
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "to_options" do
|
16
|
+
it "returns an empty Hash when org and space are not set" do
|
17
|
+
options = subject.new.to_options
|
18
|
+
|
19
|
+
assert_instance_of Hash, options
|
20
|
+
assert_equal({}, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns a Hash with org and space when set" do
|
24
|
+
options = subject.new('api', 'ORG', 'SPACE', 'user@example.com').to_options
|
25
|
+
|
26
|
+
assert_equal({ o: 'ORG', s: 'SPACE' }, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns a Hash with org when set" do
|
30
|
+
options = subject.new('api', 'ORG').to_options
|
31
|
+
|
32
|
+
assert_equal({ o: 'ORG' }, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns a Hash with the space when set" do
|
36
|
+
options = subject.new('api', '', 'SPACE').to_options
|
37
|
+
|
38
|
+
assert_equal({ s: 'SPACE' }, options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::Output::Buffer do
|
4
|
+
attr_accessor :buffer
|
5
|
+
attr_accessor :raw_text
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@raw_text = "\e[4;31;42mline 1\e[0m\n" +
|
9
|
+
"\e[4;32;44mline 2\e[0m\n" +
|
10
|
+
"\e[4;34;41mline 3\e[0m\n"
|
11
|
+
|
12
|
+
@buffer = CfScript::Output::Buffer.new(@raw_text)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "responds to raw and returns a original text" do
|
16
|
+
assert buffer.respond_to?(:raw)
|
17
|
+
assert_equal raw_text, buffer.raw
|
18
|
+
end
|
19
|
+
|
20
|
+
it "responds to content and returns a sanitized copy" do
|
21
|
+
assert buffer.respond_to?(:content)
|
22
|
+
assert_equal "line 1\nline 2\nline 3\n", buffer.content
|
23
|
+
end
|
24
|
+
|
25
|
+
it "responds to lines and returns sanitized lines" do
|
26
|
+
assert buffer.respond_to?(:lines)
|
27
|
+
assert_equal ['line 1', 'line 2', 'line 3'], buffer.lines
|
28
|
+
end
|
29
|
+
|
30
|
+
it "responds to last_line and returns last line content" do
|
31
|
+
assert_equal 'line 3', buffer.last_line
|
32
|
+
end
|
33
|
+
|
34
|
+
it "responds to subscript and returns matching range" do
|
35
|
+
assert_equal '1', buffer[5]
|
36
|
+
assert_equal 'line 2', buffer[7..12]
|
37
|
+
assert_equal 'line 3', buffer[14..-2]
|
38
|
+
end
|
39
|
+
|
40
|
+
it "responds to each_line and yields each line" do
|
41
|
+
buffer.each_line.with_index do |line, index|
|
42
|
+
assert_equal buffer.lines[index], line.strip
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "responds to from and returns text from matching line" do
|
47
|
+
assert_equal "line 2\nline 3", buffer.from('2')
|
48
|
+
end
|
49
|
+
|
50
|
+
it "responds to lines_from and returns lines from matching line" do
|
51
|
+
assert_equal ['line 2','line 3'], buffer.lines_from('2')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "responds to match and returns MatchData object" do
|
55
|
+
assert_instance_of MatchData, buffer.match(/2/)
|
56
|
+
assert_equal nil, buffer.match(/4/)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "responds to matches? and returns true or false" do
|
60
|
+
assert buffer.matches?(/2/)
|
61
|
+
refute buffer.matches?(/4/)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "responds to contains? and returns true or false" do
|
65
|
+
assert buffer.contains?('2')
|
66
|
+
refute buffer.contains?('4')
|
67
|
+
end
|
68
|
+
|
69
|
+
it "responds to last_line_matches? and returns true or false" do
|
70
|
+
assert buffer.last_line_matches?(/3/)
|
71
|
+
refute buffer.last_line_matches?(/4/)
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::Output::Parser::Attributes do
|
4
|
+
attr_accessor :parser
|
5
|
+
|
6
|
+
attr_accessor :text_buffer
|
7
|
+
attr_accessor :line_buffer
|
8
|
+
attr_accessor :line_regexp
|
9
|
+
|
10
|
+
class AttributesParserTest
|
11
|
+
include CfScript::Utils
|
12
|
+
include CfScript::Output::Parser::Attributes
|
13
|
+
include CfScript::Output::Parser::Section
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@parser = AttributesParserTest.new
|
18
|
+
|
19
|
+
@text_buffer = "" +
|
20
|
+
"one: first \n" +
|
21
|
+
" two: second \n" +
|
22
|
+
"tre : last\n"
|
23
|
+
|
24
|
+
@line_buffer = "one: first , two: second, tre: last "
|
25
|
+
@line_regexp = /one: (?<one>[^,]+), two: (?<two>[^,]+), tre: (?<tre>.+)/
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "parse_attribute" do
|
29
|
+
it "returns an Attribute object" do
|
30
|
+
attr = parser.parse_attribute(text_buffer.lines[0])
|
31
|
+
|
32
|
+
assert_instance_of CfScript::Attribute, attr
|
33
|
+
assert_equal 'one', attr.name
|
34
|
+
assert_equal 'first', attr.value
|
35
|
+
end
|
36
|
+
|
37
|
+
it "symbolizes attribute names when specified" do
|
38
|
+
attr = parser.parse_attribute(text_buffer.lines[0], true)
|
39
|
+
|
40
|
+
assert_equal :one, attr.name
|
41
|
+
end
|
42
|
+
|
43
|
+
it "strips preceeding/following whitespace" do
|
44
|
+
tests = [
|
45
|
+
['one', 'first'],
|
46
|
+
['two', 'second'],
|
47
|
+
['tre', 'last'],
|
48
|
+
]
|
49
|
+
|
50
|
+
tests.each_with_index do |pair, index|
|
51
|
+
attr = parser.parse_attribute(text_buffer.lines[index])
|
52
|
+
|
53
|
+
assert_equal pair.first, attr.name
|
54
|
+
assert_equal pair.last, attr.value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "parse_attribute_list" do
|
60
|
+
it "returns an AttributeList object" do
|
61
|
+
list = parser.parse_attribute_list(text_buffer)
|
62
|
+
|
63
|
+
assert_instance_of CfScript::AttributeList, list
|
64
|
+
assert_equal 3, list.length
|
65
|
+
end
|
66
|
+
|
67
|
+
it "symbolizes attribute names when specified" do
|
68
|
+
list = parser.parse_attribute_list(text_buffer, true)
|
69
|
+
|
70
|
+
assert_equal [:one, :two, :tre], list.names
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "parse_line_attributes" do
|
75
|
+
it "returns an AttributeList object" do
|
76
|
+
list = parser.parse_line_attributes(line_buffer, line_regexp)
|
77
|
+
|
78
|
+
assert_instance_of CfScript::AttributeList, list
|
79
|
+
assert_equal 3, list.length
|
80
|
+
end
|
81
|
+
|
82
|
+
it "symbolizes attribute names" do
|
83
|
+
list = parser.parse_line_attributes(line_buffer, line_regexp)
|
84
|
+
|
85
|
+
assert_equal [:one, :two, :tre], list.names
|
86
|
+
end
|
87
|
+
|
88
|
+
it "strips preceeding/following whitespace" do
|
89
|
+
tests = [
|
90
|
+
[:one, 'first'],
|
91
|
+
[:two, 'second'],
|
92
|
+
[:tre, 'last'],
|
93
|
+
]
|
94
|
+
|
95
|
+
list = parser.parse_line_attributes(line_buffer, line_regexp)
|
96
|
+
tests.each_with_index do |pair, index|
|
97
|
+
assert_equal pair.first, list[list.names[index]].name
|
98
|
+
assert_equal pair.last, list[list.names[index]].value
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe CfScript::Output::Parser::Section do
|
4
|
+
attr_accessor :parser
|
5
|
+
|
6
|
+
attr_accessor :text_buffer
|
7
|
+
|
8
|
+
class SectionParserTest
|
9
|
+
include CfScript::Utils
|
10
|
+
include CfScript::Output::Parser::Attributes
|
11
|
+
include CfScript::Output::Parser::Section
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@parser = SectionParserTest.new
|
16
|
+
|
17
|
+
@text_buffer = "\n" +
|
18
|
+
"Something else going on here\n" +
|
19
|
+
"Section Title:\n" +
|
20
|
+
" one: 1\n" +
|
21
|
+
" two: 2\n" +
|
22
|
+
" tre: 3\n" +
|
23
|
+
"\nSomething else"
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "extract_section" do
|
27
|
+
it "returns extracted text" do
|
28
|
+
section = parser.extract_section(text_buffer, 'Section Title')
|
29
|
+
|
30
|
+
assert_equal " one: 1\n two: 2\n tre: 3", section
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "parse_section_attributes" do
|
35
|
+
it "calls parse_attribute_list" do
|
36
|
+
parser.stub :parse_attribute_list, 'called' do
|
37
|
+
assert_equal 'called', parser.parse_section_attributes(text_buffer, 'Section Title')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns an AttributeList object" do
|
42
|
+
list = parser.parse_section_attributes(text_buffer, 'Section Title')
|
43
|
+
|
44
|
+
assert_instance_of CfScript::AttributeList, list
|
45
|
+
assert_equal 3, list.length
|
46
|
+
end
|
47
|
+
|
48
|
+
it "doesn't symbolize attribute names" do
|
49
|
+
list = parser.parse_section_attributes(text_buffer, 'Section Title')
|
50
|
+
|
51
|
+
assert_equal ['one', 'two', 'tre'], list.names
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns nil if the section title is not found" do
|
55
|
+
list = parser.parse_section_attributes(text_buffer, 'NOPE')
|
56
|
+
|
57
|
+
assert_equal nil, list
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|