~chrisppy/go-barefeed

bc538d4a5b436061195328c43f77c379b9401e4f — Chris Palmer a month ago ff17c37 v0.6.0
add tests and fixes
2 files changed, 230 insertions(+), 0 deletions(-)

A barefeed_test.go
A coverage.out
A barefeed_test.go => barefeed_test.go +200 -0
@@ 0,0 1,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))
			}
		})
	}
}

A coverage.out => coverage.out +30 -0
@@ 0,0 1,30 @@
mode: set
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:23.53,25.56 2 1
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:29.2,29.37 1 1
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:55.2,55.8 1 1
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:25.56,27.3 1 0
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:30.13,35.37 2 1
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:39.3,39.24 1 1
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:40.14,41.37 1 1
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:46.3,50.4 1 1
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:51.10,52.57 1 0
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:35.37,37.4 1 1
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:41.37,44.4 2 1
git.sr.ht/~chrisppy/go-barefeed/barefeed.go:59.44,62.2 2 1
git.sr.ht/~chrisppy/go-barefeed/schema.go:11.42,13.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:15.41,17.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:24.42,26.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:28.41,30.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:41.42,43.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:45.41,47.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:55.44,57.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:59.43,61.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:77.43,79.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:81.42,83.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:94.42,96.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:98.41,100.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:107.41,109.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:111.40,113.2 1 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:119.26,119.27 0 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:121.27,121.28 0 0
git.sr.ht/~chrisppy/go-barefeed/schema.go:123.13,128.2 1 1