github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/internal/pipe/gomod/gomod_test.go (about)

     1  package gomod
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/goreleaser/goreleaser/internal/testlib"
     9  	"github.com/goreleaser/goreleaser/pkg/config"
    10  	"github.com/goreleaser/goreleaser/pkg/context"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestRun(t *testing.T) {
    15  	ctx := context.New(config.Project{})
    16  	require.NoError(t, Pipe{}.Default(ctx))
    17  	require.NoError(t, Pipe{}.Run(ctx))
    18  	require.Equal(t, "github.com/goreleaser/goreleaser", ctx.ModulePath)
    19  }
    20  
    21  func TestRunOutsideGoModule(t *testing.T) {
    22  	dir := testlib.Mktmp(t)
    23  	require.NoError(t, os.WriteFile(filepath.Join(dir, "main.go"), []byte("package main\nfunc main() {println(0)}"), 0o666))
    24  	ctx := context.New(config.Project{})
    25  	require.NoError(t, Pipe{}.Default(ctx))
    26  	testlib.AssertSkipped(t, Pipe{}.Run(ctx))
    27  	require.Empty(t, ctx.ModulePath)
    28  }
    29  
    30  func TestRunCommandError(t *testing.T) {
    31  	ctx := context.New(config.Project{
    32  		GoMod: config.GoMod{
    33  			GoBinary: "not-a-valid-binary",
    34  		},
    35  	})
    36  	require.EqualError(t, Pipe{}.Run(ctx), "failed to get module path: exec: \"not-a-valid-binary\": executable file not found in $PATH: ")
    37  	require.Empty(t, ctx.ModulePath)
    38  }
    39  
    40  func TestDescription(t *testing.T) {
    41  	require.NotEmpty(t, Pipe{}.String())
    42  }