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.

2.4 KB
Raw Blame
<?php

use App\Models\EnvironmentVariable;
use App\Models\SharedEnvironmentVariable;

it('flags NIXPACKS_ keys as buildpack control variables', function () {
    $env = new EnvironmentVariable;
    $env->key = 'NIXPACKS_NODE_VERSION';

    expect($env->is_buildpack_control)->toBeTrue();
});

it('flags RAILPACK_ keys as buildpack control variables', function () {
    $env = new EnvironmentVariable;
    $env->key = 'RAILPACK_NODE_VERSION';

    expect($env->is_buildpack_control)->toBeTrue();
});

it('does not flag user-defined keys as buildpack control variables', function () {
    $env = new EnvironmentVariable;
    $env->key = 'MY_BUILD_VAR';

    expect($env->is_buildpack_control)->toBeFalse();
});

it('does not flag empty key as buildpack control variable', function () {
    $env = new EnvironmentVariable;

    expect($env->is_buildpack_control)->toBeFalse();
});

it('lists is_buildpack_control in appends and drops legacy is_nixpacks', function () {
    $env = new EnvironmentVariable;

    expect($env->getAppends())->toContain('is_buildpack_control');
    expect($env->getAppends())->not->toContain('is_nixpacks');
});

it('normalizes environment variable keys before storing them on the model', function () {
    $env = new EnvironmentVariable;
    $env->key = ' node.name ';

    expect($env->key)->toBe('node.name');
});

it('allows Docker-compatible environment variable keys on the model', function (string $key) {
    $env = new EnvironmentVariable;
    $env->key = $key;

    expect($env->key)->toBe($key);
})->with([
    'letters and underscore' => 'APP_ENV',
    'dot' => 'node.name',
    'uppercase dots' => 'XPACK.SECURITY.ENABLED',
]);

it('rejects environment variable keys Docker cannot represent on the model', function (string $key) {
    $env = new EnvironmentVariable;

    expect(function () use ($env, $key) {
        $env->key = $key;
    })->toThrow(InvalidArgumentException::class, 'must start with a letter or underscore');
})->with([
    'equals' => 'BAD=KEY',
    'starts with digit' => '1BAD',
    'hyphen' => 'BAD-KEY',
    'semicolon' => 'BAD;KEY',
    'command substitution' => 'BAD$(id)',
]);

it('rejects shared environment variable keys Docker cannot represent on the model', function () {
    $env = new SharedEnvironmentVariable;

    expect(function () use ($env) {
        $env->key = 'BAD=KEY';
    })->toThrow(InvalidArgumentException::class, 'must start with a letter or underscore');
});