focalboard/server/integrationtests/clienttestlib.go
Jesús Espino f1b8d88d6b
Changing mattermost-auth method to work based on shared database access (#335)
* Improving mattermost auth implementation

* Making mattermost-auth based on shared database access

* Reverting unneeded changes in the config.json file

* Fixing tiny problems

* Removing the need of using the mattermost session token

* Fixing some bugs and allowing to not-bind the server to any port

* Small fix to correctly get the templates

* Adding the mattermost-plugin code inside focalboard repo

* Adding a not working code part of the cluster websocket communication

* Updating the mattermost version

* Adding the cluster messages for the websockets

* Updating to the new node version

* Making it compatible with S3

* Addressing some tiny problems

* Fixing server tests

* Adds support for MySQL migrations and initialization

Co-authored-by: Miguel de la Cruz <miguel@mcrx.me>
2021-05-24 19:06:11 +02:00

93 lines
1.8 KiB
Go

package integrationtests
import (
"log"
"net/http"
"os"
"time"
"github.com/mattermost/focalboard/server/client"
"github.com/mattermost/focalboard/server/server"
"github.com/mattermost/focalboard/server/services/config"
)
type TestHelper struct {
Server *server.Server
Client *client.Client
}
func getTestConfig() *config.Configuration {
dbType := os.Getenv("FB_STORE_TEST_DB_TYPE")
if dbType == "" {
dbType = "sqlite3"
}
connectionString := os.Getenv("FB_STORE_TEST_CONN_STRING")
if connectionString == "" {
connectionString = ":memory:"
}
return &config.Configuration{
ServerRoot: "http://localhost:8888",
Port: 8888,
DBType: dbType,
DBConfigString: connectionString,
DBTablePrefix: "test_",
WebPath: "./pack",
FilesDriver: "local",
FilesPath: "./files",
}
}
func SetupTestHelper() *TestHelper {
sessionToken := "TESTTOKEN"
th := &TestHelper{}
srv, err := server.New(getTestConfig(), sessionToken)
if err != nil {
panic(err)
}
th.Server = srv
th.Client = client.NewClient(srv.Config().ServerRoot, sessionToken)
return th
}
func (th *TestHelper) InitBasic() *TestHelper {
go func() {
if err := th.Server.Start(); err != nil {
panic(err)
}
}()
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
}
return th
}
func (th *TestHelper) TearDown() {
err := th.Server.Shutdown()
if err != nil {
panic(err)
}
}