github.com/goreleaser/goreleaser@v1.25.1/internal/pipe/archive/archive_meta_test.go (about)

     1  package archive
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  
     7  	"github.com/goreleaser/goreleaser/internal/testctx"
     8  	"github.com/goreleaser/goreleaser/internal/testlib"
     9  	"github.com/goreleaser/goreleaser/pkg/config"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestMeta(t *testing.T) {
    14  	t.Run("good", func(t *testing.T) {
    15  		dist := t.TempDir()
    16  		ctx := testctx.NewWithCfg(config.Project{
    17  			Dist: dist,
    18  			Archives: []config.Archive{
    19  				{
    20  					Meta:         true,
    21  					NameTemplate: "foo",
    22  					Files: []config.File{
    23  						{Source: "testdata/**/*.txt"},
    24  					},
    25  				},
    26  			},
    27  		})
    28  
    29  		require.NoError(t, Pipe{}.Default(ctx))
    30  		require.NoError(t, Pipe{}.Run(ctx))
    31  		require.Equal(
    32  			t,
    33  			[]string{"testdata/a/a.txt", "testdata/a/b/a.txt", "testdata/a/b/c/d.txt"},
    34  			testlib.LsArchive(t, filepath.Join(dist, "foo.tar.gz"), "tar.gz"),
    35  		)
    36  	})
    37  
    38  	t.Run("bad tmpl", func(t *testing.T) {
    39  		dist := t.TempDir()
    40  		ctx := testctx.NewWithCfg(config.Project{
    41  			Dist: dist,
    42  			Archives: []config.Archive{
    43  				{
    44  					Meta:         true,
    45  					NameTemplate: "foo{{.Os}}",
    46  					Files: []config.File{
    47  						{Source: "testdata/**/*.txt"},
    48  					},
    49  				},
    50  			},
    51  		})
    52  
    53  		require.NoError(t, Pipe{}.Default(ctx))
    54  		testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
    55  	})
    56  
    57  	t.Run("no files", func(t *testing.T) {
    58  		dist := t.TempDir()
    59  		ctx := testctx.NewWithCfg(config.Project{
    60  			Dist: dist,
    61  			Archives: []config.Archive{
    62  				{
    63  					Meta:         true,
    64  					NameTemplate: "foo",
    65  				},
    66  			},
    67  		})
    68  
    69  		require.NoError(t, Pipe{}.Default(ctx))
    70  		require.EqualError(t, Pipe{}.Run(ctx), `no files found`)
    71  	})
    72  }