2016-12-29 15:21:50 +02:00
|
|
|
package release
|
|
|
|
|
|
|
|
import (
|
2017-03-26 20:56:35 +02:00
|
|
|
"bytes"
|
2017-04-15 17:18:09 +02:00
|
|
|
"errors"
|
2017-03-26 20:56:35 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-12-30 16:03:43 +02:00
|
|
|
"testing"
|
2017-01-02 14:47:19 +02:00
|
|
|
|
2017-03-26 20:56:35 +02:00
|
|
|
"github.com/goreleaser/goreleaser/config"
|
|
|
|
"github.com/goreleaser/goreleaser/context"
|
2017-01-02 14:47:19 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-12-29 15:21:50 +02:00
|
|
|
)
|
|
|
|
|
2017-03-26 01:46:02 +02:00
|
|
|
func TestPipeDescription(t *testing.T) {
|
2017-03-26 01:43:42 +02:00
|
|
|
assert.NotEmpty(t, Pipe{}.Description())
|
|
|
|
}
|
2017-03-26 20:56:35 +02:00
|
|
|
|
|
|
|
func TestRunPipe(t *testing.T) {
|
2017-04-15 17:18:09 +02:00
|
|
|
var assert = assert.New(t)
|
2017-04-15 19:18:17 +02:00
|
|
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
2017-03-26 20:56:35 +02:00
|
|
|
assert.NoError(err)
|
2017-04-14 17:18:59 +02:00
|
|
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
2017-03-26 20:56:35 +02:00
|
|
|
assert.NoError(err)
|
2017-04-14 17:18:59 +02:00
|
|
|
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
2017-03-26 20:56:35 +02:00
|
|
|
assert.NoError(err)
|
2017-07-15 21:49:52 +02:00
|
|
|
var config = config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-03-26 20:56:35 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-07-15 21:49:52 +02:00
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
|
|
|
ctx.Publish = true
|
2017-04-14 17:18:59 +02:00
|
|
|
ctx.AddArtifact(tarfile.Name())
|
|
|
|
ctx.AddArtifact(debfile.Name())
|
2017-03-26 20:56:35 +02:00
|
|
|
client := &DummyClient{}
|
|
|
|
assert.NoError(doRun(ctx, client))
|
|
|
|
assert.True(client.CreatedRelease)
|
|
|
|
assert.True(client.UploadedFile)
|
2017-07-05 02:47:05 +02:00
|
|
|
assert.Contains(client.UploadedFileNames, "bin.deb")
|
|
|
|
assert.Contains(client.UploadedFileNames, "bin.tar.gz")
|
2017-03-26 20:56:35 +02:00
|
|
|
}
|
|
|
|
|
2017-04-15 17:18:09 +02:00
|
|
|
func TestRunPipeReleaseCreationFailed(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
2017-07-15 21:49:52 +02:00
|
|
|
var config = config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-04-15 17:18:09 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-07-15 21:49:52 +02:00
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
|
|
|
ctx.Publish = true
|
2017-04-15 17:18:09 +02:00
|
|
|
client := &DummyClient{
|
|
|
|
FailToCreateRelease: true,
|
|
|
|
}
|
|
|
|
assert.Error(doRun(ctx, client))
|
|
|
|
assert.False(client.CreatedRelease)
|
|
|
|
assert.False(client.UploadedFile)
|
|
|
|
}
|
|
|
|
|
2017-04-14 20:53:36 +02:00
|
|
|
func TestRunPipeWithFileThatDontExist(t *testing.T) {
|
2017-04-15 17:18:09 +02:00
|
|
|
var assert = assert.New(t)
|
2017-07-15 21:49:52 +02:00
|
|
|
var config = config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-04-14 20:53:36 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-07-15 21:49:52 +02:00
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
|
|
|
ctx.Publish = true
|
2017-04-21 20:42:13 +02:00
|
|
|
ctx.AddArtifact("this-file-wont-exist-hopefully")
|
2017-04-14 20:53:36 +02:00
|
|
|
client := &DummyClient{}
|
|
|
|
assert.Error(doRun(ctx, client))
|
|
|
|
assert.True(client.CreatedRelease)
|
|
|
|
assert.False(client.UploadedFile)
|
|
|
|
}
|
|
|
|
|
2017-04-15 17:18:09 +02:00
|
|
|
func TestRunPipeUploadFailure(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
2017-04-15 19:18:17 +02:00
|
|
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
2017-04-15 17:18:09 +02:00
|
|
|
assert.NoError(err)
|
|
|
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
|
|
|
assert.NoError(err)
|
2017-07-15 21:49:52 +02:00
|
|
|
var config = config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-04-15 17:18:09 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-07-15 21:49:52 +02:00
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
|
|
|
ctx.Publish = true
|
2017-04-15 17:18:09 +02:00
|
|
|
ctx.AddArtifact(tarfile.Name())
|
|
|
|
client := &DummyClient{
|
|
|
|
FailToUpload: true,
|
|
|
|
}
|
|
|
|
assert.Error(doRun(ctx, client))
|
|
|
|
assert.True(client.CreatedRelease)
|
|
|
|
assert.False(client.UploadedFile)
|
|
|
|
}
|
|
|
|
|
2017-04-18 18:10:13 +02:00
|
|
|
func TestSkipPublish(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
|
|
|
var ctx = &context.Context{
|
2017-07-15 21:49:52 +02:00
|
|
|
Publish: false,
|
|
|
|
Parallelism: 1,
|
2017-04-18 18:10:13 +02:00
|
|
|
}
|
|
|
|
client := &DummyClient{}
|
|
|
|
assert.NoError(doRun(ctx, client))
|
|
|
|
assert.False(client.CreatedRelease)
|
|
|
|
assert.False(client.UploadedFile)
|
|
|
|
}
|
|
|
|
|
2017-03-26 20:56:35 +02:00
|
|
|
type DummyClient struct {
|
2017-04-15 17:18:09 +02:00
|
|
|
FailToCreateRelease bool
|
|
|
|
FailToUpload bool
|
|
|
|
CreatedRelease bool
|
|
|
|
UploadedFile bool
|
2017-07-05 02:28:21 +02:00
|
|
|
UploadedFileNames []string
|
2017-03-26 20:56:35 +02:00
|
|
|
}
|
|
|
|
|
2017-04-19 21:59:26 +02:00
|
|
|
func (client *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) {
|
2017-04-15 17:18:09 +02:00
|
|
|
if client.FailToCreateRelease {
|
|
|
|
return 0, errors.New("release failed")
|
|
|
|
}
|
2017-03-26 20:56:35 +02:00
|
|
|
client.CreatedRelease = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *DummyClient) CreateFile(ctx *context.Context, content bytes.Buffer, path string) (err error) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (client *DummyClient) Upload(ctx *context.Context, releaseID int, name string, file *os.File) (err error) {
|
2017-04-15 17:18:09 +02:00
|
|
|
if client.FailToUpload {
|
|
|
|
return errors.New("upload failed")
|
|
|
|
}
|
2017-03-26 20:56:35 +02:00
|
|
|
client.UploadedFile = true
|
2017-07-05 02:28:21 +02:00
|
|
|
client.UploadedFileNames = append(client.UploadedFileNames, name)
|
2017-03-26 20:56:35 +02:00
|
|
|
return
|
|
|
|
}
|