Adding changes to separate unit tests and integration tests (#13670)

* Introducing unit (not integration) tests for the app layer

* Initial support for unit tests at the API

* Adding unit tests support to the store layer

* Add unit tests support in commands

* Adding last tests needed for run unit tests properly

* Fixing govet

* Removing some duplication

* Fixing tests

* Fixing tests

* Not compiling test helpers with the main module for api

* Revert "Not compiling test helpers with the main module for api"

This reverts commit 36a199bbe0f7503f665f5d6c7b41c53aabc2e54f.

* Fixing tests

* Fixing unit tests

* More consistency between api4/apiteslib.go and app/helper_test.go

* Renaming things to make more obvious the new Setup functions purpose

* Reverting change in go.sum

* Start with empty mock for app layer

* Start with empty mock for api layer

* Start with empty mock for web layer

* Renaming SetupWithStoreMockConfig to SetupConfigWithStoreMock

* Fixing tests on web package

* Removing unnecesary function
Этот коммит содержится в:
Jesús Espino
2020-03-02 17:13:39 +01:00
коммит произвёл GitHub
родитель cd36c9f041
Коммит 7035e09fe9
27 изменённых файлов: 720 добавлений и 187 удалений

Просмотреть файл

@@ -17,6 +17,9 @@ import (
"github.com/mattermost/mattermost-server/v5/config"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/mattermost/mattermost-server/v5/testlib"
"github.com/mattermost/mattermost-server/v5/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -39,10 +42,28 @@ type TestHelper struct {
tempWorkspace string
}
func SetupWithStoreMock(tb testing.TB) *TestHelper {
if testing.Short() {
tb.SkipNow()
}
store := testlib.GetMockStoreForSetupFunctions()
th := setupTestHelper(tb, store)
emptyMockStore := mocks.Store{}
emptyMockStore.On("Close").Return(nil)
th.App.Srv().Store = &emptyMockStore
return th
}
func Setup(tb testing.TB) *TestHelper {
if testing.Short() {
tb.SkipNow()
}
store := mainHelper.GetStore()
store.DropAllTables()
return setupTestHelper(tb, store)
}
func setupTestHelper(t testing.TB, store store.Store) *TestHelper {
memoryStore, err := config.NewMemoryStoreWithOptions(&config.MemoryStoreOptions{IgnoreEnvironmentOverrides: true})
if err != nil {
panic("failed to initialize memory store: " + err.Error())