-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for properties and environment variables
- Loading branch information
Showing
7 changed files
with
115 additions
and
5 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
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,32 @@ | ||
import { System as JvmSystem } from "@gatling.io/jvm-types"; | ||
|
||
export interface GetWithDefault { | ||
(name: string): string | undefined; | ||
(name: string, defaultValue: string): string; | ||
} | ||
|
||
/** | ||
* Gets the option indicated by the specified name. | ||
* | ||
* Options can be specified in the `gatling run` command by passing arguments with the format `key=value`, e.g. | ||
* `gatling run option1=foo option2=bar`. | ||
* | ||
* @param key - the key of the option. | ||
* @param defaultValue - a default value | ||
* @returns the string value of the option if it is defined, or else `defaultValue` if provided, or else `undefined`. | ||
*/ | ||
export const getOption: GetWithDefault = (key: string, defaultValue?: string) => | ||
getOrElse(JvmSystem.getProperty(key), defaultValue) as any; | ||
|
||
/** | ||
* Gets the environment variable indicated by the specified name. | ||
* | ||
* @param name - the name of the environment variable. | ||
* @param defaultValue - a default value | ||
* @returns the string value of the environment variable if it is defined, or else `defaultValue` if provided, or else `undefined`. | ||
*/ | ||
export const getEnvironmentVariable: GetWithDefault = (name: string, defaultValue?: string) => | ||
getOrElse(JvmSystem.getenv(name), defaultValue) as any; | ||
|
||
const getOrElse = (value: string | null, defaultValue?: string): string | undefined => | ||
typeof value === "string" ? value : defaultValue; |
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