]> git.ipfire.org Git - people/stevee/perl-ipset.git/commitdiff
Add tests for get_set_data() function and methods.
authorStefan Schantl <stefan.schantl@ipfire.org>
Sat, 17 Sep 2022 13:18:39 +0000 (15:18 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sat, 17 Sep 2022 13:18:39 +0000 (15:18 +0200)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
t/IPSet.t

index 8d5da7f7c3cb388a2a370f889947179d859cfe03..c85d44b49d184be6441b02e9ce4f224750205783 100644 (file)
--- 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);