1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00
goreleaser/pipeline/git/git_test.go
Carlos Alexandro Becker c15e8c8108
logs for travis debugging
2017-04-15 13:14:01 -03:00

91 lines
2.2 KiB
Go

package git
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"testing"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/stretchr/testify/assert"
)
func TestDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.Description())
}
func TestValidVersion(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Config: config.Project{},
}
assert.NoError(Pipe{}.Run(ctx))
assert.NotEmpty(ctx.Git.CurrentTag)
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))
fmt.Println("Changed dir to", folder)
return folder, func() {
assert.NoError(os.Chdir(previous))
fmt.Println("Changed dir to", previous)
}
}