Skip to content

Commit 0ee4520

Browse files
committed
replace: Return map if missing path
Signed-off-by: Enrique Llorente <[email protected]>
1 parent d4f1057 commit 0ee4520

File tree

5 files changed

+55
-8
lines changed

5 files changed

+55
-8
lines changed

docs/examples/all-ethernet-up/captured.yaml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ethernets:
77
- accept-all-mac-addresses: false
88
lldp:
99
enabled: false
10-
mac-address: 52:55:00:D1:55:02
10+
mac-address: 52:55:00:D1:55:01
1111
name: eth0
1212
state: up
1313
type: ethernet
@@ -18,6 +18,16 @@ ethernets:
1818
name: eth1
1919
state: down
2020
type: ethernet
21+
- accept-all-mac-addresses: false
22+
mac-address: 52:55:00:D1:57:03
23+
name: eth4
24+
state: up
25+
type: ethernet
26+
- accept-all-mac-addresses: false
27+
mac-address: 52:55:00:D1:56:04
28+
name: eth2
29+
state: down
30+
type: ethernet
2131
ethernets-up:
2232
metaInfo:
2333
time: "2021-12-15T13:45:40Z"
@@ -27,10 +37,15 @@ ethernets-up:
2737
- accept-all-mac-addresses: false
2838
lldp:
2939
enabled: false
30-
mac-address: 52:55:00:D1:55:02
40+
mac-address: 52:55:00:D1:55:01
3141
name: eth0
3242
state: up
3343
type: ethernet
44+
- accept-all-mac-addresses: false
45+
mac-address: 52:55:00:D1:57:03
46+
name: eth4
47+
state: up
48+
type: ethernet
3449
ethernets-lldp:
3550
metaInfo:
3651
time: "2021-12-15T13:45:40Z"
@@ -39,8 +54,15 @@ ethernets-lldp:
3954
interfaces:
4055
- accept-all-mac-addresses: false
4156
lldp:
42-
enabled: false
43-
mac-address: 52:55:00:D1:55:02
57+
enabled: true
58+
mac-address: 52:55:00:D1:55:01
4459
name: eth0
4560
state: up
4661
type: ethernet
62+
- accept-all-mac-addresses: false
63+
lldp:
64+
enabled: true
65+
mac-address: 52:55:00:D1:57:03
66+
name: eth4
67+
state: up
68+
type: ethernet

docs/examples/all-ethernet-up/current.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ interfaces:
22
- accept-all-mac-addresses: false
33
lldp:
44
enabled: false
5-
mac-address: 52:55:00:D1:55:02
5+
mac-address: 52:55:00:D1:55:01
66
name: eth0
77
state: up
88
type: ethernet
@@ -13,3 +13,14 @@ interfaces:
1313
name: eth1
1414
state: down
1515
type: ethernet
16+
- accept-all-mac-addresses: false
17+
mac-address: 52:55:00:D1:57:03
18+
name: eth4
19+
state: up
20+
type: ethernet
21+
- accept-all-mac-addresses: false
22+
mac-address: 52:55:00:D1:56:04
23+
name: eth2
24+
state: down
25+
type: ethernet
26+

docs/examples/all-ethernet-up/generated.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ interfaces:
22
- accept-all-mac-addresses: false
33
lldp:
44
enabled: true
5-
mac-address: 52:55:00:D1:55:02
5+
mac-address: 52:55:00:D1:55:01
66
name: eth0
77
state: up
88
type: ethernet
9+
- accept-all-mac-addresses: false
10+
lldp:
11+
enabled: true
12+
mac-address: 52:55:00:D1:57:03
13+
name: eth4
14+
state: up
15+
type: ethernet

nmpolicy/internal/resolver/replace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (r replaceOpVisitor) visitMap(p path, mapToVisit map[string]interface{}) (i
6161
}
6262
interfaceToVisit, ok := mapToVisit[*p.currentStep.Identity]
6363
if !ok {
64-
return nil, nil
64+
interfaceToVisit = map[string]interface{}{}
6565
}
6666

6767
visitResult, err := visitState(p.nextStep(), interfaceToVisit, &r)

tests/examples_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ func TestExamples(t *testing.T) {
105105
assert.NoError(t, err)
106106
obtainedCaptuerdStates, err := formatCapturedStates(obtained.Cache.Capture)
107107
assert.NoError(t, err)
108-
assert.Equal(t, resetCapturedStatesTimeStamp(expectedCapturedStates), resetCapturedStatesTimeStamp(obtainedCaptuerdStates))
108+
assert.YAMLEq(t, marshalCapturedStates(t, resetCapturedStatesTimeStamp(expectedCapturedStates)),
109+
marshalCapturedStates(t, resetCapturedStatesTimeStamp(obtainedCaptuerdStates)))
109110
})
110111
}
111112
}
@@ -127,3 +128,9 @@ func formatCapturedStates(capturedStates map[string]types.CaptureState) (map[str
127128
}
128129
return capturedStates, nil
129130
}
131+
132+
func marshalCapturedStates(t *testing.T, capturedStates map[string]types.CaptureState) string {
133+
marshaledBytes, err := yaml.Marshal(capturedStates)
134+
assert.NoError(t, err)
135+
return string(marshaledBytes)
136+
}

0 commit comments

Comments
 (0)