1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-09 13:36:56 +02:00

more release tests

This commit is contained in:
Carlos Alexandro Becker 2017-04-15 12:18:09 -03:00
parent fb9d49db34
commit 7b1bc7ce70
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940

View File

@ -2,6 +2,7 @@ package release
import (
"bytes"
"errors"
"io/ioutil"
"os"
"path/filepath"
@ -18,7 +19,7 @@ func TestPipeDescription(t *testing.T) {
}
func TestRunPipe(t *testing.T) {
assert := assert.New(t)
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "gorelasertest")
assert.NoError(err)
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
@ -47,8 +48,31 @@ func TestRunPipe(t *testing.T) {
assert.True(client.UploadedFile)
}
func TestRunPipeReleaseCreationFailed(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.0",
},
Config: config.Project{
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
},
}
client := &DummyClient{
FailToCreateRelease: true,
}
assert.Error(doRun(ctx, client))
assert.False(client.CreatedRelease)
assert.False(client.UploadedFile)
}
func TestRunPipeWithFileThatDontExist(t *testing.T) {
assert := assert.New(t)
var assert = assert.New(t)
var ctx = &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.0",
@ -69,9 +93,40 @@ func TestRunPipeWithFileThatDontExist(t *testing.T) {
assert.False(client.UploadedFile)
}
func TestRunPipeUploadFailure(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "gorelasertest")
assert.NoError(err)
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
assert.NoError(err)
var ctx = &context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.0",
},
Config: config.Project{
Dist: folder,
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
},
}
ctx.AddArtifact(tarfile.Name())
client := &DummyClient{
FailToUpload: true,
}
assert.Error(doRun(ctx, client))
assert.True(client.CreatedRelease)
assert.False(client.UploadedFile)
}
type DummyClient struct {
CreatedRelease bool
UploadedFile bool
FailToCreateRelease bool
FailToUpload bool
CreatedRelease bool
UploadedFile bool
}
func (client *DummyClient) GetInfo(ctx *context.Context) (info client.Info, err error) {
@ -79,6 +134,9 @@ func (client *DummyClient) GetInfo(ctx *context.Context) (info client.Info, err
}
func (client *DummyClient) CreateRelease(ctx *context.Context) (releaseID int, err error) {
if client.FailToCreateRelease {
return 0, errors.New("release failed")
}
client.CreatedRelease = true
return
}
@ -88,6 +146,9 @@ func (client *DummyClient) CreateFile(ctx *context.Context, content bytes.Buffer
}
func (client *DummyClient) Upload(ctx *context.Context, releaseID int, name string, file *os.File) (err error) {
if client.FailToUpload {
return errors.New("upload failed")
}
client.UploadedFile = true
return
}