Skip to content

Commit bc966c7

Browse files
author
Kevin Paulisse
committed
Document and test #old_value and #new_value
1 parent b553c88 commit bc966c7

2 files changed

Lines changed: 130 additions & 0 deletions

File tree

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

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,108 @@ 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_value` (Object)
32+
33+
Returns the value of the resource from the new catalog.
34+
35+
- If a resource was added, this returns the data structure associated with the resource in the Puppet catalog. For example, if the resource was created as follows in the Puppet catalog, the `new_value` is as indicated.
36+
37+
```
38+
# Resource in New Catalog
39+
{
40+
"type": "File",
41+
"title": "/etc/foo",
42+
"parameters": {
43+
"owner": "root",
44+
"content": "hello new world"
45+
}
46+
}
47+
48+
# Demonstrates new_value
49+
diff.new_value #=> { 'parameters' => { 'owner' => 'root', 'content' => 'hello new world' } }
50+
```
51+
52+
- If a resource was removed, this returns `nil` because there was no value of this resource in the new catalog.
53+
54+
- If a resource was changed, this returns the portion of the data structure that is indicated by the `.structure` method. For example, if the resource existed as follows in both the old and new Puppet catalogs, the `new_value` is as indicated.
55+
56+
```
57+
# Resource in Old Catalog
58+
{
59+
"type": "File",
60+
"title": "/etc/foo",
61+
"parameters": {
62+
"owner": "root",
63+
"content": "This is the old file"
64+
}
65+
}
66+
67+
# Resource in New Catalog
68+
{
69+
"type": "File",
70+
"title": "/etc/foo",
71+
"parameters": {
72+
"owner": "root",
73+
"content": "This is the NEW FILE!!!!!"
74+
}
75+
}
76+
77+
# Demonstrates structure and old_value
78+
diff.structure #=> ['parameters', 'content']
79+
diff.old_value #=> 'This is the NEW FILE!!!!!'
80+
```
81+
82+
#### `#old_value` (Object)
83+
84+
Returns the value of the resource from the old catalog.
85+
86+
- If a resource was added, this returns `nil` because there was no value of this resource in the old catalog.
87+
88+
- If a resource was removed, this returns the data structure associated with the resource in the Puppet catalog. For example, if the resource existed as follows in the Puppet catalog, the `old_value` is as indicated.
89+
90+
```
91+
# Resource in Old Catalog
92+
{
93+
"type": "File",
94+
"title": "/etc/foo",
95+
"parameters": {
96+
"owner": "root",
97+
"content": "hello old world"
98+
}
99+
}
100+
101+
# Demonstrates old_value
102+
diff.old_value #=> { 'parameters' => { 'owner' => 'root', 'content' => 'hello old world' } }
103+
```
104+
105+
- If a resource was changed, this returns the portion of the data structure that is indicated by the `.structure` method. For example, if the resource existed as follows in both the old and new Puppet catalogs, the `old_value` is as indicated.
106+
107+
```
108+
# Resource in Old Catalog
109+
{
110+
"type": "File",
111+
"title": "/etc/foo",
112+
"parameters": {
113+
"owner": "root",
114+
"content": "This is the old file"
115+
}
116+
}
117+
118+
# Resource in New Catalog
119+
{
120+
"type": "File",
121+
"title": "/etc/foo",
122+
"parameters": {
123+
"owner": "root",
124+
"content": "This is the NEW FILE!!!!!"
125+
}
126+
}
127+
128+
# Demonstrates structure and old_value
129+
diff.structure #=> ['parameters', 'content']
130+
diff.old_value #=> 'This is the old file'
131+
```
132+
31133
#### `#removal?` (Boolean)
32134

33135
Returns true if this diff is a removal (resource exists in old catalog but not new catalog).

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,37 @@
132132
end
133133

134134
describe '#old_value' do
135+
it 'should return nil for an addition' do
136+
testobj = described_class.new(add_2)
137+
expect(testobj.old_value).to be_nil
138+
end
139+
140+
it 'should return the entire structure for a removal' do
141+
testobj = described_class.new(del_2)
142+
expect(testobj.old_value).to eq(parameters)
143+
end
144+
145+
it 'should return the old value for a change' do
146+
testobj = described_class.new(chg_2)
147+
expect(testobj.old_value).to eq('old')
148+
end
135149
end
136150

137151
describe '#new_value' do
152+
it 'should return the entire structure for an addition' do
153+
testobj = described_class.new(add_2)
154+
expect(testobj.new_value).to eq(parameters)
155+
end
156+
157+
it 'should return nil for a removal' do
158+
testobj = described_class.new(del_2)
159+
expect(testobj.new_value).to be_nil
160+
end
161+
162+
it 'should return the new value for a change' do
163+
testobj = described_class.new(chg_2)
164+
expect(testobj.new_value).to eq('new')
165+
end
138166
end
139167

140168
describe '#old_location' do

0 commit comments

Comments
 (0)