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