Skip to content

Commit

Permalink
refactor: using slices.Contains to simplify the code (#791)
Browse files Browse the repository at this point in the history
Signed-off-by: dashangcun <[email protected]>
Co-authored-by: Andrew Gillis <[email protected]>
  • Loading branch information
dashangcun and gammazero authored Jan 17, 2025
1 parent 720d617 commit b62b60e
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions bitswap/message/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package message

import (
"bytes"
"slices"
"testing"

"github.com/ipfs/boxo/bitswap/client/wantlist"
Expand Down Expand Up @@ -58,7 +59,7 @@ func TestAppendBlock(t *testing.T) {
// assert strings are in proto message
for _, blockbytes := range m.ToProtoV0().GetBlocks() {
s := bytes.NewBuffer(blockbytes).String()
if !contains(strs, s) {
if !slices.Contains(strs, s) {
t.Fail()
}
}
Expand Down Expand Up @@ -168,15 +169,6 @@ func wantlistContains(wantlist *pb.Message_Wantlist, c cid.Cid) bool {
return false
}

func contains(strs []string, x string) bool {
for _, s := range strs {
if s == x {
return true
}
}
return false
}

func TestDuplicates(t *testing.T) {
b := blocks.NewBlock([]byte("foo"))
msg := New(true)
Expand Down

0 comments on commit b62b60e

Please sign in to comment.