Skip to content

Commit 5bb72b8

Browse files
author
Kevin Paulisse
committed
Separate unit and integration tests for compilation_dir
1 parent ed69ad5 commit 5bb72b8

3 files changed

Lines changed: 270 additions & 90 deletions

File tree

lib/octocatalog-diff/catalog-diff/filter/compilation_dir.rb

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

33
require_relative '../../api/v1/diff'
4+
require_relative '../filter'
45

56
module OctocatalogDiff
67
module CatalogDiff
@@ -25,7 +26,6 @@ def filtered?(diff_in, options = {})
2526
dir2_rexp = Regexp.escape(dir2)
2627
dir = Regexp.new("(?:#{dir1_rexp}|#{dir2_rexp})")
2728
diff = OctocatalogDiff::API::V1::Diff.new(diff_in)
28-
# raise "Called on #{diff.inspect} with #{options.inspect}"
2929

3030
# Check for added/removed resources where the title of the resource includes the compilation directory
3131
if (diff.addition? || diff.removal?) && diff.title.match(dir)
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../tests/spec_helper'
4+
require OctocatalogDiff::Spec.require_path('/catalog')
5+
require OctocatalogDiff::Spec.require_path('/catalog-diff/filter/compilation_dir')
6+
require OctocatalogDiff::Spec.require_path('/cli/diffs')
7+
8+
describe OctocatalogDiff::CatalogDiff::Filter::CompilationDir do
9+
before(:all) do
10+
@cat_compilation_dir_1 = OctocatalogDiff::Catalog.new(
11+
node: 'my.rspec.node',
12+
basedir: '/path/to/catalog1',
13+
json: File.read(OctocatalogDiff::Spec.fixture_path('catalogs/compilation-dir-1.json'))
14+
)
15+
@cat_compilation_dir_2 = OctocatalogDiff::Catalog.new(
16+
node: 'my.rspec.node',
17+
basedir: '/path/to/catalog2',
18+
json: File.read(OctocatalogDiff::Spec.fixture_path('catalogs/compilation-dir-2.json'))
19+
)
20+
end
21+
22+
before(:each) do
23+
@logger, @logger_str = OctocatalogDiff::Spec.setup_logger
24+
end
25+
26+
it 'should remove +/- full title changes due to compilation dirs' do
27+
opts = {
28+
ignore: [
29+
{ type: 'Varies_Due_To_Compilation_Dir_2' },
30+
{ type: 'Varies_Due_To_Compilation_Dir_3' },
31+
{ type: 'Varies_Due_To_Compilation_Dir_4' }
32+
]
33+
}
34+
testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger)
35+
result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2)
36+
expect(result).to eq([])
37+
expect(@logger_str.string).to match(%r{Varies_Due_To_Compilation_Dir_1\[/path/to/catalog2\] .*Suppressed})
38+
expect(@logger_str.string).to match(%r{Varies_Due_To_Compilation_Dir_1\[/path/to/catalog1\] .*Suppressed})
39+
end
40+
41+
it 'should remove +/- partial title changes due to compilation dirs' do
42+
opts = { ignore:
43+
[
44+
{ type: 'Varies_Due_To_Compilation_Dir_1' },
45+
{ type: 'Varies_Due_To_Compilation_Dir_3' },
46+
{ type: 'Varies_Due_To_Compilation_Dir_4' }
47+
] }
48+
testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger)
49+
result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2)
50+
expect(result).to eq([])
51+
r1 = %r{Varies_Due_To_Compilation_Dir_2\[/aldsfjalkfjalksfd/path/to/catalog2/dflkjasfkljasdf\].*Suppressed}
52+
expect(@logger_str.string).to match(r1)
53+
r2 = %r{Varies_Due_To_Compilation_Dir_2\[/aldsfjalkfjalksfd/path/to/catalog1/dflkjasfkljasdf\].*Suppressed}
54+
expect(@logger_str.string).to match(r2)
55+
end
56+
57+
it 'should remove ~ changes due to compilation dirs' do
58+
opts = { ignore:
59+
[
60+
{ type: 'Varies_Due_To_Compilation_Dir_1' },
61+
{ type: 'Varies_Due_To_Compilation_Dir_2' },
62+
{ type: 'Varies_Due_To_Compilation_Dir_4' },
63+
{ attr: "parameters\fdir_in_first_cat" },
64+
{ attr: "parameters\fdir_in_second_cat" }
65+
] }
66+
testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger)
67+
result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2)
68+
expect(result).to eq([])
69+
expect(@logger_str.string).to match(/WARN -- : Resource key.*parameters => dir .*Suppressed/)
70+
expect(@logger_str.string).to match(/WARN -- : Resource key.*parameters => dir_in_middle .*Suppressed/)
71+
end
72+
73+
it 'should warn but not remove non-matching ! changes due to compilation dirs' do
74+
opts = { ignore:
75+
[
76+
{ type: 'Varies_Due_To_Compilation_Dir_1' },
77+
{ type: 'Varies_Due_To_Compilation_Dir_2' },
78+
{ type: 'Varies_Due_To_Compilation_Dir_4' },
79+
{ attr: "parameters\fdir" },
80+
{ attr: "parameters\fdir_in_middle" }
81+
] }
82+
testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger)
83+
result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2)
84+
expect(result.size).to eq(2)
85+
common_str = "Varies_Due_To_Compilation_Dir_3\fCommon Title\fparameters\f"
86+
expect(result[0][1]).to eq("#{common_str}dir_in_first_cat")
87+
expect(result[1][1]).to eq("#{common_str}dir_in_second_cat")
88+
expect(@logger_str.string).to match(/WARN.+Varies_Due_To_Compilation_Dir_3\[Common Title\] parameters => dir.*verify/)
89+
end
90+
91+
it 'should warn but not remove non-matching ~ changes due to compilation dirs' do
92+
opts = { ignore:
93+
[
94+
{ type: 'Varies_Due_To_Compilation_Dir_1' },
95+
{ type: 'Varies_Due_To_Compilation_Dir_2' },
96+
{ type: 'Varies_Due_To_Compilation_Dir_3' }
97+
] }
98+
testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger)
99+
result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2)
100+
answer = [[
101+
'~',
102+
"Varies_Due_To_Compilation_Dir_4\fCommon Title\fparameters\fdir",
103+
'/path/to/catalog1/onetime',
104+
'/path/to/catalog2/twotimes',
105+
{ 'file' => nil, 'line' => nil },
106+
{ 'file' => nil, 'line' => nil }
107+
]]
108+
expect(result).to eq(answer)
109+
expect(@logger_str.string).to match(/WARN -- : Resource key Varies_Due_To_Compilation_Dir_4.*please verify/)
110+
end
111+
end
Lines changed: 158 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,180 @@
11
# frozen_string_literal: true
22

