Skip to content

Instantly share code, notes, and snippets.

@batmany13
Last active August 29, 2017 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batmany13/820a708b195c2908aaae73ae751df28f to your computer and use it in GitHub Desktop.
Save batmany13/820a708b195c2908aaae73ae751df28f to your computer and use it in GitHub Desktop.
TestDetails
func TestDetails(t *testing.T) {
assert := setupTest(t)
test_helper.RunSimplePost("/v1/details", "",
func(c *gin.Context) {
details(c)
},
func(r *httptest.ResponseRecorder) {
assert.Equal(400, r.Code)
resp := test_helper.ParseJson(r.Body)
assert.Equal("missing 'video_id'", resp["message"])
})
key := sApi.Key
sApi.Key = "fake"
test_helper.RunSimplePost("/v1/details", `{"video_id" : "`+test_helper.VIDEO_ID+`"}`,
func(c *gin.Context) {
details(c)
},
func(r *httptest.ResponseRecorder) {
assert.Equal(400, r.Code)
resp := test_helper.ParseJson(r.Body)
reqs, vals := test_helper.GetReqs()
assert.Len(reqs, 1)
assert.Len(vals, 1)
assert.Equal("failed to make api call : Invalid uuid. Example: '1c0e3ea4529011e6991554a050defa20'.", resp["message"])
})
sApi.Key = key
type Resp struct {
ServerStarted time.Time `json:"server_started"`
Calls []ApiCall `json:"calls"`
Error string `json:"error"`
}
test_helper.RunSimplePost("/v1/details", `{"video_id" : "`+test_helper.VIDEO_ID+`"}`,
func(c *gin.Context) {
details(c)
},
func(r *httptest.ResponseRecorder) {
var resp Resp
assert.Equal(200, r.Code)
bytes, _ := ioutil.ReadAll(r.Body)
json.Unmarshal(bytes, resp)
assert.Len(resp.Calls, 0)
reqs, vals := test_helper.GetReqs()
assert.Equal("/v1/video/details", reqs[1].URL.Path)
assert.Len(reqs, 2)
assert.Len(vals, 2)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment