1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00
goreleaser/internal/pipe/dist/dist_test.go
Carlos Alexandro Becker 92f52ac406
refactor(test): use testing.TB Cleanup and Tempdir (#1945)
* refactor: use t.Cleanup instead of defer

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* refactor: use t.Cleanup instead of defer

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* refactor: use t.Cleanup instead of defer

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* refactor: use t.Cleanup instead of defer

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: filepath

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2020-12-12 13:27:35 -03:00

63 lines
1.3 KiB
Go

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