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

NewBoot should find boot.yaml in default project dir when called via Go Unit Test #135

Open
feidhlimx opened this issue Dec 20, 2022 · 2 comments

Comments

@feidhlimx
Copy link

feidhlimx commented Dec 20, 2022

When rkBoot setup is required to run a unit test in go, the NewBoot() function should find boot.yaml by default.
Providing a different Path for every Test depending on the Test location is sub-optimal.
Also, when the boot.yaml has entries which are relative to boot.yaml, they should be also be found in a Unit Test without extra path requirements.

Describe the solution you'd like
NewBoot() function should find boot,yaml by default in the project dir .

Describe alternatives you've considered
I have used TestMain to call one Setup() function which starts rkBoot, but this must also look for the path to boot,yaml relative to the Setup function location (which cannot exist in main package as it causes cricular dependancies)

Additional context
Add any other context or screenshots about the feature request here.

https://stackoverflow.com/questions/23729790/how-can-i-do-test-setup-using-the-testing-package-in-go

@feidhlimx
Copy link
Author

under api/test/setup.go the following path is required:

package test

import (
"configcontrol-api-puppet-yaml/api/config"
"context"
"embed"
rkboot "github.com/rookie-ninja/rk-boot/v2"
rkentry "github.com/rookie-ninja/rk-entry/v2/entry"
)

func Setup() {
var fs *embed.FS
boot := rkboot.NewBoot(rkboot.WithBootConfigPath("./../../boot.yaml", fs))
boot.Bootstrap(context.TODO())
config.LOG = rkentry.GlobalAppCtx.GetLoggerEntry("zap-log")
rkentry.GlobalAppCtx.GetConfigEntry("testrepoconfig").Unmarshal(&config.AppConfig)
}

and in boot,yaml an extra path parameter is also required for config/application.yaml:

config:

default

  • name: repoconfig
    path: "config/application.yaml"
  • name: testrepoconfig
    path: "./../../config/application.yaml"

@dongxuny
Copy link
Contributor

@feidhlimx good suggestion, I will try to figure out how to make rk-boot to search boot.yaml and config under project dir.

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

No branches or pull requests

2 participants