-
Notifications
You must be signed in to change notification settings - Fork 2
/
convert_test.go
51 lines (35 loc) · 1.05 KB
/
convert_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
package p
import (
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
const validRssUrl = "https://demo.theeventscalendar.com/events/feed/"
// const validRssUrl = "https://feeds.twit.tv/twit.xml"
func TestHandler(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/rss-to-ical?rssUrl="+validRssUrl, nil)
w := httptest.NewRecorder()
HandleRequest(w, req)
resp := w.Result()
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
assert.NotEmpty(t, string(data))
}
func TestSuccessfulConvert(t *testing.T) {
cal, err := doConvert(validRssUrl, 50)
assert.Nil(t, err)
calString := cal.Serialize()
assert.True(t, strings.HasPrefix(calString, "BEGIN:VCALENDAR"))
assert.Contains(t, calString, "BEGIN:VEVENT")
assert.Contains(t, calString, "END:VEVENT")
assert.Contains(t, calString, "END:VCALENDAR")
}
func TestFailedConvert(t *testing.T) {
cal, err := doConvert("https://dne.com/rss", 45)
assert.Nil(t, cal)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "404 Not Found")
}