Resolve named deploys over all branches and sources before filtering
- pick env winners over every branch, then select, so a named deploy matches a full deploy - match env names across sources first, raw branch names only when no env matches - report collision and invalid-name errors only for the named args - add tests for collision losers, all-corrected collisions, prefixed sources and unrelated invalid branches
This commit is contained in:
@@ -844,6 +844,77 @@ func TestNamedDeployTouchesOnlyNamed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamedDeployCollisionLoserKeepsOut(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", "a_b")
|
||||
win := commit(t, f.control, map[string]string{"manifests/site.pp": "node a {}\n"})
|
||||
gitT(t, f.control, "checkout", "-q", "-b", "a-b")
|
||||
commit(t, f.control, map[string]string{"manifests/site.pp": "node b {}\n"})
|
||||
_ = f.deploy(false)
|
||||
err := f.deploy(false, "a-b")
|
||||
if !strings.HasPrefix(filepath.Base(f.env("a_b")), win+"-") {
|
||||
t.Fatalf("named deploy of collision loser a-b took env a_b: %s", f.env("a_b"))
|
||||
}
|
||||
if err == nil || !strings.Contains(err.Error(), "a-b collides") {
|
||||
t.Fatalf("want collision error for a-b, got %v", err)
|
||||
}
|
||||
if err := f.deploy(false, "a_b"); err != nil || !strings.HasPrefix(filepath.Base(f.env("a_b")), win+"-") {
|
||||
t.Fatalf("named deploy of a_b must keep the full-deploy winner: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamedDeployCorrectedCollisionSkipsAll(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
commit(t, f.control, map[string]string{"manifests/site.pp": "node default {}\n"})
|
||||
gitT(t, f.control, "branch", "a-b")
|
||||
gitT(t, f.control, "branch", "a.b")
|
||||
for _, arg := range []string{"a.b", "a_b"} {
|
||||
err := f.deploy(false, arg)
|
||||
if exists(filepath.Join(f.basedir, "a_b")) {
|
||||
t.Fatalf("deploy %s built a_b, which a full deploy skips", arg)
|
||||
}
|
||||
if err == nil || !strings.Contains(err.Error(), "a-b") || !strings.Contains(err.Error(), "a.b") {
|
||||
t.Fatalf("deploy %s: want collision error naming both branches, got %v", arg, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamedDeployPrefixedSources(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
commit(t, f.control, map[string]string{"manifests/site.pp": "node default {}\n"})
|
||||
gitT(t, f.control, "branch", "benvin/x")
|
||||
pbase := filepath.Join(f.root, "code", "penvs")
|
||||
p := &Source{Name: "p", Remote: f.control, Basedir: pbase, Prefix: "p", InvalidBranches: "correct_and_warn"}
|
||||
f.cfg.Sources["p"] = p
|
||||
penv := func(name string) string { return f.deployer().owned(p, filepath.Join(pbase, name)) }
|
||||
if err := f.deploy(false, "main"); err != nil || f.env("main") == "" {
|
||||
t.Fatalf("deploy main: %v", err)
|
||||
}
|
||||
if penv("p_main") != "" {
|
||||
t.Fatal("env name main also deployed branch main of source p as p_main")
|
||||
}
|
||||
if err := f.deploy(false, "p_main"); err != nil || penv("p_main") == "" {
|
||||
t.Fatalf("deploy p_main: %v", err)
|
||||
}
|
||||
if err := f.deploy(false, "benvin/x"); err != nil || f.env("benvin_x") == "" || penv("p_benvin_x") == "" {
|
||||
t.Fatalf("raw branch benvin/x must deploy in every source: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamedDeployIgnoresUnrelatedInvalid(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
f.cfg.Sources["unkin"].InvalidBranches = "error"
|
||||
commit(t, f.control, map[string]string{"manifests/site.pp": "node default {}\n"})
|
||||
gitT(t, f.control, "branch", "bad-name")
|
||||
if err := f.deploy(false, "main"); err != nil {
|
||||
t.Fatalf("unrelated invalid branch failed named deploy: %v", err)
|
||||
}
|
||||
if err := f.deploy(false, "bad-name"); err == nil || !strings.Contains(err.Error(), "not a valid environment name") {
|
||||
t.Fatalf("named invalid branch must error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func timingLines(s string) []map[string]string {
|
||||
var out []map[string]string
|
||||
for line := range strings.Lines(s) {
|
||||
|
||||
Reference in New Issue
Block a user