diff --git a/cache.go b/cache.go index a0baef9..8643d34 100644 --- a/cache.go +++ b/cache.go @@ -8,6 +8,8 @@ import ( type HTTPCache struct { } +// Based on http.MaxBytesReader + // MaxBytesReader is similar to io.LimitReader but is intended for // limiting the size of incoming request bodies. In contrast to // io.LimitReader, MaxBytesReader's result is a ReadCloser, returns a @@ -16,8 +18,6 @@ type HTTPCache struct { // // MaxBytesReader prevents clients from accidentally or maliciously // sending a large request and wasting server resources. -// -// Based on http.MaxBytesReader func MaxBytesReader(r io.ReadCloser, n int64) io.ReadCloser { if n < 0 { // Treat negative limits as equivalent to 0. n = 0 diff --git a/mastodon_test.go b/mastodon_test.go new file mode 100644 index 0000000..c61d377 --- /dev/null +++ b/mastodon_test.go @@ -0,0 +1,48 @@ +package main + +import ( + "context" + "net/http" + "net/http/httptest" + "testing" +) + +var mastoSourceTests = []struct { + filename string + title string + itemText string +}{ + { + filename: "/masto.html", + title: "magical on tiny.tilde.website", + itemText: "here's hoping it never melts", + }, +} + +func TestMastoSource(t *testing.T) { + server := httptest.NewServer(http.FileServer(http.Dir("testdata"))) + defer server.Close() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + for _, tt := range mastoSourceTests { + src := NewMastoSource(server.URL + tt.filename) + src.update(ctx) + if err := src.Error; err != nil { + t.Errorf("%v: Error = %v, expected nil", tt.filename, err) + continue + } + if src.Title != tt.title { + t.Errorf("%v: Title = %v expected %v", tt.filename, src.Title, tt.title) + } + items := src.GetItems() + if len(items) == 0 { + t.Errorf("%v: GetItems() = %v expected len > 0", tt.filename, items) + } else { + x := items[0] + if x.Text != tt.itemText { + t.Errorf("%v: item 0 Text = %q expected %q", tt.filename, x.Text, tt.itemText) + } + } + } +} diff --git a/testdata/masto.html b/testdata/masto.html new file mode 100644 index 0000000..868ffd8 --- /dev/null +++ b/testdata/masto.html @@ -0,0 +1,1091 @@ + + + + + + + + + + + + + +magical :tilde: (@magical@tiny.tilde.website) - Tiny Tilde Website + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+ +
+ +Pinned post + +
+ + +
+
+
+
+ +
+ +Pinned post + +
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+
+
+ +

memetic hazard 

*monastic chanting*
Ring Ring Ring Ring
Ring Ring Ring
Ba Na Na Phone

+ +
+ +
+
+
+
+ +
+ + +magical :tilde: + +boosted + +
+ + +
+
+
+ +

I think BOOK might be my favourite tmbg album since Nanobots

+ +
+ +
+
+
+ +

whaaat, the futility closet podcast is ending. yesterday was the last episode.

end of an era

+ +
+ +
+
+
+ +

would you rather fight a moose-sized snail or a snail-sized moose?

+
+
+ +
+ +
+
+ +
+ +
+
+
+ +

tmbg lyrics, caps 

DOOTILY DOOTILY DOOTILY DO
DOOTILY DO DO DO DO
DOOTILY DO DO DO
DOOTILY DOOTILY DOOTILY DO
DOOTILY DO DO DO DO
DOOTILY DO DO
WHOA

+ +
+ +
+
+
+
+ +
+ + +magical :tilde: + +boosted + +
+ + +
+
+ + +
+
+ + +
+
+
+ +

Unfortunately, no one can be told what a monad is. You have to see it for yourself.

+ +
+ +
+
+
+ +

my umbrella ☂️

it goes ump
it goes dowmb
it goes all aroumb

+ +
+ +
+
+
+ +

despite all my ire
I am still just a dog in a fire
☕🔥

+ +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ +

oh man they set the tension up in the xenomorph research facility perfectly though

+Show thread + +
+ +
+ +
Show older
+
+
+
+
+ + +
+
+Tiny Tilde Website +
+
+

ttw is the unofficial Mastodon instance of tilde.town. We're only smol, but we're friendly. Please don't be a dick.

+
+
+ +
+
+
+
+ +
+
+ +
+ + + + +
+ + +