Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

4.1 KB
Raw Blame
<?php

it('reuses resolved environment credentials in database startup integrations', function (string $action, array $expected, array $unexpected) {
    $source = file_get_contents(__DIR__."/../../app/Actions/Database/{$action}.php");

    expect($source)->toContain(...$expected)
        ->not->toContain(...$unexpected);
})->with([
    'clickhouse' => [
        'StartClickhouse',
        ['$this->resolvedClickhouseUser', '$this->resolvedClickhousePassword'],
        ['$this->database->clickhouse_admin_user, \'--password\'', '$this->database->clickhouse_admin_password, \'--query\''],
    ],
    'dragonfly' => [
        'StartDragonfly',
        ['$this->resolvedRedisPassword'],
        ['$this->database->dragonfly_password, \'ping\'', 'requirepass {$this->database->dragonfly_password}'],
    ],
    'keydb' => [
        'StartKeydb',
        ['$this->resolvedRedisPassword'],
        ['$this->database->keydb_password, \'ping\'', 'requirepass {$this->database->keydb_password}'],
    ],
    'mongodb' => [
        'StartMongodb',
        ['$this->resolvedMongoDatabase', '$this->resolvedMongoUsername', '$this->resolvedMongoPassword'],
        ['json_encode($this->database->mongo_initdb_database', 'json_encode($this->database->mongo_initdb_root_username', 'json_encode($this->database->mongo_initdb_root_password'],
    ],
    'mysql' => [
        'StartMysql',
        ['$this->resolvedMysqlRootPassword'],
        ['-p{$this->database->mysql_root_password}'],
    ],
    'postgresql' => [
        'StartPostgresql',
        ['$this->resolvedPostgresUser', '$this->resolvedPostgresDatabase'],
        ['$this->database->postgres_user, \'-d\'', '$this->database->postgres_db, \'-c\''],
    ],
]);

it('runs database start commands without persisting them through remote process', function (string $action) {
    $source = file_get_contents(__DIR__."/../../app/Actions/Database/{$action}.php");

    expect($source)
        ->toContain('ExecutesDatabaseStartCommands')
        ->toContain('executeDatabaseStartCommands(')
        ->not->toContain('return remote_process(');
})->with([
    'StartClickhouse',
    'StartDragonfly',
    'StartKeydb',
    'StartMariadb',
    'StartMongodb',
    'StartMysql',
    'StartPostgresql',
    'StartRedis',
    'StartSqlite',
]);

it('queues database starts with identifiers instead of generated commands', function () {
    $source = file_get_contents(__DIR__.'/../../app/Actions/Database/StartDatabase.php');

    expect($source)
        ->toContain('DatabaseStartJob::dispatch(')
        ->not->toContain('StartPostgresql::run(')
        ->not->toContain('StartRedis::run(');
});

it('keeps raw secret values separate from compose environment formatting', function (string $action, array $rawAssignments) {
    $source = file_get_contents(__DIR__."/../../app/Actions/Database/{$action}.php");

    expect($source)
        ->toContain('$rawValue = (string) $this->database->resolveSecretManagerEnvironmentVariableValue($env);')
        ->toContain('$resolvedValue = (string) $this->database->formatEnvironmentVariableValue($env, $rawValue);')
        ->toContain('$environment_variables->push($env->key.\'=\'.$resolvedValue);')
        ->toContain(...$rawAssignments);
})->with([
    'clickhouse' => ['StartClickhouse', ['$this->resolvedClickhouseUser = $composeFileValue;', '$this->resolvedClickhousePassword = $composeFileValue;']],
    'dragonfly' => ['StartDragonfly', ['$this->resolvedRedisPassword = $this->database->formatComposeFileValue($env, $rawValue);', '$this->requirePassArgument()']],
    'keydb' => ['StartKeydb', ['$this->resolvedRedisPassword = $this->database->formatComposeFileValue($env, $rawValue);', '$this->requirePassArgument()']],
    'mongodb' => ['StartMongodb', ['$this->resolvedMongoUsername = $rawValue;', '$this->resolvedMongoPassword = $rawValue;', '$this->resolvedMongoDatabase = $rawValue;', 'json_encode($this->resolvedMongoPassword']],
    'mysql' => ['StartMysql', ['$this->resolvedMysqlRootPassword = $composeFileValue;']],
    'postgresql' => ['StartPostgresql', ['$this->resolvedPostgresUser = $composeFileValue;', '$this->resolvedPostgresDatabase = $composeFileValue;']],
]);