Skip to content

Commit c35a93c

Browse files
committed
refactor: use slices.Contains to simplify code
Signed-off-by: CoolCu <[email protected]>
1 parent 455a3d5 commit c35a93c

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

pkg/api/router_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package api_test
66

77
import (
88
"net/http"
9+
"slices"
910
"strings"
1011
"testing"
1112

@@ -438,10 +439,5 @@ func TestEndpointOptions(t *testing.T) {
438439
}
439440

440441
func contains(slice []string, item string) bool {
441-
for _, s := range slice {
442-
if s == item {
443-
return true
444-
}
445-
}
446-
return false
442+
return slices.Contains(slice, item)
447443
}

pkg/storer/netstore_test.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"errors"
1010
"fmt"
11+
"slices"
1112
"testing"
1213
"time"
1314

@@ -52,13 +53,7 @@ func testNetStore(t *testing.T, newStorer func(r retrieval.Interface) (*storer.D
5253
for {
5354
select {
5455
case op := <-lstore.PusherFeed():
55-
found := false
56-
for _, ch := range chunks {
57-
if op.Chunk.Equal(ch) {
58-
found = true
59-
break
60-
}
61-
}
56+
found := slices.ContainsFunc(chunks, op.Chunk.Equal)
6257
if !found {
6358
op.Err <- fmt.Errorf("incorrect chunk for push: have %s", op.Chunk.Address())
6459
continue
@@ -110,13 +105,7 @@ func testNetStore(t *testing.T, newStorer func(r retrieval.Interface) (*storer.D
110105
for {
111106
select {
112107
case op := <-lstore.PusherFeed():
113-
found := false
114-
for _, ch := range chunks {
115-
if op.Chunk.Equal(ch) {
116-
found = true
117-
break
118-
}
119-
}
108+
found := slices.ContainsFunc(chunks, op.Chunk.Equal)
120109
if !found {
121110
op.Err <- fmt.Errorf("incorrect chunk for push: have %s", op.Chunk.Address())
122111
continue

0 commit comments

Comments
 (0)