本文整理汇总了Golang中gopkg/in/simversity/gottp/v3/tests.MockRequest.Data方法的典型用法代码示例。如果您正苦于以下问题:Golang MockRequest.Data方法的具体用法?Golang MockRequest.Data怎么用?Golang MockRequest.Data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gopkg/in/simversity/gottp/v3/tests.MockRequest
的用法示例。
在下文中一共展示了MockRequest.Data方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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)
}
})
}
示例3: 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)
}
})
}
示例4: 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")
}
})
}
示例5: 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)
}
})
}
示例6: 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
}
})
}