Skip to content

Commit 4be8c67

Browse files
author
Kevin Paulisse
committed
Add tests for example settings and example APIv1 catalog builder
1 parent be5f9c6 commit 4be8c67

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../tests/spec_helper'
4+
5+
require 'open3'
6+
require 'stringio'
7+
8+
describe 'examples/octocatalog-diff.cfg.rb' do
9+
let(:script) { File.expand_path('../../../examples/octocatalog-diff.cfg.rb', File.dirname(__FILE__)) }
10+
let(:ls_l) { Open3.capture2e("ls -l '#{script}'").first }
11+
12+
it 'should exist' do
13+
expect(File.file?(script)).to eq(true), ls_l
14+
end
15+
16+
it 'should not raise errors when loaded' do
17+
load script
18+
end
19+
20+
it 'should create OctocatalogDiff::Config namespace and .config method' do
21+
k = Kernel.const_get('OctocatalogDiff::Config')
22+
expect(k.to_s).to eq('OctocatalogDiff::Config')
23+
end
24+
25+
it 'should return a hash from the .config method' do
26+
result = OctocatalogDiff::Config.config
27+
expect(result).to be_a_kind_of(Hash)
28+
end
29+
end
30+
31+
describe 'examples/api/v1/catalog-builder-local-files.rb' do
32+
let(:script) { File.expand_path('../../../examples/api/v1/catalog-builder-local-files.rb', File.dirname(__FILE__)) }
33+
let(:ls_l) { Open3.capture2e("ls -l '#{script}'").first }
34+
35+
it 'should exist' do
36+
expect(File.file?(script)).to eq(true), ls_l
37+
end
38+
39+
context 'executing' do
40+
before(:each) do
41+
@stdout_obj = StringIO.new
42+
@old_stdout = $stdout
43+
$stdout = @stdout_obj
44+
end
45+
46+
after(:each) do
47+
$stdout = @old_stdout
48+
end
49+
50+
it 'should compile and run' do
51+
load script
52+
output = @stdout_obj.string.split("\n")
53+
expect(output).to include('Object returned from OctocatalogDiff::API::V1.catalog is: OctocatalogDiff::API::V1::Catalog')
54+
expect(output).to include('The catalog is valid.')
55+
expect(output).to include('The catalog was built using OctocatalogDiff::Catalog::Computed')
56+
expect(output).to include('- System::User - bob')
57+
expect(output).to include('The resources are equal!')
58+
end
59+
end
60+
end

0 commit comments

Comments
 (0)