-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addresses #15
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
universal/test/operating_system/read_environment_variable.gleam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//// # Read environment variables | ||
//// | ||
//// The envoy package is used to work with environment variables. This package | ||
//// works on both Erlang and JavaScript targets. | ||
//// | ||
//// Note that we are using `let assert` to crash if any of these functions | ||
//// fail. In a real application or library, you would want to handle results | ||
//// properly. | ||
//// | ||
//// ## Dependencies | ||
//// | ||
//// - https://hex.pm/packages/envoy | ||
//// | ||
|
||
import envoy | ||
import gleam/dict | ||
|
||
pub fn main_test() { | ||
// First, unset the PORT variable. | ||
// | ||
// We do this fist to get the environment into a known state. If the PORT | ||
// variable is not already set, this will have no effect. | ||
let Nil = envoy.unset("PORT") | ||
|
||
// Try to get an environment variable by name. | ||
// | ||
// We expect that this will fail, as we unset this variable above. | ||
let assert Error(Nil) = envoy.get("PORT") | ||
|
||
// Set the PORT environment variable to 8080. | ||
let Nil = envoy.set("PORT", "8080") | ||
|
||
// Now that the PORT variable has been set, we expect to successfully get its | ||
// value. | ||
let assert Ok("8080") = envoy.get("PORT") | ||
|
||
// We can also get a Dict of all set environment variables. | ||
let environment_variables = envoy.all() | ||
let assert Ok("8080") = dict.get(environment_variables, "PORT") | ||
} |