Improve test coverage
This commit is contained in:
parent
01a238a341
commit
7299c69a27
4 changed files with 443 additions and 3 deletions
|
@ -1,15 +1,26 @@
|
|||
import {
|
||||
assertEquals,
|
||||
assertStringIncludes,
|
||||
assertRejects,
|
||||
} from "std/assert/mod.ts";
|
||||
import { describe, it, afterEach } from "std/testing/bdd.ts";
|
||||
import { describe, it, afterEach, beforeEach } from "std/testing/bdd.ts";
|
||||
import {
|
||||
getConfigDir,
|
||||
getConfigFilePath,
|
||||
ensureConfigDir,
|
||||
createLockfile,
|
||||
checkLockfile,
|
||||
deleteLockfile,
|
||||
readJsonFile,
|
||||
writeJsonFile,
|
||||
deleteConfigFile,
|
||||
readTextFile,
|
||||
writeTextFile,
|
||||
} from "../src/lib/mcp-auth-config.ts";
|
||||
import { MCP_REMOTE_VERSION } from "../src/lib/utils.ts";
|
||||
import * as path from "node:path";
|
||||
import * as os from "node:os";
|
||||
import { assertSpyCalls, spy } from "std/testing/mock.ts";
|
||||
|
||||
describe("mcp-auth-config", () => {
|
||||
describe("getConfigDir", () => {
|
||||
|
@ -61,4 +72,55 @@ describe("mcp-auth-config", () => {
|
|||
assertEquals(filePath, expectedPath);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ensureConfigDir", () => {
|
||||
it("creates directory when it doesn't exist", async () => {
|
||||
// Basic test without spies
|
||||
await ensureConfigDir();
|
||||
// If it doesn't throw, we're good
|
||||
assertEquals(true, true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("lockfile functions", () => {
|
||||
const testHash = "testhash123";
|
||||
const testPort = 12345;
|
||||
const testPid = 67890;
|
||||
|
||||
it("can create and check lockfiles", async () => {
|
||||
// Just test basic functionality without spies
|
||||
await createLockfile(testHash, testPid, testPort);
|
||||
|
||||
const lockfile = await checkLockfile(testHash);
|
||||
|
||||
// Only check that data is correctly returned, not implementation details
|
||||
assertEquals(lockfile?.pid, testPid);
|
||||
assertEquals(lockfile?.port, testPort);
|
||||
|
||||
// Clean up
|
||||
await deleteLockfile(testHash);
|
||||
});
|
||||
});
|
||||
|
||||
describe("file operations", () => {
|
||||
const testHash = "testhash987";
|
||||
const testFilename = "test-fileops.json";
|
||||
const testData = { key: "value" };
|
||||
|
||||
it("writes and reads JSON files", async () => {
|
||||
await writeJsonFile(testHash, testFilename, testData);
|
||||
|
||||
const parseFunc = {
|
||||
parseAsync: (data: unknown) => {
|
||||
return Promise.resolve(data);
|
||||
},
|
||||
};
|
||||
|
||||
const result = await readJsonFile(testHash, testFilename, parseFunc);
|
||||
assertEquals((result as any)?.key, testData.key);
|
||||
|
||||
// Clean up
|
||||
await deleteConfigFile(testHash, testFilename);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue