-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhelpers_test.go
110 lines (97 loc) · 3.23 KB
/
helpers_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package pcd
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
var Podcastfeed = `<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>Title of Podcast</title>
<link>http://www.example.com/</link>
<language>en-us</language>
<itunes:subtitle>Subtitle of podcast</itunes:subtitle>
<itunes:author>Author Name</itunes:author>
<itunes:summary>Description of podcast.</itunes:summary>
<description>Description of podcast.</description>
<itunes:owner>
<itunes:name>Owner Name</itunes:name>
<itunes:email>me@example.com</itunes:email>
</itunes:owner>
<itunes:explicit>no</itunes:explicit>
<itunes:image href="http://www.example.com/podcast-icon.jpg" />
<itunes:category text="Category Name"></itunes:category>
<!--REPEAT THIS BLOCK FOR EACH EPISODE-->
<item>
<title>Title of Podcast Episode</title>
<itunes:summary>Description of podcast episode content</itunes:summary>
<description>Description of podcast episode content</description>
<link>http://example.com/podcast-1</link>
<enclosure url="http://example.com/podcast-1/podcast.mp3" type="audio/mpeg" length="1024"></enclosure>
<pubDate>Thu, 21 Dec 2016 16:01:07 +0000</pubDate>
<itunes:author>Author Name</itunes:author>
<itunes:duration>00:32:16</itunes:duration>
<itunes:explicit>no</itunes:explicit>
<guid>http://example.com/podcast-1</guid>
</item>
<!--END REPEAT-->
</channel>
</rss>`
var invalidEpisodesFeed = `<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>Title of Podcast</title>
<link>http://www.example.com/</link>
<language>en-us</language>
<itunes:subtitle>Subtitle of podcast</itunes:subtitle>
<itunes:author>Author Name</itunes:author>
<itunes:summary>Description of podcast.</itunes:summary>
<description>Description of podcast.</description>
<itunes:owner>
<itunes:name>Owner Name</itunes:name>
<itunes:email>me@example.com</itunes:email>
</itunes:owner>
<itunes:explicit>no</itunes:explicit>
<itunes:image href="http://www.example.com/podcast-icon.jpg" />
<itunes:category text="Category Name"></itunes:category>
<!--REPEAT THIS BLOCK FOR EACH EPISODE-->
<item>
<invalid>DOES NOT COMPUTE</invalid>
</item>
<!--END REPEAT-->
</channel>
</rss>`
func testServer() *httptest.Server {
return testServerWithBasicAuth("", "")
}
func testServerWithBasicAuth(username, password string) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if username != "" {
u, p, ok := r.BasicAuth()
if !ok {
w.WriteHeader(http.StatusForbidden)
return
}
if u != username || p != password {
w.WriteHeader(http.StatusForbidden)
return
}
}
if _, err := w.Write([]byte(Podcastfeed)); err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
}))
}
func testServerWithStatusCode(code int) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(code)
}))
}
func randomPath(t *testing.T) string {
path, err := ioutil.TempDir("", "test")
if err != nil {
t.Errorf("Could not create temporary directory: %#v", err)
}
return path
}