mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
Tests for HashFile
This commit is contained in:
parent
fe9ccb8677
commit
55ae98a588
1 changed files with 24 additions and 0 deletions
|
@ -31,3 +31,27 @@ func TestFileSize(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestHashFile(t *testing.T) {
|
||||
t.Run("Hash created successfully", func(t *testing.T) {
|
||||
h, err := HashFile("testing_data/README.md")
|
||||
if err != nil {
|
||||
t.Errorf("should pass with no error, got: %v", err)
|
||||
}
|
||||
if len(h) != 32 {
|
||||
t.Errorf("invalid md5 hash, length should be 32 got: %d", len(h))
|
||||
}
|
||||
})
|
||||
t.Run("File does not exist", func(t *testing.T) {
|
||||
h, err := HashFile("testing_data/someStrangeFile")
|
||||
if err == nil {
|
||||
t.Error("should return an error")
|
||||
}
|
||||
if len(h) > 0 {
|
||||
t.Errorf("hash length should be 0, got: %d", len(h))
|
||||
}
|
||||
if h != "" {
|
||||
t.Errorf("hash should be empty string, got: %s", h)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue