-
Notifications
You must be signed in to change notification settings - Fork 4
/
api_chapters_test.go
118 lines (101 loc) · 3.1 KB
/
api_chapters_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
package apivideosdk
import (
"fmt"
"net/http"
"os"
"reflect"
"testing"
)
var chapterJSONResponses = []string{
`{
"uri": "/videos/vi2ZEQZrOQckdYZ3X5sjPse8/chapters/en",
"src": "https://cdn.api.video/vod/vi2ZEQZrOQckdYZ3X5sjPse8/chapters/en.vtt",
"language": "en"
}`,
`{
"uri": "/videos/vi2ZEQZrOQckdYZ3X5sjPse8/chapters/fr",
"src": "https://cdn.api.video/vod/vi2ZEQZrOQckdYZ3X5sjPse8/chapters/fr.vtt",
"language": "fr"
}`,
}
var chapterStructs = []Chapter{
{
Uri: PtrString("/videos/vi2ZEQZrOQckdYZ3X5sjPse8/chapters/en"),
Src: PtrString("https://cdn.api.video/vod/vi2ZEQZrOQckdYZ3X5sjPse8/chapters/en.vtt"),
Language: PtrString("en"),
},
{
Uri: PtrString("/videos/vi2ZEQZrOQckdYZ3X5sjPse8/chapters/fr"),
Src: PtrString("https://cdn.api.video/vod/vi2ZEQZrOQckdYZ3X5sjPse8/chapters/fr.vtt"),
Language: PtrString("fr"),
},
}
func TestChapters_Get(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/videos/vi2ZEQZrOQckdYZ3X5sjPse8/chapters/en", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, chapterJSONResponses[0])
})
chapter, err := client.Chapters.Get("vi2ZEQZrOQckdYZ3X5sjPse8", "en")
if err != nil {
t.Errorf("Chapters.Get error: %v", err)
}
expected := &chapterStructs[0]
if !reflect.DeepEqual(chapter, expected) {
t.Errorf("Chapters.Get\n got=%#v\nwant=%#v", chapter, expected)
}
}
func TestChapters_List(t *testing.T) {
setup()
defer teardown()
JSONResp := fmt.Sprintf(
`{"data":[%s,%s], "pagination":%s}`,
chapterJSONResponses[0],
chapterJSONResponses[1],
paginationJSON)
mux.HandleFunc("/videos/vi2ZEQZrOQckdYZ3X5sjPse8/chapters", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, JSONResp)
})
chapters, err := client.Chapters.List("vi2ZEQZrOQckdYZ3X5sjPse8", ChaptersApiListRequest{})
if err != nil {
t.Errorf("Chapters.List error: %v", err)
}
expected := &ChaptersListResponse{
Data: chapterStructs,
Pagination: paginationStruct,
}
if !reflect.DeepEqual(chapters, expected) {
t.Errorf("Chapters.List\n got=%#v\nwant=%#v", chapters, expected)
}
}
func TestChapters_Upload(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/videos/vi2ZEQZrOQckdYZ3X5sjPse8/chapters/en", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, chapterJSONResponses[0])
})
file := createTempFile("test.chapter", 1024*1024)
defer os.Remove(file.Name())
chapter, err := client.Chapters.UploadFile("vi2ZEQZrOQckdYZ3X5sjPse8", "en", file)
if err != nil {
t.Errorf("Chapters.Upload error: %v", err)
}
expected := &chapterStructs[0]
if !reflect.DeepEqual(chapter, expected) {
t.Errorf("Chapters.Upload\n got=%#v\nwant=%#v", chapter, expected)
}
}
func TestChapters_Delete(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/videos/vi2ZEQZrOQckdYZ3X5sjPse8/chapters/en", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
})
err := client.Chapters.Delete("vi2ZEQZrOQckdYZ3X5sjPse8", "en")
if err != nil {
t.Errorf("Chapters.Delete error: %v", err)
}
}