Skip to content

Commit edeced8

Browse files
committed
Unit test fixes
1 parent 055ac9e commit edeced8

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

golink.go

+9
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,15 @@ func serveMine(w http.ResponseWriter, r *http.Request) {
520520
return
521521
}
522522

523+
// Return JSON if the client doesn't accept HTML
524+
if !acceptHTML(r) {
525+
w.Header().Set("Content-Type", "application/json")
526+
if err := json.NewEncoder(w).Encode(links); err != nil {
527+
http.Error(w, err.Error(), http.StatusInternalServerError)
528+
}
529+
return
530+
}
531+
523532
mineTmpl.Execute(w, links)
524533
}
525534

golink_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,11 @@ func TestServeMine(t *testing.T) {
620620
if err != nil {
621621
t.Fatal(err)
622622
}
623-
// Seed the database with links
624-
db.Save(&Link{Short: "link1", Long: "http://example.com/1", Owner: "user1"})
625-
db.Save(&Link{Short: "link2", Long: "http://example.com/2", Owner: "user2"})
626-
db.Save(&Link{Short: "link3", Long: "http://example.com/3", Owner: "user1"})
623+
624+
// Seed the database with links - update Owner to match login format
625+
db.Save(&Link{Short: "link1", Long: "http://example.com/1", Owner: "user1@example.com"})
626+
db.Save(&Link{Short: "link2", Long: "http://example.com/2", Owner: "user2@example.com"})
627+
db.Save(&Link{Short: "link3", Long: "http://example.com/3", Owner: "user1@example.com"})
627628

628629
tests := []struct {
629630
name string
@@ -637,8 +638,8 @@ func TestServeMine(t *testing.T) {
637638
return user{login: "user1@example.com"}, nil
638639
},
639640
wantLinks: []*Link{
640-
{Short: "link1", Long: "http://example.com/1", Owner: "user1"},
641-
{Short: "link3", Long: "http://example.com/3", Owner: "user1"},
641+
{Short: "link1", Long: "http://example.com/1", Owner: "user1@example.com"},
642+
{Short: "link3", Long: "http://example.com/3", Owner: "user1@example.com"},
642643
},
643644
wantStatus: http.StatusOK,
644645
},

0 commit comments

Comments
 (0)