Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-environment

Environment files for Pudu: load .env variables safely with layered files, discovery, expansion, typed reads, and secrets kept out of every message

0.1.0Apache-2.01

InstallClose

CascadeTest.pudu

Pudu35 lines2.2 KB

GitHub ↗
1/** @Test.Domain.Cascade.Suite — environment names and layered files */2module PuduLangEnvironment.Domain.CascadeTest34import Std.Io as Io5import Std.Map as Map6import Std.Test as Test7import PuduLangEnvironment.Domain.Cascade as Cascade89/// Runs the suite.10fn main() -> Int {11  let both = Map.fromPairs(&[("PUDU_ENV", " staging "), ("PROFILE", "production")])12  let profileOnly = Map.fromPairs(&[("PUDU_ENV", "  "), ("PROFILE", "production")])13  let checks = Test.suite("Domain.Cascade", &[14      Test.equals("an explicit name wins, trimmed", &Cascade.chooseName(&Some(" test "), &both), &Some("test")),15      Test.equals("a blank explicit name defers to the variables", &Cascade.chooseName(&Some("  "), &both), &Some("staging")),16      Test.equals("PUDU_ENV comes before PROFILE", &Cascade.chooseName(&None, &both), &Some("staging")),17      Test.equals("a blank PUDU_ENV defers to PROFILE", &Cascade.chooseName(&None, &profileOnly), &Some("production")),18      Test.equals("no name anywhere is none", &Cascade.chooseName(&None, &Map.empty()), &None),19      Test.that("a plain name is safe", Cascade.isSafe("staging") && Cascade.isSafe("eu-west.1") && Cascade.isSafe("a")),20      Test.that("a blank name is unsafe", !Cascade.isSafe("") && !Cascade.isSafe("   ")),21      Test.that("a parent step is unsafe", !Cascade.isSafe("..") && !Cascade.isSafe("a..b")),22      Test.that("a single dot is safe", Cascade.isSafe("v1.2")),23      Test.that("path separators are unsafe", !Cascade.isSafe("a/b") && !Cascade.isSafe("a\\b")),24      Test.that("characters a file name cannot hold are unsafe", !Cascade.isSafe("a:b") && !Cascade.isSafe("a*") && !Cascade.isSafe("a?") && !Cascade.isSafe("a\"") && !Cascade.isSafe("<a") && !Cascade.isSafe("a>") && !Cascade.isSafe("a|b")),25      Test.that("control characters are unsafe", !Cascade.isSafe("a\nb") && !Cascade.isSafe("a\tb")),26      Test.equals("without a name the cascade is the shared files", &Cascade.candidates(&None), &[".env", ".env.local"]),27      Test.equals("a name adds its own layers", &Cascade.candidates(&Some("test")), &[".env", ".env.local", ".env.test", ".env.test.local"])28    ])29  let ran = Test.run(&checks)30  for failure in Test.failuresOf(&ran) {31    let _reported = Io.writeErrorLine(failure)32  }33  Test.report(&ran)34}35