-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathprovider_test.go
91 lines (86 loc) · 2.41 KB
/
provider_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
package service
import (
"encoding/json"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"github.com/NYTimes/gizmo/server"
"github.com/sirupsen/logrus"
"github.com/video-dev/video-transcoding-api/v2/config"
)
func TestListProviders(t *testing.T) {
srvr := server.NewSimpleServer(&server.Config{})
service, err := NewTranscodingService(&config.Config{Server: &server.Config{}}, logrus.New())
if err != nil {
t.Fatal(err)
}
srvr.Register(service)
r, _ := http.NewRequest("GET", "/providers", nil)
w := httptest.NewRecorder()
srvr.ServeHTTP(w, r)
if w.Code != http.StatusOK {
t.Errorf("listProviders: wrong status code. Want %d. Got %d", http.StatusOK, w.Code)
}
var providers []string
err = json.NewDecoder(w.Body).Decode(&providers)
if err != nil {
t.Fatal(err)
}
expected := []string{"fake", "zencoder"}
if !reflect.DeepEqual(providers, expected) {
t.Errorf("listProviders: wrong body. Want %#v. Got %#v", expected, providers)
}
}
func TestGetProvider(t *testing.T) {
tests := []struct {
testCase string
name string
expectedStatus int
expectedBody map[string]interface{}
}{
{
"get provider",
"fake",
http.StatusOK,
map[string]interface{}{
"name": "fake",
"health": map[string]interface{}{"ok": true},
"capabilities": map[string]interface{}{
"input": []interface{}{"prores", "h264"},
"output": []interface{}{"mp4", "webm", "hls"},
"destinations": []interface{}{"akamai", "s3"},
},
"enabled": true,
},
},
{
"provider not found",
"whatever",
http.StatusNotFound,
map[string]interface{}{"error": "provider not found"},
},
}
for _, test := range tests {
srvr := server.NewSimpleServer(&server.Config{})
service, err := NewTranscodingService(&config.Config{Server: &server.Config{}}, logrus.New())
if err != nil {
t.Fatal(err)
}
srvr.Register(service)
r, _ := http.NewRequest("GET", "/providers/"+test.name, nil)
w := httptest.NewRecorder()
srvr.ServeHTTP(w, r)
if w.Code != test.expectedStatus {
t.Errorf("%s: wrong status code. Want %d. Got %d", test.testCase, test.expectedStatus, w.Code)
}
var gotBody map[string]interface{}
err = json.NewDecoder(w.Body).Decode(&gotBody)
if err != nil {
t.Errorf("%s: %s", test.testCase, err)
}
if !reflect.DeepEqual(gotBody, test.expectedBody) {
t.Errorf("%s: wrong body.\nWant %#v.\nGot %#v", test.testCase, test.expectedBody, gotBody)
}
}
}