Skip to content
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

add mock and os LookupEnv implementation + tests #2

Merged
merged 2 commits into from Jun 10, 2020
Merged

add mock and os LookupEnv implementation + tests #2

merged 2 commits into from Jun 10, 2020

Conversation

tadam313
Copy link
Contributor

@tadam313 tadam313 commented Jun 1, 2020

  • added LookupEnv method

@tadam313
Copy link
Contributor Author

tadam313 commented Jun 3, 2020

@adammck let me know if this does not correlate with the package intention !

os/os_test.go Outdated
assert.Equal(t, "GHI", val)
assert.True(t, ok)

val, ok = e.LookupEnv("nope")
Copy link
Owner

@adammck adammck Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will fail if a var named nope happens to be set. That seems unlikely, but could we change it to something like THIS-VAR-MUST-BE-UNSET and use os.Unsetenv to ensure that it has the expected (absent) value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all right good point, I've done both 👍

@adammck
Copy link
Owner

adammck commented Jun 3, 2020

Thanks very much, looks like LookupEnv was added after this package was written! Patch looks good to merge with the suggested testing tweak.

@@ -28,6 +28,11 @@ func (e *MockEnv) Getenv(key string) string {
return e.data[key]
}

func (e *MockEnv) LookupEnv(key string) (string, bool) {
val, ok := e.data[key]
return val, ok
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you can skip the variables here and return e.data[key] directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I tried it but I get a compilation error: not enough arguments to return. I think go does not recognize that I want to return the ok variable as well from map access, so I did this explicitly

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I thought that'd work. Thanks for checking.

@tadam313 tadam313 requested a review from adammck June 5, 2020 15:37
@tadam313
Copy link
Contributor Author

tadam313 commented Jun 5, 2020

@adammck thanks for the review, I've done your first suggestion, the second one did not work for me

@adammck adammck merged commit e777897 into adammck:master Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants