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

Cobra not read config file when go test #995

Closed
teguh11 opened this issue Nov 25, 2019 · 1 comment
Closed

Cobra not read config file when go test #995

teguh11 opened this issue Nov 25, 2019 · 1 comment
Labels
kind/support Questions, supporting users, etc.

Comments

@teguh11
Copy link

teguh11 commented Nov 25, 2019

sorry, i have a problem with cobra when i create a test function. my config file in .yaml file. i created subcommand with
cobra add list

and in initConfig function on root.go, i pointing to my config file with this code
viper.AddConfigPath(".")
viper.SetConfigName(".todo")
viper.SetConfigType("yaml")

when i run go run main.go list, it run perfectly.
but when i run go test, config file not load.
this is my very simple test to reproduce this case
https://github.com/teguh11/todolistgotest

@jharshman jharshman added the kind/support Questions, supporting users, etc. label Dec 26, 2019
@jharshman
Copy link
Collaborator

@teguh11 When you're running your test, the init() function in root.go is not executed. Therefore no configuration is read in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Questions, supporting users, etc.
Projects
None yet
Development

No branches or pull requests

2 participants