pdi 1.0.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +8 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +25 -0
- data/.ruby-version +1 -0
- data/.travis.yml +25 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Guardfile +16 -0
- data/LICENSE +7 -0
- data/README.md +133 -0
- data/Rakefile +17 -0
- data/bin/console +18 -0
- data/lib/pdi.rb +14 -0
- data/lib/pdi/executor.rb +30 -0
- data/lib/pdi/executor/result.rb +29 -0
- data/lib/pdi/spoon.rb +82 -0
- data/lib/pdi/spoon/kitchen_error.rb +34 -0
- data/lib/pdi/spoon/options.rb +93 -0
- data/lib/pdi/spoon/options/arg.rb +68 -0
- data/lib/pdi/spoon/options/level.rb +23 -0
- data/lib/pdi/spoon/options/param.rb +29 -0
- data/lib/pdi/spoon/pan_error.rb +35 -0
- data/lib/pdi/spoon/parser.rb +25 -0
- data/lib/pdi/spoon/result.rb +25 -0
- data/lib/pdi/version.rb +12 -0
- data/pdi.gemspec +33 -0
- data/spec/mocks/spoon/return_0.sh +14 -0
- data/spec/mocks/spoon/return_1.sh +14 -0
- data/spec/mocks/spoon/return_2.sh +14 -0
- data/spec/mocks/spoon/return_3.sh +14 -0
- data/spec/mocks/spoon/return_7.sh +14 -0
- data/spec/mocks/spoon/return_8.sh +14 -0
- data/spec/mocks/spoon/return_9.sh +14 -0
- data/spec/mocks/spoon/version.sh +10 -0
- data/spec/pdi/spoon/error_spec.rb +28 -0
- data/spec/pdi/spoon/options/arg_spec.rb +73 -0
- data/spec/pdi/spoon/options/param_spec.rb +39 -0
- data/spec/pdi/spoon/options_spec.rb +102 -0
- data/spec/pdi/spoon_spec.rb +133 -0
- data/spec/spec_helper.rb +22 -0
- metadata +211 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2018-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 PDI::Spoon::PanError do
|
13
|
+
describe 'initialization' do
|
14
|
+
[1, 2, 3, 7, 8, 9].each do |code|
|
15
|
+
specify "code #{code} should have message" do
|
16
|
+
execution = PDI::Executor::Result.new('', code, '', 123)
|
17
|
+
expect(described_class.new(execution).message).not_to eq('Unknown')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
[-1, 0, 4, 5, 6, 10, 11].each do |code|
|
22
|
+
specify "code #{code} should not have message" do
|
23
|
+
execution = PDI::Executor::Result.new('', code, '', 123)
|
24
|
+
expect(described_class.new(execution).message).to eq('Unknown')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2018-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 PDI::Spoon::Options::Arg do
|
13
|
+
let(:key) { :param }
|
14
|
+
let(:value) { 'v1' }
|
15
|
+
let(:value_with_space) { 'v 1' }
|
16
|
+
|
17
|
+
describe '#initialize' do
|
18
|
+
subject { described_class.new(key, value) }
|
19
|
+
|
20
|
+
it 'requires a key' do
|
21
|
+
expect { described_class.new('') }.to raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets key' do
|
25
|
+
expect(subject.key).to eq(key)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sets value' do
|
29
|
+
expect(subject.value).to eq(value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#to_s' do
|
34
|
+
it 'works without a value' do
|
35
|
+
subject = described_class.new(key)
|
36
|
+
expected = "-#{key}"
|
37
|
+
|
38
|
+
expect(subject.to_s).to eq(expected)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'works with a value (with no space)' do
|
42
|
+
subject = described_class.new(key, value)
|
43
|
+
expected = "-#{key}:#{value}"
|
44
|
+
|
45
|
+
expect(subject.to_s).to eq(expected)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'works with a value (with a space)' do
|
49
|
+
subject = described_class.new(key, value_with_space)
|
50
|
+
expected = "\"-#{key}:#{value_with_space}\""
|
51
|
+
|
52
|
+
expect(subject.to_s).to eq(expected)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'equality' do
|
57
|
+
let(:subject2) { described_class.new(key, value) }
|
58
|
+
|
59
|
+
subject { described_class.new(key, value) }
|
60
|
+
|
61
|
+
specify '#hash compares key and value' do
|
62
|
+
expect(subject.hash).to eq(subject2.hash)
|
63
|
+
end
|
64
|
+
|
65
|
+
specify '#== compares #to_s values' do
|
66
|
+
expect(subject).to eq(subject2)
|
67
|
+
end
|
68
|
+
|
69
|
+
specify '#eql? compares #to_s values' do
|
70
|
+
expect(subject).to eql(subject2)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2018-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 PDI::Spoon::Options::Param do
|
13
|
+
let(:key) { 'k1' }
|
14
|
+
let(:value) { 'v1' }
|
15
|
+
let(:value_with_space) { 'v 1' }
|
16
|
+
|
17
|
+
describe '#to_s' do
|
18
|
+
it 'works without a value' do
|
19
|
+
subject = described_class.new(key)
|
20
|
+
expected = "-param:#{key}="
|
21
|
+
|
22
|
+
expect(subject.to_s).to eq(expected)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'works with a value (with no space)' do
|
26
|
+
subject = described_class.new(key, value)
|
27
|
+
expected = "-param:#{key}=#{value}"
|
28
|
+
|
29
|
+
expect(subject.to_s).to eq(expected)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'works with a value (with a space)' do
|
33
|
+
subject = described_class.new(key, value_with_space)
|
34
|
+
expected = "\"-param:#{key}=#{value_with_space}\""
|
35
|
+
|
36
|
+
expect(subject.to_s).to eq(expected)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2018-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 PDI::Spoon::Options do
|
13
|
+
describe '#to_args' do
|
14
|
+
let(:params) do
|
15
|
+
{
|
16
|
+
key1: 'value1',
|
17
|
+
key2: 'value2',
|
18
|
+
key3: 'value with spaces'
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:repository) { 'some repo' }
|
23
|
+
let(:name) { 'some_transformation' }
|
24
|
+
|
25
|
+
subject do
|
26
|
+
described_class.new(
|
27
|
+
params: params,
|
28
|
+
repository: repository,
|
29
|
+
name: name,
|
30
|
+
type: type
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when type is transformation' do
|
35
|
+
let(:type) { 'transformation' }
|
36
|
+
|
37
|
+
it 'wraps any args with spaces inside double quotes' do
|
38
|
+
args = subject.to_args
|
39
|
+
args_with_spaces = args.select { |a| a.to_s.include?(' ') }
|
40
|
+
|
41
|
+
raise ArgumentError, 'no examples to assert!' if args_with_spaces.empty?
|
42
|
+
|
43
|
+
args_with_spaces.each do |arg|
|
44
|
+
actual = arg.to_s
|
45
|
+
|
46
|
+
expect(actual).to start_with('"')
|
47
|
+
expect(actual).to end_with('"')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'includes each option' do
|
52
|
+
expected = [
|
53
|
+
'"-rep:some repo"',
|
54
|
+
'-trans:some_transformation',
|
55
|
+
'-level:Basic',
|
56
|
+
'-param:key1=value1',
|
57
|
+
'-param:key2=value2',
|
58
|
+
'"-param:key3=value with spaces"'
|
59
|
+
]
|
60
|
+
|
61
|
+
expected_set = Set[*expected]
|
62
|
+
actual_set = Set[*subject.to_args.map(&:to_s)]
|
63
|
+
|
64
|
+
expect(actual_set).to eq(expected_set)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when type is job' do
|
69
|
+
let(:type) { 'job' }
|
70
|
+
|
71
|
+
it 'wraps any args with spaces inside double quotes' do
|
72
|
+
args = subject.to_args
|
73
|
+
args_with_spaces = args.select { |a| a.to_s.include?(' ') }
|
74
|
+
|
75
|
+
raise ArgumentError, 'no examples to assert!' if args_with_spaces.empty?
|
76
|
+
|
77
|
+
args_with_spaces.each do |arg|
|
78
|
+
actual = arg.to_s
|
79
|
+
|
80
|
+
expect(actual).to start_with('"')
|
81
|
+
expect(actual).to end_with('"')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'includes each option' do
|
86
|
+
expected = [
|
87
|
+
'"-rep:some repo"',
|
88
|
+
'-job:some_transformation',
|
89
|
+
'-level:Basic',
|
90
|
+
'-param:key1=value1',
|
91
|
+
'-param:key2=value2',
|
92
|
+
'"-param:key3=value with spaces"'
|
93
|
+
]
|
94
|
+
|
95
|
+
expected_set = Set[*expected]
|
96
|
+
actual_set = Set[*subject.to_args.map(&:to_s)]
|
97
|
+
|
98
|
+
expect(actual_set).to eq(expected_set)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2018-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 PDI::Spoon do
|
13
|
+
let(:mocks_dir) { %w[spec mocks spoon] }
|
14
|
+
let(:dir) { File.join(*mocks_dir) }
|
15
|
+
|
16
|
+
describe '#run' do
|
17
|
+
context 'transformations' do
|
18
|
+
let(:options) do
|
19
|
+
{
|
20
|
+
repository: 'somewhere',
|
21
|
+
name: 'something',
|
22
|
+
type: :transformation
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when code is 0' do
|
27
|
+
it 'returns correct stdout, stderr and code' do
|
28
|
+
script = 'return_0.sh'
|
29
|
+
|
30
|
+
subject = described_class.new(
|
31
|
+
dir: dir,
|
32
|
+
kitchen: script,
|
33
|
+
pan: script
|
34
|
+
)
|
35
|
+
|
36
|
+
result = subject.run(options)
|
37
|
+
|
38
|
+
expect(result.execution.out_and_err).to eq("output to stdout\noutput to sterr\n")
|
39
|
+
expect(result.value).to eq(0)
|
40
|
+
expect(result.execution.code).to eq(0)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
[1, 2, 3, 7, 8, 9].each do |code|
|
45
|
+
context "when code is #{code}" do
|
46
|
+
specify 'returns correct stdout, stderr and code' do
|
47
|
+
script = "return_#{code}.sh"
|
48
|
+
|
49
|
+
subject = described_class.new(
|
50
|
+
dir: dir,
|
51
|
+
kitchen: script,
|
52
|
+
pan: script
|
53
|
+
)
|
54
|
+
|
55
|
+
expected = described_class::PanError
|
56
|
+
|
57
|
+
expect { subject.run(options) }.to raise_error(expected)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#run' do
|
65
|
+
context 'jobs' do
|
66
|
+
let(:options) do
|
67
|
+
{
|
68
|
+
repository: 'somewhere',
|
69
|
+
name: 'something',
|
70
|
+
type: :job
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when code is 0' do
|
75
|
+
it 'returns correct stdout, stderr and code' do
|
76
|
+
script = 'return_0.sh'
|
77
|
+
|
78
|
+
subject = described_class.new(
|
79
|
+
dir: dir,
|
80
|
+
kitchen: script,
|
81
|
+
pan: script
|
82
|
+
)
|
83
|
+
|
84
|
+
result = subject.run(options)
|
85
|
+
|
86
|
+
expect(result.execution.out_and_err).to eq("output to stdout\noutput to sterr\n")
|
87
|
+
expect(result.value).to eq(0)
|
88
|
+
expect(result.execution.code).to eq(0)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
[1, 2, 7, 8, 9].each do |code|
|
93
|
+
context "when code is #{code}" do
|
94
|
+
specify 'returns correct stdout, stderr and code' do
|
95
|
+
script = "return_#{code}.sh"
|
96
|
+
|
97
|
+
subject = described_class.new(
|
98
|
+
dir: dir,
|
99
|
+
kitchen: script,
|
100
|
+
pan: script
|
101
|
+
)
|
102
|
+
|
103
|
+
expected = described_class::KitchenError
|
104
|
+
|
105
|
+
expect { subject.run(options) }.to raise_error(expected)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#version' do
|
112
|
+
let(:script) { 'version.sh' }
|
113
|
+
|
114
|
+
subject do
|
115
|
+
described_class.new(
|
116
|
+
dir: dir,
|
117
|
+
kitchen: script,
|
118
|
+
pan: script
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'returns parsed version line' do
|
123
|
+
result = subject.version
|
124
|
+
expected = [
|
125
|
+
'2020/01/30 13:31:04 - Pan - Kettle version 6.1.0.1-196,',
|
126
|
+
'build 1, build date : 2016-04-07 12.08.49'
|
127
|
+
].join(' ')
|
128
|
+
|
129
|
+
expect(result.value).to eq(expected)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2018-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 'pry'
|
11
|
+
|
12
|
+
unless ENV['DISABLE_SIMPLECOV'] == 'true'
|
13
|
+
require 'simplecov'
|
14
|
+
require 'simplecov-console'
|
15
|
+
|
16
|
+
SimpleCov.formatter = SimpleCov::Formatter::Console
|
17
|
+
SimpleCov.start do
|
18
|
+
add_filter %r{\A/spec/}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
require './lib/pdi'
|