rk-boot icon indicating copy to clipboard operation
rk-boot copied to clipboard

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

Open feidhlimx opened this issue 2 years ago • 2 comments

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 avatar Dec 20 '22 08:12 feidhlimx

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"

feidhlimx avatar Dec 20 '22 08:12 feidhlimx

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

dongxuny avatar Dec 20 '22 10:12 dongxuny