* 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>
137 lines
3.8 KiB
Go
137 lines
3.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
commonParams "github.com/cloudbase/garm-provider-common/params"
|
|
"github.com/cloudbase/garm/params"
|
|
"github.com/cloudbase/garm/test/integration/e2e"
|
|
)
|
|
|
|
const (
|
|
adminUsername = "admin"
|
|
adminFullName = "GARM Admin"
|
|
adminEmail = "admin@example.com"
|
|
)
|
|
|
|
var (
|
|
baseURL = os.Getenv("GARM_BASE_URL")
|
|
adminPassword = os.Getenv("GARM_PASSWORD")
|
|
credentialsName = os.Getenv("CREDENTIALS_NAME")
|
|
|
|
repoName = os.Getenv("REPO_NAME")
|
|
repoWebhookSecret = os.Getenv("REPO_WEBHOOK_SECRET")
|
|
repoPoolParams = params.CreatePoolParams{
|
|
MaxRunners: 2,
|
|
MinIdleRunners: 0,
|
|
Flavor: "default",
|
|
Image: "ubuntu:22.04",
|
|
OSType: commonParams.Linux,
|
|
OSArch: commonParams.Amd64,
|
|
ProviderName: "lxd_local",
|
|
Tags: []string{"repo-runner"},
|
|
Enabled: true,
|
|
}
|
|
|
|
orgName = os.Getenv("ORG_NAME")
|
|
orgWebhookSecret = os.Getenv("ORG_WEBHOOK_SECRET")
|
|
orgPoolParams = params.CreatePoolParams{
|
|
MaxRunners: 2,
|
|
MinIdleRunners: 0,
|
|
Flavor: "default",
|
|
Image: "ubuntu:22.04",
|
|
OSType: commonParams.Linux,
|
|
OSArch: commonParams.Amd64,
|
|
ProviderName: "lxd_local",
|
|
Tags: []string{"org-runner"},
|
|
Enabled: true,
|
|
}
|
|
|
|
ghToken = os.Getenv("GH_TOKEN")
|
|
workflowFileName = os.Getenv("WORKFLOW_FILE_NAME")
|
|
)
|
|
|
|
func main() {
|
|
/////////////
|
|
// Cleanup //
|
|
/////////////
|
|
defer e2e.GracefulCleanup()
|
|
|
|
///////////////
|
|
// garm init //
|
|
///////////////
|
|
e2e.InitClient(baseURL)
|
|
e2e.FirstRun(adminUsername, adminPassword, adminFullName, adminEmail)
|
|
e2e.Login(adminUsername, adminPassword)
|
|
|
|
// //////////////////
|
|
// controller info //
|
|
// //////////////////
|
|
e2e.GetControllerInfo()
|
|
|
|
// ////////////////////////////
|
|
// credentials and providers //
|
|
// ////////////////////////////
|
|
e2e.ListCredentials()
|
|
e2e.ListProviders()
|
|
|
|
////////////////////
|
|
/// metrics token //
|
|
////////////////////
|
|
e2e.GetMetricsToken()
|
|
|
|
//////////////////
|
|
// repositories //
|
|
//////////////////
|
|
repo := e2e.CreateRepo(orgName, repoName, credentialsName, repoWebhookSecret)
|
|
repo = e2e.UpdateRepo(repo.ID, fmt.Sprintf("%s-clone", credentialsName))
|
|
e2e.InstallRepoWebhook(repo.ID)
|
|
// TODO:
|
|
// * Check that the webhook is properly installed in GitHub.
|
|
// * Uninstall webhook
|
|
// * Check that webhook is properly removed from GitHub.
|
|
// * Install webhook again.
|
|
|
|
repoPool := e2e.CreateRepoPool(repo.ID, repoPoolParams)
|
|
repoPool = e2e.GetRepoPool(repo.ID, repoPool.ID)
|
|
e2e.DeleteRepoPool(repo.ID, repoPool.ID)
|
|
|
|
repoPool = e2e.CreateRepoPool(repo.ID, repoPoolParams)
|
|
_ = e2e.UpdateRepoPool(repo.ID, repoPool.ID, repoPoolParams.MaxRunners, 1)
|
|
|
|
///////////////////
|
|
// organizations //
|
|
///////////////////
|
|
org := e2e.CreateOrg(orgName, credentialsName, orgWebhookSecret)
|
|
org = e2e.UpdateOrg(org.ID, fmt.Sprintf("%s-clone", credentialsName))
|
|
e2e.InstallOrgWebhook(org.ID)
|
|
// TODO:
|
|
// * Check that the webhook is properly installed in GitHub.
|
|
// * Uninstall webhook
|
|
// * Check that webhook is properly removed from GitHub.
|
|
// * Install webhook again.
|
|
|
|
orgPool := e2e.CreateOrgPool(org.ID, orgPoolParams)
|
|
orgPool = e2e.GetOrgPool(org.ID, orgPool.ID)
|
|
e2e.DeleteOrgPool(org.ID, orgPool.ID)
|
|
|
|
orgPool = e2e.CreateOrgPool(org.ID, orgPoolParams)
|
|
_ = e2e.UpdateOrgPool(org.ID, orgPool.ID, orgPoolParams.MaxRunners, 1)
|
|
|
|
///////////////
|
|
// instances //
|
|
///////////////
|
|
e2e.WaitRepoRunningIdleInstances(repo.ID, 6*time.Minute)
|
|
e2e.WaitOrgRunningIdleInstances(org.ID, 6*time.Minute)
|
|
|
|
//////////
|
|
// jobs //
|
|
//////////
|
|
e2e.TriggerWorkflow(ghToken, orgName, repoName, workflowFileName, "org-runner")
|
|
e2e.ValidateJobLifecycle("org-runner")
|
|
|
|
e2e.TriggerWorkflow(ghToken, orgName, repoName, workflowFileName, "repo-runner")
|
|
e2e.ValidateJobLifecycle("repo-runner")
|
|
}
|