• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang testflight.WithServer函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/drewolson/testflight.WithServer函数的典型用法代码示例。如果您正苦于以下问题:Golang WithServer函数的具体用法?Golang WithServer怎么用?Golang WithServer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了WithServer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestPing

func TestPing(t *testing.T) {
	testflight.WithServer(handler, func(r *testflight.Requester) {
		response := r.Get("/ping")
		assert.Equal(t, 200, response.StatusCode)
		assert.Equal(t, "OK", response.Body)
	})
}
开发者ID:presbrey,项目名称:http2mq,代码行数:7,代码来源:main_test.go


示例2: TestCommonHeaders

func TestCommonHeaders(t *testing.T) {
	corsOrigins := []string{"http://example.com"}

	Convey("Test common headers", t, func() {
		testflight.WithServer(
			testHandler(corsOrigins),
			func(r *testflight.Requester) {
				headers := r.Get("/ping").RawResponse.Header

				Convey("Sets content-type header", func() {
					actual := headers.Get("Content-Type")
					So(actual, ShouldEqual, "application/vnd.api+json")
				})

				Convey("Sets access-control-allow header", func() {
					actual := headers.Get("Access-Control-Allow-Headers")
					So(actual, ShouldEqual, "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
				})
			},
		)
	})

	Convey("Test CORS headers", t, func() {
		testflight.WithServer(
			testHandler(corsOrigins),
			func(r *testflight.Requester) {
				headerName := "Access-Control-Allow-Origin"
				request, _ := http.NewRequest(
					"GET", "/ping", strings.NewReader(""),
				)

				Convey("Returns CORS header for allowed origin", func() {
					request.Header.Add("Origin", "http://example.com")
					actual := r.Do(request).RawResponse.Header.Get(headerName)
					So(actual, ShouldEqual, "http://example.com")
				})

				Convey("Does not return CORS header for not allowed origin", func() {
					request.Header.Add("Origin", "http://not-allowed.com")
					actual := r.Do(request).RawResponse.Header.Get(headerName)
					So(actual, ShouldEqual, "")
				})
			},
		)
	})
}
开发者ID:lebedev-yury,项目名称:cities-api,代码行数:46,代码来源:common_headers_test.go


示例3: TestUserGet

func TestUserGet(t *testing.T) {
	testflight.WithServer(rooter(goji.DefaultMux), func(r *testflight.Requester) {
		req, _ := http.NewRequest("GET", "/user/edit/22", nil)
		req.Header.Set("Authorization", "Basic dXNlcjp1c2Vy")
		response := r.Do(req)
		assert.Equal(t, 200, response.StatusCode)
	})
}
开发者ID:woremacx,项目名称:goji_waf_sample,代码行数:8,代码来源:user_testflight_test.go


示例4: TestWebSocketRecordsReceivedMessages

func TestWebSocketRecordsReceivedMessages(t *testing.T) {
	testflight.WithServer(websocketHandler(), func(r *testflight.Requester) {
		connection := Connect(r, "/websocket")

		connection.WriteMessage("Drew")
		connection.ReceiveMessage()
		assert.Equal(t, "Hello, Drew", connection.ReceivedMessages[0])
	})
}
开发者ID:wjdix,项目名称:testflight,代码行数:9,代码来源:ws_test.go


示例5: TestWebSocketTimesOutWhileFlushingMessages

func TestWebSocketTimesOutWhileFlushingMessages(t *testing.T) {
	testflight.WithServer(donothingwebsocketHandler(), func(r *testflight.Requester) {
		connection := Connect(r, "/websocket")
		connection.WriteMessage("Drew")

		err := connection.FlushMessages(2)
		assert.Equal(t, TimeoutError{}, *err)
	})
}
开发者ID:wjdix,项目名称:testflight,代码行数:9,代码来源:ws_test.go


示例6: TestWebSocket

func TestWebSocket(t *testing.T) {
	testflight.WithServer(websocketHandler(), func(r *testflight.Requester) {
		connection := Connect(r, "/websocket")

		connection.SendMessage("Drew")
		message, _ := connection.ReceiveMessage()
		assert.Equal(t, "Hello, Drew", message)
	})
}
开发者ID:netracker,项目名称:netracker,代码行数:9,代码来源:ws_test.go


示例7: testDelete

func testDelete(t *testing.T, url string) {
	testflight.WithServer(
		CRUDRouter(),
		func(r *testflight.Requester) {
			response := r.Delete(url, testflight.JSON, "")

			structJSONCompare(t, http.StatusNoContent, response.StatusCode)
		},
	)
}
开发者ID:falahhaprak,项目名称:rter,代码行数:10,代码来源:crud_test.go


示例8: TestWebSocketFlushesMessages

func TestWebSocketFlushesMessages(t *testing.T) {
	testflight.WithServer(multiresponsewebsocketHandler(), func(r *testflight.Requester) {
		connection := Connect(r, "/websocket")

		connection.WriteMessage("Drew")
		connection.WriteMessage("Bob")
		connection.FlushMessages(2)
		assert.Equal(t, 2, len(connection.ReceivedMessages))
	})
}
开发者ID:wjdix,项目名称:testflight,代码行数:10,代码来源:ws_test.go


示例9: TestWebSocketReceiveMessageTimesOut

func TestWebSocketReceiveMessageTimesOut(t *testing.T) {

	testflight.WithServer(donothingwebsocketHandler(), func(r *testflight.Requester) {
		connection := Connect(r, "/websocket")

		connection.WriteMessage("Drew")
		_, err := connection.ReceiveMessage()
		assert.Equal(t, TimeoutError{}, *err)
	})
}
开发者ID:wjdix,项目名称:testflight,代码行数:10,代码来源:ws_test.go


示例10: TestClosingConnections

func TestClosingConnections(t *testing.T) {
	testflight.WithServer(pollingHandler(), func(r *testflight.Requester) {
		connection := Connect(r, "/websocket")

		connection.SendMessage("Drew")
		connection.SendMessage("Bob")
		connection.FlushMessages(2)
		connection.Close()
		assert.Equal(t, 2, len(connection.ReceivedMessages))
	})
}
开发者ID:netracker,项目名称:netracker,代码行数:11,代码来源:ws_test.go


示例11: TestWebSocketTimeoutIsConfigurable

func TestWebSocketTimeoutIsConfigurable(t *testing.T) {
	testflight.WithServer(websocketHandler(), func(r *testflight.Requester) {
		connection := Connect(r, "/websocket")
		connection.Timeout = 2 * time.Second

		go func() {
			time.Sleep(1 * time.Second)
			connection.WriteMessage("Drew")
		}()

		message, _ := connection.ReceiveMessage()
		assert.Equal(t, "Hello, Drew", message)
	})
}
开发者ID:wjdix,项目名称:testflight,代码行数:14,代码来源:ws_test.go


示例12: TestProducer

func TestProducer(t *testing.T) {
	stack := new(mango.Stack)
	handler := stack.HandlerFunc(pact.Producer)

	testflight.WithServer(handler, func(r *testflight.Requester) {

		pact_str, err := ioutil.ReadFile("../pacts/my_consumer-my_producer.json")
		if err != nil {
			t.Error(err)
		}

		pacts := make(map[string]interface{})
		err = json.Unmarshal(pact_str, &pacts)
		if err != nil {
			t.Error(err)
		}

		for _, i := range pacts["interactions"].([]interface{}) {
			interaction := i.(map[string]interface{})
			t.Logf("Given %s", interaction["producer_state"])
			t.Logf("  %s", interaction["description"])

			request := interaction["request"].(map[string]interface{})
			var actualResponse *testflight.Response
			switch request["method"] {
			case "get":
				actualResponse = r.Get(request["path"].(string) + "?" + request["query"].(string))
			}

			expectedResponse := interaction["response"].(map[string]interface{})

			assert.Equal(t, int(expectedResponse["status"].(float64)), actualResponse.StatusCode)

			for k, v := range expectedResponse["headers"].(map[string]interface{}) {
				assert.Equal(t, v, actualResponse.RawResponse.Header[k][0])
			}

			responseBody := make(map[string]interface{})
			err = json.Unmarshal([]byte(actualResponse.Body), &responseBody)
			if err != nil {
				t.Error(err)
			}
			for _, diff := range pretty.Diff(expectedResponse["body"], responseBody) {
				t.Log(diff)
			}
			assert.Equal(t, expectedResponse["body"], responseBody)
		}
	})
}
开发者ID:uglyog,项目名称:example_pact_with_go,代码行数:49,代码来源:producer_test.go


示例13: TestUserDelete

func TestUserDelete(t *testing.T) {
	testflight.WithServer(rooter(goji.DefaultMux), func(r *testflight.Requester) {
		Users := []models.User{}
		count_before := 0
		count_after := 0
		db.Find(&Users).Count(&count_before)

		req, _ := http.NewRequest("GET", "/user/delete/1", nil)
		req.Header.Set("Authorization", "Basic dXNlcjp1c2Vy")
		r.Do(req)

		db.Find(&Users).Count(&count_after)
		assert.Equal(t, count_before-1, count_after)
	})
}
开发者ID:woremacx,项目名称:goji_waf_sample,代码行数:15,代码来源:user_testflight_test.go


示例14: testRead

func testRead(t *testing.T, url string, v interface{}) {
	testflight.WithServer(
		CRUDRouter(),
		func(r *testflight.Requester) {
			response := r.Get(url)

			structJSONCompare(t, http.StatusOK, response.StatusCode)

			err := json.Unmarshal([]byte(response.Body), v)

			if err != nil {
				t.Error(err)
			}
		},
	)
}
开发者ID:falahhaprak,项目名称:rter,代码行数:16,代码来源:crud_test.go


示例15: TestUserCreateError

func TestUserCreateError(t *testing.T) {
	testflight.WithServer(rooter(goji.DefaultMux), func(r *testflight.Requester) {
		count_before := 0
		count_after := 0
		db.Table("users").Count(&count_before)

		values := url.Values{}
		values.Add("Name", "エラー")

		req, _ := http.NewRequest("POST", "/user/new", strings.NewReader(values.Encode()))
		req.Header.Set("Authorization", "Basic dXNlcjp1c2Vy")
		req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
		response := r.Do(req)

		db.Table("users").Count(&count_after)
		assert.Equal(t, 200, response.StatusCode)
		assert.Equal(t, count_before, count_after)
	})
}
开发者ID:woremacx,项目名称:goji_waf_sample,代码行数:19,代码来源:user_testflight_test.go


示例16: testUpdate

func testUpdate(t *testing.T, url string, v interface{}) {
	enc, err := json.Marshal(v)

	if err != nil {
		t.Error(err)
	}

	testflight.WithServer(
		CRUDRouter(),
		func(r *testflight.Requester) {
			response := r.Put(url, testflight.JSON, string(enc))

			structJSONCompare(t, http.StatusOK, response.StatusCode)

			err = json.Unmarshal([]byte(response.Body), v)

			if err != nil {
				t.Error(err)
			}
		},
	)
}
开发者ID:falahhaprak,项目名称:rter,代码行数:22,代码来源:crud_test.go


示例17: TestPOST

func TestPOST(t *testing.T) {
	testflight.WithServer(handler, func(r *testflight.Requester) {
		response := r.Post("/", testflight.JSON, `{"test":1}`)
		assert.Equal(t, 201, response.StatusCode)
	})
}
开发者ID:presbrey,项目名称:http2mq,代码行数:6,代码来源:main_test.go


示例18:

			return recorder
		}

		It("has a Content-Type header", func() {
			response := makeRequest()

			header := response.Header().Get("Content-Type")
			Ω(header).Should(Equal("application/json"))
		})
	})

	Describe("authentication", func() {
		makeRequestWithoutAuth := func() *testflight.Response {
			response := &testflight.Response{}
			testflight.WithServer(brokerAPI, func(r *testflight.Requester) {
				request, _ := http.NewRequest("GET", "/v2/catalog", nil)
				response = r.Do(request)
			})
			return response
		}

		makeRequestWithAuth := func(username string, password string) *testflight.Response {
			response := &testflight.Response{}
			testflight.WithServer(brokerAPI, func(r *testflight.Requester) {
				request, _ := http.NewRequest("GET", "/v2/catalog", nil)
				request.SetBasicAuth(username, password)

				response = r.Do(request)
			})
			return response
		}
开发者ID:x6j8x,项目名称:rds-broker,代码行数:31,代码来源:api_test.go


示例19: TestGET

func TestGET(t *testing.T) {
	testflight.WithServer(handler, func(r *testflight.Requester) {
		response := r.Get("/?test=1")
		assert.Equal(t, 201, response.StatusCode)
	})
}
开发者ID:presbrey,项目名称:http2mq,代码行数:6,代码来源:main_test.go


示例20: TestHandleAdd

func TestHandleAdd(t *testing.T) {
	aConfig := giles.LoadConfig("../giles.cfg")
	testArchiver = giles.NewArchiver(aConfig)
	h := NewHTTPHandler(testArchiver)
	uuid := common.NewUUID()

	for _, test := range []struct {
		title          string
		toPost         string
		expectedStatus int
		expectedBody   string
	}{
		{
			"No Readings",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v" }}`, uuid),
			200,
			"",
		},
		{
			"Empty Readings 1",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v", "Readings": [ ]}}`, uuid),
			200,
			"",
		},
		{
			"Empty Readings 2",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v", "Readings": [[ ]]}}`, uuid),
			200,
			"",
		},
		{
			"Bad JSON 1",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v", "Readings": [ ]]}}`, uuid),
			400,
			"invalid character ']' after object key:value pair",
		},
		{
			"Bad JSON 2",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v", "Readings": [[ ]]}`, uuid),
			400,
			"unexpected EOF",
		},
		{
			"Bad Readings 1: negative timestamp",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v", "Readings": [[-1, 0]]}}`, uuid),
			400,
			"json: cannot unmarshal number -1 into Go value of type uint64",
		},
		{
			"Bad Readings 2: too big timestamp",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v", "Readings": [[1000000000000000000, 0]]}}`, uuid),
			500,
			"Bad Timestamp: 1000000000000000000",
		},
		{
			"Bad Readings 3: too big timestamp",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v", "Readings": [[3458764513820540929, 0]]}}`, uuid),
			500,
			"Bad Timestamp: 3458764513820540929",
		},
		{
			"Good readings: 1 reading max timestamp",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v", "Properties": {"UnitofTime": "ns"}, "Readings": [[3458764513820540928, 0]]}}`, uuid),
			200,
			"",
		},
		{
			"Good readings: 2 repeat readings",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v", "Properties": {"UnitofTime": "ns"}, "Readings": [[1000000000000000000, 0], [1000000000000000000, 0]]}}`, uuid),
			200,
			"",
		},
		{
			"Good readings: 2 repeat readings diff values",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v", "Properties": {"UnitofTime": "ns"}, "Readings": [[2000000000000000000, 0], [2000000000000000000, 1]]}}`, uuid),
			200,
			"",
		},
		{
			"Lots of readings",
			fmt.Sprintf(`{"/sensor/0": {"Path": "/sensor/0", "uuid": "%v", "Properties": {"UnitofTime": "ns"}, "Readings": [ %v [1000000000000000000, 0]]}}`, uuid, strings.Repeat("[1000000000000000000, 0],", 1000)),
			200,
			"",
		},
	} {

		testflight.WithServer(h.handler, func(r *testflight.Requester) {
			response := r.Post("/add/dummykey", testflight.JSON, test.toPost)
			assert.Equal(t, test.expectedStatus, response.StatusCode, test.title)
			assert.Equal(t, test.expectedBody, response.Body, test.title)
		})
	}
}
开发者ID:gtfierro,项目名称:giles2,代码行数:93,代码来源:handlers_test.go



注:本文中的github.com/drewolson/testflight.WithServer函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang core.Pipeline类代码示例发布时间:2022-05-23
下一篇:
Golang stream.New函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap