package handlers import ( "context" "net/http" "strings" "testing" ) // TestProfileReadme checks that a repository named after its owner // (/) has its README rendered on the profile page, GitHub style. func TestProfileReadme(t *testing.T) { app, _, userSvc, repoSvc := setupTestApp(t) ctx := context.Background() alice, err := userSvc.Register(ctx, "alice", "alice@example.com", "strongpassword", true) if err != nil { t.Fatalf("register alice: %v", err) } if _, err := repoSvc.Create(ctx, alice, "alice", "Profile repo", false); err != nil { t.Fatalf("create profile repo: %v", err) } path, _ := repoSvc.DiskPath("alice", "alice") pushCommit(t, path, "main", "README.md", "# hi alice\n\nProfile **readme** body\n") status, body := getPage(t, app, "/alice") if status != http.StatusOK { t.Fatalf("profile status %d", status) } if !strings.Contains(body, "Profile readme body") { t.Errorf("profile page missing rendered / README") } // A user without a / repository gets no README card. bob, err := userSvc.Register(ctx, "bob", "bob@example.com", "strongpassword", true) if err != nil { t.Fatalf("register bob: %v", err) } if _, err := repoSvc.Create(ctx, bob, "engine", "Not a profile repo", false); err != nil { t.Fatalf("create bob repo: %v", err) } status, body = getPage(t, app, "/bob") if status != http.StatusOK { t.Fatalf("bob profile status %d", status) } if strings.Contains(body, "Profile readme body") { t.Errorf("bob profile must not render alice's README") } }