You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-15 01:34:21 +02:00
git on testlib
This commit is contained in:
@ -31,9 +31,9 @@ func TestSingleCommit(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitCommit(t, "commit1")
|
||||
gitTag(t, "v0.0.1")
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "commit1")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
@ -45,7 +45,7 @@ func TestNewRepository(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
testlib.GitInit(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
@ -56,8 +56,8 @@ func TestNoTagsSnapshot(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitCommit(t, "first")
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "first")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Snapshot: config.Snapshot{
|
||||
@ -75,8 +75,8 @@ func TestNoTagsSnapshotInvalidTemplate(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitCommit(t, "first")
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "first")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Snapshot: config.Snapshot{
|
||||
@ -96,8 +96,8 @@ func TestNoTagsNoSnapshot(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitCommit(t, "first")
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "first")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Snapshot: config.Snapshot{
|
||||
@ -114,9 +114,9 @@ func TestInvalidTagFormat(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitCommit(t, "commit2")
|
||||
gitTag(t, "sadasd")
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "commit2")
|
||||
testlib.GitTag(t, "sadasd")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
@ -129,12 +129,12 @@ func TestDirty(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
testlib.GitInit(t)
|
||||
dummy, err := os.Create(filepath.Join(folder, "dummy"))
|
||||
assert.NoError(err)
|
||||
gitAdd(t)
|
||||
gitCommit(t, "commit2")
|
||||
gitTag(t, "v0.0.1")
|
||||
testlib.GitAdd(t)
|
||||
testlib.GitCommit(t, "commit2")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
assert.NoError(ioutil.WriteFile(dummy.Name(), []byte("lorem ipsum"), 0644))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
@ -149,10 +149,10 @@ func TestTagIsNotLastCommit(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitCommit(t, "commit3")
|
||||
gitTag(t, "v0.0.1")
|
||||
gitCommit(t, "commit4")
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "commit3")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
testlib.GitCommit(t, "commit4")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
@ -166,11 +166,11 @@ func TestValidState(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitCommit(t, "commit3")
|
||||
gitTag(t, "v0.0.1")
|
||||
gitCommit(t, "commit4")
|
||||
gitTag(t, "v0.0.2")
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "commit3")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
testlib.GitCommit(t, "commit4")
|
||||
testlib.GitTag(t, "v0.0.2")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
@ -185,11 +185,11 @@ func TestNoValidate(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitAdd(t)
|
||||
gitCommit(t, "commit5")
|
||||
gitTag(t, "v0.0.1")
|
||||
gitCommit(t, "commit6")
|
||||
testlib.GitInit(t)
|
||||
testlib.GitAdd(t)
|
||||
testlib.GitCommit(t, "commit5")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
testlib.GitCommit(t, "commit6")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: false,
|
||||
@ -201,12 +201,12 @@ func TestChangelog(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitCommit(t, "first")
|
||||
gitTag(t, "v0.0.1")
|
||||
gitCommit(t, "added feature 1")
|
||||
gitCommit(t, "fixed bug 2")
|
||||
gitTag(t, "v0.0.2")
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "first")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
testlib.GitCommit(t, "added feature 1")
|
||||
testlib.GitCommit(t, "fixed bug 2")
|
||||
testlib.GitTag(t, "v0.0.2")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
@ -222,7 +222,7 @@ func TestChangelogOfFirstRelease(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
testlib.GitInit(t)
|
||||
var msgs = []string{
|
||||
"initial commit",
|
||||
"another one",
|
||||
@ -230,9 +230,9 @@ func TestChangelogOfFirstRelease(t *testing.T) {
|
||||
"and finally this one",
|
||||
}
|
||||
for _, msg := range msgs {
|
||||
gitCommit(t, msg)
|
||||
testlib.GitCommit(t, msg)
|
||||
}
|
||||
gitTag(t, "v0.0.1")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
@ -248,9 +248,9 @@ func TestCustomReleaseNotes(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitCommit(t, "first")
|
||||
gitTag(t, "v0.0.1")
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "first")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
ReleaseNotes: "custom",
|
||||
@ -259,48 +259,3 @@ func TestCustomReleaseNotes(t *testing.T) {
|
||||
assert.Equal("v0.0.1", ctx.Git.CurrentTag)
|
||||
assert.Equal(ctx.ReleaseNotes, "custom")
|
||||
}
|
||||
|
||||
//
|
||||
// helper functions
|
||||
//
|
||||
|
||||
func gitInit(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
out, err := git("init")
|
||||
assert.NoError(err)
|
||||
assert.Contains(out, "Initialized empty Git repository")
|
||||
_, err = git("config", "commit.gpgSign", "false")
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
func gitCommit(t *testing.T, msg string) {
|
||||
var assert = assert.New(t)
|
||||
out, err := fakeGit("commit", "--allow-empty", "-m", msg)
|
||||
assert.NoError(err)
|
||||
assert.Contains(out, "master", msg)
|
||||
}
|
||||
|
||||
func gitTag(t *testing.T, tag string) {
|
||||
var assert = assert.New(t)
|
||||
out, err := fakeGit("tag", tag)
|
||||
assert.NoError(err)
|
||||
assert.Empty(out)
|
||||
}
|
||||
|
||||
func gitAdd(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
out, err := git("add", "-A")
|
||||
assert.NoError(err)
|
||||
assert.Empty(out)
|
||||
}
|
||||
|
||||
func fakeGit(args ...string) (string, error) {
|
||||
var allArgs = []string{
|
||||
"-c",
|
||||
"user.name='GoReleaser'",
|
||||
"-c",
|
||||
"user.email='test@goreleaser.github.com'",
|
||||
}
|
||||
allArgs = append(allArgs, args...)
|
||||
return git(allArgs...)
|
||||
}
|
||||
|
Reference in New Issue
Block a user