Use fnv.New32a() in hash instead adler32

This commit is contained in:
Harry Zhang
2017-01-23 22:31:50 +08:00
parent a57967f47b
commit 3bdc3f25ec
4 changed files with 11 additions and 10 deletions

View File

@@ -21,7 +21,7 @@ package mount
import (
"bufio"
"fmt"
"hash/adler32"
"hash/fnv"
"io"
"os"
"os/exec"
@@ -282,7 +282,7 @@ func readProcMounts(mountFilePath string, out *[]MountPoint) (uint32, error) {
}
func readProcMountsFrom(file io.Reader, out *[]MountPoint) (uint32, error) {
hash := adler32.New()
hash := fnv.New32a()
scanner := bufio.NewReader(file)
for {
line, err := scanner.ReadString('\n')

View File

@@ -29,20 +29,21 @@ func TestReadProcMountsFrom(t *testing.T) {
/dev/1 /path/to/1 type1 flags 1 1
/dev/2 /path/to/2 type2 flags,1,2=3 2 2
`
// NOTE: readProcMountsFrom has been updated to using fnv.New32a()
hash, err := readProcMountsFrom(strings.NewReader(successCase), nil)
if err != nil {
t.Errorf("expected success")
}
if hash != 0xa3522051 {
t.Errorf("expected 0xa3522051, got %#x", hash)
if hash != 0xa290ff0b {
t.Errorf("expected 0xa290ff0b, got %#x", hash)
}
mounts := []MountPoint{}
hash, err = readProcMountsFrom(strings.NewReader(successCase), &mounts)
if err != nil {
t.Errorf("expected success")
}
if hash != 0xa3522051 {
t.Errorf("expected 0xa3522051, got %#x", hash)
if hash != 0xa290ff0b {
t.Errorf("expected 0xa290ff0b, got %#x", hash)
}
if len(mounts) != 3 {
t.Fatalf("expected 3 mounts, got %d", len(mounts))