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

67 lines
1.4 KiB
Go
Raw Normal View History

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