github.com/wtfutil/wtf@v0.43.0/modules/hackernews/story_test.go (about) 1 package hackernews 2 3 import ( 4 "testing" 5 6 "gotest.tools/assert" 7 ) 8 9 func Test_CommentLink(t *testing.T) { 10 story := Story{ 11 ID: 3, 12 } 13 14 assert.Equal(t, "https://news.ycombinator.com/item?id=3", story.CommentLink()) 15 } 16 17 func Test_Link(t *testing.T) { 18 tests := []struct { 19 name string 20 id int 21 url string 22 expected string 23 }{ 24 { 25 name: "no external link", 26 id: 1, 27 url: "", 28 expected: "https://news.ycombinator.com/item?id=1", 29 }, 30 { 31 name: "with external link", 32 id: 1, 33 url: "https://www.link.ca", 34 expected: "https://www.link.ca", 35 }, 36 } 37 38 for _, tt := range tests { 39 t.Run(tt.name, func(t *testing.T) { 40 story := Story{ 41 ID: tt.id, 42 URL: tt.url, 43 } 44 45 actual := story.Link() 46 47 assert.Equal(t, tt.expected, actual) 48 }) 49 } 50 }