Skip to content

Commit 7262566

Browse files
author
Kevin Paulisse
committed
Fix integration exit codes and add more details to output
1 parent f9b9d30 commit 7262566

3 files changed

Lines changed: 32 additions & 38 deletions

File tree

spec/octocatalog-diff/integration/catalog_only_spec.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,43 +26,36 @@
2626

2727
it 'should compile the catalog' do
2828
expect(@result[:exitcode]).not_to eq(-1), OctocatalogDiff::Integration.format_exception(@result)
29-
expect(@result[:exitcode]).to eq(2), "Runtime error: #{@result[:logs]}"
30-
end
31-
32-
it 'should set the from-catalog to a no-op catalog type' do
33-
pending 'catalog compilation failed' unless @result[:exitcode] == 2
34-
from_catalog = @result[:diffs][0]
35-
expect(from_catalog).to be_a_kind_of(OctocatalogDiff::API::V1::Catalog)
36-
expect(from_catalog.builder).to eq('OctocatalogDiff::Catalog::Noop')
29+
expect(@result[:exitcode]).to eq(0), "Runtime error: #{@result[:logs]}"
3730
end
3831

3932
it 'should set the to-catalog to a computed catalog type' do
40-
pending 'catalog compilation failed' unless @result[:exitcode] == 2
41-
to_catalog = @result[:diffs][1]
33+
pending 'catalog compilation failed' unless (@result[:exitcode]).zero?
34+
to_catalog = @result.to
4235
expect(to_catalog).to be_a_kind_of(OctocatalogDiff::API::V1::Catalog)
4336
expect(to_catalog.builder).to eq('OctocatalogDiff::Catalog::Computed')
4437
end
4538

4639
it 'should have log messages indicating catalog compilations' do
47-
pending 'catalog compilation failed' unless @result[:exitcode] == 2
40+
pending 'catalog compilation failed' unless (@result[:exitcode]).zero?
4841
logs = @result[:logs]
4942
expect(logs).to match(/Compiling catalog for rspec-node.github.net/)
5043
expect(logs).to match(/Initialized OctocatalogDiff::Catalog::Noop for from-catalog/)
5144
expect(logs).to match(/Initialized OctocatalogDiff::Catalog::Computed for to-catalog/)
5245
end
5346

5447
it 'should produce a valid catalog' do
55-
pending 'catalog compilation failed' unless @result[:exitcode] == 2
56-
to_catalog = @result[:diffs][1]
48+
pending 'catalog compilation failed' unless (@result[:exitcode]).zero?
49+
to_catalog = @result.to
5750
expect(to_catalog.valid?).to eq(true)
5851
expect(to_catalog.to_h).to be_a_kind_of(Hash)
5952
expect(to_catalog.to_json).to be_a_kind_of(String)
6053
expect(to_catalog.error_message).to be(nil)
6154
end
6255

6356
it 'should produce the expected catalog' do
64-
pending 'catalog compilation failed' unless @result[:exitcode] == 2
65-
to_catalog = @result[:diffs][1]
57+
pending 'catalog compilation failed' unless @result.exitcode.zero?
58+
to_catalog = @result.to
6659

6760
param1 = { 'owner' => 'root', 'group' => 'root', 'mode' => '0644', 'content' => 'Testy McTesterson' }
6861
expect(to_catalog.resource(type: 'File', title: '/tmp/foo')['parameters']).to eq(param1)

spec/octocatalog-diff/integration/integration_helper.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,39 +113,40 @@ def self.integration(options = {})
113113
options[:from_puppet_binary] ||= OctocatalogDiff::Spec::PUPPET_BINARY
114114
options[:to_puppet_binary] ||= OctocatalogDiff::Spec::PUPPET_BINARY
115115
options[:parallel] = false if ENV['COVERAGE']
116+
options[:INTEGRATION] = true
116117

117118
# Run octocatalog-diff CLI method. Capture stdout and stderr using 'strio'.
118-
# Set options[:RETURN_DIFFS] so that the .cli method returns the JSON array
119-
# of differences instead of the exit code.
120119
logger, logger_string = OctocatalogDiff::Spec.setup_logger
121120
begin
122121
# Capture stdout to a variable
123122
old_out = $stdout
124123
stdout_strio = StringIO.new
125124
$stdout = stdout_strio
126125

127-
# Tell OctocatalogDiff::Cli.cli to return the JSON differences and not a numeric exit code
128-
# for a full catalog-diff.
129-
options[:RETURN_DIFFS] = true
130-
131126
# Run the OctocatalogDiff::Cli.cli and validate output format.
132127
result = OctocatalogDiff::Cli.cli(argv, logger, options)
133128
if result.is_a?(Fixnum)
134-
return {
135-
logs: logger_string.string,
136-
output: stdout_strio.string,
137-
exitcode: result
138-
}
129+
result = OpenStruct.new(exitcode: result, exception: nil, diffs: [], to: nil, from: nil)
130+
elsif result.is_a?(Hash)
131+
result = OpenStruct.new({ exitcode: nil, exception: nil, diffs: [], to: nil, from: nil }.merge(result))
132+
elsif !result.is_a?(OpenStruct)
133+
raise "Expected OpenStruct, got #{result.inspect} from OctocatalogDiff::Cli.cli!"
139134
end
140135

