github.com/codingeasygo/util@v0.0.0-20231206062002-1ce2f004b7d9/xhash/hash_test.go (about)

     1  package xhash
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  )
     8  
     9  func TestFileHash(t *testing.T) {
    10  	defer os.Remove("test.tmp")
    11  	ioutil.WriteFile("test.tmp", []byte("abc"), os.ModePerm)
    12  	shah1 := SHA1([]byte("abc"))
    13  	md5h1 := MD5([]byte("abc"))
    14  	shah2, md5h2, _, err := FileHash("test.tmp", true, true)
    15  	if err != nil || shah1 != shah2 || md5h1 != md5h2 {
    16  		t.Error("error")
    17  		return
    18  	}
    19  	SHA256([]byte("abc"))
    20  	SHA512([]byte("abc"))
    21  }