-
Notifications
You must be signed in to change notification settings - Fork 5
Fix DECKARD_MONGODB_DATABASE environment variable not working #65
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
Open
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/fix-51
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2874fdc
Initial plan for issue
Copilot ea7cae4
Initial analysis: Add test showing DECKARD_MONGODB_DATABASE issue
Copilot 668bf8c
Fix ViperConfigKey methods to prioritize environment variables over d…
Copilot 766c4d0
Refactor: Extract helper function to reduce code duplication in getters
Copilot fb75746
Fix duration parsing consistency and remove accidental cert file
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,116 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestMongoDatabaseEnvironmentVariable(t *testing.T) { | ||
| defer func() { | ||
| // Clean up | ||
| os.Unsetenv("DECKARD_MONGODB_DATABASE") | ||
| os.Unsetenv("DECKARD_MONGO_DATABASE") | ||
| }() | ||
|
|
||
| // Clean environment | ||
| os.Unsetenv("DECKARD_MONGODB_DATABASE") | ||
| os.Unsetenv("DECKARD_MONGO_DATABASE") | ||
|
|
||
| // Test default value | ||
| Configure(true) | ||
| require.Equal(t, "deckard", MongoDatabase.Get()) | ||
|
|
||
| // Test with DECKARD_MONGODB_DATABASE environment variable | ||
| os.Setenv("DECKARD_MONGODB_DATABASE", "custom_db_1") | ||
| Configure(true) | ||
| require.Equal(t, "custom_db_1", MongoDatabase.Get()) | ||
|
|
||
| // Test with DECKARD_MONGO_DATABASE environment variable | ||
| os.Unsetenv("DECKARD_MONGODB_DATABASE") | ||
| os.Setenv("DECKARD_MONGO_DATABASE", "custom_db_2") | ||
| Configure(true) | ||
| require.Equal(t, "custom_db_2", MongoDatabase.Get()) | ||
| } | ||
|
|
||
| func TestMongoCollectionEnvironmentVariable(t *testing.T) { | ||
| defer func() { | ||
| // Clean up | ||
| os.Unsetenv("DECKARD_MONGODB_COLLECTION") | ||
| os.Unsetenv("DECKARD_MONGO_COLLECTION") | ||
| }() | ||
|
|
||
| // Clean environment | ||
| os.Unsetenv("DECKARD_MONGODB_COLLECTION") | ||
| os.Unsetenv("DECKARD_MONGO_COLLECTION") | ||
|
|
||
| // Test default value | ||
| Configure(true) | ||
| require.Equal(t, "queue", MongoCollection.Get()) | ||
|
|
||
| // Test with DECKARD_MONGODB_COLLECTION environment variable | ||
| os.Setenv("DECKARD_MONGODB_COLLECTION", "custom_collection") | ||
| Configure(true) | ||
| require.Equal(t, "custom_collection", MongoCollection.Get()) | ||
|
|
||
| // Test with DECKARD_MONGO_COLLECTION environment variable | ||
| os.Unsetenv("DECKARD_MONGODB_COLLECTION") | ||
| os.Setenv("DECKARD_MONGO_COLLECTION", "custom_collection_2") | ||
| Configure(true) | ||
| require.Equal(t, "custom_collection_2", MongoCollection.Get()) | ||
| } | ||
|
|
||
| func TestMongoBooleanEnvironmentVariable(t *testing.T) { | ||
| defer func() { | ||
| // Clean up | ||
| os.Unsetenv("DECKARD_MONGODB_SSL") | ||
| os.Unsetenv("DECKARD_MONGO_SSL") | ||
| }() | ||
|
|
||
| // Clean environment | ||
| os.Unsetenv("DECKARD_MONGODB_SSL") | ||
| os.Unsetenv("DECKARD_MONGO_SSL") | ||
|
|
||
| // Test default value | ||
| Configure(true) | ||
| require.Equal(t, false, MongoSsl.GetBool()) | ||
|
|
||
| // Test with DECKARD_MONGODB_SSL environment variable | ||
| os.Setenv("DECKARD_MONGODB_SSL", "true") | ||
| Configure(true) | ||
| require.Equal(t, true, MongoSsl.GetBool()) | ||
|
|
||
| // Test with DECKARD_MONGO_SSL environment variable | ||
| os.Unsetenv("DECKARD_MONGODB_SSL") | ||
| os.Setenv("DECKARD_MONGO_SSL", "true") | ||
| Configure(true) | ||
| require.Equal(t, true, MongoSsl.GetBool()) | ||
| } | ||
|
|
||
| func TestMongoIntegerEnvironmentVariable(t *testing.T) { | ||
| defer func() { | ||
| // Clean up | ||
| os.Unsetenv("DECKARD_MONGODB_MAX_POOL_SIZE") | ||
| os.Unsetenv("DECKARD_MONGO_MAX_POOL_SIZE") | ||
| }() | ||
|
|
||
| // Clean environment | ||
| os.Unsetenv("DECKARD_MONGODB_MAX_POOL_SIZE") | ||
| os.Unsetenv("DECKARD_MONGO_MAX_POOL_SIZE") | ||
|
|
||
| // Test default value | ||
| Configure(true) | ||
| require.Equal(t, 100, MongoMaxPoolSize.GetInt()) | ||
|
|
||
| // Test with DECKARD_MONGODB_MAX_POOL_SIZE environment variable | ||
| os.Setenv("DECKARD_MONGODB_MAX_POOL_SIZE", "250") | ||
| Configure(true) | ||
| require.Equal(t, 250, MongoMaxPoolSize.GetInt()) | ||
|
|
||
| // Test with DECKARD_MONGO_MAX_POOL_SIZE environment variable | ||
| os.Unsetenv("DECKARD_MONGODB_MAX_POOL_SIZE") | ||
| os.Setenv("DECKARD_MONGO_MAX_POOL_SIZE", "300") | ||
| Configure(true) | ||
| require.Equal(t, 300, MongoMaxPoolSize.GetInt()) | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| *.pem | ||
| *.pem | ||
| *.srl | ||
|
Collaborator
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. why is this new gitignore line needed in your PR ? |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider handling the error returned by time.ParseDuration in GetDuration to improve robustness and maintainability, even if it's only logging a warning.