2017-12-09 02:30:02 +02:00
|
|
|
package dist
|
2017-07-05 03:53:50 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2018-08-15 04:50:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2020-10-06 14:48:04 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-07-05 03:53:50 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDistDoesNotExist(t *testing.T) {
|
2017-12-10 15:36:39 +02:00
|
|
|
folder, err := ioutil.TempDir("", "disttest")
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2017-12-10 15:36:39 +02:00
|
|
|
var dist = filepath.Join(folder, "dist")
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(
|
2017-09-27 00:24:49 +02:00
|
|
|
t,
|
2017-07-05 03:53:50 +02:00
|
|
|
Pipe{}.Run(
|
|
|
|
&context.Context{
|
|
|
|
Config: config.Project{
|
2017-12-10 15:36:39 +02:00
|
|
|
Dist: dist,
|
2017-07-05 03:53:50 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPopulatedDistExists(t *testing.T) {
|
|
|
|
folder, err := ioutil.TempDir("", "disttest")
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2017-07-05 03:53:50 +02:00
|
|
|
var dist = filepath.Join(folder, "dist")
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, os.Mkdir(dist, 0755))
|
2017-07-05 03:53:50 +02:00
|
|
|
_, err = os.Create(filepath.Join(dist, "mybin"))
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2017-07-05 03:53:50 +02:00
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Dist: dist,
|
|
|
|
},
|
|
|
|
}
|
2020-10-06 14:48:04 +02:00
|
|
|
require.Error(t, Pipe{}.Run(ctx))
|
2017-07-05 03:53:50 +02:00
|
|
|
ctx.RmDist = true
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
2017-07-05 03:53:50 +02:00
|
|
|
_, err = os.Stat(dist)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.False(t, os.IsExist(err))
|
2017-07-05 03:53:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEmptyDistExists(t *testing.T) {
|
|
|
|
folder, err := ioutil.TempDir("", "disttest")
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, err)
|
2017-07-05 03:53:50 +02:00
|
|
|
var dist = filepath.Join(folder, "dist")
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, os.Mkdir(dist, 0755))
|
2017-07-05 03:53:50 +02:00
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Dist: dist,
|
|
|
|
},
|
|
|
|
}
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
2017-07-05 03:53:50 +02:00
|
|
|
_, err = os.Stat(dist)
|
2020-10-06 14:48:04 +02:00
|
|
|
require.False(t, os.IsNotExist(err))
|
2017-07-05 03:53:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDescription(t *testing.T) {
|
2020-10-06 14:48:04 +02:00
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
2017-07-05 03:53:50 +02:00
|
|
|
}
|