107 lines
3.0 KiB
TypeScript
107 lines
3.0 KiB
TypeScript
|
import { describe, expect, it } from "bun:test";
|
||
|
import { Application } from "./Caprover";
|
||
|
|
||
|
describe("Caprover", () => {
|
||
|
describe("Application", () => {
|
||
|
const anAppDefinition = {
|
||
|
hasPersistentData: false,
|
||
|
description: "",
|
||
|
instanceCount: 1,
|
||
|
captainDefinitionRelativeFilePath: "./captain-definition",
|
||
|
networks: ["captain-overlay-network"],
|
||
|
envVars: [
|
||
|
{
|
||
|
key: "ADMINER_PLUGINS",
|
||
|
value: "",
|
||
|
},
|
||
|
{
|
||
|
key: "ADMINER_DESIGN",
|
||
|
value: "",
|
||
|
},
|
||
|
],
|
||
|
volumes: [],
|
||
|
ports: [],
|
||
|
versions: [
|
||
|
{
|
||
|
version: 0,
|
||
|
timeStamp: "2020-08-02T01:25:07.232Z",
|
||
|
deployedImageName: "img-captain-adminer:0",
|
||
|
gitHash: "",
|
||
|
},
|
||
|
{
|
||
|
version: 1,
|
||
|
timeStamp: "2021-03-19T10:04:54.823Z",
|
||
|
deployedImageName: "adminer:4.8.0",
|
||
|
gitHash: "",
|
||
|
},
|
||
|
{
|
||
|
version: 2,
|
||
|
timeStamp: "2021-12-04T10:24:48.757Z",
|
||
|
deployedImageName: "adminer:4.8.1",
|
||
|
gitHash: "",
|
||
|
},
|
||
|
],
|
||
|
deployedVersion: 2,
|
||
|
notExposeAsWebApp: false,
|
||
|
customDomain: [],
|
||
|
hasDefaultSubDomainSsl: true,
|
||
|
forceSsl: true,
|
||
|
websocketSupport: false,
|
||
|
containerHttpPort: 8080,
|
||
|
preDeployFunction: "",
|
||
|
serviceUpdateOverride: "",
|
||
|
appName: "adminer",
|
||
|
isAppBuilding: false,
|
||
|
};
|
||
|
|
||
|
it("should create an application from definition", () => {
|
||
|
const app = Application.createFromDefinition(anAppDefinition);
|
||
|
expect(app.name).toBe("adminer");
|
||
|
});
|
||
|
|
||
|
describe("docker image", () => {
|
||
|
it("should return the docker image name of the current version", () => {
|
||
|
const app = Application.createFromDefinition(anAppDefinition);
|
||
|
expect(app.dockerImage).toEqual({
|
||
|
name: "adminer",
|
||
|
tag: "4.8.1",
|
||
|
hubUrl: "https://hub.docker.com/_/adminer",
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it("should parse names with organization namespace", () => {
|
||
|
const app = Application.createFromDefinition({
|
||
|
...anAppDefinition,
|
||
|
deployedVersion: 0,
|
||
|
versions: [
|
||
|
{
|
||
|
...anAppDefinition.versions[0],
|
||
|
deployedImageName: "vaultwarden/server:1.30.0-alpine",
|
||
|
},
|
||
|
],
|
||
|
});
|
||
|
expect(app.dockerImage).toEqual({
|
||
|
name: "vaultwarden/server",
|
||
|
tag: "1.30.0-alpine",
|
||
|
hubUrl: "https://hub.docker.com/r/vaultwarden/server",
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it("should not parse custom built images", () => {
|
||
|
const app = Application.createFromDefinition({
|
||
|
...anAppDefinition,
|
||
|
deployedVersion: 0,
|
||
|
versions: [
|
||
|
{
|
||
|
...anAppDefinition.versions[0],
|
||
|
deployedImageName:
|
||
|
"registry.example.org:996/captain/img-captain-nextcloud-cron:4",
|
||
|
},
|
||
|
],
|
||
|
});
|
||
|
expect(app.dockerImage).toBeUndefined();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|