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


Golang testflight.WithServer函数代码示例

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


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


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