focalboard/server/services/store/storetests/system.go

68 lines
2 KiB
Go
Raw Normal View History

2021-04-30 16:48:45 +02:00
package storetests
import (
"testing"
"github.com/mattermost/focalboard/server/services/store"
"github.com/stretchr/testify/require"
)
// 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)
})
}
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)
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)
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)
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
})
}