-
-
Notifications
You must be signed in to change notification settings - Fork 275
Proposal: add visible ToMap for tests in applications #274
Copy link
Copy link
Closed
Description
Good day.
I'm using the env library in on of my projects and I lacked ability to use toMap defined in this module. Let me elaborate.
In my application I have something like
func parseConfiguration() (*Configuration, error) which uses env library under the hood. Now I want to test it and my first thought is to parse environment as an argument to my function and then let it through my function to env library. Something lik
func parseConfiguration(environ []string) (*Configuration, error) {
// ...
err := env.ParseWithOptions(
&configuration,
env.Options{
Prefix: "STATUS_METER_",
Environment: environ, // <- this won't work
})
// ...
}The Environment: environ, line won't work because Environment is map[string]string and it uses the toMap function which is not visible outside of the library.
What are the options?
- set env vars during the test invocation. The tests will be not clear because it won't be easy to deduce where did the environment come from
- set env through
os.Setenv. This is better and this is what I'm using currently, but it still not clear because I would like to have pure function which converts input to output. - provide public
ToMapwhich just wraps internaltoMap. I would be able to duplicate the library logic, but it will be duplication. - provide another option called
Environor smth like that alongsideEnvironmentand teach library to use the former if it's provided and the latter for the backward compatibility.Environshould have[]stringtype.
What is your feedback on that?
PS: I'm a new to the Go world so I could miss something.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels