-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_test.go
67 lines (58 loc) · 1.8 KB
/
helper_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
package cached_rss2
import (
rss "github.com/ungerik/go-rss"
"testing"
"time"
)
// testFeed is a sample FetchedFeed defined here for convenience
var testFeed FetchedFeed = FetchedFeed{
time.Now(),
"http://test/feed",
&rss.Channel{
Title: "test feed",
Link: "http://test/feed",
Description: "test feed for testing",
Item: []rss.Item{
rss.Item{
Title: "test one",
Link: "http://test/1",
GUID: "test-1",
},
},
},
}
func TestHashURL(t *testing.T) {
path := "http://www.google.com"
knownCorrectHash := "ed646a3334ca891fd3467db131372140"
hashed := hashURL(path)
if hashed != knownCorrectHash {
t.Error("expected: ", knownCorrectHash, "actual: ", hashed)
}
}
func TestWriteFeedToCache(t *testing.T) {
// call writeFeedToCache on temp dir with testFeed
// verify that an output file matching the hash of the URL is there
// verify that it's readable by encodings/gob
// verify that it decodes to testFeed
// verify that if given a bad path, or a bad feed, it returns the
// right error
}
func TestReadFeedFromCache(t *testing.T) {
// verify that if given a bad path, it returns the right error
// write some junk to a temp file named with a hash URL, and verify
// that it can't read the file
// call writeFeedToCache and then readFeedFromCache and verify that
// it roundtrips correctly
}
func TestFetchFeed(t *testing.T) {
// fetch a well-known feed
// verify that the insides are as expected, the FetchDate etc is right
// fetch a bogus feed & verify that it returns error
}
func TestCachedFeed(t *testing.T) {
// fetch a bogus feed & verify it returns error
// write some junk to the filesystem named with a hash URL, and verify
// it chokes on fetching that URL
// fetch a well known feed and verify that it creates an output file
// with the right name
}