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

Config split #302

Merged
merged 11 commits into from
Jun 12, 2024
Merged

Config split #302

merged 11 commits into from
Jun 12, 2024

Conversation

najeal
Copy link
Contributor

@najeal najeal commented May 24, 2024

Why this should be merged

It is related to #251
This splits the config go file into multiple ones easier to read.
It shorten the BuildConfig function
It provides more informations about the config overwritten options.

How this works

Split does not change logic.
About BuildConfig() changes:

  • Instead of using multiple viper.UnmarshalKey(), a unique viper.Unmarshal() is done.
  • a new function NewConfig() wraps BuildConfig() + config Validation. This makes the test of viper unmarshaling easier mechanism from BuildConfig().
  • BuildConfig does not return additional var to notify if some options have been overwritten.

Information details about overwritten options are now embedded in a Config private field. It can be accessed from new methods HasOverwrittenOptions() & GetOverwrittenOptions()

How this was tested

Modified unmarshal mechanism is tested in viper_test.go

How is this documented

@najeal najeal marked this pull request as ready for review May 29, 2024 15:13
geoff-vball
geoff-vball previously approved these changes Jun 5, 2024
Copy link
Contributor

@geoff-vball geoff-vball left a comment

Choose a reason for hiding this comment

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

Thanks for this! It overall looks good to me. @cam-schultz should also take a look at this

Copy link
Collaborator

@cam-schultz cam-schultz left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together! Overall the changes look great. I have a couple of minor change requests.

main/main.go Outdated Show resolved Hide resolved
config/viper.go Outdated Show resolved Hide resolved
var configFile string

func TestBuildConfig(t *testing.T) {
v := viper.New()
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can get rid of test_files/config.json and re-use the top-level sample-relayer-config.json for this test. The following changes are necessary:

  1. Read in "../sample-relayer-config.json using os.ReadFile. go:embed does not support ...
cfgBytes, err := os.ReadFile("../sample-relayer-config.json")
configFile := string(cfgBytes)
  1. Modify the expected DestinationBlockchain AccountPrivateKey to match the partial key provided in sample-relayer-config.json
  2. Remote test_files/config.json

Co-authored-by: cam-schultz <[email protected]>
Signed-off-by: nathan haim <[email protected]>
func TestBuildConfig(t *testing.T) {
v := viper.New()
cfgBytes, err := os.ReadFile("../sample-relayer-config.json")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's check the error here. This is also the cause of the failing lint job.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry my mind was elsewhere. It should be ok now

Copy link
Collaborator

Choose a reason for hiding this comment

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

No worries! Thanks for the fix.

Copy link
Collaborator

@cam-schultz cam-schultz left a comment

Choose a reason for hiding this comment

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

Much appreciated 🙏

@cam-schultz cam-schultz merged commit 3413a0e into ava-labs:main Jun 12, 2024
5 checks passed
@geoff-vball geoff-vball mentioned this pull request Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants