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

42 lines
1015 B
Go

package checksum
import (
"crypto/sha256"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestChecksums(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err)
var file = filepath.Join(folder, "subject")
assert.NoError(ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
sum, err := SHA256(file)
assert.NoError(err)
assert.Equal("5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269", sum)
}
func TestOpenFailure(t *testing.T) {
var assert = assert.New(t)
sum, err := SHA256("/tmp/this-file-wont-exist-I-hope")
assert.Empty(sum)
assert.Error(err)
}
func TestFileDoesntExist(t *testing.T) {
var assert = assert.New(t)
folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(err)
var path = filepath.Join(folder, "subject")
file, err := os.Create(path)
assert.NoError(err)
assert.NoError(file.Close())
_, err = doCalculate(sha256.New(), file)
assert.Error(err)
}