mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 15:51:26 +00:00
Preview environments were bookkeeping only: a fabricated deployment row marked "running" and a fake *.preview.containr.local URL. Now a preview is a real service clone — full config copy (source, env, volumes, access), git_branch pinned to the requested branch, its own preview hostname under the clone's node default domain, and a real deployment through the queue. - cloneServiceRow extracted from handleCloneService for reuse - preview_environments.preview_service_id links to the clone - minute sweeper: expires past-TTL previews (removes clone runtime + row) and syncs preview status from the clone's live service status - delete/cleanup paths tear the clone down, not just the row - promote redeploys the SOURCE service at the preview branch and retires the clone — a real deployment, not a pending stub Verified live: create → clone → deploy → running container; TTL expiry → clone + container gone; promote → real deploy on the source, preview stopped. Unit test covers the DNS-safe clone naming. Generated with [Devin](https://devin.ai) Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
31 lines
792 B
Go
31 lines
792 B
Go
package api
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPreviewServiceName(t *testing.T) {
|
|
cases := []struct {
|
|
svc, branch string
|
|
want string
|
|
}{
|
|
{"whoami-web", "feature-x", "whoami-web-feature-x-preview"},
|
|
{"My App", "feat/JARV-123_foo", "my-app-feat-jarv-123-foo-preview"},
|
|
{"svc", "", "svc-preview"},
|
|
}
|
|
for _, tc := range cases {
|
|
got := previewServiceName(tc.svc, tc.branch)
|
|
if got != tc.want {
|
|
t.Fatalf("previewServiceName(%q,%q) = %q, want %q", tc.svc, tc.branch, got, tc.want)
|
|
}
|
|
if len(got) > 63 {
|
|
t.Fatalf("name exceeds DNS label limit: %q", got)
|
|
}
|
|
}
|
|
// A name that sanitizes to nothing must still be usable.
|
|
if got := previewServiceName("!!!", "%%%"); !strings.HasPrefix(got, "preview-") {
|
|
t.Fatalf("expected fallback name, got %q", got)
|
|
}
|
|
}
|