/
git_test.go
88 lines (75 loc) · 2.23 KB
/
git_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package git_test
import (
"context"
"os"
"testing"
"github.com/goreleaser/goreleaser/internal/git"
"github.com/goreleaser/goreleaser/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.Error(t, err)
require.Empty(t, out)
require.Equal(
t,
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.\n",
err.Error(),
)
}
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.Error(t, err)
require.Empty(t, out)
require.Equal(
t,
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.",
err.Error(),
)
})
t.Run("all lines error", func(t *testing.T) {
out, err := git.CleanAllLines(git.Run(ctx, "command-that-dont-exist"))
require.Error(t, err)
require.Empty(t, out)
require.Equal(
t,
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.",
err.Error(),
)
})
}