From 20bec5a881a4b375da66eab5bb34acc6ad5b51c9 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Sat, 17 Sep 2022 15:18:39 +0200 Subject: [PATCH] Add tests for get_set_data() function and methods. Signed-off-by: Stefan Schantl --- t/IPSet.t | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/t/IPSet.t b/t/IPSet.t index 8d5da7f..c85d44b 100644 --- a/t/IPSet.t +++ b/t/IPSet.t @@ -8,7 +8,7 @@ use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 14; BEGIN { use_ok('IPSet') }; ######################### @@ -16,16 +16,26 @@ BEGIN { use_ok('IPSet') }; # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. -# Name of the testset. -my $setname = "TEST"; +# Hash with data for the testset. +my %testset = ( + "name" => "TEST", + "type" => "hash:ip", + "hashsize" => "1024", + "maxelem" => "10", +); + +# Name of the renamed set. my $setname_renamed = "TEST_RENAMED"; +# Assign setname for easy access. +my $setname = $testset{'name'}; + # Init the IPSet module and create a session. my $session = &IPSet::init(); # Create new IPSet. -my $create_set = &IPSet::create_set($session, $setname, "hash:ip", "1024", "10"); -ok($create_set, "Sucessfully created set: $setname."); +my $create_set = &IPSet::create_set($session, $setname, $testset{'type'}, $testset{'hashsize'}, $testset{'maxelem'}); +ok($create_set, "Sucessfully created set: $setname"); # Check if the testset exists. my $exists = &IPSet::setname_exists($session, $setname); @@ -48,5 +58,17 @@ ok($swap, "Successfully swapped sets."); my $delete = &IPSet::delete_set($session, $setname_renamed); ok($delete, "Successfully deleted set."); +# Try to grab the data from the testset. +my $data = &IPSet::get_set_data($session, $setname); +ok($data, "Successfully grabbed set data."); + +# Various tests to check the grabbed data. +ok($data->{name} eq $testset{'name'}, "Grabbed setname equals $testset{'name'}"); +ok($data->{type} eq $testset{'type'}, "Grabbed type equals $testset{'type'}"); +ok($data->{hashsize} eq $testset{'hashsize'}, "Grabbed hashsize equals $testset{'hashsize'}"); +ok($data->{maxelem} eq $testset{'maxelem'}, "Grabbed maxelem equals $testset{'maxelem'}"); +ok($data->{entries} == 0, "$testset{'name'} should not have any elements now."); +ok($data->{references} == 0, "$testset{'name'} should not be referenced!"); + # CLEANUP: Delete the remaining set. &IPSet::delete_set($session, $setname); -- 2.47.2