Skip to content

Commit aa99c11

Browse files
wayneeseguinstephanme
authored andcommitted
Use stdlib slices.Equal and slices.Sort in dav list tests
Drop the hand-rolled equalStrings helper in favor of slices.Equal, which has the same length-and-elementwise semantics, and build the sorted copies with slices.Clone and slices.Sort instead of the sort package.
1 parent 5cb877a commit aa99c11

1 file changed

Lines changed: 9 additions & 21 deletions

File tree

dav/client/storage_client_list_test.go

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"net/http"
66
"net/http/httptest"
7-
"sort"
7+
"slices"
88
"strings"
99
"sync"
1010
"testing"
@@ -121,23 +121,11 @@ func newTestStorageClient(t *testing.T, store *fakeDavServer) (*storageClient, f
121121
}
122122

123123
func sorted(in []string) []string {
124-
out := append([]string{}, in...)
125-
sort.Strings(out)
124+
out := slices.Clone(in)
125+
slices.Sort(out)
126126
return out
127127
}
128128

129-
func equalStrings(a, b []string) bool {
130-
if len(a) != len(b) {
131-
return false
132-
}
133-
for i := range a {
134-
if a[i] != b[i] {
135-
return false
136-
}
137-
}
138-
return true
139-
}
140-
141129
func TestListScopesWalkToPrefix(t *testing.T) {
142130
store := newPartitionedStore()
143131
c, cleanup := newTestStorageClient(t, store)
@@ -149,12 +137,12 @@ func TestListScopesWalkToPrefix(t *testing.T) {
149137
}
150138

151139
wantBlobs := []string{"ab/cd/abcd-target-guid-file", "ab/cd/abcd-target-guid/cflinuxfs4"}
152-
if !equalStrings(sorted(blobs), wantBlobs) {
140+
if !slices.Equal(sorted(blobs), wantBlobs) {
153141
t.Fatalf("unexpected blobs: %v, want %v", sorted(blobs), wantBlobs)
154142
}
155143

156144
wantPropfinds := []string{"ab/cd", "ab/cd/abcd-target-guid"}
157-
if !equalStrings(sorted(store.propfinds), wantPropfinds) {
145+
if !slices.Equal(sorted(store.propfinds), wantPropfinds) {
158146
t.Fatalf("walk was not scoped to the prefix: PROPFINDs hit %v, want %v", sorted(store.propfinds), wantPropfinds)
159147
}
160148
}
@@ -177,7 +165,7 @@ func TestListEmptyPrefixWalksWholeStore(t *testing.T) {
177165
"ab/zz/abzz-unrelated",
178166
"zz/yy/zzyy-other",
179167
}
180-
if !equalStrings(sorted(blobs), wantBlobs) {
168+
if !slices.Equal(sorted(blobs), wantBlobs) {
181169
t.Fatalf("unexpected blobs: %v, want %v", sorted(blobs), wantBlobs)
182170
}
183171
}
@@ -212,7 +200,7 @@ func TestListSingleSegmentPrefixPrunesSiblings(t *testing.T) {
212200
"ab/cd/abcd-unrelated",
213201
"ab/zz/abzz-unrelated",
214202
}
215-
if !equalStrings(sorted(blobs), wantBlobs) {
203+
if !slices.Equal(sorted(blobs), wantBlobs) {
216204
t.Fatalf("unexpected blobs: %v, want %v", sorted(blobs), wantBlobs)
217205
}
218206

@@ -233,12 +221,12 @@ func TestDeleteRecursiveDeletesOnlyPrefixedBlobs(t *testing.T) {
233221
}
234222

235223
wantDeletes := []string{"ab/cd/abcd-target-guid-file", "ab/cd/abcd-target-guid/cflinuxfs4"}
236-
if !equalStrings(sorted(store.deletes), wantDeletes) {
224+
if !slices.Equal(sorted(store.deletes), wantDeletes) {
237225
t.Fatalf("unexpected deletes: %v, want %v", sorted(store.deletes), wantDeletes)
238226
}
239227

240228
wantPropfinds := []string{"ab/cd", "ab/cd/abcd-target-guid"}
241-
if !equalStrings(sorted(store.propfinds), wantPropfinds) {
229+
if !slices.Equal(sorted(store.propfinds), wantPropfinds) {
242230
t.Fatalf("walk was not scoped to the prefix: PROPFINDs hit %v, want %v", sorted(store.propfinds), wantPropfinds)
243231
}
244232
}

0 commit comments

Comments
 (0)