From 0a78165b67e4d6df6f67871f59595c75811ff677 Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Sun, 4 Oct 2026 20:36:31 +0000 Subject: [PATCH] Test that the load-test origin serves one JPEG at every path script/loadtest, added in the next commit, needs an upstream host that answers any path with the same image, so each new path is a new source image for pixad to fetch. This test checks that the origin's handler answers several paths with 200, Content-Type image/jpeg and the same bytes, and that the image decodes as a JPEG of the expected size. It does not build until the origin exists. Model: opus-5-5 --- cmd/loadtest-origin/origin_internal_test.go | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 cmd/loadtest-origin/origin_internal_test.go diff --git a/cmd/loadtest-origin/origin_internal_test.go b/cmd/loadtest-origin/origin_internal_test.go new file mode 100644 index 0000000..740fe4b --- /dev/null +++ b/cmd/loadtest-origin/origin_internal_test.go @@ -0,0 +1,51 @@ +package main + +import ( + "bytes" + "image/jpeg" + "net/http" + "net/http/httptest" + "testing" +) + +// TestEveryPathServesTheSameJPEG checks that the origin answers any path with +// 200 and the same JPEG, so every new path script/loadtest asks pixad for is +// a valid source image. +func TestEveryPathServesTheSameJPEG(t *testing.T) { + t.Parallel() + + photo, err := makeJPEG() + if err != nil { + t.Fatalf("makeJPEG: %v", err) + } + + size, err := jpeg.DecodeConfig(bytes.NewReader(photo)) + if err != nil { + t.Fatalf("the image does not decode as a JPEG: %v", err) + } + + if size.Width != imageWidth || size.Height != imageHeight { + t.Errorf("the image is %dx%d, want %dx%d", + size.Width, size.Height, imageWidth, imageHeight) + } + + handler := newHandler(photo) + + for _, path := range []string{"/", "/miss/1.jpg", "/herd/2.jpg"} { + rec := httptest.NewRecorder() + handler.ServeHTTP(rec, httptest.NewRequestWithContext( + t.Context(), http.MethodGet, path, nil)) + + if rec.Code != http.StatusOK { + t.Errorf("%s: status = %d, want %d", path, rec.Code, http.StatusOK) + } + + if ct := rec.Header().Get("Content-Type"); ct != "image/jpeg" { + t.Errorf("%s: Content-Type = %q, want image/jpeg", path, ct) + } + + if !bytes.Equal(rec.Body.Bytes(), photo) { + t.Errorf("%s: the body is not the image", path) + } + } +}