github.com/triarius/goreleaser@v1.12.5/internal/pipe/dist/dist_test.go (about)

     1  package dist
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/triarius/goreleaser/pkg/config"
     9  	"github.com/triarius/goreleaser/pkg/context"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestDistDoesNotExist(t *testing.T) {
    14  	folder := t.TempDir()
    15  	dist := filepath.Join(folder, "dist")
    16  	require.NoError(
    17  		t,
    18  		Pipe{}.Run(
    19  			&context.Context{
    20  				Config: config.Project{
    21  					Dist: dist,
    22  				},
    23  			},
    24  		),
    25  	)
    26  }
    27  
    28  func TestPopulatedDistExists(t *testing.T) {
    29  	folder := t.TempDir()
    30  	dist := filepath.Join(folder, "dist")
    31  	require.NoError(t, os.Mkdir(dist, 0o755))
    32  	f, err := os.Create(filepath.Join(dist, "mybin"))
    33  	require.NoError(t, err)
    34  	require.NoError(t, f.Close())
    35  	ctx := &context.Context{
    36  		Config: config.Project{
    37  			Dist: dist,
    38  		},
    39  	}
    40  	require.Error(t, Pipe{}.Run(ctx))
    41  	ctx.RmDist = true
    42  	require.NoError(t, Pipe{}.Run(ctx))
    43  	_, err = os.Stat(dist)
    44  	require.False(t, os.IsExist(err))
    45  }
    46  
    47  func TestEmptyDistExists(t *testing.T) {
    48  	folder := t.TempDir()
    49  	dist := filepath.Join(folder, "dist")
    50  	require.NoError(t, os.Mkdir(dist, 0o755))
    51  	ctx := &context.Context{
    52  		Config: config.Project{
    53  			Dist: dist,
    54  		},
    55  	}
    56  	require.NoError(t, Pipe{}.Run(ctx))
    57  	_, err := os.Stat(dist)
    58  	require.False(t, os.IsNotExist(err))
    59  }
    60  
    61  func TestDescription(t *testing.T) {
    62  	require.NotEmpty(t, Pipe{}.String())
    63  }