Skip to content

Commit 19be23b

Browse files
author
Kevin Paulisse
committed
Add new/old file/line tests and documentation
1 parent bc966c7 commit 19be23b

3 files changed

Lines changed: 146 additions & 24 deletions

File tree

doc/dev/api/v1/objects/diff.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ See also: `#addition?`, `#change?`, `#removal?`
2828

2929
Note: Internally `~` and `!` represent different types of changes, but when presenting the output, these can generally be considered equivalent.
3030

31+
#### `#new_file` (String)
32+
33+
Returns the filename of the Puppet manifest giving rise to the resource as it exists in the new catalog.
34+
35+
Note that this is a pass-through of information provided in the Puppet catalog, and is not calculated by octocatalog-diff. If the Puppet catalog does not contain this information, this method will return `nil`.
36+
37+
Note also that if the diff represents removal of a resource, this will return `nil`, because the resource does not exist in the new catalog.
38+
39+
#### `#new_line` (String)
40+
41+
Returns the line number within the Puppet manifest giving rise to the resource as it exists in the new catalog. (See `#new_file` for the filename of the Puppet manifest.)
42+
43+
Note that this is a pass-through of information provided in the Puppet catalog, and is not calculated by octocatalog-diff. If the Puppet catalog does not contain this information, this method will return `nil`.
44+
45+
Note also that if the diff represents removal of a resource, this will return `nil`, because the resource does not exist in the new catalog.
46+
3147
#### `#new_value` (Object)
3248

3349
Returns the value of the resource from the new catalog.
@@ -79,6 +95,22 @@ Returns the value of the resource from the new catalog.
7995
diff.old_value #=> 'This is the NEW FILE!!!!!'
8096
```
8197

98+
#### `#old_file` (String)
99+
100+
Returns the filename of the Puppet manifest giving rise to the resource as it exists in the old catalog.
101+
102+
Note that this is a pass-through of information provided in the Puppet catalog, and is not calculated by octocatalog-diff. If the Puppet catalog does not contain this information, this method will return `nil`.
103+
104+
Note also that if the diff represents addition of a resource, this will return `nil`, because the resource does not exist in the old catalog.
105+
106+
#### `#old_file` (String)
107+
108+
Returns the line number within the Puppet manifest giving rise to the resource as it exists in the old catalog. (See `#old_file` for the filename of the Puppet manifest.)
109+
110+
Note that this is a pass-through of information provided in the Puppet catalog, and is not calculated by octocatalog-diff. If the Puppet catalog does not contain this information, this method will return `nil`.
111+
112+
Note also that if the diff represents addition of a resource, this will return `nil`, because the resource does not exist in the old catalog.
113+
82114
#### `#old_value` (Object)
83115

84116
Returns the value of the resource from the old catalog.

lib/octocatalog-diff/api/v1/diff.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,6 @@ def new_value
9191
@raw[3]
9292
end
9393

94-
# Public: Get the "old" location, i.e. location in the "from" catalog
95-
# @return [Hash] <file:, line:> of resource
96-
def old_location
97-
return nil if addition?
98-
return @raw[3] if removal?
99-
@raw[4]
100-
end
101-
102-
# Public: Get the "new" location, i.e. location in the "to" catalog
103-
# @return [Hash] <file:, line:> of resource
104-
def new_location
105-
return @raw[3] if addition?
106-
return nil if removal?
107-
@raw[5]
108-
end
109-
11094
# Public: Get the filename from the "old" location
11195
# @return [String] Filename
11296
def old_file
@@ -146,8 +130,6 @@ def to_h
146130
structure: structure,
147131
old_value: old_value,
148132
new_value: new_value,
149-
old_location: old_location,
150-
new_location: new_location,
151133
old_file: old_file,
152134
old_line: old_line,
153135
new_file: new_file,
@@ -166,6 +148,24 @@ def inspect
166148
def to_s
167149
raw.inspect
168150
end
151+
152+
private
153+
154+
# Private: Get the "old" location, i.e. location in the "from" catalog
155+
# @return [Hash] <file:, line:> of resource
156+
def old_location
157+
return nil if addition?
158+
return @raw[3] if removal?
159+
@raw[4]
160+
end
161+
162+
# Private: Get the "new" location, i.e. location in the "to" catalog
163+
# @return [Hash] <file:, line:> of resource
164+
def new_location
165+
return @raw[3] if addition?
166+
return nil if removal?
167+
@raw[5]
168+
end
169169
end
170170
end
171171
end

