2021-04-30 16:48:45 +02:00
|
|
|
package storetests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mattermost/focalboard/server/services/store"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-11-11 17:01:43 +01:00
|
|
|
// these system settings are created when running the data migrations,
|
|
|
|
// so they will be present after the tests setup.
|
|
|
|
var dataMigrationSystemSettings = map[string]string{
|
|
|
|
"UniqueIDsMigrationComplete": "true",
|
|
|
|
}
|
|
|
|
|
|
|
|
func addBaseSettings(m map[string]string) map[string]string {
|
|
|
|
r := map[string]string{}
|
|
|
|
for k, v := range dataMigrationSystemSettings {
|
|
|
|
r[k] = v
|
|
|
|
}
|
|
|
|
for k, v := range m {
|
|
|
|
r[k] = v
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2021-04-30 16:48:45 +02:00
|
|
|
func StoreTestSystemStore(t *testing.T, setup func(t *testing.T) (store.Store, func())) {
|
|
|
|
container := store.Container{
|
|
|
|
WorkspaceID: "0",
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("SetGetSystemSettings", func(t *testing.T) {
|
|
|
|
store, tearDown := setup(t)
|
|
|
|
defer tearDown()
|
|
|
|
testSetGetSystemSettings(t, store, container)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-06-21 11:21:42 +02:00
|
|
|
func testSetGetSystemSettings(t *testing.T, store store.Store, _ /*container*/ store.Container) {
|
2021-04-30 16:48:45 +02:00
|
|
|
t.Run("Get empty settings", func(t *testing.T) {
|
|
|
|
settings, err := store.GetSystemSettings()
|
|
|
|
require.NoError(t, err)
|
2021-11-11 17:01:43 +01:00
|
|
|
require.Equal(t, dataMigrationSystemSettings, settings)
|
2021-04-30 16:48:45 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Set, update and get multiple settings", func(t *testing.T) {
|
|
|
|
err := store.SetSystemSetting("test-1", "test-value-1")
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = store.SetSystemSetting("test-2", "test-value-2")
|
|
|
|
require.NoError(t, err)
|
|
|
|
settings, err := store.GetSystemSettings()
|
|
|
|
require.NoError(t, err)
|
2021-11-11 17:01:43 +01:00
|
|
|
require.Equal(t, addBaseSettings(map[string]string{"test-1": "test-value-1", "test-2": "test-value-2"}), settings)
|
2021-04-30 16:48:45 +02:00
|
|
|
|
|
|
|
err = store.SetSystemSetting("test-2", "test-value-updated-2")
|
|
|
|
require.NoError(t, err)
|
|
|
|
settings, err = store.GetSystemSettings()
|
|
|
|
require.NoError(t, err)
|
2021-11-11 17:01:43 +01:00
|
|
|
require.Equal(t, addBaseSettings(map[string]string{"test-1": "test-value-1", "test-2": "test-value-updated-2"}), settings)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get a single setting", func(t *testing.T) {
|
|
|
|
value, err := store.GetSystemSetting("test-1")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "test-value-1", value)
|
2021-04-30 16:48:45 +02:00
|
|
|
})
|
|
|
|
}
|