mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-16 03:52:12 +02:00
ec2db4a727
<!-- Hi, thanks for contributing! Please make sure you read our CONTRIBUTING guide. Also, add tests and the respective documentation changes as well. --> <!-- If applied, this commit will... --> ... <!-- Why is this change being made? --> ... <!-- # Provide links to any relevant tickets, URLs or other resources --> ... --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package git_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/git"
|
|
"github.com/goreleaser/goreleaser/v2/internal/testlib"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGit(t *testing.T) {
|
|
ctx := context.Background()
|
|
out, err := git.Run(ctx, "status")
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, out)
|
|
|
|
out, err = git.Run(ctx, "command-that-dont-exist")
|
|
require.EqualError(t, err, "git: 'command-that-dont-exist' is not a git command. See 'git --help'.\n")
|
|
require.Empty(t, out)
|
|
}
|
|
|
|
func TestGitWarning(t *testing.T) {
|
|
ctx := context.Background()
|
|
testlib.Mktmp(t)
|
|
testlib.GitInit(t)
|
|
testlib.GitCommit(t, "foo")
|
|
testlib.GitBranch(t, "tags/1.2.2")
|
|
testlib.GitTag(t, "1.2.2")
|
|
testlib.GitCommit(t, "foobar")
|
|
testlib.GitBranch(t, "tags/1.2.3")
|
|
testlib.GitTag(t, "1.2.3")
|
|
testlib.GitTag(t, "nightly")
|
|
|
|
out, err := git.Run(ctx, "describe", "--tags", "--abbrev=0", "tags/1.2.3^")
|
|
require.NoError(t, err)
|
|
require.Equal(t, "1.2.2\n", out)
|
|
|
|
tags, err := git.CleanAllLines(git.Run(ctx, "tag", "--points-at", "HEAD", "--sort", "-version:refname"))
|
|
require.NoError(t, err)
|
|
require.ElementsMatch(t, []string{"1.2.3", "nightly"}, tags)
|
|
}
|
|
|
|
func TestRepo(t *testing.T) {
|
|
ctx := context.Background()
|
|
require.True(t, git.IsRepo(ctx), "goreleaser folder should be a git repo")
|
|
|
|
require.NoError(t, os.Chdir(os.TempDir()))
|
|
require.False(t, git.IsRepo(ctx), os.TempDir()+" folder should be a git repo")
|
|
}
|
|
|
|
func TestClean(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
out, err := git.Clean("asdasd 'ssadas'\nadasd", nil)
|
|
require.NoError(t, err)
|
|
require.Equal(t, "asdasd ssadas", out)
|
|
})
|
|
|
|
t.Run("error", func(t *testing.T) {
|
|
out, err := git.Clean(git.Run(ctx, "command-that-dont-exist"))
|
|
require.EqualError(t, err, "git: 'command-that-dont-exist' is not a git command. See 'git --help'.")
|
|
require.Empty(t, out)
|
|
})
|
|
|
|
t.Run("all lines error", func(t *testing.T) {
|
|
out, err := git.CleanAllLines(git.Run(ctx, "command-that-dont-exist"))
|
|
require.EqualError(t, err, "git: 'command-that-dont-exist' is not a git command. See 'git --help'.")
|
|
require.Empty(t, out)
|
|
})
|
|
}
|