-
Notifications
You must be signed in to change notification settings - Fork 71
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
acc: Implement config merge #2294
Conversation
94d2cf0
to
f65b5bd
Compare
dario.cat/mergo | ||
Copyright (c) 2013 Dario Castañé. All rights reserved. | ||
Copyright (c) 2012 The Go Authors. All rights reserved. | ||
https://github.com/darccio/mergo/blob/master/LICENSE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Historical tidbit: we used to depend on this bundle configuration merging before the move to libs/dyn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. It looks solid. From the past experience, are there any issues or quirks to be aware of?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it did its job well.
if dir == "" || dir == "." { | ||
break | ||
} | ||
|
||
if os.IsNotExist(err) { | ||
dir = filepath.Dir(dir) | ||
dir = filepath.Dir(dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the path guaranteed to never be absolute?
If it is, this loop will be infinite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in this context is always relative. If it was absolute, the logic would not work anyway as we don't want to search for configs outside of acceptance/.
Added a comment about this requirement.
acceptance/config_test.go
Outdated
// FindConfig finds the closest config file. | ||
func FindConfig(t *testing.T, dir string) (string, bool) { | ||
shared := false | ||
// FindConfigs finds the closest config file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is out of date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thanks.
continue | ||
} | ||
|
||
t.Fatalf("Error while reading %s: %s", path, err) | ||
} | ||
|
||
t.Fatal("Config not found: " + configFilename) | ||
return "", shared | ||
slices.Reverse(configs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can include a comment that the output will be ordered from outer to inner configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Included in function description.
All configs using all test.toml found from acceptance/test.toml to acceptance/<specific test>/test.toml Maps are merged, slices are appended, other values are overriden. I had to disable caching, because it is tricky when merging is involved - deep copy is needed. There is performance impact but currently it is tiny: ~/work/cli/acceptance % hyperfine -w 2 'go test -count=1' # this change: Benchmark 1: go test -count=1 Time (mean ± σ): 5.074 s ± 0.105 s [User: 6.189 s, System: 9.551 s] Range (min … max): 4.926 s … 5.263 s 10 runs ~/work/cli/acceptance % git stash # base ~/work/cli/acceptance % hyperfine -w 2 'go test -count=1' Benchmark 1: go test -count=1 Time (mean ± σ): 5.009 s ± 0.095 s [User: 6.176 s, System: 10.617 s] Range (min … max): 4.803 s … 5.123 s 10 runs
f3c155a
to
8e16c80
Compare
8e16c80
to
d14d075
Compare
Makes use of #2294
Changes
Instead of using leaf-most config, all configs from root at acceptance/test.toml to all intermediate ones to leaf config are merged into one. Maps are merged, slices are appended, other values are overridden.
I had to disable caching, because it is tricky when merging is involved - deep copy is needed. There is performance
impact but currently it is tiny, about 1%.
Also, remove empty root config.
Tests
Manually checked that inheritance of LocalOnly setting worked for these tests:
Before - integration tests showed:
After: