diff --git a/playwright/support/utils/session.ts b/playwright/support/utils/session.ts index 990f91ad8..f4806e2f0 100644 --- a/playwright/support/utils/session.ts +++ b/playwright/support/utils/session.ts @@ -3,80 +3,14 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { getContainer } from '@nextcloud/cypress/docker' +import { runExec, addUser } from '@nextcloud/cypress/docker' import { expect, type APIRequestContext } from '@playwright/test' -/** - * Run a shell command on the docker container - * @param command The command to run on the docker container - * @param options Options to pass - * @param options.env Process environment to pass - * @param options.user User to use for executing the command - * @param options.rejectOnError Reject the returned promise in case of non-zero exit code - */ -export async function runShell( - command: string, - options?: { - user?: string - rejectOnError?: boolean - env?: Record - }, -) { - const container = getContainer() - - const exec = await container.exec({ - Cmd: ['sh', '-c', command], - Env: Object.entries(options?.env ?? {}).map( - ([name, value]) => `${name}=${value}`, - ), - User: options?.user, - AttachStderr: true, - AttachStdout: true, - }) - - const stream = await exec.start({}) - return new Promise((resolve, reject) => { - let data = '' - stream.on('data', (chunk: string) => { - data += chunk - }) - stream.on('error', (error: unknown) => reject(error)) - stream.on('end', async () => { - const inspect = await exec.inspect({}) - if (options?.rejectOnError !== false && inspect.ExitCode) { - reject(data) - } else { - resolve(data) - } - }) - }) -} - -/** - * Run an OCC command - * @param command OCC command to run - * @param options Options to pass - * @param options.env Process environment to pass - * @param options.rejectOnError Reject the returned promise in case of non-zero exit code - */ -export async function runOCC( - command: string, - options?: { - env?: Record - rejectOnError?: boolean - }, -) { - return await runShell(`php ./occ ${command}`, { - ...options, - user: 'www-data', - }) -} - /** * Restore database and data folder for tests */ export function restoreDatabase() { - runShell('rm -rf data && tar -xf backup.tar') + runExec('rm -rf data && tar -xf backup.tar') } /** @@ -116,8 +50,6 @@ export async function login( */ export async function createRandomUser(): Promise { const uid = (Math.random() + 1).toString(36).substring(7) - await runOCC(`user:add --password-from-env ${uid}`, { - env: { OC_PASS: uid }, - }) + await addUser(uid) return uid }