1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00
goreleaser/internal/pipe/archive/archive_meta_test.go
Carlos Alexandro Becker ec2db4a727
feat!: rename module to /v2 (#4894)
<!--

Hi, thanks for contributing!

Please make sure you read our CONTRIBUTING guide.

Also, add tests and the respective documentation changes as well.

-->


<!-- If applied, this commit will... -->

...

<!-- Why is this change being made? -->

...

<!-- # Provide links to any relevant tickets, URLs or other resources
-->

...

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-05-26 15:02:57 -03:00

73 lines
1.5 KiB
Go

package archive
import (
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/v2/internal/testctx"
"github.com/goreleaser/goreleaser/v2/internal/testlib"
"github.com/goreleaser/goreleaser/v2/pkg/config"
"github.com/stretchr/testify/require"
)
func TestMeta(t *testing.T) {
t.Run("good", func(t *testing.T) {
dist := t.TempDir()
ctx := testctx.NewWithCfg(config.Project{
Dist: dist,
Archives: []config.Archive{
{
Meta: true,
NameTemplate: "foo",
Files: []config.File{
{Source: "testdata/**/*.txt"},
},
},
},
})
require.NoError(t, Pipe{}.Default(ctx))
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(
t,
[]string{"testdata/a/a.txt", "testdata/a/b/a.txt", "testdata/a/b/c/d.txt"},
testlib.LsArchive(t, filepath.Join(dist, "foo.tar.gz"), "tar.gz"),
)
})
t.Run("bad tmpl", func(t *testing.T) {
dist := t.TempDir()
ctx := testctx.NewWithCfg(config.Project{
Dist: dist,
Archives: []config.Archive{
{
Meta: true,
NameTemplate: "foo{{.Os}}",
Files: []config.File{
{Source: "testdata/**/*.txt"},
},
},
},
})
require.NoError(t, Pipe{}.Default(ctx))
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
})
t.Run("no files", func(t *testing.T) {
dist := t.TempDir()
ctx := testctx.NewWithCfg(config.Project{
Dist: dist,
Archives: []config.Archive{
{
Meta: true,
NameTemplate: "foo",
},
},
})
require.NoError(t, Pipe{}.Default(ctx))
require.EqualError(t, Pipe{}.Run(ctx), `no files found`)
})
}