Merge remote-tracking branch 'origin/benvin/timings' into benvin/named-deploy
# Conflicts: # internal/deploy/deploy.go
This commit is contained in:
@@ -628,7 +628,7 @@ func TestGenerateTypesBeforeSwap(t *testing.T) {
|
||||
newRepo(t, typed)
|
||||
commit(t, typed, map[string]string{
|
||||
"lib/puppet/type/typed.rb": "Puppet::Type.newtype(:typed) do\n newparam(:name, namevar: true)\nend\n",
|
||||
"lib/puppet/provider/typed/posix.rb": "",
|
||||
"lib/puppet/provider/typed/posix.rb": "Puppet::Type.type(:typed).provide(:posix) do\nend\n",
|
||||
})
|
||||
commit(t, f.control, map[string]string{
|
||||
"Puppetfile": fmt.Sprintf("moduledir 'external_modules'\nmod 'typed', :git => '%s'\n", f.url(typed)),
|
||||
@@ -658,7 +658,7 @@ func TestGenerateTypesBeforeSwap(t *testing.T) {
|
||||
}
|
||||
live = skipped
|
||||
|
||||
commit(t, f.control, map[string]string{"site/local/lib/puppet/type/local.rb": "Puppet::Type.newtype(:local) do\n newparam(:name)\nend\n" + strings.Repeat("module A\n", 300) + strings.Repeat("end\n", 300)})
|
||||
commit(t, f.control, map[string]string{"site/local/lib/puppet/type/local.rb": "Puppet::Type.newtype(:local) do\n newparam(:name) do\n newvalues(" + strings.Repeat("[", 300) + strings.Repeat("]", 300) + ")\n end\nend\n"})
|
||||
if err := f.deploy(false); err == nil || !strings.Contains(err.Error(), "deeper than") || !strings.Contains(err.Error(), "site/local/lib/puppet/type/local.rb") {
|
||||
t.Fatalf("a parser limit must fail the deploy naming the file: %v", err)
|
||||
}
|
||||
@@ -1086,3 +1086,84 @@ func TestConcurrentWorktreeAddsOneMirror(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGCRefsErrorDropsMarkOfLiveWorktree(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
s := &Source{Name: "s", Basedir: filepath.Join(root, "envs")}
|
||||
cfg := &Config{Cachedir: filepath.Join(root, "cache"), Sources: map[string]*Source{"s": s}}
|
||||
clock := time.Unix(1_700_000_000, 0)
|
||||
gc := func() error {
|
||||
d := New(cfg, 1, 10*time.Minute)
|
||||
d.now = func() time.Time { return clock }
|
||||
return d.GC(context.Background())
|
||||
}
|
||||
d := New(cfg, 1, 0)
|
||||
old, cur, broken := filepath.Join(d.srcWorktrees(s), "old"), filepath.Join(d.srcWorktrees(s), "cur"), filepath.Join(d.srcWorktrees(s), "broken")
|
||||
mkdirs(t, old, cur, broken, s.Basedir, filepath.Dir(d.doneFile(old)))
|
||||
for _, p := range []string{old, cur} {
|
||||
if err := os.WriteFile(d.doneFile(p), []byte(`{"modules":[]}`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
link := filepath.Join(s.Basedir, "develop")
|
||||
if err := Swap(cur, link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := gc(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
clock = clock.Add(time.Hour)
|
||||
if err := Swap(old, link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := Swap(broken, filepath.Join(s.Basedir, "other")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := gc(); err == nil {
|
||||
t.Fatal("want moduleRefs error from live worktree without done file")
|
||||
}
|
||||
if err := os.WriteFile(d.doneFile(broken), []byte(`{"modules":[]}`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := Swap(cur, link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = gc()
|
||||
if !exists(old) {
|
||||
t.Fatal("worktree unreferenced this run was deleted in the same run via a stale mark kept while it was live")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeployOnlyLeavesLaterSourceAlone(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
commit(t, f.control, map[string]string{"manifests/site.pp": "node default {}\n"})
|
||||
gitT(t, f.control, "branch", "production")
|
||||
other := filepath.Join(f.root, "other")
|
||||
newRepo(t, other)
|
||||
commit(t, other, map[string]string{"manifests/site.pp": "node default {}\n"})
|
||||
otherBase := filepath.Join(f.root, "other-envs")
|
||||
cfg, err := ParseConfig(fmt.Appendf(nil, "cachedir: %s\nsources:\n aaa:\n remote: %s\n basedir: %s\n zzz:\n remote: %s\n basedir: %s\n", f.cfg.Cachedir, f.control, f.basedir, other, otherBase))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f.cfg = cfg
|
||||
if err := f.deploy(false, "production"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if exists(filepath.Join(otherBase, "main")) {
|
||||
t.Fatal("deploy production also deployed every env of the next source")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeployMarkerNameIsBranch(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
commit(t, f.control, map[string]string{"manifests/site.pp": "node default {}\n"})
|
||||
gitT(t, f.control, "checkout", "-q", "-b", "feat/x")
|
||||
commit(t, f.control, map[string]string{"manifests/site.pp": "node x {}\n"})
|
||||
if err := f.deploy(false, "feat_x"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m := readMarker(t, f.env("feat_x")); m.Name != "feat/x" {
|
||||
t.Fatalf("marker name %q, want branch feat/x", m.Name)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user