1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-28 04:44:34 +02:00
goreleaser/checksum/checksum_test.go

42 lines
1015 B
Go
Raw Normal View History

2017-04-14 14:06:50 -03:00
package checksum
import (
2017-04-22 10:58:29 -03:00
"crypto/sha256"
2017-04-14 14:06:50 -03:00
"io/ioutil"
2017-04-22 10:58:29 -03:00
"os"
2017-04-14 14:06:50 -03:00
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestChecksums(t *testing.T) {
var assert = assert.New(t)
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-14 16:27:59 -03:00
var file = filepath.Join(folder, "subject")
assert.NoError(ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
sum, err := SHA256(file)
2017-04-14 14:06:50 -03:00
assert.NoError(err)
2017-04-14 16:27:59 -03:00
assert.Equal("5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269", sum)
2017-04-14 14:06:50 -03:00
}
func TestOpenFailure(t *testing.T) {
var assert = assert.New(t)
2017-04-14 14:53:25 -03:00
sum, err := SHA256("/tmp/this-file-wont-exist-I-hope")
2017-04-14 14:06:50 -03:00
assert.Empty(sum)
assert.Error(err)
}
2017-04-22 10:58:29 -03:00
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)
}