34 lines
734 B
Go
34 lines
734 B
Go
package cryptox
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestMd5(t *testing.T) {
|
|
want := "5d41402abc4b2a76b9719d911017c592"
|
|
got, err := GetMd5ByStr("hello")
|
|
if err != nil || got != want {
|
|
t.Errorf("GetMd5ByStr = %q, %v, want %q", got, err, want)
|
|
}
|
|
got, err = GetMd5ByBytes([]byte("hello"))
|
|
if err != nil || got != want {
|
|
t.Errorf("GetMd5ByBytes = %q, %v", got, err)
|
|
}
|
|
}
|
|
|
|
func TestGetFileMd5(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "test.txt")
|
|
if err := os.WriteFile(path, []byte("hello"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := GetFileMd5(path)
|
|
if err != nil {
|
|
t.Fatalf("GetFileMd5: %v", err)
|
|
}
|
|
if got != "5d41402abc4b2a76b9719d911017c592" {
|
|
t.Errorf("GetFileMd5 = %q", got)
|
|
}
|
|
}
|