1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00
goreleaser/pipeline/checksums/checksums_test.go

98 lines
2.5 KiB
Go
Raw Normal View History

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-08-27 22:08:53 -03:00
Checksum: config.Checksum{
NameTemplate: "{{ .ProjectName }}_checksums.txt",
},
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)
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,
2017-08-27 22:08:53 -03:00
Checksum: config.Checksum{
NameTemplate: "checksums.txt",
},
2017-04-14 15:39:32 -03:00
},
}
ctx.AddArtifact("nope")
2017-08-27 22:08:53 -03:00
err = Pipe{}.Run(ctx)
assert.Error(err)
assert.Contains(err.Error(), "/nope: no such file or directory")
}
func TestPipeInvalidNameTemplate(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err)
var ctx = &context.Context{
Config: config.Project{
Dist: folder,
ProjectName: "name",
Checksum: config.Checksum{
NameTemplate: "{{ .Pro }_checksums.txt",
},
},
}
ctx.AddArtifact("whatever")
err = Pipe{}.Run(ctx)
assert.Error(err)
assert.Equal(`template: name:1: unexpected "}" in operand`, err.Error())
}
func TestPipeCouldNotOpenChecksumsTxt(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err)
var file = filepath.Join(folder, "checksums.txt")
assert.NoError(ioutil.WriteFile(file, []byte("some string"), 0000))
var ctx = &context.Context{
Config: config.Project{
Dist: folder,
Checksum: config.Checksum{
NameTemplate: "checksums.txt",
},
},
}
ctx.AddArtifact("nope")
err = Pipe{}.Run(ctx)
assert.Error(err)
assert.Contains(err.Error(), "/checksums.txt: permission denied")
2017-04-14 15:39:32 -03:00
}