mirror of
https://github.com/mudler/LocalAI.git
synced 2025-01-18 10:46:46 +00:00
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 <dave@gray101.com>
This commit is contained in:
parent
c5798500cb
commit
b52ff1249f
@ -708,10 +708,26 @@ var _ = Describe("API test", func() {
|
|||||||
// The response should contain an URL
|
// The response should contain an URL
|
||||||
Expect(err).ToNot(HaveOccurred(), fmt.Sprint(resp))
|
Expect(err).ToNot(HaveOccurred(), fmt.Sprint(resp))
|
||||||
dat, err := io.ReadAll(resp.Body)
|
dat, err := io.ReadAll(resp.Body)
|
||||||
Expect(err).ToNot(HaveOccurred(), string(dat))
|
Expect(err).ToNot(HaveOccurred(), "error reading /image/generations response")
|
||||||
Expect(string(dat)).To(ContainSubstring("http://127.0.0.1:9090/"), string(dat))
|
|
||||||
Expect(string(dat)).To(ContainSubstring(".png"), string(dat))
|
|
||||||
|
|
||||||
|
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"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user