forked from verless/verless
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom_test.go
More file actions
59 lines (47 loc) · 1.04 KB
/
atom_test.go
File metadata and controls
59 lines (47 loc) · 1.04 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package atom
import (
"fmt"
"testing"
"github.com/verless/verless/model"
)
var (
a *atom = nil
pages []model.Page = []model.Page{
{ID: "page-0"},
{ID: "page-1"},
{ID: "page-2"},
{ID: "page-3"},
}
)
func TestAtom_ProcessPage(t *testing.T) {
setupAtom()
for i, page := range pages {
page.Route = getRoute(i)
if err := a.ProcessPage(&page); err != nil {
t.Fatal(err)
}
}
if len(a.feed.Items) != len(pages) {
t.Fatalf("expected %d stored pages, got %d", len(pages), len(a.feed.Items))
}
for i := 0; i < len(pages); i++ {
item := a.feed.Items[i]
if item.Title != pages[i].Title {
t.Errorf("expected title %s, got %s", pages[i].Title, item.Title)
}
canonical := fmt.Sprintf("%s%s/%s", a.meta.Base, getRoute(i), pages[i].ID)
if item.Link.Href != canonical {
t.Errorf("expected link %s, got %s", canonical, item.Link.Href)
}
}
}
func setupAtom() {
if a == nil {
a = New(&model.Meta{
Base: "https://example.com",
}, "")
}
}
func getRoute(n int) string {
return fmt.Sprintf("/route-%v", n)
}