2020-11-09 13:19:03 +01:00
|
|
|
package integrationtests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2021-04-22 22:53:01 +02:00
|
|
|
"os"
|
2021-01-06 21:55:14 +01:00
|
|
|
"time"
|
2020-11-09 13:19:03 +01:00
|
|
|
|
2021-01-26 23:13:46 +01:00
|
|
|
"github.com/mattermost/focalboard/server/client"
|
|
|
|
"github.com/mattermost/focalboard/server/server"
|
|
|
|
"github.com/mattermost/focalboard/server/services/config"
|
2021-05-29 08:23:10 +02:00
|
|
|
"github.com/mattermost/focalboard/server/services/mlog"
|
2020-11-09 13:19:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type TestHelper struct {
|
|
|
|
Server *server.Server
|
|
|
|
Client *client.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func getTestConfig() *config.Configuration {
|
2021-04-22 22:53:01 +02:00
|
|
|
dbType := os.Getenv("FB_STORE_TEST_DB_TYPE")
|
|
|
|
if dbType == "" {
|
|
|
|
dbType = "sqlite3"
|
|
|
|
}
|
|
|
|
|
|
|
|
connectionString := os.Getenv("FB_STORE_TEST_CONN_STRING")
|
|
|
|
if connectionString == "" {
|
|
|
|
connectionString = ":memory:"
|
|
|
|
}
|
|
|
|
|
2021-06-04 16:38:49 +02:00
|
|
|
logging := `
|
2021-05-29 08:23:10 +02:00
|
|
|
{
|
|
|
|
"testing": {
|
|
|
|
"type": "console",
|
|
|
|
"options": {
|
|
|
|
"out": "stdout"
|
|
|
|
},
|
|
|
|
"format": "plain",
|
|
|
|
"format_options": {
|
|
|
|
"delim": " "
|
|
|
|
},
|
|
|
|
"levels": [
|
|
|
|
{"id": 5, "name": "debug"},
|
|
|
|
{"id": 4, "name": "info"},
|
|
|
|
{"id": 3, "name": "warn"},
|
|
|
|
{"id": 2, "name": "error", "stacktrace": true},
|
|
|
|
{"id": 1, "name": "fatal", "stacktrace": true},
|
|
|
|
{"id": 0, "name": "panic", "stacktrace": true}
|
|
|
|
]
|
|
|
|
}
|
2021-06-04 16:38:49 +02:00
|
|
|
}`
|
2021-05-29 08:23:10 +02:00
|
|
|
|
2020-11-09 13:19:03 +01:00
|
|
|
return &config.Configuration{
|
2021-05-29 08:23:10 +02:00
|
|
|
ServerRoot: "http://localhost:8888",
|
|
|
|
Port: 8888,
|
|
|
|
DBType: dbType,
|
|
|
|
DBConfigString: connectionString,
|
|
|
|
DBTablePrefix: "test_",
|
|
|
|
WebPath: "./pack",
|
|
|
|
FilesDriver: "local",
|
|
|
|
FilesPath: "./files",
|
2021-06-04 16:38:49 +02:00
|
|
|
LoggingEscapedJson: logging,
|
2020-11-09 13:19:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetupTestHelper() *TestHelper {
|
2021-02-10 01:07:41 +01:00
|
|
|
sessionToken := "TESTTOKEN"
|
2020-11-09 13:19:03 +01:00
|
|
|
th := &TestHelper{}
|
2021-05-29 08:23:10 +02:00
|
|
|
logger := mlog.NewLogger()
|
|
|
|
logger.Configure("", getTestConfig().LoggingEscapedJson)
|
|
|
|
srv, err := server.New(getTestConfig(), sessionToken, logger)
|
2020-11-09 13:19:03 +01:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
th.Server = srv
|
2021-02-10 01:07:41 +01:00
|
|
|
th.Client = client.NewClient(srv.Config().ServerRoot, sessionToken)
|
2020-11-09 13:19:03 +01:00
|
|
|
|
|
|
|
return th
|
|
|
|
}
|
|
|
|
|
|
|
|
func (th *TestHelper) InitBasic() *TestHelper {
|
|
|
|
go func() {
|
2021-01-18 21:59:32 +01:00
|
|
|
if err := th.Server.Start(); err != nil {
|
2020-11-09 13:19:03 +01:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2021-01-06 21:55:14 +01:00
|
|
|
for {
|
|
|
|
URL := th.Server.Config().ServerRoot
|
2021-05-29 08:23:10 +02:00
|
|
|
th.Server.Logger().Info("Polling server", mlog.String("url", URL))
|
2021-01-06 21:55:14 +01:00
|
|
|
resp, err := http.Get(URL)
|
|
|
|
if err != nil {
|
2021-05-29 08:23:10 +02:00
|
|
|
th.Server.Logger().Error("Polling failed", mlog.Err(err))
|
2021-01-06 21:55:14 +01:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
resp.Body.Close()
|
|
|
|
|
|
|
|
// Currently returns 404
|
|
|
|
// if resp.StatusCode != http.StatusOK {
|
2021-05-29 08:23:10 +02:00
|
|
|
// th.Server.Logger().Error("Not OK", mlog.Int("statusCode", resp.StatusCode))
|
2021-01-06 21:55:14 +01:00
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Reached this point: server is up and running!
|
2021-05-29 08:23:10 +02:00
|
|
|
th.Server.Logger().Info("Server ping OK", mlog.Int("statusCode", resp.StatusCode))
|
2021-01-06 21:55:14 +01:00
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2020-11-09 13:19:03 +01:00
|
|
|
return th
|
|
|
|
}
|
|
|
|
|
|
|
|
func (th *TestHelper) TearDown() {
|
2021-05-29 08:23:10 +02:00
|
|
|
defer th.Server.Logger().Shutdown()
|
|
|
|
|
2020-11-09 13:19:03 +01:00
|
|
|
err := th.Server.Shutdown()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|