From 66c3d277cfee061b2ec3b2a31c15a1f879b8539d Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 24 May 2023 02:14:30 +0000 Subject: [PATCH] test: fixes Signed-off-by: Carlos Alexandro Becker --- arch/arch_test.go | 4 ++-- nfpm.go | 4 ++-- nfpm_test.go | 43 +++++++++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/arch/arch_test.go b/arch/arch_test.go index 738da41d..e0fc4202 100644 --- a/arch/arch_test.go +++ b/arch/arch_test.go @@ -362,8 +362,8 @@ func TestGlob(t *testing.T) { "./usr/": {"mode=755", "type=dir"}, "./usr/share/": {"mode=755", "type=dir"}, "./usr/share/nfpm-repro/": {"mode=755", "type=dir"}, - "./usr/share/nfpm-repro/files.go": {"mode=644", "size=15688", "type=file", "md5digest=e4c9ce32dba277aae42fb8ec59e29a3a", "sha256digest=7946f60272c8f42c87cd3a3832d80f0b57ed9406aa1db6b96e5df6003922060b"}, - "./usr/share/nfpm-repro/files_test.go": {"mode=644", "size=16947", "type=file", "md5digest=4824b1a82a0f694a976345fff8a6aa1f", "sha256digest=3cb4b25fe2343bf509a2d82ece2881ec92ecd4962e50bc855f27d621a5613d47"}, + "./usr/share/nfpm-repro/files.go": {"mode=664", "size=15900", "type=file", "md5digest=0c4e339bc678ab6b2b291ec3088e32a2", "sha256digest=27614421b69216e9d8ddd177210f2c9a71d8ff9d76cc2b1654276eccd04e84c2"}, + "./usr/share/nfpm-repro/files_test.go": {"mode=664", "size=17741", "type=file", "md5digest=8a42e91db704f97ceb1d24d63ab3780e", "sha256digest=5a02a196b845a52122c8c0ded24d34aeaa44617a4199ff3407d390c5d507bb33"}, } for _, line := range strings.Split(string(mtreeContentBts), "\n") { diff --git a/nfpm.go b/nfpm.go index 3c59490a..b1410f8e 100644 --- a/nfpm.go +++ b/nfpm.go @@ -75,7 +75,7 @@ func ParseWithEnvMapping(in io.Reader, mapping func(string) string) (config Conf } config.expandEnvVars() - config.Info = WithDefaults(config.Info) + WithDefaults(&config.Info) return config, nil } @@ -469,7 +469,7 @@ func Validate(info *Info) (err error) { } // WithDefaults set some sane defaults into the given Info. -func WithDefaults(info Info) Info { +func WithDefaults(info *Info) *Info { if info.Platform == "" { info.Platform = "linux" } diff --git a/nfpm_test.go b/nfpm_test.go index fc8df20c..24a75495 100644 --- a/nfpm_test.go +++ b/nfpm_test.go @@ -37,7 +37,7 @@ func TestGet(t *testing.T) { } func TestDefaultsVersion(t *testing.T) { - info := nfpm.WithDefaults(nfpm.Info{ + info := nfpm.WithDefaults(&nfpm.Info{ Version: "v1.0.0", VersionSchema: "semver", }) @@ -46,21 +46,21 @@ func TestDefaultsVersion(t *testing.T) { require.Equal(t, "", info.Release) require.Equal(t, "", info.Prerelease) - info = nfpm.WithDefaults(nfpm.Info{ + info = nfpm.WithDefaults(&nfpm.Info{ Version: "v1.0.0-rc1", }) require.Equal(t, "1.0.0", info.Version) require.Equal(t, "", info.Release) require.Equal(t, "rc1", info.Prerelease) - info = nfpm.WithDefaults(nfpm.Info{ + info = nfpm.WithDefaults(&nfpm.Info{ Version: "v1.0.0-beta1", }) require.Equal(t, "1.0.0", info.Version) require.Equal(t, "", info.Release) require.Equal(t, "beta1", info.Prerelease) - info = nfpm.WithDefaults(nfpm.Info{ + info = nfpm.WithDefaults(&nfpm.Info{ Version: "v1.0.0-1", Release: "2", Prerelease: "beta1", @@ -69,7 +69,7 @@ func TestDefaultsVersion(t *testing.T) { require.Equal(t, "2", info.Release) require.Equal(t, "beta1", info.Prerelease) - info = nfpm.WithDefaults(nfpm.Info{ + info = nfpm.WithDefaults(&nfpm.Info{ Version: "v1.0.0-1+xdg2", Release: "2", Prerelease: "beta1", @@ -78,7 +78,7 @@ func TestDefaultsVersion(t *testing.T) { require.Equal(t, "2", info.Release) require.Equal(t, "beta1", info.Prerelease) - info = nfpm.WithDefaults(nfpm.Info{ + info = nfpm.WithDefaults(&nfpm.Info{ Version: "this.is.my.version", VersionSchema: "none", Release: "2", @@ -91,20 +91,23 @@ func TestDefaultsVersion(t *testing.T) { func TestDefaults(t *testing.T) { t.Run("all given", func(t *testing.T) { - info := nfpm.Info{ - Platform: "darwin", - Version: "2.4.1", - Description: "no description given", - Arch: "arm64", - Overridables: nfpm.Overridables{ - Umask: 0o112, - }, + makeinfo := func() nfpm.Info { + return nfpm.Info{ + Platform: "darwin", + Version: "2.4.1", + Description: "no description given", + Arch: "arm64", + Overridables: nfpm.Overridables{ + Umask: 0o112, + }, + } } - got := nfpm.WithDefaults(info) - require.Equal(t, info, got) + info := makeinfo() + nfpm.WithDefaults(&info) + require.Equal(t, makeinfo(), info) }) t.Run("none given", func(t *testing.T) { - got := nfpm.WithDefaults(nfpm.Info{}) + got := nfpm.WithDefaults(&nfpm.Info{}) require.Equal(t, nfpm.Info{ Platform: "linux", Arch: "amd64", @@ -114,13 +117,13 @@ func TestDefaults(t *testing.T) { Overridables: nfpm.Overridables{ Umask: 0o002, }, - }, got) + }, *got) }) } func TestPrepareForPackager(t *testing.T) { t.Run("dirs", func(t *testing.T) { - info := nfpm.WithDefaults(nfpm.Info{ + info := nfpm.WithDefaults(&nfpm.Info{ Name: "as", Arch: "asd", Version: "1.2.3", @@ -142,7 +145,7 @@ func TestPrepareForPackager(t *testing.T) { }, }, }) - require.NoError(t, nfpm.PrepareForPackager(&info, "")) + require.NoError(t, nfpm.PrepareForPackager(info, "")) require.Len(t, info.Overridables.Contents, 5) asdFile := info.Overridables.Contents[0] require.Equal(t, "/asd", asdFile.Destination)