-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly merge plugin configuration on mmctl config patch (#26647)
* Adds a step to the config patch command to merge plugin configurations * Fix linter --------- Co-authored-by: Mattermost Build <[email protected]>
- Loading branch information
1 parent
4e32da6
commit bc49f34
Showing
4 changed files
with
225 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
package commands | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDeepMergeMaps(t *testing.T) { | ||
testCases := []struct { | ||
Name string | ||
Base map[string]any | ||
Patch map[string]any | ||
Expected map[string]any | ||
}{ | ||
{ | ||
Name: "Values of base doesn't exist in patch", | ||
Base: map[string]any{"Name": "John", "Surname": "Doe"}, | ||
Patch: map[string]any{"Name": "Jane"}, | ||
Expected: map[string]any{"Name": "Jane", "Surname": "Doe"}, | ||
}, | ||
{ | ||
Name: "Values of patch doesn't exist in base", | ||
Base: map[string]any{"Name": "John"}, | ||
Patch: map[string]any{"Name": "Jane", "Surname": "Doe"}, | ||
Expected: map[string]any{"Name": "Jane", "Surname": "Doe"}, | ||
}, | ||
{ | ||
Name: "Maps contain nested maps", | ||
Base: map[string]any{"Person": map[string]any{"Name": "John", "Surname": "Doe"}}, | ||
Patch: map[string]any{"Person": map[string]any{"Name": "Jane"}, "Age": 27}, | ||
Expected: map[string]any{"Person": map[string]any{"Name": "Jane", "Surname": "Doe"}, "Age": 27}, | ||
}, | ||
{ | ||
Name: "Values have different types", | ||
Base: map[string]any{"Person": "John Doe"}, | ||
Patch: map[string]any{"Person": map[string]any{"Name": "John", "Surname": "Doe"}}, | ||
Expected: map[string]any{"Person": map[string]any{"Name": "John", "Surname": "Doe"}}, | ||
}, | ||
{ | ||
Name: "Values have different types, reversed", | ||
Base: map[string]any{"Person": map[string]any{"Name": "John", "Surname": "Doe"}}, | ||
Patch: map[string]any{"Person": "John Doe"}, | ||
Expected: map[string]any{"Person": "John Doe"}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
require.Equal(t, DeepMergeMaps(tc.Base, tc.Patch), tc.Expected) | ||
}) | ||
} | ||
} | ||
|
||
func TestMergePluginConfigs(t *testing.T) { | ||
basePluginConfig := map[string]map[string]any{ | ||
"plugin.1": { | ||
"First": "key", | ||
"Second": map[string]any{ | ||
"nested": "key", | ||
}, | ||
}, | ||
"plugin.2": { | ||
"Name": "John", | ||
}, | ||
} | ||
|
||
patchPluginConfig := map[string]map[string]any{ | ||
"plugin.1": { | ||
"Second": map[string]any{ | ||
"nested": false, | ||
"new": 1, | ||
}, | ||
}, | ||
"plugin.3": { | ||
"New": "plugin", | ||
}, | ||
} | ||
|
||
expectedPluginConfig := map[string]map[string]any{ | ||
"plugin.1": { | ||
"First": "key", | ||
"Second": map[string]any{ | ||
"nested": false, | ||
"new": 1, | ||
}, | ||
}, | ||
"plugin.2": { | ||
"Name": "John", | ||
}, | ||
"plugin.3": { | ||
"New": "plugin", | ||
}, | ||
} | ||
|
||
mergedPluginConfigs := MergePluginConfigs(basePluginConfig, patchPluginConfig) | ||
require.Equal(t, expectedPluginConfig, mergedPluginConfigs) | ||
} |