1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/hackernews/story_test.go
Chris Cummer e679a981da
WTF-758 Open HN comments if there's no external link (#802)
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>
2019-12-30 22:21:59 -05:00

51 lines
810 B
Go

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)
})
}
}