2021-03-22 08:55:01 -03:00
|
|
|
package gomod
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2021-03-30 21:06:25 -03:00
|
|
|
"path/filepath"
|
2021-03-22 08:55:01 -03:00
|
|
|
"testing"
|
|
|
|
|
2023-03-02 00:01:11 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testctx"
|
2021-03-22 08:55:01 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRun(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New()
|
2021-03-30 21:06:25 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2021-09-22 22:25:26 -03:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
2021-03-22 08:55:01 -03:00
|
|
|
require.Equal(t, "github.com/goreleaser/goreleaser", ctx.ModulePath)
|
|
|
|
}
|
|
|
|
|
2022-03-17 08:53:39 -03:00
|
|
|
func TestRunCustomMod(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-03-17 08:53:39 -03:00
|
|
|
GoMod: config.GoMod{
|
|
|
|
Mod: "readonly",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
require.Equal(t, "github.com/goreleaser/goreleaser", ctx.ModulePath)
|
|
|
|
}
|
|
|
|
|
2022-10-04 13:01:18 -03:00
|
|
|
func TestCustomEnv(t *testing.T) {
|
|
|
|
bin := filepath.Join(t.TempDir(), "go.bin")
|
|
|
|
require.NoError(t, os.WriteFile(bin, []byte("#!/bin/sh\nenv | grep -qw FOO=bar"), 0o755))
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2022-10-04 13:01:18 -03:00
|
|
|
GoMod: config.GoMod{
|
|
|
|
GoBinary: bin,
|
|
|
|
Env: []string{"FOO=bar"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
|
|
|
}
|
|
|
|
|
2021-03-22 08:55:01 -03:00
|
|
|
func TestRunOutsideGoModule(t *testing.T) {
|
2021-03-30 21:06:25 -03:00
|
|
|
dir := testlib.Mktmp(t)
|
|
|
|
require.NoError(t, os.WriteFile(filepath.Join(dir, "main.go"), []byte("package main\nfunc main() {println(0)}"), 0o666))
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.New()
|
2021-03-30 21:06:25 -03:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
2021-03-22 08:55:01 -03:00
|
|
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
|
|
|
require.Empty(t, ctx.ModulePath)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunCommandError(t *testing.T) {
|
2023-03-02 00:01:11 -03:00
|
|
|
ctx := testctx.NewWithCfg(config.Project{
|
2021-03-30 21:06:25 -03:00
|
|
|
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: ")
|
2021-03-22 08:55:01 -03:00
|
|
|
require.Empty(t, ctx.ModulePath)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDescription(t *testing.T) {
|
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
|
|
|
}
|