package e2e import ( "net/http" "os/exec" "strings" "testing" ) // Appendix C lists a url for one release, and a url the book prints must not answer 404. func TestOneReleaseOpensTheListAtThatTag(t *testing.T) { if _, err := exec.LookPath("git"); err != nil { t.Skip("git is not installed") } in := newInstance(t) john := in.account("john") work := seed(t, in, john, "john", "johnbot") run(t, work, "git", "tag", "-a", "v1.2.0", "-m", "fixes the empty config panic") run(t, work, "git", "push", "-q", in.url(john, "/john/johnbot"), "v1.2.0") client := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }} resp, err := client.Get(in.http.URL + "/john/johnbot/release/v1.2.0") if err != nil { t.Fatal(err) } resp.Body.Close() if resp.StatusCode != http.StatusFound { t.Fatalf("the release url answered %d", resp.StatusCode) } if got := resp.Header.Get("Location"); got != "/john/johnbot/releases?from=v1.2.0" { t.Errorf("it went to %q", got) } code, _, body := get(t, in.http.URL+"/john/johnbot/releases?from=v1.2.0") if code != http.StatusOK || !strings.Contains(body, "v1.2.0") { t.Errorf("the list does not show the tag it was opened at: %d\n%s", code, body) } // A tag that is not here is a 404, not the newest release wearing the wrong name. resp, err = client.Get(in.http.URL + "/john/johnbot/release/v9.9.9") if err != nil { t.Fatal(err) } resp.Body.Close() if resp.StatusCode != http.StatusNotFound { t.Errorf("an unknown tag answered %d", resp.StatusCode) } }