33
require_relative '../../spec_helper'
4-
require OctocatalogDiff::Spec.require_path('/catalog')
54
require OctocatalogDiff::Spec.require_path('/catalog-diff/filter/compilation_dir')
6-
require OctocatalogDiff::Spec.require_path('/cli/diffs')
75

86
describe OctocatalogDiff::CatalogDiff::Filter::CompilationDir do
9-
before(:all) do
10-
@cat_compilation_dir_1 = OctocatalogDiff::Catalog.new(
11-
node: 'my.rspec.node',
12-
basedir: '/path/to/catalog1',
13-
json: File.read(OctocatalogDiff::Spec.fixture_path('catalogs/compilation-dir-1.json'))
14-
)
15-
@cat_compilation_dir_2 = OctocatalogDiff::Catalog.new(
16-
node: 'my.rspec.node',
17-
basedir: '/path/to/catalog2',
18-
json: File.read(OctocatalogDiff::Spec.fixture_path('catalogs/compilation-dir-2.json'))
19-
)
20-
end
7+
let(:opts) { { from_compilation_dir: '/path/to/catalog1', to_compilation_dir: '/path/to/catalog2' } }
218

229
before(:each) do
2310
@logger, @logger_str = OctocatalogDiff::Spec.setup_logger
2411
end
2512

