2017-04-14 13:31:47 -03:00
|
|
|
package checksums
|
|
|
|
|
|
|
|
import (
|
2017-04-14 14:06:50 -03:00
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
2017-04-14 13:31:47 -03:00
|
|
|
"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())
|
|
|
|
}
|
|
|
|
|
2017-04-14 14:21:37 -03:00
|
|
|
func TestPipe(t *testing.T) {
|
2017-04-14 13:31:47 -03:00
|
|
|
var assert = assert.New(t)
|
2017-04-17 10:52:26 -03:00
|
|
|
var binary = "binary"
|
|
|
|
var checksums = binary + "_checksums.txt"
|
2017-04-15 14:18:17 -03:00
|
|
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
2017-04-14 14:06:50 -03:00
|
|
|
assert.NoError(err)
|
2017-04-17 10:52:26 -03:00
|
|
|
var file = filepath.Join(folder, binary)
|
2017-04-14 16:27:59 -03:00
|
|
|
assert.NoError(ioutil.WriteFile(file, []byte("some string"), 0644))
|
2017-04-14 13:31:47 -03:00
|
|
|
var ctx = &context.Context{
|
2017-04-14 14:06:50 -03:00
|
|
|
Config: config.Project{
|
2017-07-01 22:42:10 -03:00
|
|
|
Dist: folder,
|
|
|
|
ProjectName: binary,
|
2017-04-14 14:06:50 -03:00
|
|
|
},
|
2017-04-14 13:31:47 -03:00
|
|
|
}
|
2017-04-14 16:27:59 -03:00
|
|
|
ctx.AddArtifact(file)
|
2017-04-14 13:31:47 -03:00
|
|
|
assert.NoError(Pipe{}.Run(ctx))
|
2017-04-17 10:52:26 -03:00
|
|
|
assert.Contains(ctx.Artifacts, checksums, binary)
|
2017-04-17 10:47:03 -03:00
|
|
|
bts, err := ioutil.ReadFile(filepath.Join(folder, checksums))
|
2017-04-14 14:06:50 -03:00
|
|
|
assert.NoError(err)
|
2017-05-11 13:34:29 -03:00
|
|
|
assert.Equal(string(bts), "61d034473102d7dac305902770471fd50f4c5b26f6831a56dd90b5184b3c30fc binary\n")
|
2017-04-14 13:31:47 -03:00
|
|
|
}
|
2017-04-14 15:39:32 -03:00
|
|
|
|
|
|
|
func TestPipeFileNotExist(t *testing.T) {
|
|
|
|
var assert = assert.New(t)
|
2017-04-15 14:18:17 -03:00
|
|
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
2017-04-14 15:39:32 -03:00
|
|
|
assert.NoError(err)
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ctx.AddArtifact("nope")
|
|
|
|
assert.Error(Pipe{}.Run(ctx))
|
|
|
|
}
|