Test named deploys and timing phase keys
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -770,3 +771,74 @@ func TestGCKeepsModulesOfRemovedSource(t *testing.T) {
|
||||
t.Fatalf("GC deleted a module still linked from a removed source's live env: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamedDeployTouchesOnlyNamed(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
commit(t, f.control, map[string]string{"Puppetfile": f.puppetfile(), "manifests/site.pp": "node default {}\n"})
|
||||
gitT(t, f.control, "branch", "gone")
|
||||
commit(t, f.control, map[string]string{"manifests/site.pp": "node default { }\n"})
|
||||
gitT(t, f.control, "branch", "benvin/foo-bar")
|
||||
f.mustDeploy(false)
|
||||
gone := f.env("gone")
|
||||
gitT(t, f.control, "branch", "-D", "gone")
|
||||
f.mustDeploy(false)
|
||||
f.clock = f.clock.Add(11 * time.Minute)
|
||||
state := readFileT(t, f.cache(gcStateFile))
|
||||
|
||||
sha := commit(t, f.control, map[string]string{"manifests/site.pp": "node x {}\n"})
|
||||
gitT(t, f.control, "branch", "-f", "benvin/foo-bar", "main")
|
||||
main := f.env("main")
|
||||
if err := f.deploy(false, "benvin/foo-bar"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.HasPrefix(filepath.Base(f.env("benvin_foo_bar")), sha+"-") {
|
||||
t.Fatal("a raw branch name deploys its sanitised env")
|
||||
}
|
||||
if f.env("main") != main || !exists(gone) || readFileT(t, f.cache(gcStateFile)) != state {
|
||||
t.Fatal("a named deploy must leave other envs, their worktrees and GC state untouched")
|
||||
}
|
||||
if err := f.deploy(false, "main"); err != nil || !strings.HasPrefix(filepath.Base(f.env("main")), sha+"-") {
|
||||
t.Fatalf("env name deploys: %v", err)
|
||||
}
|
||||
if err := f.deploy(false, "main", "nope"); err == nil || !strings.Contains(err.Error(), "nope not found") {
|
||||
t.Fatalf("unknown env must error: %v", err)
|
||||
}
|
||||
if !exists(gone) {
|
||||
t.Fatal("named deploys never GC")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimingsPhases(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.cfg.W10k.GenerateTypes = true
|
||||
commit(t, f.control, map[string]string{"Puppetfile": f.puppetfile()})
|
||||
var buf bytes.Buffer
|
||||
d := f.deployer()
|
||||
d.Timings = slog.New(slog.NewTextHandler(&buf, nil))
|
||||
unlock, err := d.Lock()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
unlock()
|
||||
for range 2 {
|
||||
if err := d.Deploy(context.Background(), nil, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
out := buf.String()
|
||||
for _, want := range []string{
|
||||
"phase=lock ", "phase=source.fetch ", "phase=source.branches ", "phase=env.resolve ", "phase=env.puppetfile ",
|
||||
"phase=module.resolve ", "phase=module.fetch ", "phase=module.worktree ", "phase=module.download ", "phase=module.extract ",
|
||||
"phase=module.link ", "phase=env.worktree ", "phase=env.generate_types ", "phase=env.marker ", "phase=env.swap ",
|
||||
"phase=env.total ", "phase=env.skip ", "reason=unchanged", "phase=gc.mark ", "phase=gc.delete ", "phase=run ",
|
||||
" dur=", " wait=", " source=unkin", " env=main", " module=bind", " module=acme-thing", " cache=hit", " cache=miss",
|
||||
" generated=", " up_to_date=", " skipped=", " marked=", " removed=", " created=1", " updated=", " unchanged=1", " failed=",
|
||||
} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Errorf("timings lack %q", want)
|
||||
}
|
||||
}
|
||||
if t.Failed() {
|
||||
t.Log(out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user