-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure nested configs can be loaded from env file (#4360)
- Loading branch information
Showing
3 changed files
with
39 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@effect/platform": patch | ||
--- | ||
|
||
Ensure that nested configuration values can be properly loaded from an env file |
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,28 @@ | ||
import * as FileSystem from "@effect/platform/FileSystem" | ||
import * as PlatformConfigProvider from "@effect/platform/PlatformConfigProvider" | ||
import { assert, describe, it } from "@effect/vitest" | ||
import * as Config from "effect/Config" | ||
import * as Effect from "effect/Effect" | ||
import * as Layer from "effect/Layer" | ||
|
||
const ConfigProviderLive = Layer.unwrapEffect( | ||
PlatformConfigProvider.fromDotEnv(".env").pipe( | ||
Effect.map(Layer.setConfigProvider) | ||
) | ||
) | ||
|
||
describe("PlatformConfigProvider", () => { | ||
it.effect("should properly load configuration values from an env file", () => | ||
Effect.gen(function*() { | ||
const fileSystem = FileSystem.layerNoop({ | ||
readFileString: () => Effect.succeed("NESTED_CONFIG=nested_config") | ||
}) | ||
|
||
const result = yield* Config.string("CONFIG").pipe( | ||
Config.nested("NESTED"), | ||
Effect.provide(Layer.provide(ConfigProviderLive, fileSystem)) | ||
) | ||
|
||
assert.strictEqual(result, "nested_config") | ||
})) | ||
}) |