-
Notifications
You must be signed in to change notification settings - Fork 62
/
search_test.go
102 lines (79 loc) · 2.17 KB
/
search_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package plex
import "testing"
func TestExtractKeyFromRatingKey(t *testing.T) {
keys := [][]string{
// Shows: test - expect
{"/library/metadata/18/children", "18"},
{"/library/metadata/1/children", "1"},
// Movies: test - expect
{"/library/metadata/797", "797"},
{"/library/metadata/33", "33"},
{"/library/metadata/700", "700"},
{"/library/metadata/7", "7"},
}
p := Plex{}
for _, k := range keys {
key := p.ExtractKeyFromRatingKey(k[0])
if key != k[1] {
t.Errorf("Expected: %s \n Got: %s", k[1], key)
}
}
}
func TestExtractKeyFromRatingKeyRegex(t *testing.T) {
keys := [][]string{
// Shows: test - expect
{"/library/metadata/18/children", "18"},
{"/library/metadata/1/children", "1"},
// Movies: test - expect
{"/library/metadata/797", "797"},
{"/library/metadata/33", "33"},
{"/library/metadata/700", "700"},
{"/library/metadata/7", "7"},
}
p := Plex{}
for _, k := range keys {
key := p.ExtractKeyFromRatingKeyRegex(k[0])
if key != k[1] {
t.Errorf("Expected: %s \n Got: %s", k[1], key)
}
}
}
func TestExtractKeyAndThumbFromURL(t *testing.T) {
thumbs := [][]string{
// test - expect
{"/library/metadata/1/thumb/1459739349", "1", "1459739349"},
{"/library/metadata/551/thumb/1455861333", "551", "1455861333"},
{"/library/metadata/786/thumb/1463374779", "786", "1463374779"},
}
p := Plex{}
for _, _thumb := range thumbs {
key, thumb := p.ExtractKeyAndThumbFromURL(_thumb[0])
if key != _thumb[1] {
t.Errorf("Expected: %s \n Got: %s\n", _thumb[1], key)
}
if thumb != _thumb[2] {
t.Errorf("Expected: %s\n Got: %s\n", _thumb[2], thumb)
}
}
}
func BenchmarkExtractKeyAndThumbFromURL(b *testing.B) {
query := "/library/metadata/18/children"
p := Plex{}
for ii := 0; ii < b.N; ii++ {
p.ExtractKeyAndThumbFromURL(query)
}
}
func BenchmarkExtractKeyFromRatingKey(b *testing.B) {
ratingKey := "/library/metadata/18/children"
p := Plex{}
for ii := 0; ii < b.N; ii++ {
p.ExtractKeyFromRatingKey(ratingKey)
}
}
func BenchmarkExtractKeyFromRatingKeyRegex(b *testing.B) {
ratingKey := "/library/metadata/18/children"
p := Plex{}
for ii := 0; ii < b.N; ii++ {
p.ExtractKeyFromRatingKeyRegex(ratingKey)
}
}