github.phpd.cn/goreleaser/goreleaser@v0.92.0/internal/pipe/dist/dist_test.go (about)

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