1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-09 13:36:56 +02:00
goreleaser/internal/pipe/gomod/gomod_test.go
Carlos Alexandro Becker f7c865c4d9
refactor: split go mod into 2 pipes (#2502)
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2021-09-22 22:25:26 -03:00

43 lines
1.2 KiB
Go

package gomod
import (
"os"
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/require"
)
func TestRun(t *testing.T) {
ctx := context.New(config.Project{})
require.NoError(t, Pipe{}.Default(ctx))
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "github.com/goreleaser/goreleaser", ctx.ModulePath)
}
func TestRunOutsideGoModule(t *testing.T) {
dir := testlib.Mktmp(t)
require.NoError(t, os.WriteFile(filepath.Join(dir, "main.go"), []byte("package main\nfunc main() {println(0)}"), 0o666))
ctx := context.New(config.Project{})
require.NoError(t, Pipe{}.Default(ctx))
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
require.Empty(t, ctx.ModulePath)
}
func TestRunCommandError(t *testing.T) {
ctx := context.New(config.Project{
GoMod: config.GoMod{
GoBinary: "not-a-valid-binary",
},
})
require.EqualError(t, Pipe{}.Run(ctx), "failed to get module path: exec: \"not-a-valid-binary\": executable file not found in $PATH: ")
require.Empty(t, ctx.ModulePath)
}
func TestDescription(t *testing.T) {
require.NotEmpty(t, Pipe{}.String())
}