mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-06 06:25:28 +02:00
test(upload): add unit tests for getRegistryTag function
- Introduced a new test suite for the getRegistryTag function, covering various scenarios including handling of usernames, image prefixes, and custom registry URLs. - Ensured that the function correctly constructs image tags based on different input conditions, improving test coverage and reliability.
This commit is contained in:
@@ -74,11 +74,40 @@ export const uploadImageRemoteCommand = async (
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Extract the repository name from imageName by taking the last part after '/'
|
||||
* Examples:
|
||||
* - "nginx" -> "nginx"
|
||||
* - "nginx:latest" -> "nginx:latest"
|
||||
* - "myuser/myrepo" -> "myrepo"
|
||||
* - "myuser/myrepo:tag" -> "myrepo:tag"
|
||||
* - "docker.io/myuser/myrepo" -> "myrepo"
|
||||
*/
|
||||
const extractRepositoryName = (imageName: string): string => {
|
||||
const lastSlashIndex = imageName.lastIndexOf("/");
|
||||
|
||||
// If no '/', return the imageName as is
|
||||
if (lastSlashIndex === -1) {
|
||||
return imageName;
|
||||
}
|
||||
|
||||
// Extract everything after the last '/'
|
||||
return imageName.substring(lastSlashIndex + 1);
|
||||
};
|
||||
|
||||
export const getRegistryTag = (registry: Registry, imageName: string) => {
|
||||
const { registryUrl, imagePrefix, username } = registry;
|
||||
return imagePrefix
|
||||
? `${registryUrl ? `${registryUrl}/` : ""}${imagePrefix}/${imageName}`
|
||||
: `${registryUrl ? `${registryUrl}/` : ""}${username}/${imageName}`;
|
||||
|
||||
// Extract the repository name (last part after '/')
|
||||
const repositoryName = extractRepositoryName(imageName);
|
||||
|
||||
// Build the final tag using registry's username/prefix
|
||||
const targetPrefix = imagePrefix || username;
|
||||
const finalRegistry = registryUrl || "";
|
||||
|
||||
return finalRegistry
|
||||
? `${finalRegistry}/${targetPrefix}/${repositoryName}`
|
||||
: `${targetPrefix}/${repositoryName}`;
|
||||
};
|
||||
|
||||
const getRegistryCommands = (
|
||||
|
||||
Reference in New Issue
Block a user