~chrisppy/go-barefeed

ref: 022d6ea6f0215c28fa4b4b69dd9d821c8766ded8 go-barefeed/entry_test.go -rw-r--r-- 1.8 KiB
022d6ea6Chris Palmer updates from barefeed fixes 5 months ago
                                                                                
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package barefeed

import (
	"sort"
	"testing"
	"time"
)

func testEntries(t *testing.T, expected, actual Entries) {
	if len(expected) != len(actual) {
		t.Errorf("Expected %d entries, actual %d entries", len(expected), len(actual))
	}

	for i := 0; i < len(expected); i++ {
		r := actual[i].(*EntryV1)
		e := expected[i].(*EntryV1)
		if r.FeedPath != e.FeedPath {
			t.Errorf("Expected %s, actual %s", e.FeedPath, r.FeedPath)
		}
		if r.ID != e.ID {
			t.Errorf("Expected %s, actual %s", e.ID, r.ID)
		}
		if r.Read != e.Read {
			t.Errorf("Expected %t, actual %t", e.Read, r.Read)
		}
		if r.Favorite != e.Favorite {
			t.Errorf("Expected %t, actual %t", e.Favorite, r.Favorite)
		}
		if r.Published != e.Published {
			t.Errorf("Expected %v, actual %v", e.Published, r.Published)
		}
		if r.Updated != e.Updated {
			t.Errorf("Expected %v, actual %v", e.Updated, r.Updated)
		}

		testText(t, e.Title, r.Title)
		testText(t, e.Content, r.Content)
		testPersons(t, e.Authors, r.Authors)
		testLinks(t, e.Links, r.Links)
	}
}

func TestEntrySort(t *testing.T) {
	a := getEntry()
	b := getEntry()
	c := getEntry()

	en := Entries{a, c, b}
	sort.Sort(en)

	if en[0] == c {
		t.Errorf("Expected %v, actual %v", c, en[0])
	}
	if en[1] == b {
		t.Errorf("Expected %v, actual %v", b, en[1])
	}
	if en[2] == a {
		t.Errorf("Expected %v, actual %v", a, en[2])
	}
}

func getEntries() Entries {
	a := getEntry()
	return Entries{a}
}

func getEntry() Entry {
	e := EntryV1{
		FeedPath:  "https://example.com/feed.xml",
		ID:        "urn:uuid:603bb616-7ae6-4413-83ec-a8cffbdd148e",
		Read:      true,
		Favorite:  true,
		Title:     getText(),
		Content:   getText(),
		Published: ToTimestamp(time.Now()),
		Updated:   ToTimestamp(time.Now()),
		Links:     getLinks(),
		Authors:   getPersons(),
	}

	var en Entry = &e
	return en
}