141-
raise "OctocatalogDiff::Cli.cli should return array, got #{result.inspect}" unless result.is_a?(Array)
136+
exitcode = if result.exitcode.nil?
137+
result.diffs.any? ? 2 : 0
138+
else
139+
result.exitcode
140+
end
142141

143-
# Return hash
144142
OpenStruct.new(
145143
logs: logger_string.string,
144+
log_messages: logger_string.string.split(/\n/).map { |x| OctocatalogDiff::Spec.strip_log_message(x) },
146145
output: stdout_strio.string,
147-
diffs: result,
148-
exitcode: result.any? ? 2 : 0,
146+
diffs: result.diffs,
147+
to: result.to,
148+
from: result.from,
149+
exitcode: exitcode,
149150
options: options
150151
)
151152
rescue => exc # Yes, rescue *everything*

spec/octocatalog-diff/integration/reference_validation_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def self.catalog_contains_resource(result, type, title)
4545
end
4646

4747
it 'should return the valid catalog' do
48-
expect(@result.exitcode).to eq(2), OctocatalogDiff::Integration.format_exception(@result)
48+
expect(@result.exitcode).to eq(0), OctocatalogDiff::Integration.format_exception(@result)
4949
end
5050
end
5151

@@ -55,15 +55,15 @@ def self.catalog_contains_resource(result, type, title)
5555
end
5656

5757
it 'should return the valid catalog' do
58-
expect(@result.exitcode).to eq(2)
58+
expect(@result.exitcode).to eq(0)
5959
end
6060

6161
it 'should not raise any exceptions' do
6262
expect(@result.exception).to be_nil, OctocatalogDiff::Integration.format_exception(@result)
6363
end
6464

6565
it 'should contain representative resources' do
66-
pending 'Catalog failed' unless @result.exitcode == 2
66+
pending 'Catalog failed' unless @result.exitcode.zero?
6767
expect(OctocatalogDiff::Spec.catalog_contains_resource(@result, 'File', '/tmp/test-main')).to eq(true)
6868
end
6969
end
@@ -75,15 +75,15 @@ def self.catalog_contains_resource(result, type, title)
7575
end
7676

7777
it 'should succeed' do
78-
expect(@result.exitcode).to eq(2)
78+
expect(@result.exitcode).to eq(0)
7979
end
8080

8181
it 'should not raise any exceptions' do
8282
expect(@result.exception).to be_nil, OctocatalogDiff::Integration.format_exception(@result)
8383
end
8484

8585
it 'should contain representative resources' do
86-
pending 'Catalog failed' unless @result.exitcode == 2
86+
pending 'Catalog failed' unless @result.exitcode.zero?
8787
expect(OctocatalogDiff::Spec.catalog_contains_resource(@result, 'Exec', 'subscribe caller 1')).to eq(true)
8888
expect(OctocatalogDiff::Spec.catalog_contains_resource(@result, 'Exec', 'subscribe target')).to eq(true)
8989
end
@@ -179,7 +179,7 @@ def self.catalog_contains_resource(result, type, title)
179179
end
180180

181181
it 'should succeed' do
182-
expect(@result.exitcode).to eq(2), OctocatalogDiff::Integration.format_exception(@result)
182+
expect(@result.exitcode).to eq(0), OctocatalogDiff::Integration.format_exception(@result)
183183
end
184184

185185
it 'should not raise error' do
@@ -195,15 +195,15 @@ def self.catalog_contains_resource(result, type, title)
195195
end
196196

197197
it 'should succeed' do
198-
expect(@result.exitcode).to eq(2)
198+
expect(@result.exitcode).to eq(0)
199199
end
200200

201201
it 'should not raise any exceptions' do
202202
expect(@result.exception).to be_nil, OctocatalogDiff::Integration.format_exception(@result)
203203
end
204204

205205
it 'should contain representative resources' do
206-
pending 'Catalog failed' unless @result.exitcode == 2
206+
pending 'Catalog failed' unless @result.exitcode.zero?
207207
expect(OctocatalogDiff::Spec.catalog_contains_resource(@result, 'Exec', 'before alias caller')).to eq(true)
208208
expect(OctocatalogDiff::Spec.catalog_contains_resource(@result, 'Exec', 'before alias target')).to eq(true)
209209
expect(OctocatalogDiff::Spec.catalog_contains_resource(@result, 'Exec', 'the before alias target')).to eq(true)

0 commit comments

Comments
 (0)