mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { generateRandomHash } from "@dokploy/server";
|
|
import { addSuffixToServiceNames } from "@dokploy/server";
|
|
import type { ComposeSpecification } from "@dokploy/server";
|
|
import { load } from "js-yaml";
|
|
import { expect, test } from "vitest";
|
|
|
|
test("Generate random hash with 8 characters", () => {
|
|
const hash = generateRandomHash();
|
|
|
|
expect(hash).toBeDefined();
|
|
expect(hash.length).toBe(8);
|
|
});
|
|
|
|
const composeFile = `
|
|
version: "3.8"
|
|
|
|
services:
|
|
web:
|
|
image: nginx:latest
|
|
|
|
api:
|
|
image: myapi:latest
|
|
|
|
networks:
|
|
default:
|
|
driver: bridge
|
|
`;
|
|
|
|
test("Add suffix to service names in compose file", () => {
|
|
const composeData = load(composeFile) as ComposeSpecification;
|
|
|
|
const suffix = generateRandomHash();
|
|
|
|
if (!composeData.services) {
|
|
return;
|
|
}
|
|
const updatedComposeData = addSuffixToServiceNames(
|
|
composeData.services,
|
|
suffix,
|
|
);
|
|
const actualComposeData = { ...composeData, services: updatedComposeData };
|
|
|
|
// Verificar que los nombres de los servicios han cambiado correctamente
|
|
expect(actualComposeData.services).toHaveProperty(`web-${suffix}`);
|
|
expect(actualComposeData.services).toHaveProperty(`api-${suffix}`);
|
|
// Verificar que las claves originales no existen
|
|
expect(actualComposeData.services).not.toHaveProperty("web");
|
|
expect(actualComposeData.services).not.toHaveProperty("api");
|
|
});
|