26-
it 'should remove +/- full title changes due to compilation dirs' do
27-
opts = {
28-
ignore: [
29-
{ type: 'Varies_Due_To_Compilation_Dir_2' },
30-
{ type: 'Varies_Due_To_Compilation_Dir_3' },
31-
{ type: 'Varies_Due_To_Compilation_Dir_4' }
13+
subject { described_class.new([], @logger) }
14+
15+
context '+/- full title change' do
16+
it 'should remove due to compilation dirs in to-catalog' do
17+
diff = [
18+
'+',
19+
"Varies_Due_To_Compilation_Dir_1\f/path/to/catalog2",
20+
{
21+
'type' => 'Varies_Due_To_Compilation_Dir_1',
22+
'title' => '/path/to/catalog2',
23+
'tags' => ['ignoreme'],
24+
'exported' => false
25+
},
26+
{ 'file' => nil, 'line' => nil }
3227
]
33-
}
34-
testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger)
35-
result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2)
36-
expect(result).to eq([])
37-
expect(@logger_str.string).to match(%r{Varies_Due_To_Compilation_Dir_1\[/path/to/catalog2\] .*Suppressed})
38-
expect(@logger_str.string).to match(%r{Varies_Due_To_Compilation_Dir_1\[/path/to/catalog1\] .*Suppressed})
39-
end
28+
expect(subject.filtered?(diff, opts)).to eq(true)
29+
end
4030

41-
it 'should remove +/- partial title changes due to compilation dirs' do
42-
opts = { ignore:
43-
[
44-
{ type: 'Varies_Due_To_Compilation_Dir_1' },
45-
{ type: 'Varies_Due_To_Compilation_Dir_3' },
46-
{ type: 'Varies_Due_To_Compilation_Dir_4' }
47-
] }
48-
testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger)
49-
result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2)
50-
expect(result).to eq([])
51-
r1 = %r{Varies_Due_To_Compilation_Dir_2\[/aldsfjalkfjalksfd/path/to/catalog2/dflkjasfkljasdf\].*Suppressed}
52-
expect(@logger_str.string).to match(r1)
53-
r2 = %r{Varies_Due_To_Compilation_Dir_2\[/aldsfjalkfjalksfd/path/to/catalog1/dflkjasfkljasdf\].*Suppressed}
54-
expect(@logger_str.string).to match(r2)
31+
it 'should remove due to compilation dirs in from-catalog' do
32+
diff = [
33+
'-',
34+
"Varies_Due_To_Compilation_Dir_1\f/path/to/catalog1",
35+
{
36+
'type' => 'Varies_Due_To_Compilation_Dir_1',
37+
'title' => '/path/to/catalog1',
38+
'tags' => ['ignoreme'],
39+
'exported' => false
40+
},
41+
{ 'file' => nil, 'line' => nil }
42+
]
43+
expect(subject.filtered?(diff, opts)).to eq(true)
44+
end
45+
46+
it 'should not remove a non-matching directory' do
47+
diff = [
48+
'-',
49+
"Varies_Due_To_Compilation_Dir_1\f/path/to/catalog3",
50+
{
51+
'type' => 'Varies_Due_To_Compilation_Dir_1',
52+
'title' => '/path/to/catalog3',
53+
'tags' => ['ignoreme'],
54+
'exported' => false
55+
},
56+
{ 'file' => nil, 'line' => nil }
57+
]
58+
expect(subject.filtered?(diff, opts)).to eq(false)
59+
end
5560
end
5661

