Skip to content

Commit

Permalink
test: fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed May 24, 2023
1 parent f64a311 commit 66c3d27
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions arch/arch_test.go
Expand Up @@ -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") {
Expand Down
4 changes: 2 additions & 2 deletions nfpm.go
Expand Up @@ -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
}

Expand Down Expand Up @@ -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"
}
Expand Down
43 changes: 23 additions & 20 deletions nfpm_test.go
Expand Up @@ -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",
})
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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)
Expand Down

0 comments on commit 66c3d27

Please sign in to comment.