-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
85 lines (77 loc) · 2.43 KB
/
main_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
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
84
85
package main
import (
"testing"
"time"
)
func TestValidatePubKeysWithValidHex(t *testing.T) {
err := validatePubKeys([]string{"b8aafafe72f7cd06ae8c337f93147f65fe2d34c0065b52696123982438cf06fe", "b8aafafe72f7cd06ae8c337f93147f65fe2d34c0065b52696123982438cf06fe"})
if err != nil {
t.Errorf("unexpected pubKey validation error: %v", err)
}
}
func TestValidatePubKeysWithNpub(t *testing.T) {
err := validatePubKeys([]string{"b8aafafe72f7cd06ae8c337f93147f65fe2d34c0065b52696123982438cf06fe", "npub1hz404lnj7lxsdt5vxdlex9rlvhlz6dxqqed4y6tpywvzgwx0qmlqfpl6sm"})
if err == nil {
t.Error("expected npub not supported error")
}
}
func TestOrderedList(t *testing.T) {
ol := &orderedList{
Anchors: []*anchor{
{Text: "a1", Href: "h1"},
{Text: "a2", Href: "h2"},
},
}
expected := "<ol>\n" +
" <li>\n" +
" <a href=\"h1\">a1</a>\n" +
" <a href=\"h2\">a2</a>\n" +
" </li>\n" +
"</ol>"
bytes, err := ol.marshal()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
actual := string(bytes)
if actual != expected {
t.Errorf("expected \n%v, received \n%v", expected, actual)
}
}
func TestFeedMarshalling(t *testing.T) {
fd := &feed{XMLNS: atomNS, Title: "Test Feed", ID: "feedid"}
t3 := time.Date(2019, 12, 23, 22, 30, 0, 0, time.UTC)
t2 := t3.Add(-1 * time.Minute)
t1 := t2.Add(-1 * time.Minute)
t0 := t1.Add(-1 * time.Minute)
fd.add("titelA v1", "locA", t1, "sumA v1", &t0)
fd.add("titelB", "locB", t2, "", nil)
fd.add("titelA v3", "locA", t3, "sumA v3", &t1)
fd.add("titelA v2", "locA", t2, "sumA v2", nil)
expected := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<feed xmlns=\"http://www.w3.org/2005/Atom\">\n" +
" <id>feedid</id>\n" +
" <title>Test Feed</title>\n" +
" <updated>2019-12-23T22:30:00Z</updated>\n" +
" <entry>\n" +
" <title>titelA v3</title>\n" +
" <link href=\"locA\"></link>\n" +
" <published>2019-12-23T22:27:00Z</published>\n" +
" <updated>2019-12-23T22:30:00Z</updated>\n" +
" <summary>sumA v3</summary>\n" +
" </entry>\n" +
" <entry>\n" +
" <title>titelB</title>\n" +
" <link href=\"locB\"></link>\n" +
" <published>2019-12-23T22:29:00Z</published>\n" +
" <updated>2019-12-23T22:29:00Z</updated>\n" +
" </entry>\n" +
"</feed>"
bytes, err := fd.marshal()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
actual := string(bytes)
if actual != expected {
t.Errorf("expected \n%v, received \n%v", expected, actual)
}
}