Files
cloud-mcp/tests/unit/tools/devops/server.test.ts

72 lines
2.1 KiB
TypeScript

/*
* @Date: 2026-01-07 09:11:20
* @LastEditors: 陈子健
* @LastEditTime: 2026-01-07 10:04:41
* @FilePath: /cloud-mcp/tests/unit/tools/devops/server.test.ts
*/
/**
* Server tools tests (with mocked SSH)
*/
import { describe, test, expect, beforeEach } from "bun:test";
import { registerServerTools } from "../../../../src/tools/devops/server.js";
import { callTool } from "../../../helpers/tool-helper.js";
import { setTestEnv } from "../../../helpers/test-utils.js";
describe("Server Tools", () => {
let cleanupEnv: () => void;
beforeEach(() => {
cleanupEnv = setTestEnv({
SERVER_HOST: "test-server",
SERVER_USERNAME: "test-user",
SERVER_PORT: "22",
SERVER_KEY_PATH: "/test/key/path",
});
registerServerTools();
});
afterEach(() => {
cleanupEnv();
});
test("should handle server status request", async () => {
const result = await callTool("server_status", {});
// Should either return status or handle connection error gracefully
expect(result.content[0].text).toBeDefined();
// Since we don't have actual SSH connection, it will likely return an error
// which is expected behavior
}, 15000); // Longer timeout for SSH attempts
test("should handle server logs request", async () => {
const result = await callTool("server_logs", {
logPath: "/var/log/test.log",
lines: 10,
});
// Should either return logs or handle connection error gracefully
expect(result.content[0].text).toBeDefined();
}, 15000);
test("should handle deploy request", async () => {
const result = await callTool("server_deploy", {
localPath: "/local/path",
remotePath: "/remote/path",
command: "pm2 restart app",
});
expect(result.content[0].text).toContain("Deployment initiated");
});
test("should handle missing server configuration", async () => {
cleanupEnv();
cleanupEnv = setTestEnv({});
registerServerTools();
const result = await callTool("server_status", {});
expect(result.content[0].text).toContain("configuration not found");
});
});