57-
it 'should remove ~ changes due to compilation dirs' do
58-
opts = { ignore:
59-
[
60-
{ type: 'Varies_Due_To_Compilation_Dir_1' },
61-
{ type: 'Varies_Due_To_Compilation_Dir_2' },
62-
{ type: 'Varies_Due_To_Compilation_Dir_4' },
63-
{ attr: "parameters\fdir_in_first_cat" },
64-
{ attr: "parameters\fdir_in_second_cat" }
65-
] }
66-
testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger)
67-
result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2)
68-
expect(result).to eq([])
69-
expect(@logger_str.string).to match(/WARN -- : Resource key.*parameters => dir .*Suppressed/)
70-
expect(@logger_str.string).to match(/WARN -- : Resource key.*parameters => dir_in_middle .*Suppressed/)
62+
context '+/- partial title change' do
63+
it 'should remove due to compilation dirs in to-catalog' do
64+
diff = [
65+
'+',
66+
"Varies_Due_To_Compilation_Dir_1\f/aldsfjalkfjalksfd/path/to/catalog2/aldsfjalkfjalksfd",
67+
{
68+
'type' => 'Varies_Due_To_Compilation_Dir_1',
69+
'title' => '/aldsfjalkfjalksfd/path/to/catalog2/aldsfjalkfjalksfd',
70+
'tags' => ['ignoreme'],
71+
'exported' => false
72+
},
73+
{ 'file' => nil, 'line' => nil }
74+
]
75+
expect(subject.filtered?(diff, opts)).to eq(true)
76+
end
77+
78+
it 'should remove due to compilation dirs in from-catalog' do
79+
diff = [
80+
'-',
81+
"Varies_Due_To_Compilation_Dir_1\f/aldsfjalkfjalksfd/path/to/catalog1/aldsfjalkfjalksfd",
82+
{
83+
'type' => 'Varies_Due_To_Compilation_Dir_1',
84+
'title' => '/aldsfjalkfjalksfd/path/to/catalog1/aldsfjalkfjalksfd',
85+
'tags' => ['ignoreme'],
86+
'exported' => false
87+
},
88+
{ 'file' => nil, 'line' => nil }
89+
]
90+
expect(subject.filtered?(diff, opts)).to eq(true)
91+
end
92+
93+
it 'should not remove a non-matching directory' do
94+
diff = [
95+
'-',
96+
"Varies_Due_To_Compilation_Dir_1\f/aldsfjalkfjalksfd/path/to/catalog3/aldsfjalkfjalksfd",
97+
{
98+
'type' => 'Varies_Due_To_Compilation_Dir_1',
99+
'title' => '/aldsfjalkfjalksfd/path/to/catalog3/aldsfjalkfjalksfd',
100+
'tags' => ['ignoreme'],
101+
'exported' => false
102+
},
103+
{ 'file' => nil, 'line' => nil }
104+
]
105+
expect(subject.filtered?(diff, opts)).to eq(false)
106+
end
71107
end
72108

