From b52ff1249f96957d1160cf77f3d8278239275a39 Mon Sep 17 00:00:00 2001 From: Dave Date: Sun, 5 May 2024 14:46:33 -0400 Subject: [PATCH] test: check the response URL during image gen in `app_test.go` (#2248) test: actually check the response URL from image gen Signed-off-by: Dave Lee --- core/http/app_test.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/core/http/app_test.go b/core/http/app_test.go index e9ff3e28..5776b99a 100644 --- a/core/http/app_test.go +++ b/core/http/app_test.go @@ -708,10 +708,26 @@ var _ = Describe("API test", func() { // The response should contain an URL Expect(err).ToNot(HaveOccurred(), fmt.Sprint(resp)) dat, err := io.ReadAll(resp.Body) - Expect(err).ToNot(HaveOccurred(), string(dat)) - Expect(string(dat)).To(ContainSubstring("http://127.0.0.1:9090/"), string(dat)) - Expect(string(dat)).To(ContainSubstring(".png"), string(dat)) + Expect(err).ToNot(HaveOccurred(), "error reading /image/generations response") + imgUrlResp := &schema.OpenAIResponse{} + err = json.Unmarshal(dat, imgUrlResp) + Expect(imgUrlResp.Data).ToNot(Or(BeNil(), BeZero())) + imgUrl := imgUrlResp.Data[0].URL + Expect(imgUrl).To(ContainSubstring("http://127.0.0.1:9090/"), imgUrl) + Expect(imgUrl).To(ContainSubstring(".png"), imgUrl) + + imgResp, err := http.Get(imgUrl) + Expect(err).To(BeNil()) + Expect(imgResp).ToNot(BeNil()) + Expect(imgResp.StatusCode).To(Equal(200)) + Expect(imgResp.ContentLength).To(BeNumerically(">", 0)) + imgData := make([]byte, 512) + count, err := io.ReadFull(imgResp.Body, imgData) + Expect(err).To(Or(BeNil(), MatchError(io.EOF))) + Expect(count).To(BeNumerically(">", 0)) + Expect(count).To(BeNumerically("<=", 512)) + Expect(http.DetectContentType(imgData)).To(Equal("image/png")) }) })