Skip to content

Commit f00d835

Browse files
committed
refactor(serverHandler/sort): implement standard methods for sort
1 parent 049c0ec commit f00d835

File tree

3 files changed

+204
-146
lines changed

3 files changed

+204
-146
lines changed

src/serverHandler/filter_test.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func TestHandler_FilterItems(t *testing.T) {
1111
now := time.Now()
1212
var h *handler
13-
var infos []os.FileInfo
13+
var items []os.FileInfo
1414
var ok bool
1515

1616
re2 := regexp.MustCompile("2")
@@ -24,76 +24,76 @@ func TestHandler_FilterItems(t *testing.T) {
2424
file2 := dummyFileInfo{"file2", 0, now, false}
2525
file3 := dummyFileInfo{"file3", 0, now, false}
2626

27-
originInfos := []os.FileInfo{dir1, dir2, dir3, file1, file2, file3}
27+
originalItems := []os.FileInfo{dir1, dir2, dir3, file1, file2, file3}
2828

2929
h = &handler{shows: re2}
30-
infos = h.FilterItems(originInfos)
31-
ok = expectInfos(infos, dir2, file2)
30+
items = h.FilterItems(originalItems)
31+
ok = expectItems(items, dir2, file2)
3232
if !ok {
33-
t.Errorf("%+v\n", infos)
33+
t.Errorf("%+v\n", items)
3434
}
3535

3636
h = &handler{showDirs: re2}
37-
infos = h.FilterItems(originInfos)
38-
ok = expectInfos(infos, dir2, file1, file2, file3)
37+
items = h.FilterItems(originalItems)
38+
ok = expectItems(items, dir2, file1, file2, file3)
3939
if !ok {
40-
t.Errorf("%+v\n", infos)
40+
t.Errorf("%+v\n", items)
4141
}
4242

4343
h = &handler{showFiles: re2}
44-
infos = h.FilterItems(originInfos)
45-
ok = expectInfos(infos, dir1, dir2, dir3, file2)
44+
items = h.FilterItems(originalItems)
45+
ok = expectItems(items, dir1, dir2, dir3, file2)
4646
if !ok {
47-
t.Errorf("%+v\n", infos)
47+
t.Errorf("%+v\n", items)
4848
}
4949

5050
h = &handler{hides: re2}
51-
infos = h.FilterItems(originInfos)
52-
ok = expectInfos(infos, dir1, dir3, file1, file3)
51+
items = h.FilterItems(originalItems)
52+
ok = expectItems(items, dir1, dir3, file1, file3)
5353
if !ok {
54-
t.Errorf("%+v\n", infos)
54+
t.Errorf("%+v\n", items)
5555
}
5656

5757
h = &handler{hideDirs: re2}
58-
infos = h.FilterItems(originInfos)
59-
ok = expectInfos(infos, dir1, dir3, file1, file2, file3)
58+
items = h.FilterItems(originalItems)
59+
ok = expectItems(items, dir1, dir3, file1, file2, file3)
6060
if !ok {
61-
t.Errorf("%+v\n", infos)
61+
t.Errorf("%+v\n", items)
6262
}
6363

6464
h = &handler{hideFiles: re2}
65-
infos = h.FilterItems(originInfos)
66-
ok = expectInfos(infos, dir1, dir2, dir3, file1, file3)
65+
items = h.FilterItems(originalItems)
66+
ok = expectItems(items, dir1, dir2, dir3, file1, file3)
6767
if !ok {
68-
t.Errorf("%+v\n", infos)
68+
t.Errorf("%+v\n", items)
6969
}
7070

7171
h = &handler{shows: re2, hides: re3}
72-
infos = h.FilterItems(originInfos)
73-
ok = expectInfos(infos, dir2, file2)
72+
items = h.FilterItems(originalItems)
73+
ok = expectItems(items, dir2, file2)
7474
if !ok {
75-
t.Errorf("%+v\n", infos)
75+
t.Errorf("%+v\n", items)
7676
}
7777

7878
h = &handler{shows: re2, hides: re2}
79-
infos = h.FilterItems(originInfos)
80-
ok = expectInfos(infos)
79+
items = h.FilterItems(originalItems)
80+
ok = expectItems(items)
8181
if !ok {
82-
t.Errorf("%+v\n", infos)
82+
t.Errorf("%+v\n", items)
8383
}
8484

8585
h = &handler{shows: re2, hideDirs: re2}
86-
infos = h.FilterItems(originInfos)
87-
ok = expectInfos(infos, file2)
86+
items = h.FilterItems(originalItems)
87+
ok = expectItems(items, file2)
8888
if !ok {
89-
t.Errorf("%+v\n", infos)
89+
t.Errorf("%+v\n", items)
9090
}
9191

9292
h = &handler{shows: re2, hideFiles: re2}
93-
infos = h.FilterItems(originInfos)
94-
ok = expectInfos(infos, dir2)
93+
items = h.FilterItems(originalItems)
94+
ok = expectItems(items, dir2)
9595
if !ok {
96-
t.Errorf("%+v\n", infos)
96+
t.Errorf("%+v\n", items)
9797
}
9898

9999
}

0 commit comments

Comments
 (0)