Change group handling in MergeMetadata

Only replace the group if one is not already explicitly set. For #64.
This commit is contained in:
Oliver Hamlet
2020-03-30 19:47:47 +01:00
parent e9519b0e91
commit 0958045e27
2 changed files with 29 additions and 4 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ void PluginMetadata::MergeMetadata(const PluginMetadata& plugin) {
// but if the 'group' value is not explicit, ignore it.
enabled_ = plugin.IsEnabled();
if (plugin.GetGroup()) {
if (!group_.has_value() && plugin.GetGroup()) {
group_ = plugin.GetGroup();
}
@@ -140,7 +140,8 @@ TEST_P(PluginMetadataTest,
EXPECT_FALSE(plugin1.IsEnabled());
}
TEST_P(PluginMetadataTest, mergeMetadataShouldUseMergedGroupIfItIsExplicit) {
TEST_P(PluginMetadataTest,
mergeMetadataShouldNotUseMergedGroupIfItAndCurrentGroupAreBothExplicit) {
PluginMetadata plugin1;
PluginMetadata plugin2;
@@ -148,10 +149,22 @@ TEST_P(PluginMetadataTest, mergeMetadataShouldUseMergedGroupIfItIsExplicit) {
plugin2.SetGroup("group2");
plugin1.MergeMetadata(plugin2);
EXPECT_EQ("group2", plugin1.GetGroup());
EXPECT_EQ("group1", plugin1.GetGroup());
}
TEST_P(PluginMetadataTest, mergeMetadataShouldNotUseMergedGroupIfItIsImplicit) {
TEST_P(PluginMetadataTest,
mergeMetadataShouldNotUseMergedGroupIfItAndCurrentGroupAreBothImplicit) {
PluginMetadata plugin1;
PluginMetadata plugin2;
plugin1.MergeMetadata(plugin2);
EXPECT_FALSE(plugin1.GetGroup().has_value());
}
TEST_P(
PluginMetadataTest,
mergeMetadataShouldNotUseMergedGroupIfItIsImplicitAndCurrentGroupIsExplicit) {
PluginMetadata plugin1;
PluginMetadata plugin2;
@@ -161,6 +174,18 @@ TEST_P(PluginMetadataTest, mergeMetadataShouldNotUseMergedGroupIfItIsImplicit) {
EXPECT_EQ("group1", plugin1.GetGroup());
}
TEST_P(
PluginMetadataTest,
mergeMetadataShouldUseMergedGroupIfItIsExplicitAndCurrentGroupIsImplicit) {
PluginMetadata plugin1;
PluginMetadata plugin2;
plugin2.SetGroup("group2");
plugin1.MergeMetadata(plugin2);
EXPECT_EQ("group2", plugin1.GetGroup());
}
TEST_P(PluginMetadataTest, mergeMetadataShouldMergeLoadAfterData) {
PluginMetadata plugin1;
PluginMetadata plugin2;