]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1635] Improved parsing unit tests
authorThomas Markwalder <tmark@isc.org>
Tue, 16 Feb 2021 18:56:48 +0000 (13:56 -0500)
committerThomas Markwalder <tmark@isc.org>
Fri, 19 Feb 2021 18:21:17 +0000 (13:21 -0500)
src/bin/dhcp4/tests/config_parser_unittest.cc
    TEST_F(Dhcp4ParserTest, clientClassValidLifetime)
    - new test

src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc
    TEST_F(ClientClassDefParserTest, validLifetimeTests)
    - improved test

src/bin/dhcp4/tests/config_parser_unittest.cc
src/lib/dhcpsrv/tests/client_class_def_parser_unittest.cc

index 9df7e54a06f0d5de877b139ee51e88e7bc11acbb..22180d968300d803e006d5829ab2569d946522c0 100644 (file)
@@ -31,6 +31,7 @@
 #include <hooks/hooks_manager.h>
 #include <stats/stats_mgr.h>
 #include <testutils/log_utils.h>
+#include <testutils/gtest_utils.h>
 #include <util/chrono_time_utils.h>
 #include <util/doubles.h>
 
@@ -6034,6 +6035,63 @@ TEST_F(Dhcp4ParserTest, invalidClientClassDictionary) {
     EXPECT_THROW(parseDHCP4(config), Dhcp4ParseError);
 }
 
+// Verifies that simple list of valid classes parses and
+// is staged for commit.
+TEST_F(Dhcp4ParserTest, clientClassValidLifetime) {
+    string config = "{ " + genIfaceConfig() + "," +
+        "\"client-classes\" : [ \n"
+        "   { \n"
+        "       \"name\": \"one\", \n"
+        "       \"min-valid-lifetime\": 1000, \n"
+        "       \"valid-lifetime\": 2000, \n"
+        "       \"max-valid-lifetime\": 3000 \n"
+        "   }, \n"
+        "   { \n"
+        "       \"name\": \"two\" \n"
+        "   } \n"
+        "], \n"
+        "\"subnet4\": [ {  \n"
+        "    \"pools\": [ { \"pool\":  \"192.0.2.1 - 192.0.2.100\" } ], \n"
+        "    \"subnet\": \"192.0.2.0/24\"  \n"
+        " } ] \n"
+        "} \n";
+
+    ConstElementPtr json;
+    ASSERT_NO_THROW_LOG(json = parseDHCP4(config));
+    extractConfig(config);
+
+    ConstElementPtr status;
+    ASSERT_NO_THROW_LOG(status = configureDhcp4Server(*srv_, json));
+    ASSERT_TRUE(status);
+    checkResult(status, 0);
+
+    // We check staging config because CfgMgr::commit hasn't been executed.
+    ClientClassDictionaryPtr dictionary;
+    dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
+    ASSERT_TRUE(dictionary);
+    EXPECT_EQ(2, dictionary->getClasses()->size());
+
+    // Execute the commit
+    ASSERT_NO_THROW(CfgMgr::instance().commit());
+
+    // Verify that after commit, the current config has the correct dictionary
+    dictionary = CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
+    ASSERT_TRUE(dictionary);
+    EXPECT_EQ(2, dictionary->getClasses()->size());
+
+    ClientClassDefPtr class_def = dictionary->findClass("one");
+    ASSERT_TRUE(class_def);
+    EXPECT_EQ(class_def->getValid().getMin(), 1000);
+    EXPECT_EQ(class_def->getValid().get(), 2000);
+    EXPECT_EQ(class_def->getValid().getMax(), 3000);
+
+    class_def = dictionary->findClass("two");
+    ASSERT_TRUE(class_def);
+    EXPECT_TRUE(class_def->getValid().unspecified());
+
+}
+
+
 // Test verifies that regular configuration does not provide any user context
 // in the address pool.
 TEST_F(Dhcp4ParserTest, poolUserContextMissing) {
index 75cee83c3c28fb02cc671e0a00d21e8bd5a4d707..0e786c50015c389a6331581bb13d885112a6525d 100644 (file)
@@ -1341,7 +1341,14 @@ TEST_F(ClientClassDefParserTest, validLifetimeTests) {
             ClientClassDefPtr class_def;
             ASSERT_NO_THROW_LOG(class_def = parseClientClassDef(oss.str(), AF_INET));
             ASSERT_TRUE(class_def);
-            EXPECT_EQ(class_def->getValid(), scenario.exp_triplet_);
+            if (scenario.exp_triplet_.unspecified()) {
+                EXPECT_TRUE(class_def->getValid().unspecified());
+            } else {
+                EXPECT_EQ(class_def->getValid(), scenario.exp_triplet_);
+                EXPECT_EQ(class_def->getValid().getMin(), scenario.exp_triplet_.getMin());
+                EXPECT_EQ(class_def->getValid().get(), scenario.exp_triplet_.get());
+                EXPECT_EQ(class_def->getValid().getMax(), scenario.exp_triplet_.getMax());
+            }
         }
     }
 }