From f4ad27cae99e62c83837eaeccc42de111062426a Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 1 Dec 2024 23:33:25 -0300 Subject: [PATCH] fix: skip gomod info loading if no go builds --- internal/pipe/gomod/gomod.go | 9 +++++++++ internal/pipe/gomod/gomod_proxy_test.go | 2 +- internal/pipe/gomod/gomod_test.go | 26 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/internal/pipe/gomod/gomod.go b/internal/pipe/gomod/gomod.go index c3c131ed8c1..5b10d13aae5 100644 --- a/internal/pipe/gomod/gomod.go +++ b/internal/pipe/gomod/gomod.go @@ -20,6 +20,15 @@ type Pipe struct{} func (Pipe) String() string { return "loading go mod information" } +func (Pipe) Skip(ctx *context.Context) bool { + for _, build := range ctx.Config.Builds { + if build.Builder == "go" { + return false + } + } + return true +} + // Default sets the pipe defaults. func (Pipe) Default(ctx *context.Context) error { if ctx.Config.GoMod.GoBinary == "" { diff --git a/internal/pipe/gomod/gomod_proxy_test.go b/internal/pipe/gomod/gomod_proxy_test.go index 38e54da9c94..ef78dc48b1a 100644 --- a/internal/pipe/gomod/gomod_proxy_test.go +++ b/internal/pipe/gomod/gomod_proxy_test.go @@ -245,7 +245,7 @@ func TestProxyDescription(t *testing.T) { require.NotEmpty(t, ProxyPipe{}.String()) } -func TestSkip(t *testing.T) { +func TestSkipProxy(t *testing.T) { t.Run("skip false gomod.proxy", func(t *testing.T) { ctx := testctx.New() require.True(t, ProxyPipe{}.Skip(ctx)) diff --git a/internal/pipe/gomod/gomod_test.go b/internal/pipe/gomod/gomod_test.go index 7ea8bf252ad..0caf2ace649 100644 --- a/internal/pipe/gomod/gomod_test.go +++ b/internal/pipe/gomod/gomod_test.go @@ -13,6 +13,32 @@ import ( "github.com/stretchr/testify/require" ) +func TestSkip(t *testing.T) { + t.Run("skip", func(t *testing.T) { + ctx := testctx.NewWithCfg(config.Project{ + Builds: []config.Build{ + { + Builder: "zig", + }, + }, + }) + require.True(t, Pipe{}.Skip(ctx)) + }) + t.Run("dont skip", func(t *testing.T) { + ctx := testctx.NewWithCfg(config.Project{ + Builds: []config.Build{ + { + Builder: "go", + }, + { + Builder: "zig", + }, + }, + }) + require.False(t, Pipe{}.Skip(ctx)) + }) +} + func TestRun(t *testing.T) { ctx := testctx.New() require.NoError(t, Pipe{}.Default(ctx))