github.com/goreleaser/goreleaser@v1.25.1/internal/pipe/partial/partial_test.go (about) 1 package partial 2 3 import ( 4 "fmt" 5 "runtime" 6 "testing" 7 8 "github.com/goreleaser/goreleaser/internal/testctx" 9 "github.com/goreleaser/goreleaser/pkg/config" 10 "github.com/stretchr/testify/require" 11 ) 12 13 var pipe = Pipe{} 14 15 func TestString(t *testing.T) { 16 require.NotEmpty(t, pipe.String()) 17 } 18 19 func TestSkip(t *testing.T) { 20 t.Run("partial", func(t *testing.T) { 21 ctx := testctx.New(testctx.Partial) 22 require.False(t, pipe.Skip(ctx)) 23 }) 24 25 t.Run("full", func(t *testing.T) { 26 require.True(t, pipe.Skip(testctx.New())) 27 }) 28 } 29 30 func TestRun(t *testing.T) { 31 t.Run("target", func(t *testing.T) { 32 ctx := testctx.NewWithCfg(config.Project{ 33 Dist: "dist", 34 }, testctx.Partial) 35 t.Setenv("GOOS", "windows") 36 t.Setenv("GOARCH", "arm64") 37 require.NoError(t, pipe.Run(ctx)) 38 require.Equal(t, "windows_arm64", ctx.PartialTarget) 39 }) 40 t.Run("using GGOOS and GGOARCH", func(t *testing.T) { 41 ctx := testctx.NewWithCfg(config.Project{ 42 Dist: "dist", 43 }, testctx.Partial) 44 t.Setenv("GGOOS", "windows") 45 t.Setenv("GGOARCH", "arm64") 46 require.NoError(t, pipe.Run(ctx)) 47 require.Equal(t, "windows_arm64", ctx.PartialTarget) 48 }) 49 t.Run("using runtime", func(t *testing.T) { 50 ctx := testctx.NewWithCfg(config.Project{ 51 Dist: "dist", 52 }, testctx.Partial) 53 require.NoError(t, pipe.Run(ctx)) 54 target := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH) 55 require.Equal(t, target, ctx.PartialTarget) 56 }) 57 }