-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_access_mock.go
44 lines (36 loc) · 1.24 KB
/
data_access_mock.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
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// @ Copyright (c) Michael Leahcim @
// @ You can find additional information regarding licensing of this work in LICENSE.md @
// @ You must not remove this notice, or any other, from this software. @
// @ All rights reserved. @
// @@@@@@ At 2019-05-16 22:12 <thereisnodotcollective@gmail.com> @@@@@@@@@@@@@@@@@@@@@@@@
package emerchantpay_rss_reader
import (
"errors"
"io/ioutil"
"time"
)
type mockFeedGetter struct {
delay time.Duration
}
func newMockFeedGetter(delay int) feedGetter {
return mockFeedGetter{delay: time.Duration(time.Millisecond * time.Duration(delay))}
}
func (s mockFeedGetter) Get(url string) (string, error) {
rsslink := ""
switch url {
case "https://news.ycombinator.com/rss":
rsslink = "testdata/news.ycombinator.com.rss"
case "https://www.theguardian.com/uk/rss":
rsslink = "testdata/theguardian.rss"
}
time.Sleep(s.delay)
if len(rsslink) == 0 {
return "", errors.New("Cannot open URL: " + url)
}
bytes, err := ioutil.ReadFile(rsslink)
if err != nil {
panic(err)
}
return string(bytes), nil
}