spf13 / viper

Go configuration with fangs
MIT License
26.47k stars 2.01k forks source link

Rewrite tests to use a local Viper instance #1700

Closed sagikazarmark closed 3 months ago

sagikazarmark commented 7 months ago

Preflight Checklist

Problem Description

Most tests currently use the global Viper instance which causes all kinds of trouble between tests.

Proposed Solution

Rewrite tests to initialize a new, local Viper instance.

Alternatives Considered

No response

Additional Information

No response

github-actions[bot] commented 7 months ago

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news, either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

smukk9 commented 4 months ago

Hi @sagikazarmark ,

Thanks for your work. i have used viper recently and would like to help with this.

Are you referring to test like these

https://github.com/spf13/viper/blob/5870123c5f385c8d88b7087d15d2e1b7fa67a7fa/viper_test.go#L677 . https://github.com/spf13/viper/blob/5870123c5f385c8d88b7087d15d2e1b7fa67a7fa/viper_test.go#L687 https://github.com/spf13/viper/blob/5870123c5f385c8d88b7087d15d2e1b7fa67a7fa/viper_test.go#L698

i see some of the test are already using new like here https://github.com/spf13/viper/blob/5870123c5f385c8d88b7087d15d2e1b7fa67a7fa/viper_test.go#L296

any additional hints or pointers you can provide would be immensely helpful.

Thanks

sagikazarmark commented 4 months ago

Hey @smukk9 !

Thanks for the kind words!

Yes, these are exactly the kind of tests that I'd like to see refactored. They currently use the global Viper instance which requires all tests to reset Viper first and makes parallelization nearly impossible.

Ideally, each test should initialize their own Viper instance.