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 f544c5ce69
test: testctx pkg (#3807)
alternative to #3806 

the idea is that both `context.New` and `context.Context{}` are never
used in tests.

not sure yet how much I like it, so far code does look a bit more
readable though.

---------

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2023-03-02 00:01:11 -03:00

47 lines
1.2 KiB
Go

package dist
import (
"os"
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/internal/testctx"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/stretchr/testify/require"
)
func TestDistDoesNotExist(t *testing.T) {
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, Pipe{}.Run(testctx.NewWithCfg(config.Project{Dist: dist})))
}
func TestPopulatedDistExists(t *testing.T) {
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
f, err := os.Create(filepath.Join(dist, "mybin"))
require.NoError(t, err)
require.NoError(t, f.Close())
ctx := testctx.NewWithCfg(config.Project{Dist: dist})
require.Error(t, Pipe{}.Run(ctx))
ctx.Clean = true
require.NoError(t, Pipe{}.Run(ctx))
_, err = os.Stat(dist)
require.False(t, os.IsExist(err))
}
func TestEmptyDistExists(t *testing.T) {
folder := t.TempDir()
dist := filepath.Join(folder, "dist")
require.NoError(t, os.Mkdir(dist, 0o755))
ctx := testctx.NewWithCfg(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())
}