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 удалений

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

@@ -57,6 +57,28 @@ func Setup(t testing.TB) *testHelper {
return testHelper
}
// Setup creates an instance of testHelper.
func SetupWithStoreMock(t testing.TB) *testHelper {
dir, err := ioutil.TempDir("", "testHelper")
if err != nil {
panic("failed to create temporary directory: " + err.Error())
}
api4TestHelper := api4.SetupWithStoreMock(t)
testHelper := &testHelper{
TestHelper: api4TestHelper,
tempDir: dir,
configFilePath: filepath.Join(dir, "config-helper.json"),
}
config := &model.Config{}
config.SetDefaults()
testHelper.SetConfig(config)
return testHelper
}
// InitBasic simply proxies to api4.InitBasic, while still returning a testHelper.
func (h *testHelper) InitBasic() *testHelper {
h.TestHelper.InitBasic()
@@ -80,7 +102,9 @@ func (h *testHelper) ConfigPath() string {
// SetConfig replaces the configuration passed to a running command.
func (h *testHelper) SetConfig(config *model.Config) {
config.SqlSettings = *mainHelper.GetSQLSettings()
if !testing.Short() {
config.SqlSettings = *mainHelper.GetSQLSettings()
}
// Disable strict password requirements for test
*config.PasswordSettings.MinimumLength = 5

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

@@ -8,7 +8,6 @@ import (
"os"
"testing"
"github.com/mattermost/mattermost-server/v5/api4"
"github.com/mattermost/mattermost-server/v5/testlib"
)
@@ -30,7 +29,5 @@ func TestMain(m *testing.M) {
mainHelper = testlib.NewMainHelperWithOptions(&options)
defer mainHelper.Close()
api4.UseTestStore(mainHelper.GetStore())
mainHelper.Main(m)
}

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

@@ -22,6 +22,9 @@ type ServerTestHelper struct {
}
func SetupServerTest(t testing.TB) *ServerTestHelper {
if testing.Short() {
t.SkipNow()
}
// Build a channel that will be used by the server to receive system signals...
interruptChan := make(chan os.Signal, 1)
// ...and sent it immediately a SIGINT value.

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

@@ -8,7 +8,7 @@ import (
)
func TestVersion(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
th.CheckCommand(t, "version")