60 lines
2.6 KiB
Go
60 lines
2.6 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/Pingu-Studio/MaidnCLI/internal/config"
|
|
)
|
|
|
|
func freshPlanConfig(t *testing.T) config.Config {
|
|
t.Helper()
|
|
workspace := t.TempDir()
|
|
return config.Config{
|
|
WorkspaceDir: workspace,
|
|
Git: config.GitConfig{Provider: "forgejo", BaseURL: "https://git.example.test", Username: "bot", Token: "token", CloneParent: filepath.Join(workspace, "checkouts")},
|
|
Flux: config.FluxConfig{RepoName: "cluster", Branch: "main", ClusterPath: "./clusters/cluster", ClusterDomain: "cluster.example.test", ManifestsRepo: "manifests", TektonCatalogRepo: "catalog"},
|
|
Talos: config.TalosConfig{RepoDirName: "talos", GeneratedDir: "generated"},
|
|
Delivery: config.DeliveryConfig{AppName: "app", AppRepoURL: "https://git.example.test/new-org/app.git", AppRepoRef: "main", ProductionBranch: "production", ImageRepository: "registry.example.test/new-org/app", BuildOutputDirectory: "dist", BuildConfiguration: "production", WebhookHostname: "tekton.cluster.example.test", WebhookPath: "/"},
|
|
Templates: config.TemplateConfig{
|
|
TalosRepoURL: "https://git.example.test/templates/talos.git", TalosRepoRef: "main",
|
|
CICDRepoURL: "https://git.example.test/templates/cicd.git", CICDRepoRef: "main",
|
|
ManifestsRepoURL: "https://git.example.test/templates/manifests.git", ManifestsRepoRef: "main",
|
|
TektonCatalogRepoURL: "https://git.example.test/templates/catalog.git", TektonCatalogRepoRef: "main",
|
|
},
|
|
}
|
|
}
|
|
|
|
func TestPlanFreshOrganizationOrdersOnlyFreshPhases(t *testing.T) {
|
|
cfg := freshPlanConfig(t)
|
|
resolved, plan, err := PlanFreshOrganization(cfg, FreshOrganizationOptions{Organization: "new-org", CreateOrganization: true, EnableDelivery: true})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if resolved.Git.Owner != "new-org" {
|
|
t.Fatal("organization was not bound to the fresh configuration")
|
|
}
|
|
want := []string{
|
|
"validate isolated workspace and configuration",
|
|
"lock template revisions in the isolated workspace",
|
|
"ensure the Forgejo organization",
|
|
"ensure baseline Flux and manifests repositories",
|
|
"initialize the user-managed Tekton catalog repository",
|
|
}
|
|
if !reflect.DeepEqual(plan.Phases, want) {
|
|
t.Fatalf("plan phases = %#v, want %#v", plan.Phases, want)
|
|
}
|
|
}
|
|
|
|
func TestPlanFreshOrganizationRejectsUnrecognizedWorkspaceState(t *testing.T) {
|
|
cfg := freshPlanConfig(t)
|
|
if err := os.WriteFile(filepath.Join(cfg.WorkspaceDir, "leftover"), []byte("state"), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, _, err := PlanFreshOrganization(cfg, FreshOrganizationOptions{Organization: "new-org", CreateOrganization: true}); err == nil {
|
|
t.Fatal("ambiguous workspace state was accepted")
|
|
}
|
|
}
|