lib/model: Use bytes.Equal instead of converting to string (#8469)

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
This commit is contained in:
deepsource-autofix[bot]
2022-07-28 20:00:07 +02:00
committed by GitHub
co-authored by deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
parent a3c724f2c3
commit 8e3f1190d1
+5 -5
View File
@@ -145,7 +145,7 @@ func TestHandleFile(t *testing.T) {
for _, block := range blocks[1:] { for _, block := range blocks[1:] {
found := false found := false
for _, toCopyBlock := range toCopy.blocks { for _, toCopyBlock := range toCopy.blocks {
if string(toCopyBlock.Hash) == string(block.Hash) { if bytes.Equal(toCopyBlock.Hash, block.Hash) {
found = true found = true
break break
} }
@@ -192,7 +192,7 @@ func TestHandleFileWithTemp(t *testing.T) {
found := false found := false
block := blocks[idx] block := blocks[idx]
for _, toCopyBlock := range toCopy.blocks { for _, toCopyBlock := range toCopy.blocks {
if string(toCopyBlock.Hash) == string(block.Hash) { if bytes.Equal(toCopyBlock.Hash, block.Hash) {
found = true found = true
break break
} }
@@ -277,7 +277,7 @@ func TestCopierFinder(t *testing.T) {
found := false found := false
block := blocks[idx] block := blocks[idx]
for _, pulledBlock := range pulls { for _, pulledBlock := range pulls {
if string(pulledBlock.block.Hash) == string(block.Hash) { if bytes.Equal(pulledBlock.block.Hash, block.Hash) {
found = true found = true
break break
} }
@@ -285,7 +285,7 @@ func TestCopierFinder(t *testing.T) {
if !found { if !found {
t.Errorf("Did not find block %s", block.String()) t.Errorf("Did not find block %s", block.String())
} }
if string(finish.file.Blocks[idx-1].Hash) != string(blocks[idx].Hash) { if !bytes.Equal(finish.file.Blocks[idx-1].Hash, blocks[idx].Hash) {
t.Errorf("Block %d mismatch: %s != %s", idx, finish.file.Blocks[idx-1].String(), blocks[idx].String()) t.Errorf("Block %d mismatch: %s != %s", idx, finish.file.Blocks[idx-1].String(), blocks[idx].String())
} }
} }
@@ -297,7 +297,7 @@ func TestCopierFinder(t *testing.T) {
} }
for _, eq := range []int{2, 3, 4, 7} { for _, eq := range []int{2, 3, 4, 7} {
if string(blks[eq-1].Hash) != string(blocks[eq].Hash) { if !bytes.Equal(blks[eq-1].Hash, blocks[eq].Hash) {
t.Errorf("Block %d mismatch: %s != %s", eq, blks[eq-1].String(), blocks[eq].String()) t.Errorf("Block %d mismatch: %s != %s", eq, blks[eq-1].String(), blocks[eq].String())
} }
} }