garm/test/integration/e2e/client.go
Ionut Balutoiu 318bc52b57 Refactor integration E2E tests
* General cleanup of the integration tests Golang code. Move the
  `e2e.go` codebase into its own package and separate files.
* Reduce the overall log spam from the integration tests output.
* Add final GitHub workflow step that stops GARM server, and does the
  GitHub cleanup of any orphaned resources.
* Add `TODO` to implement cleanup of the orphaned GitHub webhooks.
  This is useful, if the uninstall of the webhooks failed.
* Add `TODO` for extra missing checks on the GitHub webhooks
  install / uninstall logic.

Signed-off-by: Ionut Balutoiu <ibalutoiu@cloudbasesolutions.com>
2023-08-24 15:22:46 +03:00

60 lines
1.3 KiB
Go

package e2e
import (
"log"
"net/url"
"github.com/cloudbase/garm/client"
"github.com/cloudbase/garm/params"
"github.com/go-openapi/runtime"
openapiRuntimeClient "github.com/go-openapi/runtime/client"
)
var (
cli *client.GarmAPI
authToken runtime.ClientAuthInfoWriter
)
func InitClient(baseURL string) {
garmUrl, err := url.Parse(baseURL)
if err != nil {
panic(err)
}
apiPath, err := url.JoinPath(garmUrl.Path, client.DefaultBasePath)
if err != nil {
panic(err)
}
transportCfg := client.DefaultTransportConfig().
WithHost(garmUrl.Host).
WithBasePath(apiPath).
WithSchemes([]string{garmUrl.Scheme})
cli = client.NewHTTPClientWithConfig(nil, transportCfg)
}
func FirstRun(adminUsername, adminPassword, adminFullName, adminEmail string) *params.User {
log.Println("First run")
newUser := params.NewUserParams{
Username: adminUsername,
Password: adminPassword,
FullName: adminFullName,
Email: adminEmail,
}
user, err := firstRun(cli, newUser)
if err != nil {
panic(err)
}
return &user
}
func Login(username, password string) {
log.Println("Login")
loginParams := params.PasswordLoginParams{
Username: username,
Password: password,
}
token, err := login(cli, loginParams)
if err != nil {
panic(err)
}
authToken = openapiRuntimeClient.BearerToken(token)
}