This commit is contained in:
@@ -6,6 +6,9 @@ import {
|
||||
pickPrimaryComposeService,
|
||||
mergeServiceIntoTemplate,
|
||||
resolveTemplateForDeploy,
|
||||
templateEnvToEnvFile,
|
||||
buildStackDeployPayload,
|
||||
templateStackName,
|
||||
} from '../client/templateResolve.js'
|
||||
|
||||
test('isStackTemplate detects type 2/3 and repo-only entries', (t) => {
|
||||
@@ -113,3 +116,76 @@ test('resolveTemplateForDeploy leaves type-1 image templates alone', async (t) =
|
||||
t.is(resolved.image, 'nginx:latest')
|
||||
t.absent(resolved._composeResolved)
|
||||
})
|
||||
|
||||
test('templateEnvToEnvFile and buildStackDeployPayload', (t) => {
|
||||
const envFile = templateEnvToEnvFile([
|
||||
{ name: 'PUID', default: '1000' },
|
||||
{
|
||||
name: 'AUTO',
|
||||
select: [
|
||||
{ text: 'Yes', value: 'true', default: true },
|
||||
{ text: 'No', value: 'false' },
|
||||
],
|
||||
},
|
||||
'FOO=bar',
|
||||
])
|
||||
t.ok(envFile.includes('PUID=1000'))
|
||||
t.ok(envFile.includes('AUTO=true'))
|
||||
t.ok(envFile.includes('FOO=bar'))
|
||||
|
||||
const tpl = {
|
||||
type: 3,
|
||||
title: 'Activepieces',
|
||||
name: 'activepieces',
|
||||
note: 'Setup notes',
|
||||
env: [{ name: 'X', default: '1' }],
|
||||
_composeText: 'services:\n app:\n image: app:1\n',
|
||||
_serviceCount: 2,
|
||||
repository: {
|
||||
url: 'https://github.com/xneo1/portainer_templates',
|
||||
stackfile: 'Template/Stack/activepieces.yml',
|
||||
},
|
||||
}
|
||||
const payload = buildStackDeployPayload(tpl)
|
||||
t.ok(payload.ok)
|
||||
t.is(payload.stackName, templateStackName(tpl))
|
||||
t.ok(payload.composeContent.includes('image: app:1'))
|
||||
t.ok(payload.envFileContent.includes('X=1'))
|
||||
t.ok(payload.repoUrl.includes('github.com'))
|
||||
t.is(payload.composePath, 'Template/Stack/activepieces.yml')
|
||||
t.is(payload.note, 'Setup notes')
|
||||
})
|
||||
|
||||
test('resolveTemplateForDeploy attaches full compose text for stacks', async (t) => {
|
||||
const compose = `
|
||||
services:
|
||||
web:
|
||||
image: nginx:alpine
|
||||
ports: ["80:80"]
|
||||
db:
|
||||
image: postgres:15
|
||||
`
|
||||
const resolved = await resolveTemplateForDeploy(
|
||||
{
|
||||
type: 3,
|
||||
title: 'Web',
|
||||
name: 'web',
|
||||
repository: {
|
||||
url: 'https://github.com/ex/repo',
|
||||
stackfile: 'compose.yml',
|
||||
},
|
||||
},
|
||||
{
|
||||
fetchImpl: async () => ({
|
||||
ok: true,
|
||||
text: async () => compose,
|
||||
}),
|
||||
}
|
||||
)
|
||||
t.ok(resolved._composeText.includes('postgres'))
|
||||
t.is(resolved._serviceCount, 2)
|
||||
t.is(resolved.image, 'nginx:alpine')
|
||||
const payload = buildStackDeployPayload(resolved)
|
||||
t.ok(payload.ok)
|
||||
t.is(payload.serviceCount, 2)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user