1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/cleandist/dist_test.go

64 lines
1.3 KiB
Go
Raw Normal View History

2017-07-05 03:53:50 +02:00
package cleandist
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/stretchr/testify/assert"
)
func TestDistDoesNotExist(t *testing.T) {
assert.NoError(
t,
2017-07-05 03:53:50 +02:00
Pipe{}.Run(
&context.Context{
Config: config.Project{
Dist: "/wtf-this-shouldnt-exist",
},
},
),
)
}
func TestPopulatedDistExists(t *testing.T) {
folder, err := ioutil.TempDir("", "disttest")
assert.NoError(t, err)
2017-07-05 03:53:50 +02:00
var dist = filepath.Join(folder, "dist")
assert.NoError(t, os.Mkdir(dist, 0755))
2017-07-05 03:53:50 +02:00
_, err = os.Create(filepath.Join(dist, "mybin"))
assert.NoError(t, err)
2017-07-05 03:53:50 +02:00
var ctx = &context.Context{
Config: config.Project{
Dist: dist,
},
}
assert.Error(t, Pipe{}.Run(ctx))
2017-07-05 03:53:50 +02:00
ctx.RmDist = true
assert.NoError(t, Pipe{}.Run(ctx))
2017-07-05 03:53:50 +02:00
_, err = os.Stat(dist)
assert.False(t, os.IsExist(err))
2017-07-05 03:53:50 +02:00
}
func TestEmptyDistExists(t *testing.T) {
folder, err := ioutil.TempDir("", "disttest")
assert.NoError(t, err)
2017-07-05 03:53:50 +02:00
var dist = filepath.Join(folder, "dist")
assert.NoError(t, os.Mkdir(dist, 0755))
2017-07-05 03:53:50 +02:00
var ctx = &context.Context{
Config: config.Project{
Dist: dist,
},
}
assert.NoError(t, Pipe{}.Run(ctx))
2017-07-05 03:53:50 +02:00
_, err = os.Stat(dist)
assert.False(t, os.IsExist(err))
2017-07-05 03:53:50 +02:00
}
func TestDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.Description())
2017-07-05 03:53:50 +02:00
}