Skip to content

Commit

Permalink
fix: config merge
Browse files Browse the repository at this point in the history
closes #750

Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 committed Dec 10, 2023
1 parent 7439013 commit 2c8f9e0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion nfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type Config struct {
func (c *Config) Get(format string) (info *Info, err error) {
info = &Info{}
// make a deep copy of info
if err = mergo.Merge(info, c.Info); err != nil {
if err = mergo.Merge(info, c.Info, mergo.WithOverride); err != nil {
return nil, fmt.Errorf("failed to merge config into info: %w", err)
}
override, ok := c.Overrides[format]
Expand Down
1 change: 1 addition & 0 deletions nfpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ func TestOverrides(t *testing.T) {
}
}
require.Equal(t, "amd64", pkg.Arch)
require.Equal(t, time.Date(2023, 0o1, 0o2, 0, 0, 0, 0, time.UTC), pkg.MTime)
})
}

Expand Down
31 changes: 16 additions & 15 deletions testdata/overrides.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# Configuration file used to unit test overrides
name: "foo"
arch: "amd64"
mtime: 2023-01-02
version: "v1.2.3"
contents:
- src: ./testdata/whatever.conf
dst: /etc/foo/whatever.conf
type: config
- src: ./testdata/whatever.conf
dst: /deb/path.conf
type: config
packager: deb
- src: ./testdata/whatever.conf
dst: /rpm/path.conf
type: config
packager: rpm
- src: ./testdata/whatever.conf
dst: /apk/path.conf
type: config
packager: apk
- src: ./testdata/whatever.conf
dst: /etc/foo/whatever.conf
type: config
- src: ./testdata/whatever.conf
dst: /deb/path.conf
type: config
packager: deb
- src: ./testdata/whatever.conf
dst: /rpm/path.conf
type: config
packager: rpm
- src: ./testdata/whatever.conf
dst: /apk/path.conf
type: config
packager: apk
rpm:
group: foo
overrides:
Expand Down

0 comments on commit 2c8f9e0

Please sign in to comment.