~chrisppy/go-barefeed

ref: bc538d4a5b436061195328c43f77c379b9401e4f go-barefeed/barefeed_test.go -rw-r--r-- 3.6 KiB
bc538d4aChris Palmer add tests and fixes 3 months ago
                                                                                
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package barefeed

import (
	"bytes"
	"testing"
	"time"
)

func TestWriteRead(t *testing.T) {
	tt := []struct {
		Name       string
		EntryCount int
		Bins       []Bin
	}{
		{
			Name:       "Success-Feed",
			EntryCount: 0,
			Bins: []Bin{
				{
					Generator: "test",
					Content: Feed{
						FeedPath: "/feedPath",
						FeedID:   "feedID",
						Title: Text{
							TextType: "text",
							Value:    "This is a Title",
						},
						Updated: Time(time.Now().Format(time.RFC3339)),
						Authors: []Person{
							{
								Name: "John Doe",
							},
						},
						Links: []Link{
							{
								Href: "http://example.com",
							},
						},
					},
				},
			},
		},
		{
			Name:       "Success-Entry",
			EntryCount: 1,
			Bins: []Bin{
				{
					Generator: "test",
					Content: Entry{
						FeedID:  "feedID",
						EntryID: "entryID",
						Title: Text{
							TextType: "text",
							Value:    "This is a Title",
						},
						Updated: Time(time.Now().Format(time.RFC3339)),
						Authors: []Person{
							{
								Name: "John Doe",
							},
						},
						Links: []Link{
							{
								Href: "http://example.com",
							},
						},
					},
				},
			},
		},
		{
			Name:       "Success-FeedEntry",
			EntryCount: 1,
			Bins: []Bin{
				{
					Generator: "test",
					Content: Feed{
						FeedPath: "/feedPath",
						FeedID:   "feedID",
						Title: Text{
							TextType: "text",
							Value:    "This is a Title",
						},
						Updated: Time(time.Now().Format(time.RFC3339)),
						Authors: []Person{
							{
								Name: "John Doe",
							},
						},
						Links: []Link{
							{
								Href: "http://example.com",
							},
						},
					},
				},
				{
					Generator: "test",
					Content: Entry{
						FeedID:  "feedID",
						EntryID: "entryID",
						Title: Text{
							TextType: "text",
							Value:    "This is a Title",
						},
						Updated: Time(time.Now().Format(time.RFC3339)),
						Authors: []Person{
							{
								Name: "John Doe",
							},
						},
						Links: []Link{
							{
								Href: "http://example.com",
							},
						},
					},
				},
			},
		},
		{
			Name:       "Success-EntryFeed",
			EntryCount: 1,
			Bins: []Bin{
				{
					Generator: "test",
					Content: Entry{
						FeedID:  "feedID",
						EntryID: "entryID",
						Title: Text{
							TextType: "text",
							Value:    "This is a Title",
						},
						Updated: Time(time.Now().Format(time.RFC3339)),
						Authors: []Person{
							{
								Name: "John Doe",
							},
						},
						Links: []Link{
							{
								Href: "http://example.com",
							},
						},
					},
				},
				{
					Generator: "test",
					Content: Feed{
						FeedPath: "/feedPath",
						FeedID:   "feedID",
						Title: Text{
							TextType: "text",
							Value:    "This is a Title",
						},
						Updated: Time(time.Now().Format(time.RFC3339)),
						Authors: []Person{
							{
								Name: "John Doe",
							},
						},
						Links: []Link{
							{
								Href: "http://example.com",
							},
						},
					},
				},
			},
		},
	}

	for _, tc := range tt {
		t.Run(tc.Name, func(t *testing.T) {
			fm := make(FeedMap)
			for _, bin := range tc.Bins {
				var buf bytes.Buffer
				err := bin.Write(&buf)
				if err != nil {
					t.Errorf("write expected no error, recieved %s", err.Error())
					return
				}

				err = fm.Read(&buf)
				if err != nil {
					t.Errorf("read expected no error, recieved %s", err.Error())
					return
				}

			}

			if len(fm) != 1 {
				t.Errorf("expected 1 feed, got %d", len(fm))
			} else if tc.EntryCount != len(fm["feedID"].Entries) {

				t.Errorf("expected %d entry, got %d", tc.EntryCount, len(fm["feedID"].Entries))
			}
		})
	}
}