GODT-2181(test): Basic ATLAS test in test context

This commit is contained in:
James Houlahan
2022-12-13 01:46:02 +01:00
parent b9b4c1c38d
commit 9623e2de6f
6 changed files with 134 additions and 47 deletions

View File

@ -18,27 +18,73 @@
package tests
import (
"net/url"
"os"
"github.com/Masterminds/semver/v3"
"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/go-proton-api/server"
)
type API interface {
SetMinAppVersion(*semver.Version)
AddCallWatcher(func(server.Call), ...string)
GetHostURL() string
GetDomain() string
AddCallWatcher(func(server.Call), ...string)
RemoveAddressKey(userID, addrID, keyID string) error
GetAppVersion() string
Close()
}
func newTestAPI() API {
if hostURL := os.Getenv("FEATURE_TEST_HOST_URL"); hostURL != "" {
return newLiveAPI(hostURL)
}
return newFakeAPI()
}
type fakeAPI struct {
*server.Server
}
func newFakeAPI() *fakeAPI {
func newFakeAPI() API {
return &fakeAPI{
Server: server.New(),
}
}
func (api *fakeAPI) GetAppVersion() string {
return proton.DefaultAppVersion
}
type liveAPI struct {
*server.Server
domain string
}
func newLiveAPI(hostURL string) API {
url, err := url.Parse(hostURL)
if err != nil {
panic(err)
}
return &liveAPI{
Server: server.New(server.WithProxyOrigin(hostURL)),
domain: url.Hostname(),
}
}
func (api *liveAPI) GetHostURL() string {
return api.Server.GetProxyURL()
}
func (api *liveAPI) GetDomain() string {
return api.domain
}
func (api *liveAPI) GetAppVersion() string {
return os.Getenv("FEATURE_TEST_APP_VERSION")
}