2020-11-09 14:19:03 +02:00
|
|
|
package integrationtests
|
|
|
|
|
|
|
|
import (
|
2021-01-06 22:55:14 +02:00
|
|
|
"log"
|
2020-11-09 14:19:03 +02:00
|
|
|
"net/http"
|
2021-01-06 22:55:14 +02:00
|
|
|
"time"
|
2020-11-09 14:19:03 +02:00
|
|
|
|
2021-01-27 00:13:46 +02:00
|
|
|
"github.com/mattermost/focalboard/server/client"
|
|
|
|
"github.com/mattermost/focalboard/server/server"
|
|
|
|
"github.com/mattermost/focalboard/server/services/config"
|
2020-11-09 14:19:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type TestHelper struct {
|
|
|
|
Server *server.Server
|
|
|
|
Client *client.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func getTestConfig() *config.Configuration {
|
|
|
|
return &config.Configuration{
|
|
|
|
ServerRoot: "http://localhost:8888",
|
|
|
|
Port: 8888,
|
|
|
|
DBType: "sqlite3",
|
|
|
|
DBConfigString: ":memory:",
|
|
|
|
WebPath: "./pack",
|
|
|
|
FilesPath: "./files",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetupTestHelper() *TestHelper {
|
2021-02-10 02:07:41 +02:00
|
|
|
sessionToken := "TESTTOKEN"
|
2020-11-09 14:19:03 +02:00
|
|
|
th := &TestHelper{}
|
2021-02-10 02:07:41 +02:00
|
|
|
srv, err := server.New(getTestConfig(), sessionToken)
|
2020-11-09 14:19:03 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
th.Server = srv
|
2021-02-10 02:07:41 +02:00
|
|
|
th.Client = client.NewClient(srv.Config().ServerRoot, sessionToken)
|
2020-11-09 14:19:03 +02:00
|
|
|
|
|
|
|
return th
|
|
|
|
}
|
|
|
|
|
|
|
|
func (th *TestHelper) InitBasic() *TestHelper {
|
|
|
|
go func() {
|
2021-01-18 22:59:32 +02:00
|
|
|
if err := th.Server.Start(); err != nil {
|
2020-11-09 14:19:03 +02:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2021-01-06 22:55:14 +02:00
|
|
|
for {
|
|
|
|
URL := th.Server.Config().ServerRoot
|
|
|
|
log.Printf("Polling server at %v", URL)
|
|
|
|
resp, err := http.Get(URL)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Polling failed:", err)
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
resp.Body.Close()
|
|
|
|
|
|
|
|
// Currently returns 404
|
|
|
|
// if resp.StatusCode != http.StatusOK {
|
|
|
|
// log.Println("Not OK:", resp.StatusCode)
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Reached this point: server is up and running!
|
|
|
|
log.Println("Server ping OK, statusCode:", resp.StatusCode)
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2020-11-09 14:19:03 +02:00
|
|
|
return th
|
|
|
|
}
|
|
|
|
|
|
|
|
func (th *TestHelper) TearDown() {
|
|
|
|
err := th.Server.Shutdown()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|