1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

added more tests to the checksums

This commit is contained in:
Carlos Alexandro Becker 2017-04-22 10:58:29 -03:00
parent 881bba915b
commit c2642e0c52
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 18 additions and 0 deletions

View File

@ -21,6 +21,10 @@ func calculate(hash hash.Hash, path string) (result string, err error) {
} }
defer func() { _ = file.Close() }() defer func() { _ = file.Close() }()
return doCalculate(hash, file)
}
func doCalculate(hash hash.Hash, file *os.File) (result string, err error) {
_, err = io.Copy(hash, file) _, err = io.Copy(hash, file)
if err != nil { if err != nil {
return return

View File

@ -1,7 +1,9 @@
package checksum package checksum
import ( import (
"crypto/sha256"
"io/ioutil" "io/ioutil"
"os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -25,3 +27,15 @@ func TestOpenFailure(t *testing.T) {
assert.Empty(sum) assert.Empty(sum)
assert.Error(err) 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)
}