tests: shell: add packetpath test for meta time expression.
PATCH 1/1 tests: shell: add packetpath test for meta time expression.
Signed-off-by Yi Chen <[email protected]>
--- .../packetpath/dumps/meta_time.nodump | 0 tests/shell/testcases/packetpath/meta_time | 79 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 tests/shell/testcases/packetpath/dumps/meta_time.nodump create mode 100755 tests/shell/testcases/packetpath/meta_time
tests/shell/testcases/packetpath/dumps/meta_time.nodump new file +0 -0
tests/shell/testcases/packetpath/meta_time new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.51.1
Phil Sutter
reviewerHi Chen Yi,
Quoted 51 lines · Yi Chen
Signed-off-by Yi Chen <[email protected]>--- .../packetpath/dumps/meta_time.nodump | 0 tests/shell/testcases/packetpath/meta_time | 79 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 tests/shell/testcases/packetpath/dumps/meta_time.nodump create mode 100755 tests/shell/testcases/packetpath/meta_timetests/shell/testcases/packetpath/dumps/meta_time.nodump new file +0
-0tests/shell/testcases/packetpath/meta_time new file +34
-0@@ -0,0 +1,79 @@ +#!/bin/sh + +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_meta_time) + +. $NFT_TEST_LIBRARY_FILE + +gen_in_range_minute() +{ + echo $(date -d "-5 minutes" +%H:%M)-$(date -d "+5 minutes" +%H:%M) +} + +gen_out_of_range_minute() +{ + echo $(date -d "+2 minutes" +%H:%M)-$(date -d "+5 minutes" +%H:%M) +} + +gen_in_range_hour() +{ + echo $(date -d "-2 hours" +%H:%M)-$(date -d "+2 hours" +%H:%M) +} + +gen_out_of_range_hour() +{ + echo $(date -d "+1 hours" +%H:%M)-$(date -d "+2 hours" +%H:%M) +} +gen_in_range_day() +{ + #meta day "Sunday"-"Tuesday" + echo \"$(date -d "-1 days" +%A)\"-\"$(date -d "+1 days" +%A)\" +} +gen_out_of_range_day() +{ + echo \"$(date -d "-2 days" +%A)\"-\"$(date -d "-1 days" +%A)\" +}
tests/shell/testcases/packetpath/meta_time line 44
Quoted 10 lines
tests/shell/testcases/packetpath/meta_time new file +10
-0+ +gen_in_range_time() +{ + echo ">" \"$(date -d "-1 years +10 days" +%G-%m-%d" "%H:%M:%S)\" "meta time <" \"$(date -d "+2 days" +%G-%m-%d" "%H:%M:%S)\" +} + +gen_out_of_range_time() +{ + echo ">" \"$(date -d "+10 days" +%G-%m-%d" "%H:%M:%S)\" "meta time <" \"$(date -d "+1 month" +%G-%m-%d" "%H:%M:%S)\" +}
Why do you resort to using two matches instead of a range here? Something like the following works fine for me:
| nft add rule t c 'meta time "2025-11-10 10:15:45"-"2025-11-11 10:25:35"'
tests/shell/testcases/packetpath/meta_time line 49
Quoted 5 lines
tests/shell/testcases/packetpath/meta_time new file +5
-0+ +$NFT -f - <<-EOF +table ip time_test { + counter matched {} + counter unmatch {}
Nice trick to assert matches and non-matches without having to look at individual rule counters!
Thanks, Phil