Ejemplo n.º 1
0
func TestMultiHasherTypes(t *testing.T) {
	h := fs.HashSHA1
	for _, test := range hashTestSet {
		mh, err := fs.NewMultiHasherTypes(fs.NewHashSet(h))
		if err != nil {
			t.Fatal(err)
		}
		n, err := io.Copy(mh, bytes.NewBuffer(test.input))
		require.NoError(t, err)
		assert.Len(t, test.input, int(n))
		sums := mh.Sums()
		assert.Len(t, sums, 1)
		assert.Equal(t, sums[h], test.output[h])
	}
}
Ejemplo n.º 2
0
func TestMultiHasherTypes(t *testing.T) {
	h := fs.HashSHA1
	for _, test := range hashTestSet {
		mh, err := fs.NewMultiHasherTypes(fs.NewHashSet(h))
		if err != nil {
			t.Fatal(err)
		}
		n, err := io.Copy(mh, bytes.NewBuffer(test.input))
		if err != nil {
			t.Fatal(err)
		}
		if int(n) != len(test.input) {
			t.Fatalf("copy mismatch: %d != %d", n, len(test.input))
		}
		sums := mh.Sums()
		if len(sums) != 1 {
			t.Fatalf("expected 1 sum, got %d", len(sums))
		}
		expect := test.output[h]
		if expect != sums[h] {
			t.Errorf("hash %v mismatch %q != %q", h, sums[h], expect)
		}
	}
}