/
article_test.go
39 lines (36 loc) · 972 Bytes
/
article_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package content_test
import (
"testing"
"github.com/urandom/readeef/content"
)
func TestArticle_Validate(t *testing.T) {
type fields struct {
ID content.ArticleID
FeedID content.FeedID
Link string
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{"valid", fields{ID: 1, FeedID: 1, Link: "http://sugr.org"}, false},
{"link not absolute", fields{ID: 1, FeedID: 1, Link: "sugr.org"}, true},
{"no link", fields{ID: 1, FeedID: 1}, true},
{"no feed id", fields{ID: 1, Link: "http://sugr.org"}, true},
{"no id", fields{FeedID: 1, Link: "http://sugr.org"}, true},
{"nothing", fields{}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := content.Article{
ID: tt.fields.ID,
FeedID: tt.fields.FeedID,
Link: tt.fields.Link,
}
if err := a.Validate(); (err != nil) != tt.wantErr {
t.Errorf("Article.Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}