From 8f6ad0a7a36b4060a1ae1f8be7d638678523a5e9 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Wed, 10 Oct 2018 13:28:20 -0600 Subject: [PATCH] Add rssserver to main_test --- main_test.go | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/main_test.go b/main_test.go index 10abeec..217e2c1 100644 --- a/main_test.go +++ b/main_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "fmt" "io" "io/ioutil" "net/http" @@ -16,6 +17,41 @@ import ( func Test_Core(t *testing.T) { server := httptest.NewUnstartedServer(nil) server.Close() + + rssserver := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/feed" { + fmt.Fprintln(w, + ` + + + fake.com + /feed + this is fake + + title A + /itemA + + Wed, 10 Oct 2018 04:00:00 -0000 + + + title B + /itemB + content B + Wed, 10 Oct 2018 04:00:00 -0000 + + + `, + ) + } else { + fmt.Fprintln(w, + ` + body of an item here 12345 + `, + ) + } + })) + defer server.Close() + wasDBPath := os.Getenv("DBPATH") wasPort := os.Getenv("PORT") defer os.Setenv("DBPATH", wasDBPath) @@ -46,20 +82,20 @@ func Test_Core(t *testing.T) { { method: "post", 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, post: func() { time.Sleep(time.Second * 10) }, }, { method: "get", path: "api/feed", - body: "https://utw.me/feed/", + body: rssserver.URL + "/feed", status: 200, }, { method: "get", 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, }, }