mirror of
https://github.com/certd/certd.git
synced 2026-07-16 18:57:32 +08:00
chore: 修复单元测试
This commit is contained in:
+23
-17
@@ -19,16 +19,23 @@ describe("VolcengineDeployToVKE", () => {
|
||||
plugin.kubeconfigType = "Public";
|
||||
plugin.logger = { info: () => undefined } as any;
|
||||
|
||||
let requestBody: any;
|
||||
const kubeconfigId = await (plugin as any).createKubeconfig({
|
||||
let createRequestBody: any;
|
||||
const kubeconfig = ["apiVersion: v1", "clusters:", "- cluster:", " server: https://example.com", " name: vke", "contexts: []", "current-context: vke"].join("\n");
|
||||
const vkeService = {
|
||||
request: async (req: any) => {
|
||||
requestBody = req.body;
|
||||
return { Result: { Id: "kc-123" } };
|
||||
if (req.action === "CreateKubeconfig") {
|
||||
createRequestBody = req.body;
|
||||
return { Result: { Id: "kc-123" } };
|
||||
} else if (req.action === "ListKubeconfigs") {
|
||||
return { Result: { Items: [{ Id: "kc-123", Kubeconfig: Buffer.from(kubeconfig).toString("base64") }] } };
|
||||
}
|
||||
return {};
|
||||
},
|
||||
});
|
||||
};
|
||||
const kubeconfigStr = await (plugin as any).createKubeconfig({ vkeService });
|
||||
|
||||
assert.equal(kubeconfigId, "kc-123");
|
||||
assert.equal(requestBody.ClusterId, "cc1234567890123456789");
|
||||
assert.equal(createRequestBody.ClusterId, "cc1234567890123456789");
|
||||
assert.equal(kubeconfigStr, kubeconfig);
|
||||
});
|
||||
|
||||
it("decodes the base64 kubeconfig returned by VKE", async () => {
|
||||
@@ -38,16 +45,15 @@ describe("VolcengineDeployToVKE", () => {
|
||||
|
||||
const kubeconfig = ["apiVersion: v1", "clusters:", "- cluster:", " server: https://example.com", " name: vke", "contexts: []", "current-context: vke"].join("\n");
|
||||
|
||||
const result = await (plugin as any).getKubeconfig(
|
||||
{
|
||||
request: async () => ({
|
||||
Result: {
|
||||
Items: [{ Id: "kc-123", Kubeconfig: Buffer.from(kubeconfig).toString("base64") }],
|
||||
},
|
||||
}),
|
||||
},
|
||||
"kc-123"
|
||||
);
|
||||
const vkeService = {
|
||||
request: async () => ({
|
||||
Result: {
|
||||
Items: [{ Id: "kc-123", Kubeconfig: Buffer.from(kubeconfig).toString("base64") }],
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
const result = await (plugin as any).getKubeconfig({ vkeService, kubeconfigId: "kc-123" });
|
||||
|
||||
assert.equal(result, kubeconfig);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user