-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopds_test.go
62 lines (52 loc) · 1.43 KB
/
opds_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
package tanuki
import (
"encoding/xml"
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestOPDS_Author(t *testing.T) {
a := opdsAuthor{
Name: "a",
URI: "b",
}
expected := `
<author>
<name>a</name>
<uri>b</uri>
</author>`
b, err := xml.MarshalIndent(a, "", " ")
require.NoError(t, err)
require.Equal(t, trimNewline(expected), string(b))
}
func TestOPDS_Time(t *testing.T) {
t.Run("marshal XML", func(t *testing.T) {
ti := opdsTime{time.Date(1999, 1, 1, 1, 1, 1, 1, time.UTC)}
expected := `<opdsTime>1999-01-01T01:01:01.000000001Z</opdsTime>`
b, err := xml.MarshalIndent(ti, "", " ")
require.NoError(t, err)
require.Equal(t, expected, string(b))
})
}
func TestOPDS_Search(t *testing.T) {
t.Run("marshal XML", func(t *testing.T) {
s := newOpdsSearch()
expected := `
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>Search</ShortName>
<Description>Search for Series</Description>
<InputEncoding>UTF-8</InputEncoding>
<OutputEncoding>UTF-8</OutputEncoding>
<Url template="/opds/v1.2/catalog?search={searchTerms}" type="application/atom+xml;profile=opds-catalog;kind=acquisition"></Url>
</OpenSearchDescription>`
b, err := xml.MarshalIndent(s, "", " ")
require.NoError(t, err)
require.Equal(t, trimNewline(expected), string(b))
})
}
// Utils
func trimNewline(l string) string {
l = strings.TrimPrefix(l, "\n")
return strings.TrimSuffix(l, "\n")
}