当前位置: 首页>>代码示例>>Golang>>正文


Golang tests.MockRequest类代码示例

本文整理汇总了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.")
			}
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:29,代码来源:collection_test.go

示例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)
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:35,代码来源:pdf_flow_test.go

示例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)
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:34,代码来源:pdf_flow_test.go

示例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)
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:14,代码来源:pdf_flow_test.go

示例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)
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:16,代码来源:assets_test.go

示例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")
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:17,代码来源:assets_test.go

示例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")
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:18,代码来源:image_flow_test.go

示例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)
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:44,代码来源:pdf_flow_test.go

示例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.")
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:20,代码来源:pdf_flow_test.go

示例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
		}

	})
}
开发者ID:josjevv,项目名称:moire,代码行数:41,代码来源:pdf_flow_test.go

示例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)
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:21,代码来源:pdf_flow_test.go

示例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)
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:22,代码来源:pdf_flow_test.go

示例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)
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:22,代码来源:pdf_flow_test.go

示例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")
		}
	})
}
开发者ID:josjevv,项目名称:moire,代码行数:24,代码来源:urls_test.go


注:本文中的gopkg/in/simversity/gottp/v3/tests.MockRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。