github.com/goreleaser/goreleaser@v1.25.1/internal/builders/buildtarget/targets_test.go (about)

     1  package buildtarget
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/goreleaser/goreleaser/pkg/config"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestAllBuildTargets(t *testing.T) {
    12  	build := config.Build{
    13  		GoBinary: "go",
    14  		Goos: []string{
    15  			"linux",
    16  			"darwin",
    17  			"freebsd",
    18  			"openbsd",
    19  			"windows",
    20  			"js",
    21  			"ios",
    22  			"wasip1",
    23  		},
    24  		Goarch: []string{
    25  			"386",
    26  			"amd64",
    27  			"arm",
    28  			"arm64",
    29  			"wasm",
    30  			"mips",
    31  			"mips64",
    32  			"mipsle",
    33  			"mips64le",
    34  			"riscv64",
    35  			"loong64",
    36  		},
    37  		Goarm: []string{
    38  			"6",
    39  			"7",
    40  		},
    41  		Gomips: []string{
    42  			"hardfloat",
    43  			"softfloat",
    44  		},
    45  		Goamd64: []string{
    46  			"v1",
    47  			"v2",
    48  			"v3",
    49  			"v4",
    50  		},
    51  		Ignore: []config.IgnoredBuild{
    52  			{
    53  				Goos:   "linux",
    54  				Goarch: "arm",
    55  				Goarm:  "7",
    56  			}, {
    57  				Goos:   "openbsd",
    58  				Goarch: "arm",
    59  			}, {
    60  				Goarch: "mips64",
    61  				Gomips: "hardfloat",
    62  			}, {
    63  				Goarch: "mips64le",
    64  				Gomips: "softfloat",
    65  			}, {
    66  				Goarch:  "amd64",
    67  				Goamd64: "v3",
    68  			},
    69  		},
    70  	}
    71  
    72  	t.Run("go 1.18", func(t *testing.T) {
    73  		result, err := List(build)
    74  		require.NoError(t, err)
    75  		require.Equal(t, []string{
    76  			"linux_386",
    77  			"linux_amd64_v1",
    78  			"linux_amd64_v2",
    79  			"linux_amd64_v4",
    80  			"linux_arm_6",
    81  			"linux_arm64",
    82  			"linux_mips_hardfloat",
    83  			"linux_mips_softfloat",
    84  			"linux_mips64_softfloat",
    85  			"linux_mipsle_hardfloat",
    86  			"linux_mipsle_softfloat",
    87  			"linux_mips64le_hardfloat",
    88  			"linux_riscv64",
    89  			"linux_loong64",
    90  			"darwin_amd64_v1",
    91  			"darwin_amd64_v2",
    92  			"darwin_amd64_v4",
    93  			"darwin_arm64",
    94  			"freebsd_386",
    95  			"freebsd_amd64_v1",
    96  			"freebsd_amd64_v2",
    97  			"freebsd_amd64_v4",
    98  			"freebsd_arm_6",
    99  			"freebsd_arm_7",
   100  			"freebsd_arm64",
   101  			"openbsd_386",
   102  			"openbsd_amd64_v1",
   103  			"openbsd_amd64_v2",
   104  			"openbsd_amd64_v4",
   105  			"openbsd_arm64",
   106  			"windows_386",
   107  			"windows_amd64_v1",
   108  			"windows_amd64_v2",
   109  			"windows_amd64_v4",
   110  			"windows_arm_6",
   111  			"windows_arm_7",
   112  			"windows_arm64",
   113  			"js_wasm",
   114  			"ios_arm64",
   115  			"wasip1_wasm",
   116  		}, result)
   117  	})
   118  
   119  	t.Run("invalid goos", func(t *testing.T) {
   120  		_, err := List(config.Build{
   121  			Goos:    []string{"invalid"},
   122  			Goarch:  []string{"amd64"},
   123  			Goamd64: []string{"v2"},
   124  		})
   125  		require.EqualError(t, err, "invalid goos: invalid")
   126  	})
   127  
   128  	t.Run("invalid goarch", func(t *testing.T) {
   129  		_, err := List(config.Build{
   130  			Goos:   []string{"linux"},
   131  			Goarch: []string{"invalid"},
   132  		})
   133  		require.EqualError(t, err, "invalid goarch: invalid")
   134  	})
   135  
   136  	t.Run("invalid goarm", func(t *testing.T) {
   137  		_, err := List(config.Build{
   138  			Goos:   []string{"linux"},
   139  			Goarch: []string{"arm"},
   140  			Goarm:  []string{"invalid"},
   141  		})
   142  		require.EqualError(t, err, "invalid goarm: invalid")
   143  	})
   144  
   145  	t.Run("invalid gomips", func(t *testing.T) {
   146  		_, err := List(config.Build{
   147  			Goos:   []string{"linux"},
   148  			Goarch: []string{"mips"},
   149  			Gomips: []string{"invalid"},
   150  		})
   151  		require.EqualError(t, err, "invalid gomips: invalid")
   152  	})
   153  
   154  	t.Run("invalid goamd64", func(t *testing.T) {
   155  		_, err := List(config.Build{
   156  			Goos:    []string{"linux"},
   157  			Goarch:  []string{"amd64"},
   158  			Goamd64: []string{"invalid"},
   159  		})
   160  		require.EqualError(t, err, "invalid goamd64: invalid")
   161  	})
   162  }
   163  
   164  func TestGoosGoarchCombos(t *testing.T) {
   165  	platforms := []struct {
   166  		os    string
   167  		arch  string
   168  		valid bool
   169  	}{
   170  		// valid targets:
   171  		{"aix", "ppc64", true},
   172  		{"android", "386", true},
   173  		{"android", "amd64", true},
   174  		{"android", "arm", true},
   175  		{"android", "arm64", true},
   176  		{"darwin", "amd64", true},
   177  		{"darwin", "arm64", true},
   178  		{"dragonfly", "amd64", true},
   179  		{"freebsd", "386", true},
   180  		{"freebsd", "amd64", true},
   181  		{"freebsd", "arm", true},
   182  		{"freebsd", "arm64", true},
   183  		{"illumos", "amd64", true},
   184  		{"ios", "arm64", true},
   185  		{"linux", "386", true},
   186  		{"linux", "amd64", true},
   187  		{"linux", "arm", true},
   188  		{"linux", "arm64", true},
   189  		{"linux", "mips", true},
   190  		{"linux", "mipsle", true},
   191  		{"linux", "mips64", true},
   192  		{"linux", "mips64le", true},
   193  		{"linux", "ppc64", true},
   194  		{"linux", "ppc64le", true},
   195  		{"linux", "s390x", true},
   196  		{"linux", "riscv64", true},
   197  		{"linux", "loong64", true},
   198  		{"netbsd", "386", true},
   199  		{"netbsd", "amd64", true},
   200  		{"netbsd", "arm", true},
   201  		{"netbsd", "arm64", true},
   202  		{"openbsd", "386", true},
   203  		{"openbsd", "amd64", true},
   204  		{"openbsd", "arm", true},
   205  		{"openbsd", "arm64", true},
   206  		{"plan9", "386", true},
   207  		{"plan9", "amd64", true},
   208  		{"plan9", "arm", true},
   209  		{"solaris", "amd64", true},
   210  		{"windows", "386", true},
   211  		{"windows", "amd64", true},
   212  		{"windows", "arm", true},
   213  		{"windows", "arm64", true},
   214  		{"js", "wasm", true},
   215  		// invalid targets
   216  		{"darwin", "386", false},
   217  		{"darwin", "arm", false},
   218  		{"windows", "riscv64", false},
   219  	}
   220  	for _, p := range platforms {
   221  		t.Run(fmt.Sprintf("%v %v valid=%v", p.os, p.arch, p.valid), func(t *testing.T) {
   222  			require.Equal(t, p.valid, valid(target{p.os, p.arch, "", "", ""}))
   223  		})
   224  	}
   225  }
   226  
   227  func TestList(t *testing.T) {
   228  	t.Run("success", func(t *testing.T) {
   229  		targets, err := List(config.Build{
   230  			Goos:     []string{"linux"},
   231  			Goarch:   []string{"amd64"},
   232  			Goamd64:  []string{"v2"},
   233  			GoBinary: "go",
   234  		})
   235  		require.NoError(t, err)
   236  		require.Equal(t, []string{"linux_amd64_v2"}, targets)
   237  	})
   238  
   239  	t.Run("success with dir", func(t *testing.T) {
   240  		targets, err := List(config.Build{
   241  			Goos:     []string{"linux"},
   242  			Goarch:   []string{"amd64"},
   243  			Goamd64:  []string{"v2"},
   244  			GoBinary: "go",
   245  			Dir:      "./testdata",
   246  		})
   247  		require.NoError(t, err)
   248  		require.Equal(t, []string{"linux_amd64_v2"}, targets)
   249  	})
   250  }