lorj 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -2
- data/lib/core/core.rb +25 -15
- data/lib/core/core_internal.rb +82 -6
- data/lib/core/core_object_params.rb +43 -12
- data/lib/core/core_process_setup.rb +60 -172
- data/lib/core/core_setup_ask.rb +18 -3
- data/lib/core/core_setup_init.rb +929 -58
- data/lib/core/core_setup_list.rb +6 -3
- data/lib/core/definition.rb +2 -2
- data/lib/core/definition_internal.rb +1 -1
- data/lib/core/lorj_basedefinition.rb +6 -0
- data/lib/core/process.rb +67 -8
- data/lib/logging.rb +9 -5
- data/lib/lorj/version.rb +2 -2
- data/lib/lorj_account.rb +40 -20
- data/lib/lorj_config.rb +7 -2
- data/lib/lorj_defaults.rb +7 -4
- data/lib/lorj_meta.rb +61 -16
- data/lorj-spec/{controllers → process/mock/controllers}/mock/mock.rb +0 -0
- data/lorj-spec/{data.yaml → process/mock/data.yaml} +0 -0
- data/lorj-spec/process/mock/defaults.yaml +42 -0
- data/lorj-spec/{providers → process/mock/providers}/mock2/mock2.rb +0 -0
- data/lorj-spec/process/mock_process.rb +1 -1
- data/lorj-spec/providers_extra/mock3/mock3.rb +144 -0
- data/lorj.gemspec +1 -1
- data/spec/05_lorj_keypath_spec.rb +128 -2
- data/spec/06_lorj_object_data_spec.rb +77 -0
- data/spec/13_lorj_account_spec.rb +67 -0
- data/spec/20_lorj_meta_spec.rb +17 -7
- data/spec/21_lorj_processes_spec.rb +54 -23
- data/spec/22_lorj_core_spec.rb +49 -0
- metadata +13 -8
@@ -0,0 +1,144 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# This class describes how to process some actions, and will do everything prior
|
18
|
+
# this task to make it to work.
|
19
|
+
|
20
|
+
# This Mock controller keep the data in memory in hash/Array data.
|
21
|
+
class Mock
|
22
|
+
# mock do not need to use any mapping. It adapts itself to what the process
|
23
|
+
# has defined.
|
24
|
+
end
|
25
|
+
|
26
|
+
# This Mock controller keep the data in memory in hash/Array data.
|
27
|
+
class MockController
|
28
|
+
@@data = {} # rubocop: disable ClassVars
|
29
|
+
|
30
|
+
def create(sObjectType, hParams)
|
31
|
+
PrcLib.debug("Mock: create object '%s' with parameters (hdata) '%s'",
|
32
|
+
sObjectType, hParams[:hdata])
|
33
|
+
|
34
|
+
result = {}
|
35
|
+
hParams[].keys.each do |key|
|
36
|
+
next if key == :hdata
|
37
|
+
result[key] = hParams[key]
|
38
|
+
end
|
39
|
+
result.merge!(hParams[:hdata])
|
40
|
+
|
41
|
+
@@data[sObjectType] = [] unless @@data.key?(sObjectType)
|
42
|
+
|
43
|
+
array = @@data[sObjectType]
|
44
|
+
|
45
|
+
array.each do |value|
|
46
|
+
fail if value.key?(result[:name])
|
47
|
+
end
|
48
|
+
array << result
|
49
|
+
|
50
|
+
result[:id] = array.length - 1
|
51
|
+
|
52
|
+
# Typical code:
|
53
|
+
# ~ case sObjectType
|
54
|
+
# ~ when :public_ip
|
55
|
+
# Following function can be executed to ensure the object :connection exists
|
56
|
+
# ~ required?(hParams, :connection)
|
57
|
+
# ~ required?(hParams, :server)
|
58
|
+
# ~ ... CODE to create
|
59
|
+
# ~ else
|
60
|
+
# ~ controller_error "'%s' is not a valid object for 'create'", sObjectType
|
61
|
+
# ~ end
|
62
|
+
# The code should return some data
|
63
|
+
# This data will be encapsulated in Lorj::Data object.
|
64
|
+
# data will be extracted by the framework with the controller get_attr
|
65
|
+
# function and mapped.
|
66
|
+
PrcLib.debug("Mock: object '%s' = '%s' is created.", sObjectType, result)
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
# This function return a collection which have to provide:
|
71
|
+
# functions: [], length, each
|
72
|
+
# Used by network process.
|
73
|
+
def query(sObjectType, sQuery, hParams)
|
74
|
+
PrcLib.debug("Mock: query object '%s' with hdata '%s' using query '%s'",
|
75
|
+
sObjectType, hParams[:hdata], sQuery)
|
76
|
+
|
77
|
+
return [] unless @@data.key?(sObjectType)
|
78
|
+
|
79
|
+
result = []
|
80
|
+
|
81
|
+
@@data[sObjectType].each do |value|
|
82
|
+
elem = value
|
83
|
+
sQuery.each do |query_key, query_value|
|
84
|
+
elem = nil if !value.key?(query_key) || value[query_key] != query_value
|
85
|
+
end
|
86
|
+
result << elem if elem
|
87
|
+
end
|
88
|
+
result
|
89
|
+
end
|
90
|
+
|
91
|
+
def delete(sObjectType, hParams)
|
92
|
+
PrcLib.debug("Mock: delete object '%s' with hdata '%s'",
|
93
|
+
sObjectType, hParams[:hdata])
|
94
|
+
return nil unless @@data.key?(sObjectType)
|
95
|
+
|
96
|
+
return false if !hParams.exist?(sObjectType) || hParams[sObjectType].nil?
|
97
|
+
@@data[sObjectType].delete(hParams[sObjectType])
|
98
|
+
PrcLib.debug("Mock: object '%s' = '%s' is deleted.",
|
99
|
+
sObjectType, hParams[sObjectType])
|
100
|
+
true
|
101
|
+
end
|
102
|
+
|
103
|
+
def get(sObjectType, sUniqId, hParams)
|
104
|
+
PrcLib.debug("Mock: Get object '%s' = '%s' with hdata '%s'",
|
105
|
+
sObjectType, sUniqId, hParams[:hdata])
|
106
|
+
return nil unless @@data.key?(sObjectType)
|
107
|
+
@@data[sObjectType][sUniqId]
|
108
|
+
end
|
109
|
+
|
110
|
+
def get_attr(oControlerObject, key)
|
111
|
+
# This controller function read the data and
|
112
|
+
# extract the information requested by the framework.
|
113
|
+
# Those data will be mapped to the process data model.
|
114
|
+
# The key is an array, to get data from a level tree.
|
115
|
+
# [data_l1, data_l2, data_l3] => should retrieve data from structure like
|
116
|
+
# data[ data_l2[ data_l3 ] ]
|
117
|
+
attributes = oControlerObject
|
118
|
+
|
119
|
+
attributes.rh_get(key)
|
120
|
+
rescue => e
|
121
|
+
controller_error "Unable to map '%s'.\n%s", key, e.message
|
122
|
+
end
|
123
|
+
|
124
|
+
def set_attr(oControlerObject, key, value)
|
125
|
+
attributes = oControlerObject
|
126
|
+
|
127
|
+
attributes.rh_set(value, key)
|
128
|
+
rescue => e
|
129
|
+
controller_error "Unable to map '%s' on '%s'.\n%s",
|
130
|
+
key, sObjectType, e.message
|
131
|
+
end
|
132
|
+
|
133
|
+
def update(sObjectType, oObject, hParams)
|
134
|
+
PrcLib.debug("Mock: Update object '%s' = '%s' with hdata '%s'",
|
135
|
+
sObjectType, sUniqId, hParams[:hdata])
|
136
|
+
return false unless @@data.key?(sObjectType)
|
137
|
+
|
138
|
+
return false unless @@data[sObjectType][oObject[:id]].nil?
|
139
|
+
# Considered hash object is already updated.
|
140
|
+
# This action emule the object save which doesn't make sense in this empty
|
141
|
+
# Mock controller.
|
142
|
+
true
|
143
|
+
end
|
144
|
+
end
|
data/lorj.gemspec
CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
'--title Lorj - The Process Controllers framework system' << \
|
37
37
|
'--main README.md'
|
38
38
|
|
39
|
-
spec.add_runtime_dependency 'config_layers', '~>0.1.
|
39
|
+
spec.add_runtime_dependency 'config_layers', '~>0.1.3'
|
40
40
|
# spec.add_runtime_dependency 'git', '>=1.2.7'
|
41
41
|
# spec.add_runtime_dependency 'rbx-require-relative', '~>0.0.7'
|
42
42
|
spec.add_runtime_dependency 'highline', '~> 1.6.21'
|
@@ -15,7 +15,7 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
|
-
#
|
18
|
+
# require 'byebug'
|
19
19
|
|
20
20
|
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib/core')
|
21
21
|
|
@@ -26,6 +26,9 @@ describe 'Lorj::KeyPath,' do
|
|
26
26
|
before(:all) do
|
27
27
|
@o_key = Lorj::KeyPath.new(:test)
|
28
28
|
end
|
29
|
+
it 'Test method #length' do
|
30
|
+
expect(@o_key.length).to eq(1)
|
31
|
+
end
|
29
32
|
it 'Test method #to_s' do
|
30
33
|
expect(@o_key.to_s).to eq('test')
|
31
34
|
end
|
@@ -45,7 +48,7 @@ describe 'Lorj::KeyPath,' do
|
|
45
48
|
expect(@o_key.key).to eq(:test)
|
46
49
|
end
|
47
50
|
it 'Test method #key_tree' do
|
48
|
-
expect(@o_key.
|
51
|
+
expect(@o_key.key_tree).to eq(:test)
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
@@ -53,6 +56,9 @@ describe 'Lorj::KeyPath,' do
|
|
53
56
|
before(:all) do
|
54
57
|
@o_key = Lorj::KeyPath.new([:test, :test2, :test3])
|
55
58
|
end
|
59
|
+
it 'Test method #length' do
|
60
|
+
expect(@o_key.length).to eq(3)
|
61
|
+
end
|
56
62
|
it 'Test method #to_s' do
|
57
63
|
expect(@o_key.to_s).to eq('test/test2/test3')
|
58
64
|
end
|
@@ -75,4 +81,124 @@ describe 'Lorj::KeyPath,' do
|
|
75
81
|
expect(@o_key.key_tree).to eq(':test/:test2/:test3')
|
76
82
|
end
|
77
83
|
end
|
84
|
+
|
85
|
+
context 'initialize with string test1/test2' do
|
86
|
+
before(:all) do
|
87
|
+
@o_key = Lorj::KeyPath.new('test1/test2')
|
88
|
+
end
|
89
|
+
it 'Test method #length' do
|
90
|
+
expect(@o_key.length).to eq(2)
|
91
|
+
end
|
92
|
+
it 'Test method #to_s' do
|
93
|
+
expect(@o_key.to_s).to eq('test1/test2')
|
94
|
+
end
|
95
|
+
it 'Test method #key' do
|
96
|
+
expect(@o_key.key).to eq('test2')
|
97
|
+
end
|
98
|
+
it 'Test method #key(0)' do
|
99
|
+
expect(@o_key.key(0)).to eq('test1')
|
100
|
+
end
|
101
|
+
it 'Test method #key(1)' do
|
102
|
+
expect(@o_key.key(1)).to eq('test2')
|
103
|
+
end
|
104
|
+
it 'Test method #fpath' do
|
105
|
+
expect(@o_key.fpath).to eq('test1/test2')
|
106
|
+
end
|
107
|
+
it 'Test method #tree' do
|
108
|
+
expect(@o_key.tree).to eq(%w(test1 test2))
|
109
|
+
end
|
110
|
+
it 'Test method #key_tree' do
|
111
|
+
expect(@o_key.key_tree).to eq('test1/test2')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'initialize with string :test' do
|
116
|
+
before(:all) do
|
117
|
+
@o_key = Lorj::KeyPath.new(':test')
|
118
|
+
end
|
119
|
+
it 'Test method #length' do
|
120
|
+
expect(@o_key.length).to eq(1)
|
121
|
+
end
|
122
|
+
it 'Test method #to_s' do
|
123
|
+
expect(@o_key.to_s).to eq('test')
|
124
|
+
end
|
125
|
+
it 'Test method #key' do
|
126
|
+
expect(@o_key.key).to eq(:test)
|
127
|
+
end
|
128
|
+
it 'Test method #key(0)' do
|
129
|
+
expect(@o_key.key(0)).to eq(:test)
|
130
|
+
end
|
131
|
+
it 'Test method #key(1)' do
|
132
|
+
expect(@o_key.key(1)).to eq(nil)
|
133
|
+
end
|
134
|
+
it 'Test method #fpath' do
|
135
|
+
expect(@o_key.fpath).to eq(':test')
|
136
|
+
end
|
137
|
+
it 'Test method #tree' do
|
138
|
+
expect(@o_key.tree).to eq([:test])
|
139
|
+
end
|
140
|
+
it 'Test method #key_tree' do
|
141
|
+
expect(@o_key.key_tree).to eq(:test)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'initialize with string test' do
|
146
|
+
before(:all) do
|
147
|
+
@o_key = Lorj::KeyPath.new('test')
|
148
|
+
end
|
149
|
+
it 'Test method #length' do
|
150
|
+
expect(@o_key.length).to eq(1)
|
151
|
+
end
|
152
|
+
it 'Test method #to_s' do
|
153
|
+
expect(@o_key.to_s).to eq('test')
|
154
|
+
end
|
155
|
+
it 'Test method #key' do
|
156
|
+
expect(@o_key.key).to eq('test')
|
157
|
+
end
|
158
|
+
it 'Test method #key(0)' do
|
159
|
+
expect(@o_key.key(0)).to eq('test')
|
160
|
+
end
|
161
|
+
it 'Test method #key(1)' do
|
162
|
+
expect(@o_key.key(1)).to eq(nil)
|
163
|
+
end
|
164
|
+
it 'Test method #fpath' do
|
165
|
+
expect(@o_key.fpath).to eq('test')
|
166
|
+
end
|
167
|
+
it 'Test method #tree' do
|
168
|
+
expect(@o_key.tree).to eq(['test'])
|
169
|
+
end
|
170
|
+
it 'Test method #key_tree' do
|
171
|
+
expect(@o_key.key_tree).to eq('test')
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'initialize with nil' do
|
176
|
+
before(:all) do
|
177
|
+
@o_key = Lorj::KeyPath.new(nil)
|
178
|
+
end
|
179
|
+
it 'Test method #length' do
|
180
|
+
expect(@o_key.length).to eq(0)
|
181
|
+
end
|
182
|
+
it 'Test method #to_s' do
|
183
|
+
expect(@o_key.to_s).to eq(nil)
|
184
|
+
end
|
185
|
+
it 'Test method #key' do
|
186
|
+
expect(@o_key.key).to eq(nil)
|
187
|
+
end
|
188
|
+
it 'Test method #key(0)' do
|
189
|
+
expect(@o_key.key(0)).to eq(nil)
|
190
|
+
end
|
191
|
+
it 'Test method #key(1)' do
|
192
|
+
expect(@o_key.key(1)).to eq(nil)
|
193
|
+
end
|
194
|
+
it 'Test method #fpath' do
|
195
|
+
expect(@o_key.fpath).to eq(nil)
|
196
|
+
end
|
197
|
+
it 'Test method #tree' do
|
198
|
+
expect(@o_key.tree).to eq([])
|
199
|
+
end
|
200
|
+
it 'Test method #key_tree' do
|
201
|
+
expect(@o_key.key_tree).to eq(nil)
|
202
|
+
end
|
203
|
+
end
|
78
204
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
# require 'byebug'
|
19
|
+
|
20
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib/core')
|
21
|
+
|
22
|
+
require 'core_object_data'
|
23
|
+
require 'subhash'
|
24
|
+
require 'lorj_data'
|
25
|
+
|
26
|
+
describe 'Lorj::ObjectData' do
|
27
|
+
context 'initialize with internal false' do
|
28
|
+
before(:all) do
|
29
|
+
@obj_data = Lorj::ObjectData.new
|
30
|
+
@obj_data[[:key1]] = 'value1'
|
31
|
+
@obj_data[[:key2, :key22]] = 'value2'
|
32
|
+
end
|
33
|
+
it 'Test method #[]' do
|
34
|
+
expect(@obj_data[[:key1]]).to eq('value1')
|
35
|
+
expect(@obj_data[[:key2, :key22]]).to eq('value2')
|
36
|
+
end
|
37
|
+
it 'Test method #exist?' do
|
38
|
+
expect(@obj_data.exist?(:key1)).to eq(true)
|
39
|
+
expect(@obj_data.exist?([:key2, :key22])).to eq(true)
|
40
|
+
expect(@obj_data.exist?(:otherkey)).to eq(false)
|
41
|
+
end
|
42
|
+
it 'Test method #<<' do
|
43
|
+
h_hash = { :key3 => [:key31, :key32] }
|
44
|
+
@obj_data.<< h_hash
|
45
|
+
expect(@obj_data[[:key3]]).to eq([:key31, :key32])
|
46
|
+
end
|
47
|
+
it 'Test method #to_s' do
|
48
|
+
expect(@obj_data.to_s).to eq('-- Lorj::ObjectData --
|
49
|
+
hdata:
|
50
|
+
{}
|
51
|
+
key1:
|
52
|
+
value1
|
53
|
+
key2:
|
54
|
+
{:key22=>"value2"}
|
55
|
+
key3:
|
56
|
+
[:key31, :key32]
|
57
|
+
')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
context 'initialize with internal true' do
|
61
|
+
before(:all) do
|
62
|
+
@obj_data = Lorj::ObjectData.new(true)
|
63
|
+
@internal_data = Lorj::Data.new
|
64
|
+
data = [{ :name => 'toto' }]
|
65
|
+
@internal_data.set(data, :list, :name => /^t/) { |oObject| oObject }
|
66
|
+
end
|
67
|
+
it 'Test method #add' do
|
68
|
+
@obj_data.add(@internal_data)
|
69
|
+
expect(@obj_data.exist?(:list)).to eq(true)
|
70
|
+
end
|
71
|
+
it 'Test method #delete' do
|
72
|
+
deleted_data = @obj_data.delete(@internal_data)
|
73
|
+
expect(@obj_data.exist?(:list)).to eq(false)
|
74
|
+
expect(deleted_data.is_registered).to eq(false)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -116,6 +116,7 @@ describe 'class: Lorj::Account,' do
|
|
116
116
|
it "account[:data] return 'nova_local', stored only in local." do
|
117
117
|
expect(@account[:data]).to eq(nil)
|
118
118
|
end
|
119
|
+
|
119
120
|
it 'account.where?(:data) return false, as account not loaded.' do
|
120
121
|
expect(@account.where?(:data)).to equal(false)
|
121
122
|
end
|
@@ -220,6 +221,72 @@ describe 'class: Lorj::Account,' do
|
|
220
221
|
expect(@account.get(:keypair_name, nil,
|
221
222
|
:name => 'account')).to eq('nova_test2')
|
222
223
|
end
|
224
|
+
|
225
|
+
context ':credentials as section name and runtime set' do
|
226
|
+
it 'account.get(:"credentials#keypair_name") return '\
|
227
|
+
'"nova_test3"(runtime)' do
|
228
|
+
expect(@account.get(:"credentials#keypair_name")).to eq('nova_test3')
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'account.get(:keypair_name, nil, :section => :credentials) '\
|
232
|
+
'return "nova_test3"(runtime)' do
|
233
|
+
expect(@account.get(:keypair_name, nil,
|
234
|
+
:section => :credentials)).to eq('nova_test3')
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context 'with section, no runtime' do
|
239
|
+
before(:all) do
|
240
|
+
@account.del(:keypair_name)
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'account.get(:"credentials#keypair_name") return '\
|
244
|
+
'"nova_test2"(account)' do
|
245
|
+
expect(@account.get(:"credentials#keypair_name")).to eq('nova_test2')
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'account.get(:keypair_name, nil, :section => :credentials) '\
|
249
|
+
'return "nova_test2"(account)' do
|
250
|
+
expect(@account.get(:keypair_name, nil,
|
251
|
+
:section => :credentials)).to eq('nova_test2')
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'account.get(:"test#keypair_name") return "nova_local"(local)' do
|
255
|
+
expect(@account.get(:"test#keypair_name")).to eq('nova_local')
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'account.get(:keypair_name, nil, :section => :test) '\
|
259
|
+
'return "nova_local"(local)' do
|
260
|
+
expect(@account.get(:keypair_name, nil,
|
261
|
+
:section => :test)).to eq('nova_local')
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'account.where?(:"credentials#keypair_name") return %w(account local '\
|
265
|
+
'default)' do
|
266
|
+
expect(@account.where?('credentials#keypair_name'
|
267
|
+
)).to eq(%w(account local default))
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'account.where?(:"test#keypair_name") return %w(local '\
|
271
|
+
'default)' do
|
272
|
+
expect(@account.where?('test#keypair_name'
|
273
|
+
)).to eq(%w(local default))
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context 'Setting a new section, no runtime' do
|
278
|
+
it 'account.set(:"test#keypair_name", "nova_test3",'\
|
279
|
+
':name => "account") return "nova_test3"(account)' do
|
280
|
+
expect(@account.set('test#keypair_name', 'nova_test3',
|
281
|
+
:name => 'account')).to eq('nova_test3')
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'account.where?(:"test#keypair_name") return %w(account local '\
|
285
|
+
'default)' do
|
286
|
+
expect(@account.where?('test#keypair_name'
|
287
|
+
)).to eq(%w(account local default))
|
288
|
+
end
|
289
|
+
end
|
223
290
|
end
|
224
291
|
|
225
292
|
context "Key | runtime | accounts | local | default)\n"\
|
data/spec/20_lorj_meta_spec.rb
CHANGED
@@ -78,16 +78,26 @@ YAMLDOC
|
|
78
78
|
expect(@metadata.datas).to eq([:data1, :data2, :data3])
|
79
79
|
end
|
80
80
|
|
81
|
-
it 'first_section(:data2) returns :section1' do
|
82
|
-
expect(@metadata.first_section(:data2)).to
|
81
|
+
it 'first_section(:data2) returns [:section1, :data2]' do
|
82
|
+
expect(@metadata.first_section(:data2)).to eq([:section1, :data2])
|
83
83
|
end
|
84
84
|
|
85
|
-
it 'first_section(
|
86
|
-
expect(@metadata.first_section(
|
85
|
+
it 'first_section("section2#data2") returns [:section2, :data2]' do
|
86
|
+
expect(@metadata.first_section('section2#data2')
|
87
|
+
).to eq([:section2, :data2])
|
87
88
|
end
|
88
89
|
|
89
|
-
it 'first_section(
|
90
|
-
expect(@metadata.first_section(
|
90
|
+
it 'first_section("section3#data2") returns [:section3, :data2]' do
|
91
|
+
expect(@metadata.first_section('section3#data2')
|
92
|
+
).to eq([:section3, :data2])
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'first_section(:data1) returns [:section1, :data1]' do
|
96
|
+
expect(@metadata.first_section(:data1)).to eq([:section1, :data1])
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'first_section(:data3) returns [:section3, :data3]' do
|
100
|
+
expect(@metadata.first_section(:data3)).to eq([:section3, :data3])
|
91
101
|
end
|
92
102
|
|
93
103
|
it 'meta_exist?(:section1, :data1) returns true' do
|
@@ -140,7 +150,7 @@ YAMLDOC
|
|
140
150
|
|
141
151
|
# To simplify spec code, app layer contains String values for each options
|
142
152
|
# while controller options values are Symbol.
|
143
|
-
# This helps to identify if the merge
|
153
|
+
# This helps to identify if the merge works.
|
144
154
|
it 'define_controller_data(:section2, :data2, :option2 => :value4) works' do
|
145
155
|
data = { :option2 => :value4 }
|
146
156
|
expect(@metadata[:sections, :section2, :data2, :option2]).to eq('value3')
|
@@ -27,7 +27,7 @@ $LOAD_PATH << File.join(app_path, '..', 'lib')
|
|
27
27
|
require 'lorj' # Load lorj framework
|
28
28
|
|
29
29
|
describe 'Lorj::Process,' do
|
30
|
-
context '
|
30
|
+
context 'Lorj::ProcessResource,' do
|
31
31
|
before(:all) do
|
32
32
|
@lorj_spec = 'lorj-spec'
|
33
33
|
@process_path = File.expand_path(File.join(app_path, '..', @lorj_spec))
|
@@ -35,13 +35,11 @@ describe 'Lorj::Process,' do
|
|
35
35
|
|
36
36
|
it 'default initialization is ok' do
|
37
37
|
process_file = File.join(@process_path, 'process', 'mock_process.rb')
|
38
|
-
controllers = { 'mock' => File.join(@process_path, '
|
39
|
-
'mock', 'mock.rb') }
|
40
|
-
default = File.join(@process_path, 'defaults.yaml')
|
41
|
-
data = File.join(@process_path, 'data.yaml')
|
42
|
-
process_data = Lorj::ProcessResource.new('mock',
|
43
|
-
'..',
|
44
|
-
@lorj_spec))
|
38
|
+
controllers = { 'mock' => File.join(@process_path, 'process', 'mock',
|
39
|
+
'controllers', 'mock', 'mock.rb') }
|
40
|
+
default = File.join(@process_path, 'process', 'mock', 'defaults.yaml')
|
41
|
+
data = File.join(@process_path, 'process', 'mock', 'data.yaml')
|
42
|
+
process_data = Lorj::ProcessResource.new('mock', @process_path)
|
45
43
|
expect(process_data).to be
|
46
44
|
expect(process_data.name).to eq('mock')
|
47
45
|
expect(process_data.process).to eq(process_file)
|
@@ -62,12 +60,11 @@ describe 'Lorj::Process,' do
|
|
62
60
|
|
63
61
|
it 'accepts symbol as name, but converted.' do
|
64
62
|
process_file = File.join(@process_path, 'process', 'mock_process.rb')
|
65
|
-
controllers = { 'mock' => File.join(@process_path, '
|
66
|
-
'mock', 'mock.rb') }
|
67
|
-
default = File.join(@process_path, 'defaults.yaml')
|
68
|
-
data = File.join(@process_path, 'data.yaml')
|
69
|
-
process_data = Lorj::ProcessResource.new(:mock,
|
70
|
-
@lorj_spec))
|
63
|
+
controllers = { 'mock' => File.join(@process_path, 'process', 'mock',
|
64
|
+
'controllers', 'mock', 'mock.rb') }
|
65
|
+
default = File.join(@process_path, 'process', 'mock', 'defaults.yaml')
|
66
|
+
data = File.join(@process_path, 'process', 'mock', 'data.yaml')
|
67
|
+
process_data = Lorj::ProcessResource.new(:mock, @process_path)
|
71
68
|
expect(process_data).to be
|
72
69
|
expect(process_data.name).to eq('mock')
|
73
70
|
expect(process_data.process).to eq(process_file)
|
@@ -77,19 +74,48 @@ describe 'Lorj::Process,' do
|
|
77
74
|
end
|
78
75
|
|
79
76
|
it 'initialization with :controllers_dir is ok' do
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
default = File.join(@process_path, 'defaults.yaml')
|
84
|
-
data = File.join(@process_path, 'data.yaml')
|
77
|
+
controllers = { 'mock2' => File.join(@process_path, 'process', 'mock',
|
78
|
+
'providers', 'mock2', 'mock2.rb') }
|
79
|
+
|
85
80
|
process_data = Lorj::ProcessResource.new('mock', @process_path,
|
86
81
|
:controllers_dir => 'providers')
|
87
82
|
expect(process_data).to be
|
88
83
|
expect(process_data.name).to eq('mock')
|
89
|
-
expect(process_data.process).to eq(process_file)
|
90
84
|
expect(process_data.controllers).to eq(controllers)
|
91
|
-
|
92
|
-
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'initialization with :controllers_path is ok' do
|
88
|
+
controller_path = File.join(@process_path, 'providers_extra')
|
89
|
+
controllers = { 'mock3' => File.join(controller_path,
|
90
|
+
'mock3', 'mock3.rb') }
|
91
|
+
process_data = Lorj::ProcessResource.new('mock', @process_path,
|
92
|
+
:controllers_path =>
|
93
|
+
controller_path)
|
94
|
+
expect(process_data).to be
|
95
|
+
expect(process_data.controllers).to eq(controllers)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'initialization with :default_file is ok' do
|
99
|
+
defaults_file = File.join(@process_path, 'defaults.yaml')
|
100
|
+
process_data = Lorj::ProcessResource.new('mock', @process_path,
|
101
|
+
:defaults_file => defaults_file)
|
102
|
+
expect(process_data).to be
|
103
|
+
expect(process_data.defaults_file).to eq(defaults_file)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'initialization with :data_file is ok' do
|
107
|
+
data_file = File.join(@process_path, 'process', 'mock', 'data.yaml')
|
108
|
+
process_data = Lorj::ProcessResource.new('mock', @process_path,
|
109
|
+
:data_file => data_file)
|
110
|
+
expect(process_data).to be
|
111
|
+
expect(process_data.data_file).to eq(data_file)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context('Lorj.declare_process, ') do
|
116
|
+
before(:all) do
|
117
|
+
@lorj_spec = 'lorj-spec'
|
118
|
+
@process_path = File.expand_path(File.join(app_path, '..', @lorj_spec))
|
93
119
|
end
|
94
120
|
|
95
121
|
it 'can declare a module process' do
|
@@ -101,12 +127,17 @@ describe 'Lorj::Process,' do
|
|
101
127
|
expect(Lorj.processes['mock'].class).to equal(Lorj::ProcessResource)
|
102
128
|
end
|
103
129
|
|
104
|
-
it 'can declare several module processes' do
|
130
|
+
it 'Lorj.declare_process, can declare several module processes' do
|
105
131
|
expect(Lorj.declare_process('mock', @process_path)).to be
|
106
132
|
expect(Lorj.declare_process(:mock2, @process_path)).to be
|
107
133
|
expect(Lorj.declare_process('mock3', @process_path)).to equal(nil)
|
108
134
|
end
|
109
135
|
|
136
|
+
it 'become empty, if name or process_path are incorrect' do
|
137
|
+
expect(Lorj.declare_process(nil, @process_path)).to equal(nil)
|
138
|
+
expect(Lorj.declare_process('mock', nil)).to equal(nil)
|
139
|
+
end
|
140
|
+
|
110
141
|
it 'all kept module processes in Lorj.processes not duplicated.' do
|
111
142
|
expect(Lorj.processes.length).to eq(2)
|
112
143
|
expect(Lorj.processes.keys).to eq(%w(mock mock2))
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
# require 'rubygems'
|
19
|
+
# require 'byebug'
|
20
|
+
# require 'debugger'
|
21
|
+
# require 'bundler/setup'
|
22
|
+
|
23
|
+
app_path = File.dirname(__FILE__)
|
24
|
+
|
25
|
+
$LOAD_PATH << File.join(app_path, '..', 'lib')
|
26
|
+
|
27
|
+
require 'lorj' # Load lorj framework
|
28
|
+
|
29
|
+
describe 'Lorj::Core,' do
|
30
|
+
context 'Using lorj-spec process, ' do
|
31
|
+
process_path = File.expand_path(File.join(app_path, '..', 'lorj-spec'))
|
32
|
+
Lorj.declare_process('mock', process_path)
|
33
|
+
Lorj.declare_process('mock2', process_path,
|
34
|
+
:controllers_path => File.join(process_path,
|
35
|
+
'providers_extra'))
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'Lorj::Core.new(nil, :mock) return an error' do
|
39
|
+
expect { Lorj::Core.new(nil, :mock) }.to raise_error(Lorj::PrcError)
|
40
|
+
end
|
41
|
+
it 'Lorj::Core.new(nil, [{ :process_module => :mock}]) gets loaded.' do
|
42
|
+
expect(core = Lorj::Core.new(nil, [{ :process_module => :mock }])).to be
|
43
|
+
expect(core.config).to be
|
44
|
+
expect(core.config.layers.include?('mock')).to equal(true)
|
45
|
+
expect(core.config.layer_index('mock')).to equal(4)
|
46
|
+
expect(Lorj.data.layers.include?('mock')).to equal(true)
|
47
|
+
expect(Lorj.data.layer_index('mock')).to equal(3)
|
48
|
+
end
|
49
|
+
end
|