2022-05-10 09:17:30 -03:00
|
|
|
package archive
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2024-05-26 15:02:57 -03:00
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/testctx"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/testlib"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/pkg/config"
|
2022-05-10 09:17:30 -03:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMeta(t *testing.T) {
|
|
|
|
t.Run("good", func(t *testing.T) {
|
|
|
|
dist := t.TempDir()
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-05-10 09:17:30 -03:00
|
|
|
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"},
|
2023-04-07 22:53:15 -03:00
|
|
|
testlib.LsArchive(t, filepath.Join(dist, "foo.tar.gz"), "tar.gz"),
|
2022-05-10 09:17:30 -03:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("bad tmpl", func(t *testing.T) {
|
|
|
|
dist := t.TempDir()
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-05-10 09:17:30 -03:00
|
|
|
Dist: dist,
|
|
|
|
Archives: []config.Archive{
|
|
|
|
{
|
|
|
|
Meta: true,
|
|
|
|
NameTemplate: "foo{{.Os}}",
|
|
|
|
Files: []config.File{
|
|
|
|
{Source: "testdata/**/*.txt"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2023-08-24 22:06:12 -03:00
|
|
|
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
2022-05-10 09:17:30 -03:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no files", func(t *testing.T) {
|
|
|
|
dist := t.TempDir()
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-05-10 09:17:30 -03:00
|
|
|
Dist: dist,
|
|
|
|
Archives: []config.Archive{
|
|
|
|
{
|
|
|
|
Meta: true,
|
|
|
|
NameTemplate: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), `no files found`)
|
|
|
|
})
|
|
|
|
}
|