Skip to content

Commit de61eb1

Browse files
author
Kevin Paulisse
committed
Update integration result to return catalogs and diffs
1 parent 4fddd36 commit de61eb1

2 files changed

Lines changed: 11 additions & 17 deletions

File tree

lib/octocatalog-diff/cli.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def self.cli(argv = ARGV, logger = Logger.new(STDERR), opts = {})
116116
printer_obj = OctocatalogDiff::Cli::Printer.new(options, logger)
117117
printer_obj.printer(diffs, catalog_diff.from.compilation_dir, catalog_diff.to.compilation_dir)
118118

119-
# Return the diff object if requested (generally for testing) or otherwise return exit code
120-
return diffs if opts[:RETURN_DIFFS]
119+
# Return the resulting diff object if requested (generally for testing) or otherwise return exit code
120+
return catalog_diff if opts[:INTEGRATION]
121121
diffs.any? ? EXITCODE_SUCCESS_WITH_DIFFS : EXITCODE_SUCCESS_NO_DIFFS
122122
end
123123

spec/octocatalog-diff/integration/integration_helper.rb

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ 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'.
118119
# Set options[:RETURN_DIFFS] so that the .cli method returns the JSON array
@@ -124,28 +125,21 @@ def self.integration(options = {})
124125
stdout_strio = StringIO.new
125126
$stdout = stdout_strio
126127

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-
131128
# Run the OctocatalogDiff::Cli.cli and validate output format.
132129
result = OctocatalogDiff::Cli.cli(argv, logger, options)
133-
if result.is_a?(Fixnum)
134-
return {
135-
logs: logger_string.string,
136-
output: stdout_strio.string,
137-
exitcode: result
138-
}
139-
end
140130

141-
raise "OctocatalogDiff::Cli.cli should return array, got #{result.inspect}" unless result.is_a?(Array)
131+
unless result.is_a?(OpenStruct)
132+
raise "Expected OpenStruct, got #{result.inspect} from OctocatalogDiff::Cli.cli!"
133+
end
142134

143-
# Return hash
144135
OpenStruct.new(
145136
logs: logger_string.string,
137+
log_messages: logger_string.string.split(/\n/).map { |x| OctocatalogDiff::Spec.strip_log_message(x) },
146138
output: stdout_strio.string,
147-
diffs: result,
148-
exitcode: result.any? ? 2 : 0,
139+
diffs: result.diffs,
140+
to: result.to,
141+
from: result.from,
142+
exitcode: result.diffs.any? ? 2 : 0,
149143
options: options
150144
)
151145
rescue => exc # Yes, rescue *everything*

0 commit comments

Comments
 (0)