Skip to content

Commit 2eae673

Browse files
authored
Merge pull request #54 from github/kpaulisse-catalog-api-use-internally
Use the catalog API internally
2 parents 67aa476 + 20ed698 commit 2eae673

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

lib/octocatalog-diff/cli.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

3-
require_relative 'api/v1/catalog-compile'
4-
require_relative 'api/v1/catalog-diff'
3+
require_relative 'api/v1'
54
require_relative 'catalog-util/cached_master_directory'
65
require_relative 'errors'
76
require_relative 'util/catalogs'
@@ -159,19 +158,23 @@ def self.setup_logger(logger, options, argv_save)
159158
# Compile the catalog only
160159
def self.catalog_only(logger, options)
161160
opts = options.merge(logger: logger)
162-
to_catalog = OctocatalogDiff::API::V1::CatalogCompile.catalog(opts).raw
161+
to_catalog = OctocatalogDiff::API::V1.catalog(opts)
163162

164163
# If the catalog compilation failed, an exception would have been thrown. So if
165164
# we get here, the catalog succeeded. Dump the catalog to the appropriate place
166165
# and exit successfully.
167166
if options[:output_file]
168-
File.open(options[:output_file], 'w') { |f| f.write(to_catalog.catalog_json) }
167+
File.open(options[:output_file], 'w') { |f| f.write(to_catalog.to_json) }
169168
logger.info "Wrote catalog to #{options[:output_file]}"
170169
else
171-
puts to_catalog.catalog_json
170+
puts to_catalog.to_json
172171
end
173-
return [OctocatalogDiff::Catalog.new(backend: :noop), to_catalog] if options[:RETURN_DIFFS] # For integration testing
174-
EXITCODE_SUCCESS_NO_DIFFS
172+
173+
return EXITCODE_SUCCESS_NO_DIFFS unless options[:RETURN_DIFFS] # For integration testing
174+
# :nocov:
175+
dummy_catalog = OctocatalogDiff::API::V1::Catalog.new(OctocatalogDiff::Catalog.new(backend: :noop))
176+
[dummy_catalog, to_catalog]
177+
# :nocov:
175178
end
176179

177180
# --bootstrap-then-exit command

spec/octocatalog-diff/integration/catalog_only_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
it 'should set the from-catalog to a no-op catalog type' do
3333
pending 'catalog compilation failed' unless @result[:exitcode] == 2
3434
from_catalog = @result[:diffs][0]
35-
expect(from_catalog).to be_a_kind_of(OctocatalogDiff::Catalog)
35+
expect(from_catalog).to be_a_kind_of(OctocatalogDiff::API::V1::Catalog)
3636
expect(from_catalog.builder).to eq('OctocatalogDiff::Catalog::Noop')
3737
end
3838

3939
it 'should set the to-catalog to a computed catalog type' do
4040
pending 'catalog compilation failed' unless @result[:exitcode] == 2
4141
to_catalog = @result[:diffs][1]
42-
expect(to_catalog).to be_a_kind_of(OctocatalogDiff::Catalog)
42+
expect(to_catalog).to be_a_kind_of(OctocatalogDiff::API::V1::Catalog)
4343
expect(to_catalog.builder).to eq('OctocatalogDiff::Catalog::Computed')
4444
end
4545

@@ -55,8 +55,8 @@
5555
pending 'catalog compilation failed' unless @result[:exitcode] == 2
5656
to_catalog = @result[:diffs][1]
5757
expect(to_catalog.valid?).to eq(true)
58-
expect(to_catalog.catalog).to be_a_kind_of(Hash)
59-
expect(to_catalog.catalog_json).to be_a_kind_of(String)
58+
expect(to_catalog.to_h).to be_a_kind_of(Hash)
59+
expect(to_catalog.to_json).to be_a_kind_of(String)
6060
expect(to_catalog.error_message).to be(nil)
6161
end
6262

0 commit comments

Comments
 (0)