本文整理汇总了Golang中gopkg/in/simversity/gottp/v3/tests.MockRequest类的典型用法代码示例。如果您正苦于以下问题:Golang MockRequest类的具体用法?Golang MockRequest怎么用?Golang MockRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockRequest类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCreatePDFCollection
func TestCreatePDFCollection(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
req := tests.MockRequest{}
req.Url = "/assets"
req.Method = "post"
req.Data = map[string]interface{}{
"mime_type": "application/pdf",
"name": randSeq(10),
"collection": randSeq(5),
}
server.Test(&req, func(msg *tests.MockResponse) {
utils.Convert(&msg.Data, &assetRet)
if msg.Status != 200 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error("Asset creation should return status 200.")
}
for _, key := range []string{"upload_url", "url", "_id"} {
if val, ok := assetRet[key]; !ok || len(val) == 0 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(key + " should be a valid string in creation return.")
}
}
})
}
示例2: TestSNSMessageIgnoredPath
func TestSNSMessageIgnoredPath(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
snsString := fmt.Sprintf(`{
"Type" : "Notification",
"MessageId" : "12",
"TopicArn" : "arn",
"Subject" : "Amazon S3 Notification",
"Message" : "{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"sc-gallery\"},\"object\":{\"key\":\"%v\",\"size\":71501}}}]}",
"Timestamp" : "2015-04-14T03:48:23.584Z",
"SignatureVersion" : "1",
"Signature" : "liP1M"
}`, "/hello/world/")
req := tests.MockRequest{}
req.Url = "/notify/sns/"
req.Method = "post"
req.Data = map[string]interface{}{}
utils.Decoder([]byte(snsString), &req.Data)
server.Test(&req, func(msg *tests.MockResponse) {
exception := "This path should have been ignroed."
if msg.Status != 400 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
if !strings.Contains(msg.Message, "not meant to be monitored") {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
})
}
示例3: TestSNSMessageNotFound
func TestSNSMessageNotFound(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
snsString := fmt.Sprintf(`{
"Type" : "Notification",
"MessageId" : "12",
"TopicArn" : "arn",
"Subject" : "Amazon S3 Notification",
"Message" : "{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"sc-gallery\"},\"object\":{\"key\":\"%v\",\"size\":71501}}}]}",
"Timestamp" : "2015-04-14T03:48:23.584Z",
"SignatureVersion" : "1",
"Signature" : "liP1M"
}`, "original_file/134444")
req := tests.MockRequest{}
req.Url = "/notify/sns/"
req.Method = "post"
req.Data = map[string]interface{}{}
utils.Decoder([]byte(snsString), &req.Data)
server.Test(&req, func(msg *tests.MockResponse) {
exception := "This message should be ignored."
if msg.Status != 200 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
if msg.Message != "" {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
})
}
示例4: TestGetPDFWithSignature
func TestGetPDFWithSignature(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
req := tests.MockRequest{}
req.Url = makeSignatureURL("/assets/" + assetRet["_id"])
req.Method = "get"
server.Test(&req, func(msg *tests.MockResponse) {
fmt.Printf("%# v", pretty.Formatter(msg))
fmt.Println(msg.Error)
})
}
示例5: TestAssetShouldRaiseException
func TestAssetShouldRaiseException(t *testing.T) {
server := server.MockDBServer()
config.Settings.Moire.SignRequests = false
defer server.Close()
req := tests.MockRequest{}
req.Url = "/assets/hello_world/"
req.Method = "get"
server.Test(&req, func(msg *tests.MockResponse) {
config.Settings.Moire.SignRequests = true
if msg.Status != 500 {
t.Errorf("Message should return 500 (Exception), but returned %v", msg.Status)
}
})
}
示例6: TestCreateAssetFailAgain
func TestCreateAssetFailAgain(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
req := tests.MockRequest{}
req.Url = "/assets"
req.Method = "post"
req.Data = map[string]interface{}{
"mime_type": "image/png",
}
server.Test(&req, func(msg *tests.MockResponse) {
if msg.Status != 400 {
t.Error("Asset creation should fail without name")
}
})
}
示例7: TestGetImageTimeout
func TestGetImageTimeout(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
req := tests.MockRequest{}
req.Url = makeSignatureURL("/assets/" + imageRet["_id"])
req.Method = "get"
time1 := time.Now()
server.Test(&req, func(msg *tests.MockResponse) {
elapsed := time.Since(time1)
if elapsed < time.Duration(config.Settings.Moire.ImageTimeout)*time.Second {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error("Should have taken more than 5 seconds to return")
}
})
}
示例8: TestSNSMessage
func TestSNSMessage(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
parsed_url, err := url.Parse(assetRet["upload_url"])
if err != nil {
t.Error(err.Error())
return
}
upload_path := parsed_url.Path
fmt.Println("Submitting messages for", upload_path)
snsString := fmt.Sprintf(`{
"Type" : "Notification",
"MessageId" : "12",
"TopicArn" : "arn",
"Subject" : "Amazon S3 Notification",
"Message" : "{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"%v\"},\"object\":{\"key\":\"%v\",\"size\":71501}}}]}",
"Timestamp" : "2015-04-14T03:48:23.584Z",
"SignatureVersion" : "1",
"Signature" : "liP1M"
}`, config.Settings.S3.Bucket, strings.TrimPrefix(upload_path, "/"))
req := tests.MockRequest{}
req.Url = "/notify/sns/"
req.Method = "post"
req.Data = map[string]interface{}{}
utils.Decoder([]byte(snsString), &req.Data)
server.Test(&req, func(msg *tests.MockResponse) {
exception := "This asset should be marked as ready."
if msg.Status != 200 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
if msg.Message != "" {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
})
}
示例9: TestGetPDF
func TestGetPDF(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
req := tests.MockRequest{}
req.Url = makeSignatureURL("/assets/" + assetRet["_id"])
req.Method = "get"
server.Test(&req, func(msg *tests.MockResponse) {
if msg.Status != 404 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error("Message should be in pending state.")
}
if !strings.Contains(msg.Message, "content is still being uploaded") {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error("Message should be in pending state.")
}
})
}
示例10: TestCreatePDFURLName
func TestCreatePDFURLName(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
f1 := randSeq(5)
f2 := randSeq(10)
f3 := randSeq(3)
name := fmt.Sprintf("%v--%v//-%v.pdf", f1, f2, f3)
req := tests.MockRequest{}
req.Url = "/assets"
req.Method = "post"
req.Data = map[string]interface{}{
"mime_type": "application/pdf",
"name": name,
}
server.Test(&req, func(msg *tests.MockResponse) {
utils.Convert(&msg.Data, &assetRet)
if msg.Status != 200 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error("Asset creation should return status 200.")
return
}
upload_url, err := url.Parse(assetRet["upload_url"])
if err != nil {
t.Error(err.Error())
return
}
fmt.Println(assetRet["upload_url"])
if !strings.HasSuffix(upload_url.Path, ".pdf") {
t.Error("URL must end with pdf. Found: " + upload_url.Path)
return
}
})
}
示例11: TestPDFThumbnailNeedsSignature
func TestPDFThumbnailNeedsSignature(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
req := tests.MockRequest{}
req.Url = "/assets/" + assetRet["_id"] + "/thumbnail/?no_redirect=true"
req.Method = "get"
server.Test(&req, func(msg *tests.MockResponse) {
exception := "This asset needs signature."
if msg.Status != 412 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
if !strings.Contains(msg.Message, "required parameter") {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
})
}
示例12: TestPDFThumbnailGetDefault
func TestPDFThumbnailGetDefault(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
req := tests.MockRequest{}
req.Url = makeSignatureURL("/assets/" + assetRet["_id"] + "/thumbnail")
req.Method = "get"
server.Test(&req, func(msg *tests.MockResponse) {
exception := "Message should be in pending state."
if msg.Status != 301 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
if !strings.Contains(msg.Message, "attachment.png") {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
})
}
示例13: TestPDFThumbnailNoRedirect
func TestPDFThumbnailNoRedirect(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
req := tests.MockRequest{}
req.Url = makeSignatureURL("/assets/"+assetRet["_id"]+"/thumbnail") + "&no_redirect=true"
req.Method = "get"
server.Test(&req, func(msg *tests.MockResponse) {
exception := "Message should be in pending state."
if msg.Status != 404 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
if !strings.Contains(msg.Message, "content is still being uploaded") {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
})
}
示例14: TestUrls
func TestUrls(t *testing.T) {
server := MockDBServer()
defer server.Close()
req := tests.MockRequest{}
req.Url = "/urls"
server.Test(&req, func(msg *tests.MockResponse) {
if msg.Status != 200 {
t.Error("Expected Status return", msg.Status)
}
urlResponse := map[string]string{}
utils.Convert(&msg.Data, &urlResponse)
if _, ok := urlResponse["assets"]; !ok {
t.Error("Invalid response from Server")
}
if _, ok := urlResponse["thumbnail"]; !ok {
t.Error("Invalid response from Server")
}
})
}