-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjob_test.go
146 lines (132 loc) · 3.88 KB
/
job_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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package client
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"encoding/json"
"net/http"
)
var _ = Describe("Jobs", func() {
var (
jobInput JobInput
job Job
jobJSONOutput string
)
BeforeEach(func() {
jobJSONOutput = `{
"id":"5iNcv6pMWYVCZhRL",
"source":"http://flv.io/KailuaBeach.mp4",
"destination":"http://AKIAII3C6HP:[email protected]/outputs/",
"preset":{
"name":"mp4_240p",
"description":"Encodes video in H264/MP4 @ 240p",
"container":"mp4",
"rateControl":"vbr",
"video":{
"width":"426",
"height":"240",
"codec":"h264",
"bitrate":"1000000",
"gopSize":"90",
"gopMode":"fixed",
"profile":"main",
"profileLevel":"3.1",
"interlaceMode":"progressive"
},
"audio":{
"codec":"aac",
"bitrate":"64000"
}
},
"status":"created",
"progress":""
}`
json.Unmarshal([]byte(jobJSONOutput), &job)
jobInput = JobInput{
Source: "http://flv.io/KailuaBeach.mp4",
Destination: "http://AKIAII3C6HP:[email protected]/outputs/",
PresetName: "mp4_240p",
}
})
It("should return a list of jobs", func() {
expectedJobs := []Job{
job,
}
server := StartFakeServer(http.StatusOK, "["+jobJSONOutput+"]")
defer server.Close()
client, _ := NewClient(server.URL)
respJob, err := client.GetJobs()
Expect(respJob).To(Equal(expectedJobs))
Expect(err).NotTo(HaveOccurred())
})
It("should fail to retrieve a list of jobs", func() {
apiError := &APIError{
Status: http.StatusBadRequest,
Errors: "Failed to retrieve a list of jobs",
}
server := StartFakeServer(http.StatusBadRequest, "Failed to retrieve a list of jobs")
defer server.Close()
client, _ := NewClient(server.URL)
_, err := client.GetJobs()
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(apiError))
})
It("should return a given job details", func() {
server := StartFakeServer(http.StatusOK, jobJSONOutput)
defer server.Close()
client, _ := NewClient(server.URL)
respJob, err := client.GetJob("5iNcv6pMWYVCZhRL")
Expect(respJob).To(Equal(&job))
Expect(err).NotTo(HaveOccurred())
})
It("should fail to retrieve a given job details", func() {
apiError := &APIError{
Status: http.StatusBadRequest,
Errors: "Failed to retrieve job details",
}
server := StartFakeServer(http.StatusBadRequest, "Failed to retrieve job details")
defer server.Close()
client, _ := NewClient(server.URL)
_, err := client.GetJob("5iNcv6pMWYVCZhRL")
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(apiError))
})
It("should start a job given a job id", func() {
server := StartFakeServer(http.StatusOK, "")
defer server.Close()
client, _ := NewClient(server.URL)
_, err := client.StartJob("5iNcv6pMWYVCZhRL")
Expect(err).NotTo(HaveOccurred())
})
It("should fail to start a job", func() {
apiError := &APIError{
Status: http.StatusBadRequest,
Errors: "Failed to start a job",
}
server := StartFakeServer(http.StatusBadRequest, "Failed to start a job")
defer server.Close()
client, _ := NewClient(server.URL)
_, err := client.StartJob("5iNcv6pMWYVCZhRL")
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(apiError))
})
It("should create a job", func() {
server := StartFakeServer(http.StatusOK, jobJSONOutput)
defer server.Close()
client, _ := NewClient(server.URL)
respJob, err := client.CreateJob(jobInput)
Expect(respJob).To(Equal(&job))
Expect(err).NotTo(HaveOccurred())
})
It("should fail to create a job", func() {
apiError := &APIError{
Status: http.StatusBadRequest,
Errors: "Failed to create a job",
}
server := StartFakeServer(http.StatusBadRequest, "Failed to create a job")
defer server.Close()
client, _ := NewClient(server.URL)
_, err := client.CreateJob(jobInput)
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(apiError))
})
})