Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit d4f1057

Browse files
author
Radim Hrazdil
committed
resolver: unit test filtering from cached capture
Signed-off-by: Radim Hrazdil <rhrazdil@redhat.com>
1 parent d1aefd1 commit d4f1057

File tree

5 files changed

+174
-0
lines changed

5 files changed

+174
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
ethernets:
2+
metaInfo:
3+
time: "2021-12-15T13:45:40Z"
4+
version: "0"
5+
state:
6+
interfaces:
7+
- accept-all-mac-addresses: false
8+
lldp:
9+
enabled: false
10+
mac-address: 52:55:00:D1:55:02
11+
name: eth0
12+
state: up
13+
type: ethernet
14+
- accept-all-mac-addresses: false
15+
lldp:
16+
enabled: false
17+
mac-address: 52:55:00:D1:56:02
18+
name: eth1
19+
state: down
20+
type: ethernet
21+
ethernets-up:
22+
metaInfo:
23+
time: "2021-12-15T13:45:40Z"
24+
version: "0"
25+
state:
26+
interfaces:
27+
- accept-all-mac-addresses: false
28+
lldp:
29+
enabled: false
30+
mac-address: 52:55:00:D1:55:02
31+
name: eth0
32+
state: up
33+
type: ethernet
34+
ethernets-lldp:
35+
metaInfo:
36+
time: "2021-12-15T13:45:40Z"
37+
version: "0"
38+
state:
39+
interfaces:
40+
- accept-all-mac-addresses: false
41+
lldp:
42+
enabled: false
43+
mac-address: 52:55:00:D1:55:02
44+
name: eth0
45+
state: up
46+
type: ethernet
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
interfaces:
2+
- accept-all-mac-addresses: false
3+
lldp:
4+
enabled: false
5+
mac-address: 52:55:00:D1:55:02
6+
name: eth0
7+
state: up
8+
type: ethernet
9+
- accept-all-mac-addresses: false
10+
lldp:
11+
enabled: false
12+
mac-address: 52:55:00:D1:56:02
13+
name: eth1
14+
state: down
15+
type: ethernet
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interfaces:
2+
- accept-all-mac-addresses: false
3+
lldp:
4+
enabled: true
5+
mac-address: 52:55:00:D1:55:02
6+
name: eth0
7+
state: up
8+
type: ethernet
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% raw %}
2+
capture:
3+
ethernets: interfaces.type=="ethernet"
4+
ethernets-up: capture.ethernets.interfaces.state=="up"
5+
ethernets-lldp: capture.ethernets-up | interfaces.lldp.enabled:=true
6+
7+
desiredState:
8+
interfaces: "{{ capture.ethernets-lldp.interfaces }}"
9+
{% endraw %}

nmpolicy/internal/resolver/resolver_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func TestFilter(t *testing.T) {
145145
testReplaceCapturedState(t)
146146
testReplaceWithCaptureRef(t)
147147
testReplaceOptionalField(t)
148+
testFilterStateCaptureRef(t)
148149
})
149150
}
150151

@@ -376,6 +377,101 @@ base-iface-routes:
376377
})
377378
}
378379

380+
func testFilterStateCaptureRef(t *testing.T) {
381+
t.Run("Replace boolean in filtered list with capture reference", func(t *testing.T) {
382+
testToRun := test{
383+
capturedStatesCache: `
384+
ethernets:
385+
state:
386+
interfaces:
387+
- name: eth1
388+
description: "1st ethernet interface"
389+
type: ethernet
390+
state: up
391+
ipv4:
392+
address:
393+
- ip: 10.244.0.1
394+
prefix-length: 24
395+
- ip: 169.254.1.0
396+
prefix-length: 16
397+
dhcp: false
398+
enabled: true
399+
- name: eth2
400+
type: ethernet
401+
state: down
402+
ipv4:
403+
address:
404+
- ip: 1.2.3.4
405+
prefix-length: 24
406+
dhcp: false
407+
enabled: false
408+
`,
409+
captureASTPool: `
410+
ethernets-up:
411+
pos: 1
412+
eqfilter:
413+
- pos: 2
414+
path:
415+
- pos: 3
416+
identity: capture
417+
- pos: 4
418+
identity: ethernets
419+
- pos: 5
420+
path:
421+
- pos: 6
422+
identity: interfaces
423+
- pos: 7
424+
identity: state
425+
- pos: 8
426+
string: up
427+
`,
428+
429+
expectedCapturedStates: `
430+
ethernets:
431+
state:
432+
interfaces:
433+
- name: eth1
434+
description: "1st ethernet interface"
435+
type: ethernet
436+
state: up
437+
ipv4:
438+
address:
439+
- ip: 10.244.0.1
440+
prefix-length: 24
441+
- ip: 169.254.1.0
442+
prefix-length: 16
443+
dhcp: false
444+
enabled: true
445+
- name: eth2
446+
type: ethernet
447+
state: down
448+
ipv4:
449+
address:
450+
- ip: 1.2.3.4
451+
prefix-length: 24
452+
dhcp: false
453+
enabled: false
454+
ethernets-up:
455+
state:
456+
interfaces:
457+
- name: eth1
458+
description: "1st ethernet interface"
459+
type: ethernet
460+
state: up
461+
ipv4:
462+
address:
463+
- ip: 10.244.0.1
464+
prefix-length: 24
465+
- ip: 169.254.1.0
466+
prefix-length: 16
467+
dhcp: false
468+
enabled: true
469+
`,
470+
}
471+
runTest(t, &testToRun)
472+
})
473+
}
474+
379475
func testFilterCaptureRefWithoutCapturedState(t *testing.T) {
380476
t.Run("Filter list with capture reference", func(t *testing.T) {
381477
testToRun := test{

0 commit comments

Comments
 (0)