This repository has been archived by the owner on Aug 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
autoscan_test.go
101 lines (94 loc) · 2.26 KB
/
autoscan_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
package autoscan
import (
"testing"
)
func TestRewriter(t *testing.T) {
type Test struct {
Name string
Rewrites []Rewrite
Input string
Expected string
}
var testCases = []Test{
{
Name: "One parameter with wildcard",
Input: "/mnt/unionfs/Media/Movies/Example Movie/movie.mkv",
Expected: "/data/Movies/Example Movie/movie.mkv",
Rewrites: []Rewrite{{
From: "/mnt/unionfs/Media/",
To: "/data/",
}},
},
{
Name: "One parameter with glob thingy",
Input: "/Media/Movies/test.mkv",
Expected: "/data/Movies/test.mkv",
Rewrites: []Rewrite{{
From: "/Media/(.*)",
To: "/data/$1",
}},
},
{
Name: "No wildcard",
Input: "/Media/whatever",
Expected: "/whatever",
Rewrites: []Rewrite{{
From: "^/Media/",
To: "/",
}},
},
{
Name: "Unicode (PAS issue #73)",
Input: "/media/b33f/saitoh183/private/Videos/FrenchTV/L'échappée/Season 03",
Expected: "/Videos/FrenchTV/L'échappée/Season 03",
Rewrites: []Rewrite{{
From: "/media/b33f/saitoh183/private/",
To: "/",
}},
},
{
Name: "Returns input when no rules are given",
Input: "/mnt/unionfs/test/example.mp4",
Expected: "/mnt/unionfs/test/example.mp4",
},
{
Name: "Returns input when rule does not match",
Input: "/test/example.mp4",
Expected: "/test/example.mp4",
Rewrites: []Rewrite{{
From: "^/Media/",
To: "/mnt/unionfs/Media/",
}},
},
{
Name: "Uses second rule if first one does not match",
Input: "/test/example.mp4",
Expected: "/mnt/unionfs/example.mp4",
Rewrites: []Rewrite{
{From: "^/Media/", To: "/mnt/unionfs/Media/"},
{From: "^/test/", To: "/mnt/unionfs/"},
},
},
{
Name: "Hotio",
Input: "/movies4k/example.mp4",
Expected: "/mnt/unionfs/movies4k/example.mp4",
Rewrites: []Rewrite{
{From: "^/movies/", To: "/mnt/unionfs/movies/"},
{From: "^/movies4k/", To: "/mnt/unionfs/movies4k/"},
},
},
}
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
rewriter, err := NewRewriter(tc.Rewrites)
if err != nil {
t.Fatal(err)
}
result := rewriter(tc.Input)
if result != tc.Expected {
t.Errorf("%s does not equal %s", result, tc.Expected)
}
})
}
}