You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +02:00 
			
		
		
		
	fix: pass goversion.Info instead of string
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
		| @@ -5,6 +5,7 @@ import ( | ||||
| 	"fmt" | ||||
| 	"time" | ||||
|  | ||||
| 	goversion "github.com/caarlos0/go-version" | ||||
| 	"github.com/caarlos0/log" | ||||
| 	"github.com/charmbracelet/lipgloss" | ||||
| 	"github.com/goreleaser/goreleaser/pkg/context" | ||||
| @@ -17,7 +18,7 @@ var ( | ||||
| 	codeStyle = lipgloss.NewStyle().Italic(true) | ||||
| ) | ||||
|  | ||||
| func Execute(version string, exit func(int), args []string) { | ||||
| func Execute(version goversion.Info, exit func(int), args []string) { | ||||
| 	newRootCmd(version, exit).Execute(args) | ||||
| } | ||||
|  | ||||
| @@ -49,7 +50,7 @@ type rootCmd struct { | ||||
| 	exit  func(int) | ||||
| } | ||||
|  | ||||
| func newRootCmd(version string, exit func(int)) *rootCmd { | ||||
| func newRootCmd(version goversion.Info, exit func(int)) *rootCmd { | ||||
| 	root := &rootCmd{ | ||||
| 		exit: exit, | ||||
| 	} | ||||
| @@ -65,11 +66,11 @@ You can customize your entire release process through a single .goreleaser.yaml | ||||
|  | ||||
| Check out our website for more information, examples and documentation: https://goreleaser.com | ||||
| `, | ||||
| 		Version:       version, | ||||
| 		Version:       version.String(), | ||||
| 		SilenceUsage:  true, | ||||
| 		SilenceErrors: true, | ||||
| 		Args:          cobra.NoArgs, | ||||
| 		PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||||
| 		PersistentPreRun: func(_ *cobra.Command, _ []string) { | ||||
| 			if root.debug { | ||||
| 				log.SetLevel(log.DebugLevel) | ||||
| 				log.Debug("debug logs enabled") | ||||
|   | ||||
| @@ -4,18 +4,23 @@ import ( | ||||
| 	"bytes" | ||||
| 	"testing" | ||||
|  | ||||
| 	goversion "github.com/caarlos0/go-version" | ||||
| 	"github.com/stretchr/testify/require" | ||||
| ) | ||||
|  | ||||
| var testversion = goversion.Info{ | ||||
| 	GitVersion: "1.2.3", | ||||
| } | ||||
|  | ||||
| func TestRootCmd(t *testing.T) { | ||||
| 	mem := &exitMemento{} | ||||
| 	Execute("1.2.3", mem.Exit, []string{"-h"}) | ||||
| 	Execute(testversion, mem.Exit, []string{"-h"}) | ||||
| 	require.Equal(t, 0, mem.code) | ||||
| } | ||||
|  | ||||
| func TestRootCmdHelp(t *testing.T) { | ||||
| 	mem := &exitMemento{} | ||||
| 	cmd := newRootCmd("", mem.Exit).cmd | ||||
| 	cmd := newRootCmd(testversion, mem.Exit).cmd | ||||
| 	cmd.SetArgs([]string{"-h"}) | ||||
| 	require.NoError(t, cmd.Execute()) | ||||
| 	require.Equal(t, 0, mem.code) | ||||
| @@ -24,17 +29,17 @@ func TestRootCmdHelp(t *testing.T) { | ||||
| func TestRootCmdVersion(t *testing.T) { | ||||
| 	var b bytes.Buffer | ||||
| 	mem := &exitMemento{} | ||||
| 	cmd := newRootCmd("1.2.3", mem.Exit).cmd | ||||
| 	cmd := newRootCmd(testversion, mem.Exit).cmd | ||||
| 	cmd.SetOut(&b) | ||||
| 	cmd.SetArgs([]string{"-v"}) | ||||
| 	require.NoError(t, cmd.Execute()) | ||||
| 	require.Equal(t, "1.2.3", b.String()) | ||||
| 	require.Contains(t, b.String(), "1.2.3") | ||||
| 	require.Equal(t, 0, mem.code) | ||||
| } | ||||
|  | ||||
| func TestRootCmdExitCode(t *testing.T) { | ||||
| 	mem := &exitMemento{} | ||||
| 	cmd := newRootCmd("", mem.Exit) | ||||
| 	cmd := newRootCmd(testversion, mem.Exit) | ||||
| 	args := []string{"check", "--deprecated", "-f", "testdata/good.yml"} | ||||
| 	cmd.Execute(args) | ||||
| 	require.Equal(t, 2, mem.code) | ||||
| @@ -43,7 +48,7 @@ func TestRootCmdExitCode(t *testing.T) { | ||||
| func TestRootRelease(t *testing.T) { | ||||
| 	setup(t) | ||||
| 	mem := &exitMemento{} | ||||
| 	cmd := newRootCmd("", mem.Exit) | ||||
| 	cmd := newRootCmd(testversion, mem.Exit) | ||||
| 	cmd.Execute([]string{}) | ||||
| 	require.Equal(t, 1, mem.code) | ||||
| } | ||||
| @@ -51,14 +56,14 @@ func TestRootRelease(t *testing.T) { | ||||
| func TestRootReleaseDebug(t *testing.T) { | ||||
| 	setup(t) | ||||
| 	mem := &exitMemento{} | ||||
| 	cmd := newRootCmd("", mem.Exit) | ||||
| 	cmd := newRootCmd(testversion, mem.Exit) | ||||
| 	cmd.Execute([]string{"r", "--debug"}) | ||||
| 	require.Equal(t, 1, mem.code) | ||||
| } | ||||
|  | ||||
| func TestShouldPrependRelease(t *testing.T) { | ||||
| 	result := func(args []string) bool { | ||||
| 		return shouldPrependRelease(newRootCmd("1", func(_ int) {}).cmd, args) | ||||
| 		return shouldPrependRelease(newRootCmd(testversion, func(_ int) {}).cmd, args) | ||||
| 	} | ||||
|  | ||||
| 	t.Run("no args", func(t *testing.T) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user