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,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::OptionGroups::RPC do
|
4
|
+
include_examples 'option_group'
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
%w(server_socket server_external_address server_address server_port ssl_ca
|
8
|
+
server_ssl_private_key server_ssl_certificate client_ssl_private_key
|
9
|
+
client_ssl_certificate client_max_retries).each do |method|
|
10
|
+
it { is_expected.to respond_to method }
|
11
|
+
it { is_expected.to respond_to "#{method}=" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#to_client_options' do
|
15
|
+
it 'returns RPC client options' do
|
16
|
+
subject.connection_pool_size = 2
|
17
|
+
subject.client_max_retries = 3
|
18
|
+
subject.client_ssl_private_key = '2'
|
19
|
+
subject.client_ssl_certificate = '3'
|
20
|
+
subject.ssl_ca = '4'
|
21
|
+
|
22
|
+
expect(subject.to_client_options).to eq(
|
23
|
+
connection_pool_size: subject.connection_pool_size,
|
24
|
+
max_retries: subject.client_max_retries,
|
25
|
+
ssl_ca: subject.ssl_ca,
|
26
|
+
ssl_pkey: subject.client_ssl_private_key,
|
27
|
+
ssl_cert: subject.client_ssl_certificate
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#to_server_options' do
|
33
|
+
it 'returns RPC server options' do
|
34
|
+
subject.server_address = 'blah'
|
35
|
+
subject.server_external_address = 'fsfs'
|
36
|
+
subject.server_port = 2
|
37
|
+
subject.server_socket = '3'
|
38
|
+
subject.ssl_ca = '4'
|
39
|
+
subject.server_ssl_private_key = '4'
|
40
|
+
subject.server_ssl_certificate = '4'
|
41
|
+
|
42
|
+
expect(subject.to_server_options).to eq(
|
43
|
+
host: subject.server_address,
|
44
|
+
external_address: subject.server_external_address,
|
45
|
+
port: subject.server_port,
|
46
|
+
socket: subject.server_socket,
|
47
|
+
ssl_ca: subject.ssl_ca,
|
48
|
+
ssl_pkey: subject.server_ssl_private_key,
|
49
|
+
ssl_cert: subject.server_ssl_certificate
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::OptionGroups::Snapshot 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['snapshots']" do
|
14
|
+
it 'returns it' do
|
15
|
+
allow(Cuboid::OptionGroups::Paths).to receive(:config) do
|
16
|
+
{
|
17
|
+
'snapshots' => Dir.tmpdir
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
expect(subject.path).to eq(Dir.tmpdir + '/')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::OptionGroups::System do
|
4
|
+
include_examples 'option_group'
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
%w(max_slots).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,218 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::Options do
|
4
|
+
|
5
|
+
subject { described_class.instance }
|
6
|
+
groups = described_class.group_classes.keys
|
7
|
+
|
8
|
+
it 'proxies missing class methods to instance methods' do
|
9
|
+
datastore = 'http://test.com/'
|
10
|
+
expect(subject.datastore.url).not_to eq(datastore)
|
11
|
+
subject.datastore.url = datastore
|
12
|
+
expect(subject.datastore.url).to eq(datastore)
|
13
|
+
end
|
14
|
+
|
15
|
+
%w(authorized_by).each do |method|
|
16
|
+
it { is_expected.to respond_to method }
|
17
|
+
it { is_expected.to respond_to "#{method}=" }
|
18
|
+
end
|
19
|
+
|
20
|
+
groups.each do |group|
|
21
|
+
describe "##{group}" do
|
22
|
+
it 'is an OptionGroup' do
|
23
|
+
expect(subject.send( group )).to be_kind_of Cuboid::OptionGroup
|
24
|
+
expect(subject.send( group ).class.to_s.downcase).to eq(
|
25
|
+
"cuboid::optiongroups::#{group}".gsub( '_', '' )
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#validate' do
|
32
|
+
context 'when valid' do
|
33
|
+
it 'returns nil' do
|
34
|
+
expect(subject.validate).to be_empty
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when invalid' do
|
39
|
+
it 'returns errors by group'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#update' do
|
44
|
+
it 'sets options by hash' do
|
45
|
+
opts = { authorized_by: 'test@test.test' }
|
46
|
+
|
47
|
+
subject.update( opts )
|
48
|
+
expect(subject.authorized_by).to eq(opts[:authorized_by])
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when key refers to an OptionGroup' do
|
52
|
+
it 'updates that group' do
|
53
|
+
opts = {
|
54
|
+
datastore: {
|
55
|
+
key2: 'val2'
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
subject.update( opts )
|
60
|
+
expect(subject.datastore.to_h).to eq(opts[:datastore])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#save' do
|
66
|
+
it 'dumps #to_h to a file' do
|
67
|
+
f = 'options'
|
68
|
+
|
69
|
+
subject.save( f )
|
70
|
+
|
71
|
+
raised = false
|
72
|
+
begin
|
73
|
+
File.delete( f )
|
74
|
+
rescue
|
75
|
+
raised = true
|
76
|
+
end
|
77
|
+
expect(raised).to be_falsey
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns the file location'do
|
81
|
+
f = 'options'
|
82
|
+
|
83
|
+
f = subject.save( f )
|
84
|
+
|
85
|
+
raised = false
|
86
|
+
begin
|
87
|
+
File.delete( f )
|
88
|
+
rescue
|
89
|
+
raised = true
|
90
|
+
end
|
91
|
+
expect(raised).to be_falsey
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#load' do
|
96
|
+
it 'loads a file created by #save' do
|
97
|
+
f = "#{Dir.tmpdir}/options"
|
98
|
+
|
99
|
+
subject.datastore.stuff = 'test'
|
100
|
+
subject.save( f )
|
101
|
+
|
102
|
+
options = subject.load( f )
|
103
|
+
expect(options).to eq(subject)
|
104
|
+
expect(options.datastore.stuff).to eq('test')
|
105
|
+
|
106
|
+
raised = false
|
107
|
+
begin
|
108
|
+
File.delete( f )
|
109
|
+
rescue
|
110
|
+
raised = true
|
111
|
+
end
|
112
|
+
expect(raised).to be_falsey
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#to_rpc_data' do
|
117
|
+
let(:data) { subject.to_rpc_data }
|
118
|
+
|
119
|
+
it 'converts self to a serializable hash' do
|
120
|
+
expect(data).to be_kind_of Hash
|
121
|
+
|
122
|
+
expect(Cuboid::RPC::Serializer.load(
|
123
|
+
Cuboid::RPC::Serializer.dump( data )
|
124
|
+
)).to eq(data)
|
125
|
+
end
|
126
|
+
|
127
|
+
(groups - described_class::TO_RPC_IGNORE.to_a).each do |k|
|
128
|
+
k = k.to_s
|
129
|
+
|
130
|
+
it "includes the '#{k}' group" do
|
131
|
+
expect(data[k]).to eq(subject.send(k).to_rpc_data)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
described_class::TO_RPC_IGNORE.each do |k|
|
136
|
+
k = k.to_s
|
137
|
+
|
138
|
+
it "does not include the '#{k}' group" do
|
139
|
+
expect(subject.to_rpc_data).not_to include k
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#to_rpc_data_without_defaults' do
|
145
|
+
before do
|
146
|
+
Cuboid::Options.reset
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'returns RPC data that are not identical to default settings' do
|
150
|
+
expect(subject.dup.reset.to_rpc_data_without_defaults).to eq subject.to_rpc_data_without_defaults
|
151
|
+
|
152
|
+
subject.authorized_by = 'test@test.test'
|
153
|
+
subject.datastore.elements = 'forms'
|
154
|
+
|
155
|
+
expect(subject.to_rpc_data_without_defaults).to eq({
|
156
|
+
'authorized_by' => 'test@test.test',
|
157
|
+
'datastore' => {
|
158
|
+
'elements' => 'forms'
|
159
|
+
}
|
160
|
+
})
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#to_hash' do
|
165
|
+
let(:data) { subject.to_hash }
|
166
|
+
|
167
|
+
it 'converts self to a hash' do
|
168
|
+
subject.datastore.stuff = 'test2'
|
169
|
+
|
170
|
+
h = subject.to_hash
|
171
|
+
expect(h).to be_kind_of Hash
|
172
|
+
end
|
173
|
+
|
174
|
+
(groups - described_class::TO_HASH_IGNORE.to_a).each do |k|
|
175
|
+
it "includes the '#{k}' group" do
|
176
|
+
expect(data[k]).to eq(subject.send(k).to_hash)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
described_class::TO_HASH_IGNORE.each do |k|
|
181
|
+
it "does not include the '#{k}' group" do
|
182
|
+
expect(subject.to_hash).not_to include k
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
describe '#to_h' do
|
189
|
+
it 'aliased to to_hash' do
|
190
|
+
expect(subject.to_hash).to eq(subject.to_h)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#rpc_data_to_hash' do
|
195
|
+
it 'normalizes the given hash into #to_hash format' do
|
196
|
+
normalized = subject.rpc_data_to_hash(
|
197
|
+
'datastore' => {
|
198
|
+
'request_timeout' => 90_000
|
199
|
+
}
|
200
|
+
)
|
201
|
+
|
202
|
+
expect(normalized[:datastore][:request_timeout]).to eq(90_000)
|
203
|
+
expect(subject.datastore.request_timeout).not_to eq(90_000)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe '#hash_to_rpc_data' do
|
208
|
+
it 'normalizes the given hash into #to_rpc_data format' do
|
209
|
+
normalized = subject.hash_to_rpc_data(
|
210
|
+
datastore: { request_timeout: 90_000 }
|
211
|
+
)
|
212
|
+
|
213
|
+
expect(normalized['datastore']['request_timeout']).to eq(90_000)
|
214
|
+
expect(subject.datastore.request_timeout).not_to eq(90_000)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
@@ -0,0 +1,221 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::Report do
|
4
|
+
|
5
|
+
after :each do
|
6
|
+
File.delete( @report_file ) rescue nil
|
7
|
+
end
|
8
|
+
|
9
|
+
let( :report_data ) { Factory[:report_data] }
|
10
|
+
let( :report ) { Factory[:report] }
|
11
|
+
let( :report_empty ) { Factory[:report_empty] }
|
12
|
+
|
13
|
+
it "supports #{Cuboid::RPC::Serializer}" do
|
14
|
+
cloned = Cuboid::RPC::Serializer.deep_clone( report )
|
15
|
+
cloned.options.delete :input
|
16
|
+
|
17
|
+
expect(report).to eq(cloned)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#to_rpc_data' do
|
21
|
+
let(:subject) { report }
|
22
|
+
let(:data) { subject.to_rpc_data }
|
23
|
+
|
24
|
+
%w(seed version).each do |attribute|
|
25
|
+
it "includes '#{attribute}'" do
|
26
|
+
expect(data[attribute]).to eq(subject.send( attribute ))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "includes serialized 'data'" do
|
31
|
+
expect(data['data']).to eq Cuboid::Application.application.serializer.dump(subject.data)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "includes 'options'" do
|
35
|
+
expect(data['options']).to eq(
|
36
|
+
Cuboid::Application.application.serializer.dump subject.options
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
%w(start_datetime finish_datetime).each do |attribute|
|
41
|
+
it "includes '#{attribute}'" do
|
42
|
+
expect(data[attribute]).to eq(subject.send( attribute ).to_s)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.from_rpc_data' do
|
48
|
+
let(:subject) { report }
|
49
|
+
|
50
|
+
let(:restored) { described_class.from_rpc_data data }
|
51
|
+
let(:data) { Cuboid::RPC::Serializer.rpc_data( subject ) }
|
52
|
+
|
53
|
+
%w(seed version data).each do |attribute|
|
54
|
+
it "restores '#{attribute}'" do
|
55
|
+
expect(restored.send( attribute )).to eq(subject.send( attribute ))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "restores 'options'" do
|
60
|
+
restored.options.delete :input
|
61
|
+
subject.options.delete :input
|
62
|
+
|
63
|
+
expect(restored.options).to eq(subject.options)
|
64
|
+
end
|
65
|
+
|
66
|
+
%w(start_datetime finish_datetime).each do |attribute|
|
67
|
+
it "restores '#{attribute}'" do
|
68
|
+
expect(restored.send( attribute )).to be_kind_of Time
|
69
|
+
expect(restored.send( attribute ).to_s).to eq(subject.send( attribute ).to_s)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#version' do
|
75
|
+
it 'returns the version number' do
|
76
|
+
expect(report.version).to eq(Cuboid::VERSION)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#seed' do
|
81
|
+
it 'returns the scan seed' do
|
82
|
+
expect(report.seed).to eq(Cuboid::Utilities.random_seed)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#options' do
|
87
|
+
it 'returns application options'
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#start_datetime' do
|
91
|
+
it 'returns a Time object' do
|
92
|
+
expect(report.start_datetime).to be_kind_of Time
|
93
|
+
end
|
94
|
+
context 'when no start datetime info has been provided' do
|
95
|
+
it 'falls-back to Time.now' do
|
96
|
+
expect(report_empty.start_datetime).to be_kind_of Time
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#finish_datetime' do
|
102
|
+
it 'returns a Time object' do
|
103
|
+
expect(report.finish_datetime).to be_kind_of Time
|
104
|
+
end
|
105
|
+
it 'returns the start finish of the scan' do
|
106
|
+
expect(report.finish_datetime.to_s).to eq(
|
107
|
+
Factory[:report_data][:finish_datetime].to_s
|
108
|
+
)
|
109
|
+
end
|
110
|
+
context 'when no start datetime info has been provided' do
|
111
|
+
it 'falls-back to Time.now' do
|
112
|
+
expect(report_empty.finish_datetime).to be_kind_of Time
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#delta_time' do
|
118
|
+
it 'returns the time difference between start and finish time' do
|
119
|
+
expect(report.delta_time).to eq('02:46:40')
|
120
|
+
end
|
121
|
+
context 'when no #finish_datetime has been provided' do
|
122
|
+
it 'uses Time.now for the calculation' do
|
123
|
+
report_empty.start_datetime = Time.now - 2000
|
124
|
+
expect(report_empty.delta_time.to_s).to eq('00:33:19')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '.read_summary' do
|
130
|
+
it 'returns summary' do
|
131
|
+
summary = report.summary
|
132
|
+
summary[:application] = summary[:application].to_s
|
133
|
+
|
134
|
+
@report_file = report.save
|
135
|
+
expect(described_class.read_summary( @report_file )).to eq(
|
136
|
+
Cuboid::RPC::Serializer.load( Cuboid::RPC::Serializer.dump( summary ) ).
|
137
|
+
my_symbolize_keys.tap do |s|
|
138
|
+
s[:application] = ObjectSpace.const_get( s[:application].to_sym )
|
139
|
+
end
|
140
|
+
)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#save' do
|
145
|
+
it 'dumps the object to a file' do
|
146
|
+
@report_file = report.save
|
147
|
+
|
148
|
+
expect(described_class.load( @report_file )).to eq(report)
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'when given a location' do
|
152
|
+
context 'which is a filepath' do
|
153
|
+
it 'saves the object to that file' do
|
154
|
+
@report_file = 'report'
|
155
|
+
report.save( @report_file )
|
156
|
+
|
157
|
+
expect(described_class.load( @report_file )).to eq(report)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'which is a directory' do
|
162
|
+
it 'saves the object under that directory' do
|
163
|
+
directory = Dir.tmpdir
|
164
|
+
@report_file = report.save( directory )
|
165
|
+
|
166
|
+
expect(described_class.load( @report_file )).to eq(report)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe '#to_crf' do
|
173
|
+
it 'returns the object in CRF format' do
|
174
|
+
@report_file = report.save
|
175
|
+
|
176
|
+
expect(IO.binread( @report_file )).to eq(report.to_crf)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#from_crf' do
|
181
|
+
it 'loads an object from CRF data'
|
182
|
+
end
|
183
|
+
|
184
|
+
describe '#to_h' do
|
185
|
+
it 'returns the object as a hash' do
|
186
|
+
expect(report.to_h).to eq({
|
187
|
+
application: MockApp,
|
188
|
+
version: report.version,
|
189
|
+
status: report.status,
|
190
|
+
data: report.data,
|
191
|
+
seed: report.seed,
|
192
|
+
options: Cuboid::Options.hash_to_rpc_data( report.options ),
|
193
|
+
start_datetime: report.start_datetime.to_s,
|
194
|
+
finish_datetime: report.finish_datetime.to_s,
|
195
|
+
delta_time: report.delta_time,
|
196
|
+
})
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe '#to_hash' do
|
201
|
+
it 'alias of #to_h' do
|
202
|
+
expect(report.to_h).to eq(report.to_hash)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe '#==' do
|
207
|
+
context 'when the reports are equal' do
|
208
|
+
it 'returns true' do
|
209
|
+
expect(described_class.from_crf( report.to_crf )).to eq(report)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
context 'when the reports are not equal' do
|
213
|
+
it 'returns false' do
|
214
|
+
a = described_class.from_crf( report.to_crf )
|
215
|
+
a.options[:authorized_by] = 'http://stuff/'
|
216
|
+
expect(a).not_to eq(report)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|