1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-15 01:34:21 +02:00

improved git coverage, code, and function

This commit is contained in:
Carlos Alexandro Becker
2017-04-15 13:05:54 -03:00
parent 7b1bc7ce70
commit ceb5c1162c
9 changed files with 108 additions and 151 deletions

View File

@ -1,6 +1,9 @@
package git
import (
"io/ioutil"
"os"
"os/exec"
"testing"
"github.com/goreleaser/goreleaser/config"
@ -13,7 +16,7 @@ func TestDescription(t *testing.T) {
}
func TestValidVersion(t *testing.T) {
assert := assert.New(t)
var assert = assert.New(t)
var ctx = &context.Context{
Config: config.Project{},
@ -23,3 +26,62 @@ func TestValidVersion(t *testing.T) {
assert.NotEmpty(ctx.Git.PreviousTag)
assert.NotEmpty(ctx.Git.Diff)
}
func TestNotAGitFolder(t *testing.T) {
var assert = assert.New(t)
_, back := createAndChdir(t)
defer back()
var ctx = &context.Context{
Config: config.Project{},
}
assert.Error(Pipe{}.Run(ctx))
}
func TestSingleCommit(t *testing.T) {
var assert = assert.New(t)
_, back := createAndChdir(t)
defer back()
assert.NoError(exec.Command("git", "init").Run())
assert.NoError(exec.Command("git", "commit", "--allow-empty", "-m", "asd").Run())
assert.NoError(exec.Command("git", "tag", "v0.0.1").Run())
var ctx = &context.Context{
Config: config.Project{},
}
assert.NoError(Pipe{}.Run(ctx))
}
func TestNewRepository(t *testing.T) {
var assert = assert.New(t)
_, back := createAndChdir(t)
defer back()
assert.NoError(exec.Command("git", "init").Run())
var ctx = &context.Context{
Config: config.Project{},
}
assert.Error(Pipe{}.Run(ctx))
}
func TestInvalidTagFormat(t *testing.T) {
var assert = assert.New(t)
_, back := createAndChdir(t)
defer back()
assert.NoError(exec.Command("git", "init").Run())
assert.NoError(exec.Command("git", "commit", "--allow-empty", "-m", "asd").Run())
assert.NoError(exec.Command("git", "tag", "sadasd").Run())
var ctx = &context.Context{
Config: config.Project{},
}
assert.EqualError(Pipe{}.Run(ctx), "sadasd is not in a valid version format")
}
func createAndChdir(t *testing.T) (current string, back func()) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "gorelasertest")
assert.NoError(err)
previous, err := os.Getwd()
assert.NoError(err)
assert.NoError(os.Chdir(folder))
return folder, func() {
assert.NoError(os.Chdir(previous))
}
}