From ace7694bad5752aa38fec3a13c071cf7b2bebfce Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 7 May 2026 13:09:58 -0400 Subject: implement GET /validate-cover --- lulu_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lulu_test.go') diff --git a/lulu_test.go b/lulu_test.go index 05d37ad..f657681 100644 --- a/lulu_test.go +++ b/lulu_test.go @@ -1,11 +1,13 @@ package lulu import ( + "context" "encoding/json" "fmt" "os" "strings" "testing" + "time" "github.com/stretchr/testify/require" ) @@ -18,6 +20,9 @@ const ( interiorUrl = "https://www.dropbox.com/sh/p3zh22vzsaegiri/AACOUn3LFKsITDzylh13bQpsa/161025/thesis2.pdf?dl=1" coverUrl = "https://www.dropbox.com/sh/p3zh22vzsaegiri/AADP367j0bTWlt8fCu-_tm2ia/161025/139056_cover.pdf?dl=1" + + pollTimeout = 15 * time.Second + pollPeriod = time.Second ) var ( @@ -62,3 +67,22 @@ func requireUnmarshalJsonEq[T any](t *testing.T, expected T, j string) { require.NoError(t, json.Unmarshal([]byte(j), &actual)) require.Equal(t, expected, actual) } + +// poll periodically calls f() until it returns true or the deadline is exceeded. +func poll(t *testing.T, f func() bool) { + t.Helper() + ctx, cancel := context.WithTimeout(t.Context(), pollTimeout) + defer cancel() + timer := time.NewTimer(pollPeriod) + for { + select { + case <-timer.C: + if f() { + return + } + timer.Reset(pollPeriod) + case <-ctx.Done(): + t.Errorf("timed out after %v", pollTimeout) + } + } +} -- cgit v1.2.3