73-
it 'should warn but not remove non-matching ! changes due to compilation dirs' do
74-
opts = { ignore:
75-
[
76-
{ type: 'Varies_Due_To_Compilation_Dir_1' },
77-
{ type: 'Varies_Due_To_Compilation_Dir_2' },
78-
{ type: 'Varies_Due_To_Compilation_Dir_4' },
79-
{ attr: "parameters\fdir" },
80-
{ attr: "parameters\fdir_in_middle" }
81-
] }
82-
testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger)
83-
result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2)
84-
expect(result.size).to eq(2)
85-
common_str = "Varies_Due_To_Compilation_Dir_3\fCommon Title\fparameters\f"
86-
expect(result[0][1]).to eq("#{common_str}dir_in_first_cat")
87-
expect(result[1][1]).to eq("#{common_str}dir_in_second_cat")
88-
expect(@logger_str.string).to match(/WARN.+Varies_Due_To_Compilation_Dir_3\[Common Title\] parameters => dir.*verify/)
109+
context '~ value changes' do
110+
it 'should remove a change where directories are a partial match' do
111+
diff = [
112+
'~',
113+
"Varies_Due_To_Compilation_Dir_3\fCommon Title\fparameters\fdir_in_middle",
114+
'/asdfjkafds/path/to/catalog1/slkdfjasflkd',
115+
'/asdfjkafds/path/to/catalog2/slkdfjasflkd',
116+
{ 'file' => nil, 'line' => nil },
117+
{ 'file' => nil, 'line' => nil }
118+
]
119+
expect(subject.filtered?(diff, opts)).to eq(true)
120+
end
121+
122+
it 'should remove a change where directories are a full match' do
123+
diff = [
124+
'~',
125+
"Varies_Due_To_Compilation_Dir_3\fCommon Title\fparameters\fdir",
126+
'/path/to/catalog1',
127+
'/path/to/catalog2',
128+
{ 'file' => nil, 'line' => nil },
129+
{ 'file' => nil, 'line' => nil }
130+
]
131+
expect(subject.filtered?(diff, opts)).to eq(true)
132+
end
133+
134+
it 'should not remove a change where directories are inverted' do
135+
diff = [
136+
'~',
137+
"Varies_Due_To_Compilation_Dir_3\fCommon Title\fparameters\fdir",
138+
'/path/to/catalog2',
139+
'/path/to/catalog1',
140+
{ 'file' => nil, 'line' => nil },
141+
{ 'file' => nil, 'line' => nil }
142+
]
143+
expect(subject.filtered?(diff, opts)).to eq(false)
144+
end
145+
146+
it 'should not remove a change where directories do not match' do
147+
diff = [
148+
'~',
149+
"Varies_Due_To_Compilation_Dir_3\fCommon Title\fparameters\fdir",
150+
'/var/tmp/alsdfksfmd',
151+
'/var/tmp/adfklweoif',
152+
{ 'file' => nil, 'line' => nil },
153+
{ 'file' => nil, 'line' => nil }
154+
]
155+
expect(subject.filtered?(diff, opts)).to eq(false)
156+
end
89157
end
90158

91-
it 'should warn but not remove non-matching ~ changes due to compilation dirs' do
92-
opts = { ignore:
159+
context '~ partial indeterminate matches' do
160+
let(:diff) do
93161
[
94-
{ type: 'Varies_Due_To_Compilation_Dir_1' },
95-
{ type: 'Varies_Due_To_Compilation_Dir_2' },
96-
{ type: 'Varies_Due_To_Compilation_Dir_3' }
97-
] }
98-
testobj = OctocatalogDiff::Cli::Diffs.new(opts, @logger)
99-
result = testobj.diffs(from: @cat_compilation_dir_1, to: @cat_compilation_dir_2)
100-
answer = [[
101-
'~',
102-
"Varies_Due_To_Compilation_Dir_4\fCommon Title\fparameters\fdir",
103-
'/path/to/catalog1/onetime',
104-
'/path/to/catalog2/twotimes',
105-
{ 'file' => nil, 'line' => nil },
106-
{ 'file' => nil, 'line' => nil }
107-
]]
108-
expect(result).to eq(answer)
109-
expect(@logger_str.string).to match(/WARN -- : Resource key Varies_Due_To_Compilation_Dir_4.*please verify/)
162+
'~',
163+
"Varies_Due_To_Compilation_Dir_3\fCommon Title\fparameters\fdir",
164+
'/var/tmp/alsdfksfmd',
165+
'/path/to/catalog2',
166+
{ 'file' => nil, 'line' => nil },
167+
{ 'file' => nil, 'line' => nil }
168+
]
169+
end
170+
171+
it 'should not remove changes that do not match fully' do
172+
expect(subject.filtered?(diff, opts)).to eq(false)
173+
end
174+
175+
it 'should log warning message' do
176+
subject.filtered?(diff, opts)
177+
expect(@logger_str.string).to match(/WARN.*Varies_Due_To_Compilation_Dir_3\[Common Title\] parameters => dir.+differences/)
178+
end
110179
end
111180
end

0 commit comments

Comments
 (0)