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

39 lines
961 B
Go
Raw Normal View History

2017-04-14 19:06:50 +02:00
package checksum
import (
2017-04-22 15:58:29 +02:00
"crypto/sha256"
2017-04-14 19:06:50 +02:00
"io/ioutil"
2017-04-22 15:58:29 +02:00
"os"
2017-04-14 19:06:50 +02:00
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestChecksums(t *testing.T) {
2017-04-15 19:18:17 +02:00
folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(t, err)
2017-04-14 21:27:59 +02:00
var file = filepath.Join(folder, "subject")
assert.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
2017-04-14 21:27:59 +02:00
sum, err := SHA256(file)
assert.NoError(t, err)
assert.Equal(t, "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269", sum)
2017-04-14 19:06:50 +02:00
}
func TestOpenFailure(t *testing.T) {
2017-04-14 19:53:25 +02:00
sum, err := SHA256("/tmp/this-file-wont-exist-I-hope")
assert.Empty(t, sum)
assert.Error(t, err)
2017-04-14 19:06:50 +02:00
}
2017-04-22 15:58:29 +02:00
func TestFileDoesntExist(t *testing.T) {
folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(t, err)
2017-04-22 15:58:29 +02:00
var path = filepath.Join(folder, "subject")
file, err := os.Create(path)
assert.NoError(t, err)
assert.NoError(t, file.Close())
2017-04-22 15:58:29 +02:00
_, err = doCalculate(sha256.New(), file)
assert.Error(t, err)
2017-04-22 15:58:29 +02:00
}