config_parser: Split up sections
We can't always combine sections together in network files as sections
like
[Address]
Address=::1/128
Peer=fe80::1
[Address]
Address=::2/128
Peer=fe80::2
Require that they are grouped accordingly. Rewrite the storage logic of
the config parser to support this logical organization.
Change-Id: I34ae1523202f8770fe3dcac010fb6226dd28b9ec
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/test_vlan_interface.cpp b/test/test_vlan_interface.cpp
index 5ee1cf9..728199a 100644
--- a/test/test_vlan_interface.cpp
+++ b/test/test_vlan_interface.cpp
@@ -102,27 +102,25 @@
fs::path filePath = confDir;
filePath /= "test0.50.netdev";
- config::Parser parser(filePath.string());
-
- EXPECT_EQ(parser.getValues("NetDev", "Name"),
- (config::ValueList{"test0.50"}));
- EXPECT_EQ(parser.getValues("NetDev", "Kind"), (config::ValueList{"vlan"}));
- EXPECT_EQ(parser.getValues("VLAN", "Id"), (config::ValueList{"50"}));
+ config::Parser parser(filePath);
+ EXPECT_EQ(parser.getMap(),
+ config::SectionMap(config::SectionMapInt{
+ {"NetDev",
+ {
+ {{"Name", {"test0.50"}}, {"Kind", {"vlan"}}},
+ }},
+ {"VLAN", {{{"Id", {"50"}}}}},
+ }));
}
TEST_F(TestVlanInterface, deleteVLAN)
{
createVlan(50);
deleteVlan("test0.50");
- bool fileFound = false;
fs::path filePath = confDir;
filePath /= "test0.50.netdev";
- if (fs::is_regular_file(filePath.string()))
- {
- fileFound = true;
- }
- EXPECT_EQ(fileFound, false);
+ EXPECT_FALSE(fs::is_regular_file(filePath));
}
TEST_F(TestVlanInterface, createMultipleVLAN)
@@ -132,19 +130,27 @@
fs::path filePath = confDir;
filePath /= "test0.50.netdev";
- config::Parser parser(filePath.string());
- EXPECT_EQ(parser.getValues("NetDev", "Name"),
- (config::ValueList{"test0.50"}));
- EXPECT_EQ(parser.getValues("NetDev", "Kind"), (config::ValueList{"vlan"}));
- EXPECT_EQ(parser.getValues("VLAN", "Id"), (config::ValueList{"50"}));
+ config::Parser parser(filePath);
+ EXPECT_EQ(parser.getMap(),
+ config::SectionMap(config::SectionMapInt{
+ {"NetDev",
+ {
+ {{"Name", {"test0.50"}}, {"Kind", {"vlan"}}},
+ }},
+ {"VLAN", {{{"Id", {"50"}}}}},
+ }));
filePath = confDir;
filePath /= "test0.60.netdev";
- parser.setFile(filePath.string());
- EXPECT_EQ(parser.getValues("NetDev", "Name"),
- (config::ValueList{"test0.60"}));
- EXPECT_EQ(parser.getValues("NetDev", "Kind"), (config::ValueList{"vlan"}));
- EXPECT_EQ(parser.getValues("VLAN", "Id"), (config::ValueList{"60"}));
+ parser.setFile(filePath);
+ EXPECT_EQ(parser.getMap(),
+ config::SectionMap(config::SectionMapInt{
+ {"NetDev",
+ {
+ {{"Name", {"test0.60"}}, {"Kind", {"vlan"}}},
+ }},
+ {"VLAN", {{{"Id", {"60"}}}}},
+ }));
deleteVlan("test0.50");
deleteVlan("test0.60");