focalboard/server/services/store/storetests/system.go
Miguel de la Cruz e7c38c8822
Adds data migrations and the unique IDs migration (#1776)
* Adds data migrations and the unique IDs migration

* Adds GetSystemSetting tests

* Add log statements to data migrations

* Move migrations to the store and ensure they follow an order mixing database and data migrations

* Fix system settings

* Add tests for unique id migration

* Small comment change

* Make a couple of methods private and wrap the migration in a transaction

* Update public methods

* Add database mutex to data migrations

* Create server params and pass a mutex factory to the store

* Fix plugin linter

* Make isPlugin private

* Fix comment typo

Co-authored-by: Doug Lauder <wiggin77@warpmail.net>

Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
2021-11-11 17:01:43 +01:00

67 lines
2 KiB
Go

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
}
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) {
t.Run("Get empty settings", func(t *testing.T) {
settings, err := store.GetSystemSettings()
require.NoError(t, err)
require.Equal(t, dataMigrationSystemSettings, settings)
})
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)
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)
})
}