1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2024-12-31 01:53:50 +02:00
goreleaser/internal/pipe/partial/partial_test.go
Carlos Alexandro Becker 96c87fff72
fix: build --single-target filters (#5114)
make them more precise, as its currently only taking GOOS/GOARCH into
account, and we can do more.

closes #5112

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-09-04 10:10:27 -03:00

114 lines
3.1 KiB
Go

package partial
import (
"fmt"
"runtime"
"testing"
"github.com/goreleaser/goreleaser/v2/internal/testctx"
"github.com/goreleaser/goreleaser/v2/pkg/config"
"github.com/stretchr/testify/require"
)
var pipe = Pipe{}
func TestString(t *testing.T) {
require.NotEmpty(t, pipe.String())
}
func TestSkip(t *testing.T) {
t.Run("partial", func(t *testing.T) {
ctx := testctx.New(testctx.Partial)
require.False(t, pipe.Skip(ctx))
})
t.Run("full", func(t *testing.T) {
require.True(t, pipe.Skip(testctx.New()))
})
}
func TestRun(t *testing.T) {
t.Run("target", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: "dist",
}, testctx.Partial)
t.Setenv("GOOS", "windows")
t.Setenv("GOARCH", "arm64")
require.NoError(t, pipe.Run(ctx))
require.Equal(t, "windows_arm64", ctx.PartialTarget)
})
t.Run("using GGOOS and GGOARCH", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: "dist",
}, testctx.Partial)
t.Setenv("GGOOS", "windows")
t.Setenv("GGOARCH", "arm64")
require.NoError(t, pipe.Run(ctx))
require.Equal(t, "windows_arm64", ctx.PartialTarget)
})
t.Run("custom GGOARM", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: "dist",
}, testctx.Partial)
t.Setenv("GGOOS", "linux")
t.Setenv("GGOARCH", "arm")
t.Run("default", func(t *testing.T) {
require.NoError(t, pipe.Run(ctx))
require.Equal(t, "linux_arm_6", ctx.PartialTarget)
})
t.Run("default", func(t *testing.T) {
t.Setenv("GGOARM", "7")
require.NoError(t, pipe.Run(ctx))
require.Equal(t, "linux_arm_7", ctx.PartialTarget)
})
})
t.Run("custom GGOAMD64", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: "dist",
}, testctx.Partial)
t.Setenv("GGOOS", "linux")
t.Setenv("GGOARCH", "amd64")
t.Run("default", func(t *testing.T) {
require.NoError(t, pipe.Run(ctx))
require.Equal(t, "linux_amd64_v1", ctx.PartialTarget)
})
t.Run("default", func(t *testing.T) {
t.Setenv("GGOAMD64", "v4")
require.NoError(t, pipe.Run(ctx))
require.Equal(t, "linux_amd64_v4", ctx.PartialTarget)
})
})
t.Run("custom GGOMIPS", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: "dist",
}, testctx.Partial)
t.Setenv("GGOOS", "linux")
for _, mips := range []string{"mips", "mips64", "mipsle", "mips64le"} {
t.Run(mips, func(t *testing.T) {
t.Setenv("GGOARCH", mips)
t.Run("default", func(t *testing.T) {
require.NoError(t, pipe.Run(ctx))
require.Equal(t, "linux_"+mips+"_hardfloat", ctx.PartialTarget)
})
t.Run("default", func(t *testing.T) {
t.Setenv("GGOMIPS", "softfloat")
require.NoError(t, pipe.Run(ctx))
require.Equal(t, "linux_"+mips+"_softfloat", ctx.PartialTarget)
})
})
}
})
t.Run("using runtime", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: "dist",
}, testctx.Partial)
require.NoError(t, pipe.Run(ctx))
target := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
// commonly tests will run on either arm64 or amd64.
if runtime.GOARCH == "amd64" {
target += "_v1"
}
require.Equal(t, target, ctx.PartialTarget)
})
}