simmer 1.0.0.pre.alpha.3 → 1.0.0.pre.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +5 -0
  4. data/lib/simmer.rb +103 -9
  5. data/lib/simmer/configuration.rb +7 -17
  6. data/lib/simmer/database.rb +10 -0
  7. data/lib/simmer/{util → database}/fixture.rb +7 -3
  8. data/lib/simmer/{util → database}/fixture_set.rb +10 -4
  9. data/lib/simmer/externals/aws_file_system.rb +30 -23
  10. data/lib/simmer/externals/mysql_database.rb +17 -10
  11. data/lib/simmer/externals/spoon_client.rb +5 -19
  12. data/lib/simmer/runner.rb +2 -2
  13. data/lib/simmer/specification/act.rb +1 -6
  14. data/lib/simmer/specification/assert/assertions/table.rb +1 -6
  15. data/lib/simmer/spoon_mock.rb +35 -0
  16. data/lib/simmer/suite.rb +49 -43
  17. data/lib/simmer/{session → suite}/reporter.rb +1 -1
  18. data/lib/simmer/{session → suite}/result.rb +1 -1
  19. data/lib/simmer/util.rb +0 -1
  20. data/lib/simmer/util/evaluator.rb +4 -5
  21. data/lib/simmer/util/record.rb +2 -0
  22. data/lib/simmer/util/record_set.rb +5 -1
  23. data/lib/simmer/util/resolver.rb +2 -2
  24. data/lib/simmer/util/yaml_reader.rb +9 -12
  25. data/lib/simmer/version.rb +1 -1
  26. data/spec/config/simmer.yaml.ci +7 -0
  27. data/spec/db/database.sql +1 -0
  28. data/spec/db/tables.sql +20 -0
  29. data/spec/db_helper.rb +26 -0
  30. data/spec/fixtures/agent_fixtures.yaml +14 -0
  31. data/spec/fixtures/configuration.yaml +11 -0
  32. data/spec/fixtures/noc_list.csv +3 -0
  33. data/spec/fixtures/specifications/load_noc_list.yaml +30 -0
  34. data/spec/fixtures/yaml_reader/bar.yaml +2 -0
  35. data/spec/fixtures/yaml_reader/baz/baz.yaml +2 -0
  36. data/spec/fixtures/yaml_reader/foo.yaml +2 -0
  37. data/spec/simmer/configuration_spec.rb +46 -0
  38. data/spec/simmer/database/fixture_set_spec.rb +75 -0
  39. data/spec/simmer/database/fixture_spec.rb +57 -0
  40. data/spec/simmer/externals/aws_file_system_spec.rb +75 -0
  41. data/spec/simmer/externals/mysql_database_spec.rb +79 -0
  42. data/spec/simmer/externals/spoon_client_spec.rb +67 -0
  43. data/spec/simmer/specification/act/params_spec.rb +38 -0
  44. data/spec/simmer/specification/act_spec.rb +37 -0
  45. data/spec/simmer/specification/assert_spec.rb +27 -0
  46. data/spec/simmer/specification/stage_spec.rb +32 -0
  47. data/spec/simmer/specification_spec.rb +28 -0
  48. data/spec/simmer/util/evaluator_spec.rb +82 -0
  49. data/spec/simmer/util/record_set_spec.rb +41 -0
  50. data/spec/simmer/util/record_spec.rb +218 -0
  51. data/spec/simmer/util/yaml_reader_spec.rb +49 -0
  52. data/spec/spec_helper.rb +21 -0
  53. metadata +60 -8
  54. data/lib/simmer/externals/spoon_client/mock.rb +0 -39
  55. data/lib/simmer/session.rb +0 -79
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'spec_helper'
11
+
12
+ describe Simmer::Specification::Act::Params do
13
+ let(:spec_path) { File.join('specifications', 'load_noc_list.yaml') }
14
+ let(:params_config) { yaml_fixture(spec_path).dig('act', 'params') }
15
+
16
+ let(:config) do
17
+ {
18
+ codes: {
19
+ the_secret_one: '123ABC'
20
+ }
21
+ }
22
+ end
23
+
24
+ let(:files_path) { 'files_are_here' }
25
+
26
+ subject { described_class.make(params_config) }
27
+
28
+ it '#compile combines files and keys' do
29
+ actual = subject.compile(files_path, config)
30
+ expected_path = File.expand_path(File.join(files_path, subject.files.values.first))
31
+ expected = {
32
+ 'input_file' => expected_path,
33
+ 'code' => 'The secret code is: 123ABC'
34
+ }
35
+
36
+ expect(actual).to eq(expected)
37
+ end
38
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'spec_helper'
11
+
12
+ describe Simmer::Specification::Act do
13
+ let(:path) { File.join('specifications', 'load_noc_list.yaml') }
14
+
15
+ let(:config) { yaml_fixture(path)['act'] }
16
+
17
+ describe 'initialization using acts_as_hashable' do
18
+ subject { described_class.make(config) }
19
+
20
+ it 'sets repository' do
21
+ expect(subject.repository).to eq('top_secret')
22
+ end
23
+
24
+ it 'sets name' do
25
+ expect(subject.name).to eq('load_noc_list')
26
+ end
27
+
28
+ it 'sets type' do
29
+ expect(subject.type).to eq('transformation')
30
+ end
31
+
32
+ it 'sets params' do
33
+ expect(subject.params.files).to eq('input_file' => 'noc_list.csv')
34
+ expect(subject.params.keys).to eq('code' => 'The secret code is: {codes.the_secret_one}')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'spec_helper'
11
+
12
+ describe Simmer::Specification::Assert do
13
+ let(:path) { File.join('specifications', 'load_noc_list.yaml') }
14
+
15
+ let(:config) { yaml_fixture(path)['assert'] }
16
+
17
+ describe 'initialization using acts_as_hashable' do
18
+ subject { described_class.make(config) }
19
+
20
+ it 'sets assertions' do
21
+ expect(subject.assertions.length).to eq(2)
22
+ expect(subject.assertions.first.name).to eq('agents')
23
+ expect(subject.assertions.first.record_set.length).to eq(2)
24
+ expect(subject.assertions.last.value).to eq('Decoding Agents')
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'spec_helper'
11
+
12
+ describe Simmer::Specification::Stage do
13
+ let(:path) { File.join('specifications', 'load_noc_list.yaml') }
14
+
15
+ let(:config) { yaml_fixture(path)['stage'] }
16
+
17
+ describe 'initialization using acts_as_hashable' do
18
+ subject { described_class.make(config) }
19
+
20
+ it 'sets files' do
21
+ expect(subject.files.length).to eq(1)
22
+ expect(subject.files.first.src).to eq('noc_list.csv')
23
+ expect(subject.files.first.dest).to eq('input/noc_list.csv')
24
+ end
25
+
26
+ it 'sets fixtures' do
27
+ expect(subject.fixtures.length).to eq(2)
28
+ expect(subject.fixtures.first).to eq('iron_man')
29
+ expect(subject.fixtures.last).to eq('hulk')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'spec_helper'
11
+
12
+ describe Simmer::Specification do
13
+ let(:path) { File.join('specifications', 'load_noc_list.yaml') }
14
+
15
+ let(:config) { yaml_fixture(path).merge(path: path) }
16
+
17
+ describe 'initialization using acts_as_hashable' do
18
+ subject { described_class.make(config) }
19
+
20
+ it 'sets name' do
21
+ expect(subject.name).to eq('Declassify Users')
22
+ end
23
+
24
+ it 'sets path' do
25
+ expect(subject.path).to eq(path)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'spec_helper'
11
+
12
+ describe Simmer::Util::Evaluator do
13
+ let(:template) do
14
+ 'The {traits.speed} {animal} jumps over the {thing}.'
15
+ end
16
+
17
+ describe '#evaluate' do
18
+ context 'when input is hash with string keys' do
19
+ let(:input) do
20
+ {
21
+ 'animal' => :fox,
22
+ 'traits' => {
23
+ 'speed' => :quick
24
+ },
25
+ 'thing' => :wall
26
+ }
27
+ end
28
+
29
+ it 'renders template' do
30
+ expected = 'The quick fox jumps over the wall.'
31
+
32
+ expect(subject.evaluate(template, input)).to eq(expected)
33
+ end
34
+ end
35
+
36
+ context 'when input is hash with symbol keys' do
37
+ let(:input) do
38
+ {
39
+ animal: :fox,
40
+ traits: {
41
+ speed: :quick
42
+ },
43
+ thing: :wall
44
+ }
45
+ end
46
+
47
+ it 'renders template' do
48
+ expected = 'The quick fox jumps over the wall.'
49
+
50
+ expect(subject.evaluate(template, input)).to eq(expected)
51
+ end
52
+ end
53
+
54
+ context 'when input is OpenStruct' do
55
+ let(:input) do
56
+ OpenStruct.new(
57
+ animal: :fox,
58
+ traits: OpenStruct.new(
59
+ speed: :quick
60
+ ),
61
+ thing: :wall
62
+ )
63
+ end
64
+
65
+ it 'renders template' do
66
+ expected = 'The quick fox jumps over the wall.'
67
+
68
+ expect(subject.evaluate(template, input)).to eq(expected)
69
+ end
70
+ end
71
+
72
+ context 'when input is nil' do
73
+ let(:input) { nil }
74
+
75
+ it 'renders against nil' do
76
+ expected = 'The jumps over the .'
77
+
78
+ expect(subject.evaluate(template, input)).to eq(expected)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'spec_helper'
11
+
12
+ describe Simmer::Util::RecordSet do
13
+ let(:hash1) do
14
+ {
15
+ a: 'a',
16
+ b: 'b'
17
+ }
18
+ end
19
+
20
+ let(:hash2) do
21
+ {
22
+ c: 'c',
23
+ d: 'd'
24
+ }
25
+ end
26
+
27
+ subject { described_class.new([hash1, hash2]) }
28
+
29
+ describe 'equality' do
30
+ specify 'hash order does not matter' do
31
+ subject2 = described_class.new([hash2, hash1])
32
+
33
+ expect(subject).to eq(subject2)
34
+ expect(subject).to eql(subject2)
35
+ end
36
+ end
37
+
38
+ specify '#keys includes all record keys' do
39
+ expect(subject.keys).to eq(%w[a b c d])
40
+ end
41
+ end
@@ -0,0 +1,218 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'spec_helper'
11
+
12
+ describe Simmer::Util::Record do
13
+ describe 'initialization' do
14
+ let(:data) do
15
+ {
16
+ 'a' => 'a'
17
+ }
18
+ end
19
+
20
+ it 'accepts hash' do
21
+ subject = described_class.new(data)
22
+
23
+ expect(subject.to_h).to eq(data)
24
+ end
25
+
26
+ it 'accepts Record' do
27
+ record = Simmer::Util::Record.new(data)
28
+ subject = described_class.new(record)
29
+
30
+ expect(subject.to_h).to eq(data)
31
+ end
32
+
33
+ it 'accepts OpenStruct' do
34
+ record = OpenStruct.new(data)
35
+ subject = described_class.new(record)
36
+
37
+ expect(subject.to_h).to eq(data)
38
+ end
39
+ end
40
+
41
+ describe 'equality' do
42
+ context 'when key types do not equal' do
43
+ let(:symbol_hash) do
44
+ {
45
+ '1': 1
46
+ }
47
+ end
48
+
49
+ let(:string_hash) do
50
+ {
51
+ '1' => 1
52
+ }
53
+ end
54
+
55
+ let(:numeric_hash) do
56
+ {}.tap do |hash|
57
+ hash[1] = 1
58
+ end
59
+ end
60
+
61
+ it 'compares symbol to string keys' do
62
+ record1 = described_class.new(symbol_hash)
63
+ record2 = described_class.new(string_hash)
64
+
65
+ expect(record1).to eq(record2)
66
+ expect(record1).to eql(record2)
67
+ end
68
+
69
+ it 'compares symbol to number keys' do
70
+ record1 = described_class.new(symbol_hash)
71
+ record2 = described_class.new(numeric_hash)
72
+
73
+ expect(record1).to eq(record2)
74
+ expect(record1).to eql(record2)
75
+ end
76
+
77
+ it 'compares string to number keys' do
78
+ record1 = described_class.new(string_hash)
79
+ record2 = described_class.new(numeric_hash)
80
+
81
+ expect(record1).to eq(record2)
82
+ expect(record1).to eql(record2)
83
+ end
84
+ end
85
+
86
+ context 'when value types do not equal' do
87
+ let(:symbol_hash) do
88
+ {
89
+ a: :'1'
90
+ }
91
+ end
92
+
93
+ let(:string_hash) do
94
+ {
95
+ a: '1'
96
+ }
97
+ end
98
+
99
+ let(:numeric_hash) do
100
+ {
101
+ a: 1
102
+ }
103
+ end
104
+
105
+ it 'compares symbol to string keys' do
106
+ record1 = described_class.new(symbol_hash)
107
+ record2 = described_class.new(string_hash)
108
+
109
+ expect(record1).to eq(record2)
110
+ expect(record1).to eql(record2)
111
+ end
112
+
113
+ it 'compares symbol to number keys' do
114
+ record1 = described_class.new(symbol_hash)
115
+ record2 = described_class.new(numeric_hash)
116
+
117
+ expect(record1).to eq(record2)
118
+ expect(record1).to eql(record2)
119
+ end
120
+
121
+ it 'compares string to number keys' do
122
+ record1 = described_class.new(string_hash)
123
+ record2 = described_class.new(numeric_hash)
124
+
125
+ expect(record1).to eq(record2)
126
+ expect(record1).to eql(record2)
127
+ end
128
+ end
129
+
130
+ context 'when keys and values are not in same order and mixed type' do
131
+ let(:alphabetical_hash) do
132
+ {
133
+ a: 'a',
134
+ b: :b,
135
+ 'c': 'c'
136
+ }
137
+ end
138
+
139
+ let(:reverse_alphabetical_hash) do
140
+ {
141
+ b: 'b',
142
+ c: 'c',
143
+ 'a': :a
144
+ }
145
+ end
146
+
147
+ it 'should ignore key ordering' do
148
+ record1 = described_class.new(alphabetical_hash)
149
+ record2 = described_class.new(reverse_alphabetical_hash)
150
+
151
+ expect(record1).to eq(record2)
152
+ expect(record1).to eql(record2)
153
+ end
154
+ end
155
+
156
+ context 'when value(s) are of type BigDecimal' do
157
+ let(:string_value) { '12.005' }
158
+
159
+ let(:float_hash) do
160
+ {
161
+ a: string_value.to_f
162
+ }
163
+ end
164
+
165
+ let(:big_decimal_hash) do
166
+ {
167
+ a: BigDecimal(string_value)
168
+ }
169
+ end
170
+
171
+ let(:string_hash) do
172
+ {
173
+ a: string_value
174
+ }
175
+ end
176
+
177
+ it 'compares floats with big decimals' do
178
+ record1 = described_class.new(float_hash)
179
+ record2 = described_class.new(big_decimal_hash)
180
+
181
+ expect(record1).to eq(record2)
182
+ expect(record1).to eql(record2)
183
+ end
184
+
185
+ it 'compares floats with strings' do
186
+ record1 = described_class.new(float_hash)
187
+ record2 = described_class.new(string_hash)
188
+
189
+ expect(record1).to eq(record2)
190
+ expect(record1).to eql(record2)
191
+ end
192
+
193
+ it 'compares big decimals with strings' do
194
+ record1 = described_class.new(big_decimal_hash)
195
+ record2 = described_class.new(string_hash)
196
+
197
+ expect(record1).to eq(record2)
198
+ expect(record1).to eql(record2)
199
+ end
200
+ end
201
+
202
+ it 'should not equal if values are not equal' do
203
+ record1 = described_class.new(a: 'a')
204
+ record2 = described_class.new(a: 'b')
205
+
206
+ expect(record1).not_to eq(record2)
207
+ expect(record1).not_to eql(record2)
208
+ end
209
+
210
+ it 'should not equal if keys are not equal' do
211
+ record1 = described_class.new(a: 'a')
212
+ record2 = described_class.new(b: 'a')
213
+
214
+ expect(record1).not_to eq(record2)
215
+ expect(record1).not_to eql(record2)
216
+ end
217
+ end
218
+ end