1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/pipe/archive/archive_meta_test.go
Carlos Alexandro Becker e38e76cac8
feat: meta archives (#3093)
adds support for creating meta archives

closes #3085

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
2022-05-10 09:17:30 -03:00

72 lines
1.5 KiB
Go

package archive
import (
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/require"
)
func TestMeta(t *testing.T) {
t.Run("good", func(t *testing.T) {
dist := t.TempDir()
ctx := context.New(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"},
tarFiles(t, filepath.Join(dist, "foo.tar.gz")),
)
})
t.Run("bad tmpl", func(t *testing.T) {
dist := t.TempDir()
ctx := context.New(config.Project{
Dist: dist,
Archives: []config.Archive{
{
Meta: true,
NameTemplate: "foo{{.Os}}",
Files: []config.File{
{Source: "testdata/**/*.txt"},
},
},
},
})
require.NoError(t, Pipe{}.Default(ctx))
require.EqualError(t, Pipe{}.Run(ctx), `template: tmpl:1:5: executing "tmpl" at <.Os>: map has no entry for key "Os"`)
})
t.Run("no files", func(t *testing.T) {
dist := t.TempDir()
ctx := context.New(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`)
})
}