-
-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WTF-758 Open HN comments if there's no external link
If an HN story has no external link associated with it, open the HN comments page for the story. Closes #758 Signed-off-by: Chris Cummer <chriscummer@me.com>
- Loading branch information
1 parent
ac28176
commit 1c8d411
Showing
5 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package hackernews | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
) | ||
|
||
func Test_CommentLink(t *testing.T) { | ||
story := Story{ | ||
ID: 3, | ||
} | ||
|
||
assert.Equal(t, "https://news.ycombinator.com/item?id=3", story.CommentLink()) | ||
} | ||
|
||
func Test_Link(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
id int | ||
url string | ||
expected string | ||
}{ | ||
{ | ||
name: "no external link", | ||
id: 1, | ||
url: "", | ||
expected: "https://news.ycombinator.com/item?id=1", | ||
}, | ||
{ | ||
name: "with external link", | ||
id: 1, | ||
url: "https://www.link.ca", | ||
expected: "https://www.link.ca", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
story := Story{ | ||
ID: tt.id, | ||
URL: tt.url, | ||
} | ||
|
||
actual := story.Link() | ||
|
||
assert.Equal(t, tt.expected, actual) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters