From 8932d672f6d64f215ed22719031c5b80e3cb6058 Mon Sep 17 00:00:00 2001 From: Radim Hrazdil Date: Fri, 2 Sep 2022 11:33:28 +0200 Subject: [PATCH] resolver: unit test filtering from cached capture Signed-off-by: Radim Hrazdil --- nmpolicy/internal/resolver/resolver_test.go | 107 ++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/nmpolicy/internal/resolver/resolver_test.go b/nmpolicy/internal/resolver/resolver_test.go index 8e490f05..f0aeaeb9 100644 --- a/nmpolicy/internal/resolver/resolver_test.go +++ b/nmpolicy/internal/resolver/resolver_test.go @@ -145,6 +145,7 @@ func TestFilter(t *testing.T) { testReplaceCapturedState(t) testReplaceWithCaptureRef(t) testReplaceOptionalField(t) + testFilterMultipleFilterCaptureRef(t) }) } @@ -376,6 +377,112 @@ base-iface-routes: }) } +func testFilterMultipleFilterCaptureRef(t *testing.T) { + t.Run("Replace boolean in filtered list with capture reference", func(t *testing.T) { + testToRun := test{ + capturedStatesCache: ` +ethernets: + metaInfo: + time: "2021-12-15T13:45:40Z" + version: "0" + state: + interfaces: + - name: eth1 + description: "1st ethernet interface" + type: ethernet + state: up + ipv4: + address: + - ip: 10.244.0.1 + prefix-length: 24 + - ip: 169.254.1.0 + prefix-length: 16 + dhcp: false + enabled: true + - name: eth2 + type: ethernet + state: down + ipv4: + address: + - ip: 1.2.3.4 + prefix-length: 24 + dhcp: false + enabled: false +`, + captureASTPool: ` +ethernets-up: + pos: 1 + eqfilter: + - pos: 2 + path: + - identity: capture + - identity: ethernets + - pos: 5 + path: + - pos: 6 + identity: interfaces + - pos: 7 + identity: state + - pos: 8 + string: up + - pos: 9 + path: + - pos: 10 + boolean: true +`, + + expectedCapturedStates: ` +ethernets: + metaInfo: + time: "2021-12-15T13:45:40Z" + version: "0" + state: + interfaces: + - name: eth1 + description: "1st ethernet interface" + type: ethernet + state: up + ipv4: + address: + - ip: 10.244.0.1 + prefix-length: 24 + - ip: 169.254.1.0 + prefix-length: 16 + dhcp: false + enabled: true + - name: eth2 + type: ethernet + state: down + ipv4: + address: + - ip: 1.2.3.4 + prefix-length: 24 + dhcp: false + enabled: false +ethernets-up: + metaInfo: + time: "2021-12-15T13:45:40Z" + version: "0" + state: + interfaces: + - name: eth1 + description: "1st ethernet interface" + type: ethernet + state: up + ipv4: + address: + - ip: 10.244.0.1 + prefix-length: 24 + - ip: 169.254.1.0 + prefix-length: 16 + dhcp: false + enabled: true +`, + } + runTest(t, &testToRun) + }) +} + func testFilterCaptureRefWithoutCapturedState(t *testing.T) { t.Run("Filter list with capture reference", func(t *testing.T) { testToRun := test{