package e2e import ( "net/http" "net/url" "os/exec" "strings" "testing" ) // Chapter 21.2: the old name is never freed, or it inherits the old identity's threads and mentions. func TestARenamedRepositoryNeverFreesItsOldName(t *testing.T) { if _, err := exec.LookPath("git"); err != nil { t.Skip("git is not installed") } in := newInstance(t) john := in.account("john") seed(t, in, john, "john", "johnbot") resp := post(t, in, "john", "/john/johnbot/rename", url.Values{"name": {"ircbot"}}) if resp.StatusCode != http.StatusFound { t.Fatalf("the rename answered %d", resp.StatusCode) } // The old path redirects, which is what keeps every clone working. 44.2. code, _, _ := get(t, in.http.URL+"/john/johnbot") if code != http.StatusOK { t.Errorf("the old path answered %d instead of following the redirect", code) } // The form must not hand the old name to anybody, including the person who moved it. resp = post(t, in, "john", "/new", url.Values{"name": {"johnbot"}, "default_branch": {"master"}}) if resp.StatusCode == http.StatusFound { t.Error("the form gave the old name back out, so the redirect now lies") } // Nor may a push take it, which is the other way a repository comes into being. Chapter 11. work := t.TempDir() run(t, work, "git", "init", "-q", "-b", "master", work) write(t, work, "f", "hi\n") run(t, work, "git", "add", "-A") run(t, work, "git", "commit", "-qm", "first") out, err := try(t, work, "git", "push", in.url(john, "/john/johnbot"), "master") if err == nil && !strings.Contains(out, "ircbot") { t.Errorf("a push claimed the old name instead of following the redirect:\n%s", out) } } // Chapter 44.4: a deleted repository keeps its name claimed while it waits out its window. func TestADeletedNameIsNotHandedOutWhileItWaits(t *testing.T) { if _, err := exec.LookPath("git"); err != nil { t.Skip("git is not installed") } in := newInstance(t) john := in.account("john") seed(t, in, john, "john", "johnbot") resp := post(t, in, "john", "/john/johnbot/delete", url.Values{"confirm": {"johnbot"}}) if resp.StatusCode != http.StatusFound { t.Fatalf("the delete answered %d", resp.StatusCode) } resp = post(t, in, "john", "/new", url.Values{"name": {"johnbot"}, "default_branch": {"master"}}) if resp.StatusCode == http.StatusFound { t.Error("a name still in the trash window was handed straight back out") } }