cuboid 0.0.0 → 0.0.1alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +0 -0
- data/Gemfile +20 -5
- data/LICENSE.md +22 -0
- data/README.md +158 -19
- data/Rakefile +56 -3
- data/config/paths.yml +15 -0
- data/cuboid.gemspec +61 -23
- data/lib/cuboid.rb +96 -4
- data/lib/cuboid/application.rb +326 -0
- data/lib/cuboid/application/parts/data.rb +18 -0
- data/lib/cuboid/application/parts/report.rb +29 -0
- data/lib/cuboid/application/parts/state.rb +274 -0
- data/lib/cuboid/application/runtime.rb +25 -0
- data/lib/cuboid/banner.rb +13 -0
- data/lib/cuboid/data.rb +86 -0
- data/lib/cuboid/data/application.rb +52 -0
- data/lib/cuboid/error.rb +9 -0
- data/lib/cuboid/option_group.rb +129 -0
- data/lib/cuboid/option_groups.rb +8 -0
- data/lib/cuboid/option_groups/datastore.rb +23 -0
- data/lib/cuboid/option_groups/dispatcher.rb +38 -0
- data/lib/cuboid/option_groups/output.rb +14 -0
- data/lib/cuboid/option_groups/paths.rb +184 -0
- data/lib/cuboid/option_groups/report.rb +39 -0
- data/lib/cuboid/option_groups/rpc.rb +105 -0
- data/lib/cuboid/option_groups/scheduler.rb +27 -0
- data/lib/cuboid/option_groups/snapshot.rb +13 -0
- data/lib/cuboid/option_groups/system.rb +10 -0
- data/lib/cuboid/options.rb +254 -0
- data/lib/cuboid/processes.rb +13 -0
- data/lib/cuboid/processes/dispatchers.rb +140 -0
- data/lib/cuboid/processes/executables/base.rb +54 -0
- data/lib/cuboid/processes/executables/dispatcher.rb +5 -0
- data/lib/cuboid/processes/executables/instance.rb +12 -0
- data/lib/cuboid/processes/executables/rest_service.rb +13 -0
- data/lib/cuboid/processes/executables/scheduler.rb +5 -0
- data/lib/cuboid/processes/helpers.rb +4 -0
- data/lib/cuboid/processes/helpers/dispatchers.rb +23 -0
- data/lib/cuboid/processes/helpers/instances.rb +39 -0
- data/lib/cuboid/processes/helpers/processes.rb +23 -0
- data/lib/cuboid/processes/helpers/schedulers.rb +23 -0
- data/lib/cuboid/processes/instances.rb +203 -0
- data/lib/cuboid/processes/manager.rb +262 -0
- data/lib/cuboid/processes/schedulers.rb +128 -0
- data/lib/cuboid/report.rb +220 -0
- data/lib/cuboid/rest/server.rb +165 -0
- data/lib/cuboid/rest/server/instance_helpers.rb +99 -0
- data/lib/cuboid/rest/server/routes/dispatcher.rb +41 -0
- data/lib/cuboid/rest/server/routes/grid.rb +41 -0
- data/lib/cuboid/rest/server/routes/instances.rb +131 -0
- data/lib/cuboid/rest/server/routes/scheduler.rb +140 -0
- data/lib/cuboid/rpc/client.rb +3 -0
- data/lib/cuboid/rpc/client/base.rb +58 -0
- data/lib/cuboid/rpc/client/dispatcher.rb +58 -0
- data/lib/cuboid/rpc/client/instance.rb +100 -0
- data/lib/cuboid/rpc/client/instance/service.rb +37 -0
- data/lib/cuboid/rpc/client/scheduler.rb +46 -0
- data/lib/cuboid/rpc/serializer.rb +92 -0
- data/lib/cuboid/rpc/server/active_options.rb +38 -0
- data/lib/cuboid/rpc/server/application_wrapper.rb +138 -0
- data/lib/cuboid/rpc/server/base.rb +63 -0
- data/lib/cuboid/rpc/server/dispatcher.rb +317 -0
- data/lib/cuboid/rpc/server/dispatcher/node.rb +247 -0
- data/lib/cuboid/rpc/server/dispatcher/service.rb +145 -0
- data/lib/cuboid/rpc/server/instance.rb +338 -0
- data/lib/cuboid/rpc/server/output.rb +92 -0
- data/lib/cuboid/rpc/server/scheduler.rb +482 -0
- data/lib/cuboid/ruby.rb +4 -0
- data/lib/cuboid/ruby/array.rb +17 -0
- data/lib/cuboid/ruby/hash.rb +41 -0
- data/lib/cuboid/ruby/object.rb +32 -0
- data/lib/cuboid/snapshot.rb +186 -0
- data/lib/cuboid/state.rb +94 -0
- data/lib/cuboid/state/application.rb +309 -0
- data/lib/cuboid/state/options.rb +27 -0
- data/lib/cuboid/support.rb +11 -0
- data/lib/cuboid/support/buffer.rb +3 -0
- data/lib/cuboid/support/buffer/autoflush.rb +61 -0
- data/lib/cuboid/support/buffer/base.rb +91 -0
- data/lib/cuboid/support/cache.rb +7 -0
- data/lib/cuboid/support/cache/base.rb +226 -0
- data/lib/cuboid/support/cache/least_cost_replacement.rb +77 -0
- data/lib/cuboid/support/cache/least_recently_pushed.rb +21 -0
- data/lib/cuboid/support/cache/least_recently_used.rb +31 -0
- data/lib/cuboid/support/cache/preference.rb +31 -0
- data/lib/cuboid/support/cache/random_replacement.rb +20 -0
- data/lib/cuboid/support/crypto.rb +2 -0
- data/lib/cuboid/support/crypto/rsa_aes_cbc.rb +86 -0
- data/lib/cuboid/support/database.rb +5 -0
- data/lib/cuboid/support/database/base.rb +177 -0
- data/lib/cuboid/support/database/categorized_queue.rb +195 -0
- data/lib/cuboid/support/database/hash.rb +300 -0
- data/lib/cuboid/support/database/queue.rb +149 -0
- data/lib/cuboid/support/filter.rb +3 -0
- data/lib/cuboid/support/filter/base.rb +110 -0
- data/lib/cuboid/support/filter/set.rb +29 -0
- data/lib/cuboid/support/glob.rb +27 -0
- data/lib/cuboid/support/mixins.rb +8 -0
- data/lib/cuboid/support/mixins/observable.rb +99 -0
- data/lib/cuboid/support/mixins/parts.rb +20 -0
- data/lib/cuboid/support/mixins/profiler.rb +93 -0
- data/lib/cuboid/support/mixins/spec_instances.rb +65 -0
- data/lib/cuboid/support/mixins/terminal.rb +57 -0
- data/lib/cuboid/system.rb +119 -0
- data/lib/cuboid/system/platforms.rb +84 -0
- data/lib/cuboid/system/platforms/linux.rb +26 -0
- data/lib/cuboid/system/platforms/mixins/unix.rb +46 -0
- data/lib/cuboid/system/platforms/osx.rb +25 -0
- data/lib/cuboid/system/platforms/windows.rb +81 -0
- data/lib/cuboid/system/slots.rb +143 -0
- data/lib/cuboid/ui/output.rb +52 -0
- data/lib/cuboid/ui/output_interface.rb +43 -0
- data/lib/cuboid/ui/output_interface/abstract.rb +68 -0
- data/lib/cuboid/ui/output_interface/controls.rb +84 -0
- data/lib/cuboid/ui/output_interface/error_logging.rb +119 -0
- data/lib/cuboid/ui/output_interface/implemented.rb +58 -0
- data/lib/cuboid/ui/output_interface/personalization.rb +62 -0
- data/lib/cuboid/utilities.rb +155 -0
- data/lib/cuboid/version.rb +4 -3
- data/lib/version +1 -0
- data/logs/placeholder +0 -0
- data/spec/cuboid/application/parts/data_spec.rb +12 -0
- data/spec/cuboid/application/parts/report_spec.rb +6 -0
- data/spec/cuboid/application/parts/state_spec.rb +192 -0
- data/spec/cuboid/application/runtime_spec.rb +21 -0
- data/spec/cuboid/application_spec.rb +37 -0
- data/spec/cuboid/data/application_spec.rb +22 -0
- data/spec/cuboid/data_spec.rb +47 -0
- data/spec/cuboid/error_spec.rb +23 -0
- data/spec/cuboid/option_groups/datastore_spec.rb +54 -0
- data/spec/cuboid/option_groups/dispatcher_spec.rb +12 -0
- data/spec/cuboid/option_groups/output_spec.rb +11 -0
- data/spec/cuboid/option_groups/paths_spec.rb +184 -0
- data/spec/cuboid/option_groups/report_spec.rb +26 -0
- data/spec/cuboid/option_groups/rpc_spec.rb +53 -0
- data/spec/cuboid/option_groups/snapshot_spec.rb +26 -0
- data/spec/cuboid/option_groups/system.rb +12 -0
- data/spec/cuboid/options_spec.rb +218 -0
- data/spec/cuboid/report_spec.rb +221 -0
- data/spec/cuboid/rest/server_spec.rb +1205 -0
- data/spec/cuboid/rpc/client/base_spec.rb +151 -0
- data/spec/cuboid/rpc/client/dispatcher_spec.rb +13 -0
- data/spec/cuboid/rpc/client/instance_spec.rb +38 -0
- data/spec/cuboid/rpc/server/active_options_spec.rb +21 -0
- data/spec/cuboid/rpc/server/base_spec.rb +60 -0
- data/spec/cuboid/rpc/server/dispatcher/node_spec.rb +222 -0
- data/spec/cuboid/rpc/server/dispatcher/service_spec.rb +112 -0
- data/spec/cuboid/rpc/server/dispatcher_spec.rb +317 -0
- data/spec/cuboid/rpc/server/instance_spec.rb +307 -0
- data/spec/cuboid/rpc/server/output_spec.rb +32 -0
- data/spec/cuboid/rpc/server/scheduler_spec.rb +400 -0
- data/spec/cuboid/ruby/array_spec.rb +77 -0
- data/spec/cuboid/ruby/hash_spec.rb +63 -0
- data/spec/cuboid/ruby/object_spec.rb +22 -0
- data/spec/cuboid/snapshot_spec.rb +123 -0
- data/spec/cuboid/state/application_spec.rb +538 -0
- data/spec/cuboid/state/options_spec.rb +37 -0
- data/spec/cuboid/state_spec.rb +53 -0
- data/spec/cuboid/support/buffer/autoflush_spec.rb +78 -0
- data/spec/cuboid/support/buffer/base_spec.rb +193 -0
- data/spec/cuboid/support/cache/least_cost_replacement_spec.rb +61 -0
- data/spec/cuboid/support/cache/least_recently_pushed_spec.rb +90 -0
- data/spec/cuboid/support/cache/least_recently_used_spec.rb +80 -0
- data/spec/cuboid/support/cache/preference_spec.rb +37 -0
- data/spec/cuboid/support/cache/random_replacement_spec.rb +42 -0
- data/spec/cuboid/support/crypto/rsa_aes_cbc_spec.rb +28 -0
- data/spec/cuboid/support/database/categorized_queue_spec.rb +327 -0
- data/spec/cuboid/support/database/hash_spec.rb +204 -0
- data/spec/cuboid/support/database/scheduler_spec.rb +325 -0
- data/spec/cuboid/support/filter/set_spec.rb +19 -0
- data/spec/cuboid/support/glob_spec.rb +75 -0
- data/spec/cuboid/support/mixins/observable_spec.rb +95 -0
- data/spec/cuboid/system/platforms/linux_spec.rb +31 -0
- data/spec/cuboid/system/platforms/osx_spec.rb +32 -0
- data/spec/cuboid/system/platforms/windows_spec.rb +41 -0
- data/spec/cuboid/system/slots_spec.rb +202 -0
- data/spec/cuboid/system_spec.rb +105 -0
- data/spec/cuboid/utilities_spec.rb +131 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/factories/placeholder +0 -0
- data/spec/support/factories/scan_report.rb +18 -0
- data/spec/support/fixtures/empty/placeholder +0 -0
- data/spec/support/fixtures/executables/node.rb +50 -0
- data/spec/support/fixtures/mock_app.rb +61 -0
- data/spec/support/fixtures/mock_app/test_service.rb +64 -0
- data/spec/support/fixtures/services/echo.rb +64 -0
- data/spec/support/helpers/framework.rb +3 -0
- data/spec/support/helpers/matchers.rb +5 -0
- data/spec/support/helpers/misc.rb +3 -0
- data/spec/support/helpers/paths.rb +15 -0
- data/spec/support/helpers/request_helpers.rb +38 -0
- data/spec/support/helpers/requires.rb +8 -0
- data/spec/support/helpers/resets.rb +52 -0
- data/spec/support/helpers/web_server.rb +15 -0
- data/spec/support/lib/factory.rb +107 -0
- data/spec/support/lib/web_server_client.rb +41 -0
- data/spec/support/lib/web_server_dispatcher.rb +25 -0
- data/spec/support/lib/web_server_manager.rb +118 -0
- data/spec/support/logs/placeholder +0 -0
- data/spec/support/pems/cacert.pem +37 -0
- data/spec/support/pems/client/cert.pem +37 -0
- data/spec/support/pems/client/foo-cert.pem +39 -0
- data/spec/support/pems/client/foo-key.pem +51 -0
- data/spec/support/pems/client/key.pem +51 -0
- data/spec/support/pems/server/cert.pem +37 -0
- data/spec/support/pems/server/key.pem +51 -0
- data/spec/support/reports/placeholder +0 -0
- data/spec/support/shared/application.rb +10 -0
- data/spec/support/shared/component.rb +31 -0
- data/spec/support/shared/component/options/base.rb +187 -0
- data/spec/support/shared/option_group.rb +98 -0
- data/spec/support/shared/support/cache.rb +419 -0
- data/spec/support/shared/support/filter.rb +143 -0
- data/spec/support/shared/system/platforms/base.rb +25 -0
- data/spec/support/shared/system/platforms/mixins/unix.rb +37 -0
- data/spec/support/snapshots/placeholder +0 -0
- metadata +566 -21
- data/.gitignore +0 -8
- data/bin/console +0 -15
- data/bin/setup +0 -8
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::Application::Runtime do
|
4
|
+
include_examples 'application'
|
5
|
+
|
6
|
+
describe '#state' do
|
7
|
+
it 'provides access to the application runtime state'
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#state=' do
|
11
|
+
it 'sets the application runtime state'
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#data' do
|
15
|
+
it 'provides access to the application runtime data'
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#data=' do
|
19
|
+
it 'sets the application runtime data'
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::Application do
|
4
|
+
include_examples 'application'
|
5
|
+
|
6
|
+
describe '#version' do
|
7
|
+
it "returns #{Cuboid::VERSION}" do
|
8
|
+
expect(subject.version).to eq(Cuboid::VERSION)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#run' do
|
13
|
+
context 'on invalid options' do
|
14
|
+
it 'raises ArgumentError'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#statistics' do
|
19
|
+
let(:statistics) { subject.statistics }
|
20
|
+
|
21
|
+
describe ':runtime' do
|
22
|
+
context 'when the app has been running' do
|
23
|
+
it 'returns the runtime in seconds' do
|
24
|
+
subject.run
|
25
|
+
expect(statistics[:runtime]).to be > 0
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when no scan has been running' do
|
30
|
+
it 'returns 0' do
|
31
|
+
expect(statistics[:runtime]).to eq(0)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::Data::Application do
|
4
|
+
|
5
|
+
subject { described_class.new }
|
6
|
+
let(:dump_directory) do
|
7
|
+
"#{Dir.tmpdir}/framework-#{Cuboid::Utilities.generate_token}"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#statistics' do
|
11
|
+
let(:statistics) { subject.statistics }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#dump' do
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.load' do
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#clear' do
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::Data do
|
4
|
+
|
5
|
+
subject { described_class }
|
6
|
+
let(:dump_directory) do
|
7
|
+
"#{Dir.tmpdir}/data-#{Cuboid::Utilities.generate_token}/"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#application' do
|
11
|
+
it "returns an instance of #{described_class::Application}" do
|
12
|
+
expect(subject.application).to be_kind_of described_class::Application
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#statistics' do
|
17
|
+
%w(application).each do |name|
|
18
|
+
it "includes :#{name} statistics" do
|
19
|
+
expect(subject.statistics[name.to_sym]).to eq(subject.send(name).statistics)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.dump' do
|
25
|
+
%w(application).each do |name|
|
26
|
+
it "stores ##{name} to disk" do
|
27
|
+
previous_instance = subject.send(name)
|
28
|
+
|
29
|
+
subject.dump( dump_directory )
|
30
|
+
|
31
|
+
new_instance = subject.load( dump_directory ).send(name)
|
32
|
+
|
33
|
+
expect(new_instance).to be_kind_of subject.send(name).class
|
34
|
+
expect(new_instance.object_id).not_to eq(previous_instance.object_id)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#clear' do
|
40
|
+
%w(application).each do |method|
|
41
|
+
it "clears ##{method}" do
|
42
|
+
expect(subject.send(method)).to receive(:clear).at_least(:once)
|
43
|
+
subject.clear
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::Error do
|
4
|
+
it 'inherits from StandardError' do
|
5
|
+
expect(Cuboid::Error <= StandardError).to be_truthy
|
6
|
+
|
7
|
+
caught = false
|
8
|
+
begin
|
9
|
+
fail Cuboid::Error
|
10
|
+
rescue StandardError => e
|
11
|
+
caught = true
|
12
|
+
end
|
13
|
+
expect(caught).to be_truthy
|
14
|
+
|
15
|
+
caught = false
|
16
|
+
begin
|
17
|
+
fail Cuboid::Error
|
18
|
+
rescue
|
19
|
+
caught = true
|
20
|
+
end
|
21
|
+
expect(caught).to be_truthy
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::OptionGroups::Datastore do
|
4
|
+
include_examples 'option_group'
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
it 'creates attribute accessors on the fly' do
|
8
|
+
subject.test = 1
|
9
|
+
expect(subject.test).to eq(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#to_h' do
|
13
|
+
it 'only includes attributes with accessors' do
|
14
|
+
method = :stuff=
|
15
|
+
|
16
|
+
subject.instance_variable_set( :@blah, true )
|
17
|
+
|
18
|
+
value = subject.send( method, 'stuff' )
|
19
|
+
expect(subject.to_h).to eq({ method.to_s[0...-1].to_sym => value })
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#update' do
|
24
|
+
it 'updates self with the values of the given hash' do
|
25
|
+
method = :stuff
|
26
|
+
value = 'stuff'
|
27
|
+
|
28
|
+
subject.update( { method => value } )
|
29
|
+
expect(subject.send( method )).to include value
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns self' do
|
33
|
+
expect(subject.update({})).to eq(subject)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#merge' do
|
38
|
+
it 'updates self with the values of the given OptionGroup' do
|
39
|
+
method = :stuff
|
40
|
+
value = 'stuff'
|
41
|
+
|
42
|
+
group = described_class.new
|
43
|
+
group.update( { method => value } )
|
44
|
+
|
45
|
+
subject.merge( group )
|
46
|
+
expect(subject.send( method )).to include value
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns self' do
|
50
|
+
group = described_class.new
|
51
|
+
expect(subject.merge( group )).to eq(subject)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::OptionGroups::Dispatcher do
|
4
|
+
include_examples 'option_group'
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
%w(url instance_port_range neighbour ping_interval name).each do |method|
|
8
|
+
it { is_expected.to respond_to method }
|
9
|
+
it { is_expected.to respond_to "#{method}=" }
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::OptionGroups::Output do
|
4
|
+
include_examples 'option_group'
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
%w(reroute_to_logfile).each do |method|
|
8
|
+
it { is_expected.to respond_to method }
|
9
|
+
it { is_expected.to respond_to "#{method}=" }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::OptionGroups::Paths do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
@created_resources = []
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
ENV['CUBOID_LOGDIR'] = nil
|
11
|
+
|
12
|
+
(@created_resources + [paths_config_file]).each do |r|
|
13
|
+
FileUtils.rm_rf r
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:paths_config_file) { "#{Cuboid::Options.paths.tmpdir}/paths-#{Process.pid}.yml" }
|
18
|
+
|
19
|
+
%w(root logs reports lib support mixins snapshots).each do |method|
|
20
|
+
|
21
|
+
describe "##{method}" do
|
22
|
+
it 'points to an existing directory' do
|
23
|
+
expect(File.exists?( subject.send method )).to be_truthy
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "##{method}=" do
|
28
|
+
context 'when the path is missing a slash in the end' do
|
29
|
+
it 'raises error' do
|
30
|
+
dir = subject.tmpdir[0..-1]
|
31
|
+
subject.send "#{method}=", dir
|
32
|
+
|
33
|
+
expect(dir).to_not end_with '/'
|
34
|
+
expect(subject.send(method)).to end_with '/'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when given an invalid directory' do
|
39
|
+
it 'raises error' do
|
40
|
+
expect do
|
41
|
+
subject.send "#{method}=", 'flflflfl'
|
42
|
+
end.to raise_error ArgumentError
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it { is_expected.to respond_to method }
|
48
|
+
it { is_expected.to respond_to "#{method}=" }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#tmpdir' do
|
52
|
+
context 'when no tmpdir has been specified via config' do
|
53
|
+
it 'defaults to the OS tmpdir' do
|
54
|
+
expect(subject.tmpdir).to eq Cuboid.get_long_win32_filename( "#{Dir.tmpdir}/Cuboid_#{Process.pid}" )
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when #{described_class}.config['tmpdir']" do
|
59
|
+
it 'returns its value' do
|
60
|
+
allow(described_class).to receive(:config) do
|
61
|
+
{
|
62
|
+
'tmpdir' => "#{Dir.tmpdir}/my/tmpdir"
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
expect(subject.tmpdir).to eq("#{Dir.tmpdir}/my/tmpdir/Cuboid_#{Process.pid}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#logs' do
|
72
|
+
it 'returns the default location' do
|
73
|
+
expect(subject.logs).to eq("#{subject.root}logs/")
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when the CUBOID_LOGDIR environment variable' do
|
77
|
+
after { ENV['CUBOID_LOGDIR'] = '' }
|
78
|
+
|
79
|
+
it 'returns its value' do
|
80
|
+
ENV['CUBOID_LOGDIR'] = 'test'
|
81
|
+
expect(subject.logs).to eq('test/')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when #{described_class}.config['logs']" do
|
86
|
+
it 'returns its value' do
|
87
|
+
allow(described_class).to receive(:config) do
|
88
|
+
{
|
89
|
+
'logs' => 'logs-stuff/'
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
expect(described_class.new.logs).to eq('logs-stuff/')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#snapshots' do
|
99
|
+
it 'returns the default location' do
|
100
|
+
expect(subject.snapshots).to eq("#{subject.root}snapshots/")
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when #{described_class}.config['snapshots']" do
|
104
|
+
it 'returns its value' do
|
105
|
+
allow(described_class).to receive(:config) do
|
106
|
+
{
|
107
|
+
'snapshots' => 'snapshots-stuff/'
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
expect(described_class.new.snapshots).to eq('snapshots-stuff/')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#reports' do
|
117
|
+
it 'returns the default location' do
|
118
|
+
expect(subject.reports).to eq("#{subject.root}reports/")
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when #{described_class}.config['reports']" do
|
122
|
+
it 'returns its value' do
|
123
|
+
allow(described_class).to receive(:config) do
|
124
|
+
{
|
125
|
+
'reports' => 'reports-stuff/'
|
126
|
+
}
|
127
|
+
end
|
128
|
+
|
129
|
+
expect(described_class.new.reports).to eq('reports-stuff/')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '.config' do
|
135
|
+
let(:config) { described_class.config }
|
136
|
+
|
137
|
+
it 'expands ~ to $HOME', if: !Cuboid.windows? do
|
138
|
+
yaml = {
|
139
|
+
'blah' => "~/foo-#{Process.pid}/"
|
140
|
+
}.to_yaml
|
141
|
+
|
142
|
+
allow(described_class).to receive(:paths_config_file) { paths_config_file }
|
143
|
+
IO.write( described_class.paths_config_file, yaml )
|
144
|
+
described_class.clear_config_cache
|
145
|
+
|
146
|
+
@created_resources << described_class.config['blah']
|
147
|
+
|
148
|
+
expect(described_class.config['blah']).to eq("#{ENV['HOME']}/foo-#{Process.pid}/")
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'appends / to paths' do
|
152
|
+
dir = "#{Dir.tmpdir}/foo-#{Process.pid}"
|
153
|
+
yaml = {
|
154
|
+
'blah' => dir
|
155
|
+
}.to_yaml
|
156
|
+
|
157
|
+
allow(described_class).to receive(:paths_config_file) { paths_config_file }
|
158
|
+
IO.write( described_class.paths_config_file, yaml )
|
159
|
+
described_class.clear_config_cache
|
160
|
+
|
161
|
+
@created_resources << described_class.config['blah']
|
162
|
+
|
163
|
+
expect(described_class.config['blah']).to eq("#{dir}/")
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'creates the given directories' do
|
167
|
+
dir = "#{Dir.tmpdir}/foo/stuff-#{Process.pid}"
|
168
|
+
yaml = {
|
169
|
+
'blah' => dir
|
170
|
+
}.to_yaml
|
171
|
+
|
172
|
+
allow(described_class).to receive(:paths_config_file) { paths_config_file }
|
173
|
+
IO.write( described_class.paths_config_file, yaml )
|
174
|
+
described_class.clear_config_cache
|
175
|
+
|
176
|
+
@created_resources << dir
|
177
|
+
|
178
|
+
expect(File.exist?( dir )).to be_falsey
|
179
|
+
described_class.config
|
180
|
+
expect(File.exist?( dir )).to be_truthy
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::OptionGroups::Report do
|
4
|
+
include_examples 'option_group'
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
%w(path).each do |method|
|
8
|
+
it { is_expected.to respond_to method }
|
9
|
+
it { is_expected.to respond_to "#{method}=" }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#path' do
|
13
|
+
context "when #{Cuboid::OptionGroups::Paths}.config['reports']" do
|
14
|
+
it 'returns it' do
|
15
|
+
allow(Cuboid::OptionGroups::Paths).to receive(:config) do
|
16
|
+
{
|
17
|
+
'reports' => Dir.tmpdir
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
expect(subject.path).to eq(Dir.tmpdir + '/')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|