test: cover Ollama health check outcomes
- Verify healthy responses return true - Verify non-OK HTTP responses return false - Verify network failures return false without propagating errors - Restore the global fetch implementation after each test
This commit is contained in:
parent
ed0630bbc1
commit
6828f31003
1 changed files with 36 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { it } from "node:test";
|
import { it } from "node:test";
|
||||||
|
|
||||||
import { generateResponse } from "./ollama.js";
|
import { checkOllamaHealth, generateResponse } from "./ollama.js";
|
||||||
|
|
||||||
it("returns generated text from Ollama", async () => {
|
it("returns generated text from Ollama", async () => {
|
||||||
const originalFetch = globalThis.fetch;
|
const originalFetch = globalThis.fetch;
|
||||||
|
|
@ -79,3 +79,38 @@ it("propagates an error when an Ollama request times out", async () => {
|
||||||
globalThis.fetch = originalFetch;
|
globalThis.fetch = originalFetch;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("returns true when Ollama is healthy", async () => {
|
||||||
|
const originalFetch = globalThis.fetch;
|
||||||
|
globalThis.fetch = async () => new Response("{}", { status: 200 });
|
||||||
|
|
||||||
|
try {
|
||||||
|
assert.equal(await checkOllamaHealth(), true);
|
||||||
|
} finally {
|
||||||
|
globalThis.fetch = originalFetch;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns false when Ollama returns a non-OK health response", async () => {
|
||||||
|
const originalFetch = globalThis.fetch;
|
||||||
|
globalThis.fetch = async () => new Response("Unavailable", { status: 503 });
|
||||||
|
|
||||||
|
try {
|
||||||
|
assert.equal(await checkOllamaHealth(), false);
|
||||||
|
} finally {
|
||||||
|
globalThis.fetch = originalFetch;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns false when Ollama is unreachable during a health check", async () => {
|
||||||
|
const originalFetch = globalThis.fetch;
|
||||||
|
globalThis.fetch = async () => {
|
||||||
|
throw new TypeError("fetch failed");
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
assert.equal(await checkOllamaHealth(), false);
|
||||||
|
} finally {
|
||||||
|
globalThis.fetch = originalFetch;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue