From: Andrei Pavel Date: Mon, 15 Jun 2026 13:51:07 +0000 (+0300) Subject: [#4589] Add unit tests X-Git-Tag: Kea-3.3.0~43 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=963cd4cd7fbdb45954a5843c1f99fb8d7b352abb;p=thirdparty%2Fkea.git [#4589] Add unit tests --- diff --git a/src/bin/admin/tests/data/lease6_dump_test.reference.csv b/src/bin/admin/tests/data/lease6_dump_test.reference.csv index d937ae88f5..2eb5242082 100644 --- a/src/bin/admin/tests/data/lease6_dump_test.reference.csv +++ b/src/bin/admin/tests/data/lease6_dump_test.reference.csv @@ -1,4 +1,5 @@ address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source,pool_id ::10,32:30:33,30,1642000000,40,50,0,60,128,1,1,one.example.com,38:30,0,,90,16,0 ::11,32:31:33,30,1643210000,40,50,0,60,128,1,1,,38:30,1,{ },90,1,0 -::12,32:32:33,30,1643212345,40,50,0,60,128,1,1,threeˎxampleˌom,38:30,2,{ "a": 1, "b": "c" },90,4,0 +::12,32:32:33,30,1643212345,40,50,0,60,128,1,1,threeˎxampleˌom,38:30,2,{ "a": 1, "b": "c" },0,0,0 +::13,32:33:33,30,1700000000,40,50,0,60,128,1,1,no.hwaddr.only.duid,,2,,0,0,0 diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index 4c91939e2c..c48a1a6374 100755 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in @@ -2079,9 +2079,11 @@ mysql_lease6_dump_test() { # Insert the reference record insert_sql="\ -insert into lease6 values(inet6_aton('::10'),203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,0,60,128,1,1,'one.example.com',80,90,16,0,NULL,0);\ -insert into lease6 values(inet6_aton('::11'),213,30,(SELECT FROM_UNIXTIME(1643210000)),40,50,0,60,128,1,1,'',80,90,1,1,'{ }',0);\ -insert into lease6 values(inet6_aton('::12'),223,30,(SELECT FROM_UNIXTIME(1643212345)),40,50,0,60,128,1,1,'three,example,com',80,90,4,2,'{ \"a\": 1, \"b\": \"c\" }',0)" +insert into lease6 values(inet6_aton('::10'),203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,0,60,128,1,1,'one.example.com',80,90,16,0,NULL,0); \ +insert into lease6 values(inet6_aton('::11'),213,30,(SELECT FROM_UNIXTIME(1643210000)),40,50,0,60,128,1,1,'',80,90,1,1,'{ }',0); \ +insert into lease6 values(inet6_aton('::12'),223,30,(SELECT FROM_UNIXTIME(1643212345)),40,50,0,60,128,1,1,'three,example,com',80,0,0,2,'{ \"a\": 1, \"b\": \"c\" }',0); \ +insert into lease6 values(inet6_aton('::13'),233,30,(SELECT FROM_UNIXTIME(1700000000)),40,50,0,60,128,1,1,'no.hwaddr.only.duid',NULL,0,0,2,'',0); \ +" run_command \ mysql_execute "$insert_sql" diff --git a/src/bin/admin/tests/pgsql_tests.sh.in b/src/bin/admin/tests/pgsql_tests.sh.in index 2a95db7ec1..0a5c947a5a 100755 --- a/src/bin/admin/tests/pgsql_tests.sh.in +++ b/src/bin/admin/tests/pgsql_tests.sh.in @@ -1488,7 +1488,9 @@ pgsql_lease6_dump_test() { insert_sql="\ insert into lease6 values(cast('::10' as inet),E'\\\\x323033',30,TO_TIMESTAMP(1642000000),40,50,0,60,128,'t','t','one.example.com',0,decode(encode('80','hex'),'hex'),90,16,'',0); \ insert into lease6 values(cast('::11' as inet),E'\\\\x323133',30,TO_TIMESTAMP(1643210000),40,50,0,60,128,'t','t','',1,decode(encode('80','hex'),'hex'),90,1,'{ }',0); \ -insert into lease6 values(cast('::12' as inet),E'\\\\x323233',30,TO_TIMESTAMP(1643212345),40,50,0,60,128,'t','t','three,example,com',2,decode(encode('80','hex'),'hex'),90,4,'{ \"a\": 1, \"b\": \"c\" }',0)" +insert into lease6 values(cast('::12' as inet),E'\\\\x323233',30,TO_TIMESTAMP(1643212345),40,50,0,60,128,'t','t','three,example,com',2,decode(encode('80','hex'),'hex'),0,0,'{ \"a\": 1, \"b\": \"c\" }',0); \ +insert into lease6 values(cast('::13' as inet),E'\\\\x323333',30,TO_TIMESTAMP(1700000000),40,50,0,60,128,'t','t','no.hwaddr.only.duid',2,NULL,0,0,'',0); \ +" run_command \ pgsql_execute "$insert_sql" diff --git a/src/bin/lfc/tests/lfc_controller_unittests.cc b/src/bin/lfc/tests/lfc_controller_unittests.cc index aade9bc814..5403ab35aa 100644 --- a/src/bin/lfc/tests/lfc_controller_unittests.cc +++ b/src/bin/lfc/tests/lfc_controller_unittests.cc @@ -551,42 +551,42 @@ TEST_F(LFCControllerTest, launch6) { // We have several entries for different leases, the naming is: // _. string a_1 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," - "200,200,8,100,0,7,0,1,1,host.example.com,,1,,,,0\n"; + "200,200,8,100,0,7,0,1,1,host.example.com,,1,,0,0,0\n"; string a_2 = "2001:db8:1::1,,200,200,8,100,0,7,0,1,1," - "host.example.com,,1,,,,0\n"; + "host.example.com,,1,,0,0,0\n"; string a_3 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," - "200,400,8,100,0,7,0,1,1,host.example.com,,1,,,,0\n"; + "200,400,8,100,0,7,0,1,1,host.example.com,,1,,0,0,0\n"; string a_4 = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," "0,200,8,100,0,7,0,1,1,host.example.com,,1," - "{ \"foo\": true },,,0\n"; + "{ \"foo\": true },0,0,0\n"; string b_1 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," - "300,300,6,150,0,8,0,0,0,,,1,{ \"bar\": false },,,0\n"; + "300,300,6,150,0,8,0,0,0,,,1,{ \"bar\": false },0,0,0\n"; string b_2 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," - "300,800,6,150,0,8,0,0,0,,,1,,,,0\n"; + "300,800,6,150,0,8,0,0,0,,,1,,0,0,0\n"; string b_3 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," - "300,1000,6,150,0,8,0,0,0,,,1,,,,0\n"; + "300,1000,6,150,0,8,0,0,0,,,1,,0,0,0\n"; string c_1 = "3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," - "100,200,8,0,2,16,64,0,0,,,1,,,,0\n"; + "100,200,8,0,2,16,64,0,0,,,1,,0,0,0\n"; string c_2 = "3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," - "100,400,8,0,2,16,64,0,0,,,1,,,,0\n"; + "100,400,8,0,2,16,64,0,0,,,1,,0,0,0\n"; string d_1 = "2001:db8:1::3,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," - "200,600,8,100,0,7,0,1,1,host.example.com,,1,,,,0\n"; + "200,600,8,100,0,7,0,1,1,host.example.com,,1,,0,0,0\n"; // new files have 128 prefixlen for non PD type string a_3_n = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," - "200,400,8,100,0,7,128,1,1,host.example.com,,1,,,,0\n"; + "200,400,8,100,0,7,128,1,1,host.example.com,,1,,0,0,0\n"; string b_2_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," - "300,800,6,150,0,8,128,0,0,,,1,,,,0\n"; + "300,800,6,150,0,8,128,0,0,,,1,,0,0,0\n"; string b_3_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," - "300,1000,6,150,0,8,128,0,0,,,1,,,,0\n"; + "300,1000,6,150,0,8,128,0,0,,,1,,0,0,0\n"; string d_1_n = "2001:db8:1::3,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," - "200,600,8,100,0,7,128,1,1,host.example.com,,1,,,,0\n"; + "200,600,8,100,0,7,128,1,1,host.example.com,,1,,0,0,0\n"; // Subtest 1: both previous and copy available // Create the test previous file diff --git a/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc b/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc index 0311debc8e..3b224c4a51 100644 --- a/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc +++ b/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc @@ -328,12 +328,12 @@ TEST_F(CSVLeaseFile6Test, recreate) { "lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr," "state,user_context,hwtype,hwaddr_source,pool_id\n" "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," - "200,200,8,100,0,7,128,1,1,host.example.com,,0,,,,0\n" + "200,200,8,100,0,7,128,1,1,host.example.com,,0,,0,0,0\n" "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05" - ",300,300,6,150,0,8,128,0,0,,,0,,,,0\n" + ",300,300,6,150,0,8,128,0,0,,,0,,0,0,0\n" "3000:1:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," - "300,300,10,150,2,7,64,0,0,,,0,{ \"foobar\": true },,,0\n" - "2001:db8:2::10,00:00:00,300,300,6,150,0,8,128,0,0,,,1,,,,0\n", + "300,300,10,150,2,7,64,0,0,,,0,{ \"foobar\": true },0,0,0\n" + "2001:db8:2::10,00:00:00,300,300,6,150,0,8,128,0,0,,,1,,0,0,0\n", io_.readFile()); } diff --git a/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc b/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc index 3d23e5946e..8082f269b7 100644 --- a/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_file_loader_unittest.cc @@ -532,20 +532,20 @@ TEST_F(LeaseFileLoaderTest, loadWrite6) { "{ \"foobar\": true },,,0\n"; std::string b_1 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," - "300,300,6,150,0,8,0,0,0,,,1,,,,0\n"; + "300,300,6,150,0,8,0,0,0,,,1,,0,0,0\n"; std::string b_2 = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," - "300,800,6,150,0,8,0,0,0,,,1,,,,0\n"; + "300,800,6,150,0,8,0,0,0,,,1,,0,0,0\n"; std::string c_1 = "3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," - "100,200,8,0,2,16,64,0,0,,,1,,,,0\n"; + "100,200,8,0,2,16,64,0,0,,,1,,0,0,0\n"; // new files have 128 prefixlen for non PD type std::string a_3_n = "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f," "200,400,8,100,0,7,128,1,1,host.example.com,,1," - "{ \"foobar\": true },,,0\n"; + "{ \"foobar\": true },0,0,0\n"; std::string b_2_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," - "300,800,6,150,0,8,128,0,0,,,1,,,,0\n"; + "300,800,6,150,0,8,128,0,0,,,1,,0,0,0\n"; // Create a lease file with three valid leases: 2001:db8:1::1, // 3000:1:: and 2001:db8:2::10. @@ -623,7 +623,7 @@ TEST_F(LeaseFileLoaderTest, loadWrite6LeaseRemove) { // new files have 128 prefixlen for non PD type std::string b_2_n = "2001:db8:2::10,01:01:01:01:0a:01:02:03:04:05," - "300,800,6,150,0,8,128,0,0,,,1,,,,0\n"; + "300,800,6,150,0,8,128,0,0,,,1,,0,0,0\n"; // Create lease file in which one of the entries for the 2001:db8:1::1 // has valid lifetime set to 0, in which case the lease should be diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 90cfd78567..a0b17119a1 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -889,7 +889,7 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCleanup6) { std::string update_file_contents = new_file_contents + "3000::1,00:00:00:00:00:00:00:00:00:00:00:00:00,400," - "400,2,300,0,123,128,0,0,,,0,,,,0\n"; + "400,2,300,0,123,128,0,0,,,0,,0,0,0\n"; EXPECT_EQ(update_file_contents, current_file.readFile()); // This string contains the contents of the lease file we @@ -897,9 +897,9 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCleanup6) { // entry each. std::string result_file_contents = new_file_contents + "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800," - "8,100,0,7,128,1,1,,,1,{ \"foo\": true },,,0\n" + "8,100,0,7,128,1,1,,,1,{ \"foo\": true },0,0,0\n" "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800," - "8,100,0,7,128,1,1,,,1,,,,0\n"; + "8,100,0,7,128,1,1,,,1,,0,0,0\n"; // The LFC should have created a file with the two leases and moved it // to leasefile6_0.csv.2 @@ -1031,7 +1031,7 @@ TEST_F(MemfileLeaseMgrTest, leaseFileCopy) { // the same. std::string input_file_contents = new_file_contents + "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800," - "8,100,0,7,128,1,1,,,1,{ \"foo\": true },,,0\n"; + "8,100,0,7,128,1,1,,,1,{ \"foo\": true },0,0,0\n"; LeaseFileIO input_file(getLeaseFilePath("leasefile6_0.csv.1")); input_file.writeFile(input_file_contents); @@ -2268,7 +2268,7 @@ TEST_F(MemfileLeaseMgrTest, leaseUpgrade6) { // Verify cleaned, converted contents std::string result_file_contents = header_5_0 + "2001:db8:1::1,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,200,800," - "8,100,0,7,128,1,1,,,0,,,,0\n" + "8,100,0,7,128,1,1,,,0,,0,0,0\n" "2001:db8:1::2,01:01:01:01:01:01:01:01:01:01:01:01:01,200,800," "8,100,0,7,128,1,1,,11:22:33:44:55,0,,1,0,0\n"; EXPECT_EQ(result_file_contents, input_file.readFile());