profile_readme_test.go
·
49 lines
·
1.6 KB
| 1 | package handlers |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "net/http" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | // TestProfileReadme checks that a repository named after its owner |
| 11 | // (<user>/<user>) has its README rendered on the profile page, GitHub style. |
| 12 | func TestProfileReadme(t *testing.T) { |
| 13 | app, _, userSvc, repoSvc := setupTestApp(t) |
| 14 | ctx := context.Background() |
| 15 | |
| 16 | alice, err := userSvc.Register(ctx, "alice", "alice@example.com", "strongpassword", true) |
| 17 | if err != nil { |
| 18 | t.Fatalf("register alice: %v", err) |
| 19 | } |
| 20 | if _, err := repoSvc.Create(ctx, alice, "alice", "Profile repo", false); err != nil { |
| 21 | t.Fatalf("create profile repo: %v", err) |
| 22 | } |
| 23 | path, _ := repoSvc.DiskPath("alice", "alice") |
| 24 | pushCommit(t, path, "main", "README.md", "# hi alice\n\nProfile **readme** body\n") |
| 25 | |
| 26 | status, body := getPage(t, app, "/alice") |
| 27 | if status != http.StatusOK { |
| 28 | t.Fatalf("profile status %d", status) |
| 29 | } |
| 30 | if !strings.Contains(body, "Profile <strong>readme</strong> body") { |
| 31 | t.Errorf("profile page missing rendered <user>/<user> README") |
| 32 | } |
| 33 | |
| 34 | // A user without a <user>/<user> repository gets no README card. |
| 35 | bob, err := userSvc.Register(ctx, "bob", "bob@example.com", "strongpassword", true) |
| 36 | if err != nil { |
| 37 | t.Fatalf("register bob: %v", err) |
| 38 | } |
| 39 | if _, err := repoSvc.Create(ctx, bob, "engine", "Not a profile repo", false); err != nil { |
| 40 | t.Fatalf("create bob repo: %v", err) |
| 41 | } |
| 42 | status, body = getPage(t, app, "/bob") |
| 43 | if status != http.StatusOK { |
| 44 | t.Fatalf("bob profile status %d", status) |
| 45 | } |
| 46 | if strings.Contains(body, "Profile <strong>readme</strong> body") { |
| 47 | t.Errorf("bob profile must not render alice's README") |
| 48 | } |
| 49 | } |
| 50 |