-
Notifications
You must be signed in to change notification settings - Fork 17
Add support for one zero and yes no boolean strings in environement variables provider #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fc56f4b
9b6bc7b
85667b4
5ba67cb
e235d9b
eaf878d
0f3bde2
d45e629
8ad1813
b4cda9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,6 +68,57 @@ struct EnvironmentVariablesProviderTests { | |||||||||||
| #expect(provider.debugDescription == expectedDebugDescription) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @Test() | ||||||||||||
| @available(Configuration 1.0, *) | ||||||||||||
| func decodeBoolFromString() throws { | ||||||||||||
|
Comment on lines
+71
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| let sut = EnvironmentVariablesProvider.Snapshot.decodeBool | ||||||||||||
| let cases: [(expected: Bool?, input: [String])] = [ | ||||||||||||
| (true, ["1"]), | ||||||||||||
| (false, ["0"]), | ||||||||||||
| (true, ["Yes", "yes", "YES", "yES"]), | ||||||||||||
| (false, ["No", "no", "NO", "nO"]), | ||||||||||||
| (true, ["true", "TRUE", "trUe"]), | ||||||||||||
| (false, ["false", "FALSE", "faLse"]), | ||||||||||||
| (nil, ["", "_true_", "_false_", "_yes_", "_no_", "_1_", "_0_", "11", "00"]) | ||||||||||||
| ] | ||||||||||||
| for (expected, inputs) in cases { | ||||||||||||
| for input in inputs { | ||||||||||||
| #expect(sut(input) == expected, "input: \(input)") | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @available(Configuration 1.0, *) | ||||||||||||
| @Test func valueForKeyOfBoolAndBoolArrayTypes() throws { | ||||||||||||
| let sut = EnvironmentVariablesProvider( | ||||||||||||
| environmentVariables: [ | ||||||||||||
| "BOOL_TRUE": "true", | ||||||||||||
| "BOOL_FALSE": "false", | ||||||||||||
| "BOOL_1": "1", | ||||||||||||
| "BOOL_0": "0", | ||||||||||||
| "BOOL_YES": "YES", | ||||||||||||
| "BOOL_NO": "NO", | ||||||||||||
| "BOOL_THROWS_ERROR_EMPTY": "", | ||||||||||||
| "BOOL_THROWS_ERROR_NOT_BOOL_STRING": "2", | ||||||||||||
| "BOOLY_ARRAY_TRUE": "true,1,,YES", | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, I'd expect this to throw an error due to the 3rd element being an empty string - can you take a look why it doesn't? Probably a pre-existing bug |
||||||||||||
| "BOOLY_ARRAY_FALSE": "false,0,NO", | ||||||||||||
| "BOOLY_ARRAY_THROWS_1": "true,1,YESS", | ||||||||||||
| "BOOLY_ARRAY_THROWS_2": "false,00,no", | ||||||||||||
| ]) | ||||||||||||
| #expect(try sut.value(forKey: "BOOL_TRUE", type: .bool).value == true) | ||||||||||||
| #expect(try sut.value(forKey: "BOOL_FALSE", type: .bool).value == false) | ||||||||||||
| #expect(try sut.value(forKey: "BOOL_1", type: .bool).value == true) | ||||||||||||
| #expect(try sut.value(forKey: "BOOL_0", type: .bool).value == false) | ||||||||||||
| #expect(try sut.value(forKey: "BOOL_YES", type: .bool).value == true) | ||||||||||||
| #expect(try sut.value(forKey: "BOOL_NO", type: .bool).value == false) | ||||||||||||
| #expect(throws: ConfigError.self) { try sut.value(forKey: "BOOL_THROWS_ERROR_EMPTY", type: .bool) } | ||||||||||||
| #expect(throws: ConfigError.self) { try sut.value(forKey: "BOOL_THROWS_ERROR_NOT_BOOL_STRING", type: .bool) } | ||||||||||||
| #expect(try sut.value(forKey: "BOOLY_ARRAY_TRUE", type: .boolArray).value == .init([true, true, true], isSecret: false)) | ||||||||||||
| #expect(try sut.value(forKey: "BOOLY_ARRAY_FALSE", type: .boolArray).value == .init([false, false, false], isSecret: false)) | ||||||||||||
| #expect(throws: ConfigError.self) { try sut.value(forKey: "BOOLY_ARRAY_THROWS_1", type: .boolArray) } | ||||||||||||
| #expect(throws: ConfigError.self) { try sut.value(forKey: "BOOLY_ARRAY_THROWS_2", type: .boolArray) } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @available(Configuration 1.0, *) | ||||||||||||
| @Test func compat() async throws { | ||||||||||||
| try await ProviderCompatTest(provider: provider).runTest() | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a bit shorter :)