2020-07-09 22:40:37 +02:00
|
|
|
package git_test
|
2017-08-19 17:47:04 +02:00
|
|
|
|
|
|
|
import (
|
2017-10-16 19:43:26 +02:00
|
|
|
"os"
|
2017-08-19 17:47:04 +02:00
|
|
|
"testing"
|
|
|
|
|
2020-07-09 22:40:37 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/git"
|
2017-08-19 17:47:04 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGit(t *testing.T) {
|
2020-07-09 22:40:37 +02:00
|
|
|
out, err := git.Run("status")
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, out)
|
2017-08-19 17:47:04 +02:00
|
|
|
|
2020-07-09 22:40:37 +02:00
|
|
|
out, err = git.Run("command-that-dont-exist")
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, out)
|
2017-08-19 17:47:04 +02:00
|
|
|
assert.Equal(
|
2017-09-27 00:24:49 +02:00
|
|
|
t,
|
2017-08-19 17:47:04 +02:00
|
|
|
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.\n",
|
|
|
|
err.Error(),
|
|
|
|
)
|
|
|
|
}
|
2017-10-16 19:43:26 +02:00
|
|
|
|
|
|
|
func TestRepo(t *testing.T) {
|
2020-07-09 22:40:37 +02:00
|
|
|
assert.True(t, git.IsRepo(), "goreleaser folder should be a git repo")
|
2017-10-16 19:43:26 +02:00
|
|
|
|
|
|
|
assert.NoError(t, os.Chdir(os.TempDir()))
|
2020-07-09 22:40:37 +02:00
|
|
|
assert.False(t, git.IsRepo(), os.TempDir()+" folder should be a git repo")
|
2017-10-16 19:43:26 +02:00
|
|
|
}
|
2017-10-16 00:47:52 +02:00
|
|
|
|
|
|
|
func TestClean(t *testing.T) {
|
2020-07-09 22:40:37 +02:00
|
|
|
out, err := git.Clean("asdasd 'ssadas'\nadasd", nil)
|
2017-10-16 00:47:52 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "asdasd ssadas", out)
|
2018-02-26 01:17:45 +02:00
|
|
|
|
2020-07-09 22:40:37 +02:00
|
|
|
out, err = git.Clean(git.Run("command-that-dont-exist"))
|
2018-02-26 01:17:45 +02:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, out)
|
|
|
|
assert.Equal(
|
|
|
|
t,
|
|
|
|
"git: 'command-that-dont-exist' is not a git command. See 'git --help'.",
|
|
|
|
err.Error(),
|
|
|
|
)
|
2017-10-16 00:47:52 +02:00
|
|
|
}
|