1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00

trying with test fixtures

This commit is contained in:
Carlos Alexandro Becker 2017-04-15 13:58:18 -03:00
parent 36efad3f78
commit 0b7936eb0d
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
7 changed files with 71 additions and 28 deletions

@ -0,0 +1 @@
Subproject commit 593de7f025f3817cc0a56bb11f5a6f0131c67452

@ -0,0 +1 @@
Subproject commit 7cafca4c382e2d83b123281bb31dd7b4f0e19a8b

View File

@ -0,0 +1 @@
Subproject commit 211cca43da0ebbe5109c1cf09bee3ea0bb0bf04f

@ -0,0 +1 @@
Subproject commit 4bf27bfd08049ae6187cefa5e9d50e2e0f205ebe

View File

@ -3,6 +3,7 @@
package git
import (
"log"
"os"
"regexp"
"strings"
@ -37,6 +38,7 @@ func (p Pipe) Run(ctx *context.Context) (err error) {
}
func (Pipe) doRun(ctx *context.Context, pwd string) (err error) {
log.Println("git:", pwd)
tag, err := cleanGit(pwd, "describe", "--tags", "--abbrev=0", "--always")
if err != nil {
return
@ -56,16 +58,16 @@ func (Pipe) doRun(ctx *context.Context, pwd string) (err error) {
PreviousTag: prev,
Diff: log,
}
// removes usual `v` prefix
ctx.Version = strings.TrimPrefix(tag, "v")
if versionErr := isVersionValid(ctx.Version); versionErr != nil {
return versionErr
}
commit, err := cleanGit(pwd, "show", "--format='%H'", "HEAD")
if err != nil {
return
}
ctx.Git.Commit = commit
// removes usual `v` prefix
ctx.Version = strings.TrimPrefix(tag, "v")
if versionErr := isVersionValid(ctx.Version); versionErr != nil {
return versionErr
}
return
}

View File

@ -1,8 +1,8 @@
package git
import (
"io/ioutil"
"os/exec"
"os"
"path/filepath"
"testing"
"github.com/goreleaser/goreleaser/config"
@ -14,7 +14,7 @@ func TestDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.Description())
}
func TestValidVersion(t *testing.T) {
func TestRunPipe(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
@ -26,49 +26,86 @@ func TestValidVersion(t *testing.T) {
assert.NotEmpty(ctx.Git.Diff)
}
func TestNotAGitFolder(t *testing.T) {
func TestGoodRepo(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "gorelasertest")
assert.NoError(err)
var ctx = &context.Context{
Config: config.Project{},
}
assert.Error(Pipe{}.doRun(ctx, folder))
assert.NoError(Pipe{}.doRun(ctx, getFixture("good-repo")))
assert.Equal(
context.GitInfo{
CurrentTag: "v0.0.2",
PreviousTag: "v0.0.1",
Diff: "593de7f commit5\nf365005 commit4\n3eb6c7b commit3\n",
Commit: "593de7f025f3817cc0a56bb11f5a6f0131c67452",
},
ctx.Git,
)
}
func TestSingleCommitNoTags(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Config: config.Project{},
}
assert.NoError(Pipe{}.doRun(ctx, getFixture("single-commit-no-tags-repo")))
assert.Equal(
context.GitInfo{
CurrentTag: "211cca43da0ebbe5109c1cf09bee3ea0bb0bf04f",
PreviousTag: "211cca43da0ebbe5109c1cf09bee3ea0bb0bf04f",
Commit: "211cca43da0ebbe5109c1cf09bee3ea0bb0bf04f",
},
ctx.Git,
)
}
func TestSingleCommit(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "gorelasertest")
assert.NoError(err)
assert.NoError(exec.Command("git", "-C", folder, "init").Run())
assert.NoError(exec.Command("git", "-C", folder, "commit", "--allow-empty", "-m", "asd").Run())
assert.NoError(exec.Command("git", "-C", folder, "tag", "v0.0.1").Run())
var ctx = &context.Context{
Config: config.Project{},
}
assert.NoError(Pipe{}.doRun(ctx, folder))
assert.NoError(Pipe{}.doRun(ctx, getFixture("single-commit-repo")))
assert.Equal(
context.GitInfo{
CurrentTag: "v0.0.1",
PreviousTag: "4bf27bfd08049ae6187cefa5e9d50e2e0f205ebe",
Commit: "4bf27bfd08049ae6187cefa5e9d50e2e0f205ebe",
},
ctx.Git,
)
}
func TestNewRepository(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "gorelasertest")
assert.NoError(err)
assert.NoError(exec.Command("git", "-C", folder, "init").Run())
var ctx = &context.Context{
Config: config.Project{},
}
assert.Error(Pipe{}.doRun(ctx, folder))
assert.Error(Pipe{}.doRun(ctx, getFixture("new-repo")))
assert.Equal(context.GitInfo{}, ctx.Git)
}
func TestInvalidTagFormat(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "gorelasertest")
assert.NoError(err)
assert.NoError(exec.Command("git", "-C", folder, "init").Run())
assert.NoError(exec.Command("git", "-C", folder, "commit", "--allow-empty", "-m", "asd").Run())
assert.NoError(exec.Command("git", "-C", folder, "tag", "sadasd").Run())
var ctx = &context.Context{
Config: config.Project{},
}
assert.EqualError(Pipe{}.doRun(ctx, folder), "sadasd is not in a valid version format")
assert.EqualError(
Pipe{}.doRun(ctx, getFixture("invalid-tag-format-repo")),
"invalid-tag-name is not in a valid version format",
)
assert.Equal(
context.GitInfo{
CurrentTag: "invalid-tag-name",
PreviousTag: "v0.0.1",
Diff: "7cafca4 commit5\n1781c0e commit4\n633c559 commit3\n",
Commit: "7cafca4c382e2d83b123281bb31dd7b4f0e19a8b",
},
ctx.Git,
)
}
func getFixture(name string) string {
wd, _ := os.Getwd()
return filepath.Join(wd, "fixtures", name)
}