mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-03 20:40:00 -05:00
* Adds a step to the config patch command to merge plugin configurations * Fix linter --------- Co-authored-by: Mattermost Build <build@mattermost.com>
101 lines
2.6 KiB
Go
101 lines
2.6 KiB
Go
// 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)
|
|
}
|