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

53 lines
1.3 KiB
Go
Raw Normal View History

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