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

ConfigurationTest.pudu

Pudu34 lines1.6 KB

GitHub ↗
1/** @Test.Configuration.Suite — variables layered over configuration */2module PuduLangEnvironment.ConfigurationTest34import Std.App.Config as Config5import Std.Io as Io6import Std.Map as Map7import Std.Test as Test8import PuduLangEnvironment.Configuration as Configuration9import PuduLangEnvironment.Variables as Variables1011/// A view over the given variables.12fn over(pairs: Array[(Str, Str)]) -> Variables.Variables {13  Variables.settled(&Map.empty(), &Map.fromPairs(&pairs), true, [], [])14}1516/// Runs the suite.17fn main() -> Int {18  let declared = Config.declaring(&[("server.port", "8080"), ("log-level", "info"), ("name", "app")])19  let layered = declared.withVariables(&over([("SERVER_PORT", "9090"), ("LOG_LEVEL", ""), ("UNDECLARED", "x")]))20  let checks = Test.suite("Configuration", &[21      Test.equals("a declared setting takes its variable", &Config.whole(&layered, "server.port"), &Ok(9090)),22      Test.equals("the setting records the environment as its source", &Config.sourceOf(&layered, "server.port"), &Some(Config.Environment)),23      Test.equals("an empty variable leaves the setting", &(Config.textOr(&layered, "log-level", ""), Config.sourceOf(&layered, "log-level")), &("info", Some(Config.Declared))),24      Test.equals("a setting without a variable is kept", &Config.textOr(&layered, "name", ""), &"app"),25      Test.equals("an undeclared variable does not become a setting", &Config.sourceOf(&layered, "undeclared"), &None),26      Test.equals("the profile is kept", &Config.profileOf(&layered), &Config.profileOf(&declared))27    ])28  let ran = Test.run(&checks)29  for failure in Test.failuresOf(&ran) {30    let _reported = Io.writeErrorLine(failure)31  }32  Test.report(&ran)33}34