Skip to content

Commit

Permalink
replace: Return map if missing path
Browse files Browse the repository at this point in the history
Signed-off-by: Enrique Llorente <[email protected]>
  • Loading branch information
qinqon committed Sep 14, 2022
1 parent d4f1057 commit 0ee4520
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
30 changes: 26 additions & 4 deletions docs/examples/all-ethernet-up/captured.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ethernets:
- accept-all-mac-addresses: false
lldp:
enabled: false
mac-address: 52:55:00:D1:55:02
mac-address: 52:55:00:D1:55:01
name: eth0
state: up
type: ethernet
Expand All @@ -18,6 +18,16 @@ ethernets:
name: eth1
state: down
type: ethernet
- accept-all-mac-addresses: false
mac-address: 52:55:00:D1:57:03
name: eth4
state: up
type: ethernet
- accept-all-mac-addresses: false
mac-address: 52:55:00:D1:56:04
name: eth2
state: down
type: ethernet
ethernets-up:
metaInfo:
time: "2021-12-15T13:45:40Z"
Expand All @@ -27,10 +37,15 @@ ethernets-up:
- accept-all-mac-addresses: false
lldp:
enabled: false
mac-address: 52:55:00:D1:55:02
mac-address: 52:55:00:D1:55:01
name: eth0
state: up
type: ethernet
- accept-all-mac-addresses: false
mac-address: 52:55:00:D1:57:03
name: eth4
state: up
type: ethernet
ethernets-lldp:
metaInfo:
time: "2021-12-15T13:45:40Z"
Expand All @@ -39,8 +54,15 @@ ethernets-lldp:
interfaces:
- accept-all-mac-addresses: false
lldp:
enabled: false
mac-address: 52:55:00:D1:55:02
enabled: true
mac-address: 52:55:00:D1:55:01
name: eth0
state: up
type: ethernet
- accept-all-mac-addresses: false
lldp:
enabled: true
mac-address: 52:55:00:D1:57:03
name: eth4
state: up
type: ethernet
13 changes: 12 additions & 1 deletion docs/examples/all-ethernet-up/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ interfaces:
- accept-all-mac-addresses: false
lldp:
enabled: false
mac-address: 52:55:00:D1:55:02
mac-address: 52:55:00:D1:55:01
name: eth0
state: up
type: ethernet
Expand All @@ -13,3 +13,14 @@ interfaces:
name: eth1
state: down
type: ethernet
- accept-all-mac-addresses: false
mac-address: 52:55:00:D1:57:03
name: eth4
state: up
type: ethernet
- accept-all-mac-addresses: false
mac-address: 52:55:00:D1:56:04
name: eth2
state: down
type: ethernet

9 changes: 8 additions & 1 deletion docs/examples/all-ethernet-up/generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ interfaces:
- accept-all-mac-addresses: false
lldp:
enabled: true
mac-address: 52:55:00:D1:55:02
mac-address: 52:55:00:D1:55:01
name: eth0
state: up
type: ethernet
- accept-all-mac-addresses: false
lldp:
enabled: true
mac-address: 52:55:00:D1:57:03
name: eth4
state: up
type: ethernet
2 changes: 1 addition & 1 deletion nmpolicy/internal/resolver/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r replaceOpVisitor) visitMap(p path, mapToVisit map[string]interface{}) (i
}
interfaceToVisit, ok := mapToVisit[*p.currentStep.Identity]
if !ok {
return nil, nil
interfaceToVisit = map[string]interface{}{}
}

visitResult, err := visitState(p.nextStep(), interfaceToVisit, &r)
Expand Down
9 changes: 8 additions & 1 deletion tests/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func TestExamples(t *testing.T) {
assert.NoError(t, err)
obtainedCaptuerdStates, err := formatCapturedStates(obtained.Cache.Capture)
assert.NoError(t, err)
assert.Equal(t, resetCapturedStatesTimeStamp(expectedCapturedStates), resetCapturedStatesTimeStamp(obtainedCaptuerdStates))
assert.YAMLEq(t, marshalCapturedStates(t, resetCapturedStatesTimeStamp(expectedCapturedStates)),
marshalCapturedStates(t, resetCapturedStatesTimeStamp(obtainedCaptuerdStates)))
})
}
}
Expand All @@ -127,3 +128,9 @@ func formatCapturedStates(capturedStates map[string]types.CaptureState) (map[str
}
return capturedStates, nil
}

func marshalCapturedStates(t *testing.T, capturedStates map[string]types.CaptureState) string {
marshaledBytes, err := yaml.Marshal(capturedStates)
assert.NoError(t, err)
return string(marshaledBytes)
}

0 comments on commit 0ee4520

Please sign in to comment.