spec/octocatalog-diff/tests/api/v1/diff_spec.rb

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
let(:loc_2) { { 'file' => '/var/tmp/foo.pp', 'line' => 12 } }
1414

1515
let(:add_1) { ['+', type_title, parameters] }
16-
let(:add_2) { ['+', type_title, parameters, loc_1] }
16+
let(:add_2) { ['+', type_title, parameters, loc_2] }
1717

1818
let(:del_1) { ['-', type_title, parameters] }
1919
let(:del_2) { ['-', type_title, parameters, loc_1] }
@@ -165,21 +165,111 @@
165165
end
166166
end
167167

168-
describe '#old_location' do
169-
end
168+
describe '#old_file' do
169+
it 'should return nil for an addition' do
170+
testobj = described_class.new(add_2)
171+
expect(testobj.old_file).to be_nil
172+
end
170173

171-
describe '#new_location' do
172-
end
174+
it 'should return the filename for a removal' do
175+
testobj = described_class.new(del_2)
176+
expect(testobj.old_file).to eq(loc_1['file'])
177+
end
173178

174-
describe '#old_file' do
179+
it 'should return nil when information is not present for a removal' do
180+
testobj = described_class.new(del_1)
181+
expect(testobj.old_file).to be_nil
182+
end
183+
184+
it 'should return the filename for a change' do
185+
testobj = described_class.new(chg_2)
186+
expect(testobj.old_file).to eq(loc_1['file'])
187+
end
188+
189+
it 'should return nil when information is not present for a change' do
190+
testobj = described_class.new(chg_1)
191+
expect(testobj.old_file).to be_nil
192+
end
175193
end
176194

177195
describe '#old_line' do
196+
it 'should return nil for an addition' do
197+
testobj = described_class.new(add_2)
198+
expect(testobj.old_line).to be_nil
199+
end
200+
201+
it 'should return the line for a removal' do
202+
testobj = described_class.new(del_2)
203+
expect(testobj.old_line).to eq(loc_1['line'])
204+
end
205+
206+
it 'should return nil when information is not present for a removal' do
207+
testobj = described_class.new(del_1)
208+
expect(testobj.old_line).to be_nil
209+
end
210+
211+
it 'should return the line for a change' do
212+
testobj = described_class.new(chg_2)
213+
expect(testobj.old_line).to eq(loc_1['line'])
214+
end
215+
216+
it 'should return nil when information is not present for a change' do
217+
testobj = described_class.new(chg_1)
218+
expect(testobj.old_line).to be_nil
219+
end
178220
end
179221

180222
describe '#new_file' do
223+
it 'should return nil for a removal' do
224+
testobj = described_class.new(del_2)
225+
expect(testobj.new_file).to be_nil
226+
end
227+
228+
it 'should return the filename for an addition' do
229+
testobj = described_class.new(add_2)
230+
expect(testobj.new_file).to eq(loc_2['file'])
231+
end
232+
233+
it 'should return nil when information is not present for an addition' do
234+
testobj = described_class.new(add_1)
235+
expect(testobj.new_file).to be_nil
236+
end
237+
238+
it 'should return the filename for a change' do
239+
testobj = described_class.new(chg_2)
240+
expect(testobj.new_file).to eq(loc_2['file'])
241+
end
242+
243+
it 'should return nil when information is not present for a change' do
244+
testobj = described_class.new(chg_1)
245+
expect(testobj.new_file).to be_nil
246+
end
181247
end
182248

183249
describe '#new_line' do
250+
it 'should return nil for a removal' do
251+
testobj = described_class.new(del_2)
252+
expect(testobj.new_line).to be_nil
253+
end
254+
255+
it 'should return the line for an addition' do
256+
testobj = described_class.new(add_2)
257+
expect(testobj.new_line).to eq(loc_2['line'])
258+
end
259+
260+
it 'should return nil when information is not present for an addition' do
261+
testobj = described_class.new(add_1)
262+
expect(testobj.new_line).to be_nil
263+
end
264+
265+
it 'should return the line for a change' do
266+
testobj = described_class.new(chg_2)
267+
expect(testobj.new_line).to eq(loc_2['line'])
268+
end
269+
270+
it 'should return nil when information is not present for a change' do
271+
testobj = described_class.new(chg_1)
272+
expect(testobj.new_line).to be_nil
273+
end
184274
end
185275
end

0 commit comments

Comments
 (0)