-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguessit_test.go
125 lines (115 loc) · 2.67 KB
/
guessit_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package guessit
import (
"encoding/json"
"net/http"
"net/http/httptest"
"reflect"
"testing"
)
var responseMap = map[string][]byte{
"Mr.Robot.S04E01.401.Unauthorized.720p.AMZN.WEB-DL.DDP5.1.H.264-NTG[eztv].mkv": []byte(`
{
"audio_channels": "5.1",
"audio_codec": "Dolby Digital Plus",
"container": "mkv",
"episode": 1,
"episode_title": "401 Unauthorized",
"release_group": "NTG[eztv]",
"screen_size": "720p",
"season": 4,
"source": "Web",
"streaming_service": "Amazon Prime",
"title": "Mr Robot",
"type": "episode",
"video_codec": "H.264"
}`),
"The.Matrix.Reloaded.2003.1080p.BrRip.x264.YIFY.mp4": []byte(`
{
"container": "mp4",
"mimetype": "video/mp4",
"other": [
"Reencoded",
"Rip"
],
"release_group": "YIFY",
"screen_size": "1080p",
"source": "Blu-ray",
"title": "The Matrix Reloaded",
"type": "movie",
"video_codec": "H.264",
"year": 2003
}`),
}
type testServer struct {
*testing.T
}
func (ts *testServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
params := struct {
Name string `json:"name"`
}{}
if err := json.NewDecoder(r.Body).Decode(¶ms); err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
data, ok := responseMap[params.Name]
if !ok {
w.WriteHeader(http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "applicationjson")
w.WriteHeader(http.StatusOK)
w.Write(data)
}
func TestGuessit(t *testing.T) {
server := httptest.NewServer(&testServer{T: t})
defer server.Close()
client := New(server.URL)
tt := []struct {
name string
expectedError error
expected *Response
}{
{
name: "Mr.Robot.S04E01.401.Unauthorized.720p.AMZN.WEB-DL.DDP5.1.H.264-NTG[eztv].mkv",
expected: &Response{
Type: "episode",
Title: "Mr Robot",
Episode: 1,
Season: 4,
Quality: "720p",
ReleaseGroup: "NTG[eztv]",
AudioCodec: "Dolby Digital Plus",
VideoCodec: "H.264",
Container: "mkv",
},
},
{
name: "The.Matrix.Reloaded.2003.1080p.BrRip.x264.YIFY.mp4",
expected: &Response{
Type: "movie",
Title: "The Matrix Reloaded",
Year: 2003,
Quality: "1080p",
ReleaseGroup: "YIFY",
VideoCodec: "H.264",
Container: "mp4",
MimeType: "video/mp4",
},
},
{
name: "yolo",
expectedError: ErrServerError,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
got, err := client.Guess(tc.name)
if err != tc.expectedError {
t.Fatalf("expected error %q, got %q", tc.expectedError.Error(), err.Error())
}
if !reflect.DeepEqual(got, tc.expected) {
t.Fatalf("invalid result")
}
})
}
}