1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/builders/buildtarget/targets_test.go

283 lines
6.3 KiB
Go
Raw Normal View History

package buildtarget
2017-04-27 01:08:25 +02:00
import (
"fmt"
"testing"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/stretchr/testify/require"
2017-04-27 01:08:25 +02:00
)
func TestAllBuildTargets(t *testing.T) {
build := config.Build{
GoBinary: "go",
2017-07-01 18:21:07 +02:00
Goos: []string{
"linux",
"darwin",
"freebsd",
"openbsd",
"windows",
"js",
2017-07-01 18:21:07 +02:00
},
Goarch: []string{
"386",
"amd64",
"arm",
"arm64",
"wasm",
"mips",
"mips64",
"mipsle",
"mips64le",
"riscv64",
2017-07-01 18:21:07 +02:00
},
Goarm: []string{
"6",
"7",
},
Gomips: []string{
"hardfloat",
"softfloat",
},
2017-07-01 18:21:07 +02:00
Ignore: []config.IgnoredBuild{
{
Goos: "linux",
Goarch: "arm",
Goarm: "7",
}, {
Goos: "openbsd",
Goarch: "arm",
}, {
Goarch: "mips64",
Gomips: "hardfloat",
}, {
Goarch: "mips64le",
Gomips: "softfloat",
2017-04-27 01:08:25 +02:00
},
},
}
t.Run("go 1.15", func(t *testing.T) {
result, err := matrix(build, []byte("go version go1.15.0"))
require.NoError(t, err)
require.Equal(t, []string{
"linux_386",
"linux_amd64",
"linux_arm_6",
"linux_arm64",
"linux_mips_hardfloat",
"linux_mips_softfloat",
"linux_mips64_softfloat",
"linux_mipsle_hardfloat",
"linux_mipsle_softfloat",
"linux_mips64le_hardfloat",
"linux_riscv64",
"darwin_amd64",
"freebsd_386",
"freebsd_amd64",
"freebsd_arm_6",
"freebsd_arm_7",
"freebsd_arm64",
"openbsd_386",
"openbsd_amd64",
"openbsd_arm64",
"windows_386",
"windows_amd64",
"windows_arm_6",
"windows_arm_7",
"js_wasm",
}, result)
})
t.Run("go 1.16", func(t *testing.T) {
result, err := matrix(build, []byte("go version go1.16.2"))
require.NoError(t, err)
require.Equal(t, []string{
"linux_386",
"linux_amd64",
"linux_arm_6",
"linux_arm64",
"linux_mips_hardfloat",
"linux_mips_softfloat",
"linux_mips64_softfloat",
"linux_mipsle_hardfloat",
"linux_mipsle_softfloat",
"linux_mips64le_hardfloat",
"linux_riscv64",
"darwin_amd64",
"darwin_arm64",
"freebsd_386",
"freebsd_amd64",
"freebsd_arm_6",
"freebsd_arm_7",
"freebsd_arm64",
"openbsd_386",
"openbsd_amd64",
"openbsd_arm64",
"windows_386",
"windows_amd64",
"windows_arm_6",
"windows_arm_7",
"js_wasm",
}, result)
})
t.Run("go 1.17", func(t *testing.T) {
result, err := matrix(build, []byte("go version go1.17.0"))
require.NoError(t, err)
require.Equal(t, []string{
"linux_386",
"linux_amd64",
"linux_arm_6",
"linux_arm64",
"linux_mips_hardfloat",
"linux_mips_softfloat",
"linux_mips64_softfloat",
"linux_mipsle_hardfloat",
"linux_mipsle_softfloat",
"linux_mips64le_hardfloat",
"linux_riscv64",
"darwin_amd64",
"darwin_arm64",
"freebsd_386",
"freebsd_amd64",
"freebsd_arm_6",
"freebsd_arm_7",
"freebsd_arm64",
"openbsd_386",
"openbsd_amd64",
"openbsd_arm64",
"windows_386",
"windows_amd64",
"windows_arm_6",
"windows_arm_7",
"windows_arm64",
"js_wasm",
}, result)
})
t.Run("invalid goos", func(t *testing.T) {
_, err := matrix(config.Build{
Goos: []string{"invalid"},
Goarch: []string{"amd64"},
}, []byte("go version go1.17.0"))
require.EqualError(t, err, "invalid goos: invalid")
})
t.Run("invalid goarch", func(t *testing.T) {
_, err := matrix(config.Build{
Goos: []string{"linux"},
Goarch: []string{"invalid"},
}, []byte("go version go1.17.0"))
require.EqualError(t, err, "invalid goarch: invalid")
})
t.Run("invalid goarm", func(t *testing.T) {
_, err := matrix(config.Build{
Goos: []string{"linux"},
Goarch: []string{"arm"},
Goarm: []string{"invalid"},
}, []byte("go version go1.17.0"))
require.EqualError(t, err, "invalid goarm: invalid")
})
t.Run("invalid gomips", func(t *testing.T) {
_, err := matrix(config.Build{
Goos: []string{"linux"},
Goarch: []string{"mips"},
Gomips: []string{"invalid"},
}, []byte("go version go1.17.0"))
require.EqualError(t, err, "invalid gomips: invalid")
})
2017-04-27 01:08:25 +02:00
}
2017-07-07 01:13:02 +02:00
func TestGoosGoarchCombos(t *testing.T) {
platforms := []struct {
2017-07-07 01:13:02 +02:00
os string
arch string
valid bool
2017-04-27 01:08:25 +02:00
}{
2017-07-07 01:13:02 +02:00
// valid targets:
{"aix", "ppc64", true},
{"android", "386", true},
{"android", "amd64", true},
2017-07-07 01:13:02 +02:00
{"android", "arm", true},
{"android", "arm64", true},
2017-07-07 01:13:02 +02:00
{"darwin", "amd64", true},
{"darwin", "arm64", true},
2017-07-07 01:13:02 +02:00
{"dragonfly", "amd64", true},
{"freebsd", "386", true},
{"freebsd", "amd64", true},
{"freebsd", "arm", true},
{"illumos", "amd64", true},
2017-07-07 01:13:02 +02:00
{"linux", "386", true},
{"linux", "amd64", true},
{"linux", "arm", true},
{"linux", "arm64", true},
{"linux", "mips", true},
{"linux", "mipsle", true},
{"linux", "mips64", true},
{"linux", "mips64le", true},
{"linux", "ppc64", true},
{"linux", "ppc64le", true},
2017-07-26 09:04:03 +02:00
{"linux", "s390x", true},
{"linux", "riscv64", true},
2017-07-07 01:13:02 +02:00
{"netbsd", "386", true},
{"netbsd", "amd64", true},
{"netbsd", "arm", true},
{"openbsd", "386", true},
{"openbsd", "amd64", true},
{"openbsd", "arm", true},
{"plan9", "386", true},
{"plan9", "amd64", true},
{"plan9", "arm", true},
2017-07-07 01:13:02 +02:00
{"solaris", "amd64", true},
{"windows", "386", true},
{"windows", "amd64", true},
{"windows", "arm", true},
{"windows", "arm64", true},
{"js", "wasm", true},
2017-07-07 01:13:02 +02:00
// invalid targets
{"darwin", "386", false},
2017-07-07 01:13:02 +02:00
{"darwin", "arm", false},
{"windows", "riscv64", false},
2017-04-27 01:08:25 +02:00
}
for _, p := range platforms {
2017-07-07 01:13:02 +02:00
t.Run(fmt.Sprintf("%v %v valid=%v", p.os, p.arch, p.valid), func(t *testing.T) {
require.Equal(t, p.valid, valid(target{p.os, p.arch, "", ""}))
2017-04-27 01:08:25 +02:00
})
}
}
func TestList(t *testing.T) {
t.Run("success", func(t *testing.T) {
targets, err := List(config.Build{
Goos: []string{"linux"},
Goarch: []string{"amd64"},
GoBinary: "go",
})
require.NoError(t, err)
require.Equal(t, []string{"linux_amd64"}, targets)
})
t.Run("success with dir", func(t *testing.T) {
targets, err := List(config.Build{
Goos: []string{"linux"},
Goarch: []string{"amd64"},
GoBinary: "go",
Dir: "./testdata",
})
require.NoError(t, err)
require.Equal(t, []string{"linux_amd64"}, targets)
})
t.Run("fail", func(t *testing.T) {
_, err := List(config.Build{
Goos: []string{"linux"},
Goarch: []string{"amd64"},
GoBinary: "nope",
})
require.EqualError(t, err, `unable to determine version of go binary (nope): exec: "nope": executable file not found in $PATH`)
})
}