Add rssserver to main_test

master
Bel LaPointe 2018-10-10 13:28:20 -06:00
parent 822766e780
commit 8f6ad0a7a3
1 changed files with 39 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -16,6 +17,41 @@ import (
func Test_Core(t *testing.T) { func Test_Core(t *testing.T) {
server := httptest.NewUnstartedServer(nil) server := httptest.NewUnstartedServer(nil)
server.Close() server.Close()
rssserver := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/feed" {
fmt.Fprintln(w,
`
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel>
<title>fake.com</title>
<link>/feed</link>
<description>this is fake</description>
<item>
<title>title A</title>
<link>/itemA</link>
<description></description>
<pubDate>Wed, 10 Oct 2018 04:00:00 -0000</pubDate>
</item>
<item>
<title>title B</title>
<link>/itemB</link>
<description>content B</description>
<pubDate>Wed, 10 Oct 2018 04:00:00 -0000</pubDate>
</item>
</channel></rss>
`,
)
} else {
fmt.Fprintln(w,
`
body of an item here 12345 <img src="fake/path"></img>
`,
)
}
}))
defer server.Close()
wasDBPath := os.Getenv("DBPATH") wasDBPath := os.Getenv("DBPATH")
wasPort := os.Getenv("PORT") wasPort := os.Getenv("PORT")
defer os.Setenv("DBPATH", wasDBPath) defer os.Setenv("DBPATH", wasDBPath)
@ -46,20 +82,20 @@ func Test_Core(t *testing.T) {
{ {
method: "post", method: "post",
path: "api/feed", path: "api/feed",
body: `{"url":"https://utw.me/feed/", "refresh":"1m", "items":"Fate", "content":"25"}`, body: `{"url":"` + rssserver.URL + `/feed", "refresh":"1m", "items":"[AB]", "content":"25"}`,
status: 200, status: 200,
post: func() { time.Sleep(time.Second * 10) }, post: func() { time.Sleep(time.Second * 10) },
}, },
{ {
method: "get", method: "get",
path: "api/feed", path: "api/feed",
body: "https://utw.me/feed/", body: rssserver.URL + "/feed",
status: 200, status: 200,
}, },
{ {
method: "get", method: "get",
path: "api/feed/item", path: "api/feed/item",
body: "https___utw_me_feed_.20180108_https___utw_me_2018_01_08_fate_apocrypha_25_", body: "http___127_0_0_1_" + strings.Split(rssserver.URL, ":")[2] + "_feed.20181010__itemB",
status: 200, status: 200,
}, },
} }