Skip to content

Commit 6f29688

Browse files
author
Kevin Paulisse
committed
Add integration test for the CLI
1 parent 7bc7749 commit 6f29688

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This is a configuration file for octocatalog-diff
2+
3+
module OctocatalogDiff
4+
class Config
5+
def self.config
6+
raise 'Fizz Buzz'
7+
end
8+
end
9+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This is a configuration file for octocatalog-diff
2+
3+
module OctocatalogDiff
4+
class Config
5+
def self.config
6+
{
7+
header: :default,
8+
hiera_config: 'config/hiera.yaml',
9+
hiera_path: 'hieradata'
10+
}
11+
end
12+
end
13+
end
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../tests/spec_helper'
4+
5+
require 'open3'
6+
require 'shellwords'
7+
8+
describe 'bin/octocatalog-diff' do
9+
let(:script) { File.expand_path('../../../bin/octocatalog-diff', File.dirname(__FILE__)) }
10+
let(:ls_l) { Open3.capture2e("ls -l #{script}").first }
11+
let(:config_test) { '--config-test' }
12+
let(:normal_settings) do
13+
[
14+
'-d',
15+
'-n rspec-node.github.net',
16+
'--fact-file', OctocatalogDiff::Spec.fixture_path('facts/facts.yaml'),
17+
'--from-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/tiny-catalog.json'),
18+
'--bootstrapped-to-dir', OctocatalogDiff::Spec.fixture_path('repos/default'),
19+
'--puppet-binary', OctocatalogDiff::Spec::PUPPET_BINARY
20+
].map { |x| Shellwords.escape(x) }.join(' ')
21+
end
22+
23+
it 'should exist' do
24+
expect(File.file?(script)).to eq(true), ls_l
25+
end
26+
27+
it 'should be executable' do
28+
expect(File.executable?(script)).to eq(true), ls_l
29+
end
30+
31+
context 'with an invalid configuration file' do
32+
let(:cfg) { OctocatalogDiff::Spec.fixture_path('cli-configs/invalid.rb') }
33+
let(:env) { { 'OCTOCATALOG_DIFF_CONFIG_FILE' => cfg } }
34+
35+
it 'should error with --config-test' do
36+
text, status = Open3.capture2e(env, "#{script} #{config_test}")
37+
expect(status.exitstatus).to eq(1), text
38+
expect(text).to match(%r{Loading octocatalog-diff configuration from .+/fixtures/cli-configs/invalid.rb})
39+
expect(text).to match(/FATAL .+: Fizz Buzz/)
40+
end
41+
42+
it 'should error with normal settings' do
43+
text, status = Open3.capture2e(env, "#{script} #{normal_settings}")
44+
expect(status.exitstatus).to eq(1), text
45+
expect(text).to match(%r{Loading octocatalog-diff configuration from .+/fixtures/cli-configs/invalid.rb})
46+
expect(text).to match(/FATAL .+: Fizz Buzz/)
47+
end
48+
end
49+
50+
context 'with a valid configuration file' do
51+
let(:cfg) { OctocatalogDiff::Spec.fixture_path('cli-configs/valid.rb') }
52+
let(:env) { { 'OCTOCATALOG_DIFF_CONFIG_FILE' => cfg } }
53+
54+
it 'should print values with --config-test and exit' do
55+
text, status = Open3.capture2e(env, "#{script} #{config_test}")
56+
expect(status.exitstatus).to eq(0), text
57+
expect(text).to match(%r{Loading octocatalog-diff configuration from .+/fixtures/cli-configs/valid.rb})
58+
expect(text).to match(/:header => \(Symbol\) :default/)
59+
expect(text).to match(%r{:hiera_config => \(String\) "config/hiera.yaml"})
60+
expect(text).to match(/:hiera_path => \(String\) "hieradata"/)
61+
expect(text).to match(/Exiting now because --config-test was specified/)
62+
end
63+
64+
it 'should print settings details and then invoke the main CLI' do
65+
text, status = Open3.capture2e(env, "#{script} #{normal_settings}")
66+
expect(status.exitstatus).to eq(2), text
67+
expect(text).to match(%r{Loading octocatalog-diff configuration from .+/fixtures/cli-configs/valid.rb})
68+
expect(text).to match(%r{Loaded 3 settings from .+/fixtures/cli-configs/valid.rb})
69+
expect(text).to match(/Initialized OctocatalogDiff::Catalog::Computed for to-catalog/)
70+
expect(text).to match(/Entering catdiff; catalog sizes: 2, 21/)
71+
expect(text).to match(/Entering filter_diffs_for_absent_files with 14 diffs/)
72+
expect(text).to match(/Added resources: 14/)
73+
expect(text).to match(/\+ Ssh_authorized_key\[root@6def27049c06f48eea8b8f37329f40799d07dc84\]/)
74+
end
75+
end
76+
end

0 commit comments

Comments
 (0)