diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2026-05-07 13:09:58 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2026-05-07 13:09:58 -0400 |
| commit | ace7694bad5752aa38fec3a13c071cf7b2bebfce (patch) | |
| tree | 2f391107b6aa7bce7b0a028aff8f7c5b32839852 /lulu_test.go | |
| parent | b57f03381e4bccba2963cebabe51a9cf32bd96dd (diff) | |
| download | lulu-ace7694bad5752aa38fec3a13c071cf7b2bebfce.zip | |
implement GET /validate-cover
Diffstat (limited to 'lulu_test.go')
| -rw-r--r-- | lulu_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
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) + } + } +} |