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


Golang RequestResponsePair.Encode方法代码示例

本文整理汇总了Golang中github.com/SpectoLabs/hoverfly/core/models.RequestResponsePair.Encode方法的典型用法代码示例。如果您正苦于以下问题:Golang RequestResponsePair.Encode方法的具体用法?Golang RequestResponsePair.Encode怎么用?Golang RequestResponsePair.Encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/SpectoLabs/hoverfly/core/models.RequestResponsePair的用法示例。


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

示例1: SaveRequestResponsePair

func (this *RequestMatcher) SaveRequestResponsePair(pair *models.RequestResponsePair) error {
	var key string

	if *this.Webserver {
		key = pair.IdWithoutHost()
	} else {
		key = pair.Id()
	}

	log.WithFields(log.Fields{
		"path":          pair.Request.Path,
		"rawQuery":      pair.Request.Query,
		"requestMethod": pair.Request.Method,
		"bodyLen":       len(pair.Request.Body),
		"destination":   pair.Request.Destination,
		"hashKey":       key,
	}).Debug("Capturing")

	pairBytes, err := pair.Encode()

	if err != nil {
		return err
	}

	return this.RequestCache.Set([]byte(key), pairBytes)
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:26,代码来源:matcher.go

示例2: Test_rebuildHashes_whenDataIsHashedForAProxy_andStillAProxy_keysAreNotChanged

func Test_rebuildHashes_whenDataIsHashedForAProxy_andStillAProxy_keysAreNotChanged(t *testing.T) {
	RegisterTestingT(t)
	webserver := false

	db := cache.NewInMemoryCache()

	pair := models.RequestResponsePair{
		Request: models.RequestDetails{
			Path:        "/hello",
			Destination: "a-host.com",
		},
		Response: models.ResponseDetails{
			Body: "a body",
		},
	}

	pairBytes, _ := pair.Encode()

	db.Set([]byte(pair.Id()), pairBytes)

	rebuildHashes(db, webserver)

	result, err := db.Get([]byte(pair.Id()))

	Expect(err).To(BeNil())
	Expect(result).To(Equal(pairBytes))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:27,代码来源:cache_utils_test.go

示例3: save

// save gets request fingerprint, extracts request body, status code and headers, then saves it to cache
func (hf *Hoverfly) save(req *http.Request, reqBody []byte, resp *http.Response, respBody []byte) {

	if resp == nil {
		resp = emptyResp
	} else {
		responseObj := models.ResponseDetails{
			Status:  resp.StatusCode,
			Body:    string(respBody),
			Headers: resp.Header,
		}

		requestObj := models.RequestDetails{
			Path:        req.URL.Path,
			Method:      req.Method,
			Destination: req.Host,
			Scheme:      req.URL.Scheme,
			Query:       req.URL.RawQuery,
			Body:        string(reqBody),
			Headers:     req.Header,
		}

		pair := models.RequestResponsePair{
			Response: responseObj,
			Request:  requestObj,
		}

		err := hf.RequestMatcher.SaveRequestResponsePair(&pair)
		if err != nil {
			log.WithFields(log.Fields{
				"error": err.Error(),
			}).Error("Failed to save payload")
		}

		pairBytes, err := pair.Encode()
		if err != nil {
			log.WithFields(log.Fields{
				"error": err.Error(),
			}).Error("Failed to serialize payload")
		} else {
			// hook
			var en Entry
			en.ActionType = ActionTypeRequestCaptured
			en.Message = "captured"
			en.Time = time.Now()
			en.Data = pairBytes

			if err := hf.Hooks.Fire(ActionTypeRequestCaptured, &en); err != nil {
				log.WithFields(log.Fields{
					"error":      err.Error(),
					"message":    en.Message,
					"actionType": ActionTypeRequestCaptured,
				}).Error("failed to fire hook")
			}
		}

	}
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:58,代码来源:hoverfly.go

示例4: TestRequestResponsePairEncodeEmpty

func TestRequestResponsePairEncodeEmpty(t *testing.T) {
	RegisterTestingT(t)

	pair := models.RequestResponsePair{}

	pairBytes, err := pair.Encode()
	Expect(err).To(BeNil())

	_, err = models.NewRequestResponsePairFromBytes(pairBytes)
	Expect(err).To(BeNil())
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:11,代码来源:models_test.go

示例5: TestRequestResponsePairEncodeDecode

func TestRequestResponsePairEncodeDecode(t *testing.T) {
	RegisterTestingT(t)

	resp := models.ResponseDetails{
		Status: 200,
		Body:   "body here",
	}

	pair := models.RequestResponsePair{Response: resp}

	pairBytes, err := pair.Encode()
	Expect(err).To(BeNil())

	pairFromBytes, err := models.NewRequestResponsePairFromBytes(pairBytes)
	Expect(err).To(BeNil())
	Expect(pairFromBytes.Response.Body).To(Equal(resp.Body))
	Expect(pairFromBytes.Response.Status).To(Equal(resp.Status))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:18,代码来源:models_test.go

示例6: TestHoverflyGetSimulationReturnsMultipleRequestResponsePairs

func TestHoverflyGetSimulationReturnsMultipleRequestResponsePairs(t *testing.T) {
	RegisterTestingT(t)

	server, unit := testTools(201, `{'message': 'here'}`)
	defer server.Close()

	recording := models.RequestResponsePair{
		Request: models.RequestDetails{
			Destination: "testhost.com",
			Path:        "/test",
		},
		Response: models.ResponseDetails{
			Status: 200,
			Body:   "test",
		},
	}

	recordingBytes, err := recording.Encode()
	Expect(err).To(BeNil())

	unit.RequestCache.Set([]byte("key"), recordingBytes)
	unit.RequestCache.Set([]byte("key2"), recordingBytes)

	simulation, err := unit.GetSimulation()
	Expect(err).To(BeNil())

	Expect(simulation.DataView.RequestResponsePairs).To(HaveLen(2))

	Expect(*simulation.DataView.RequestResponsePairs[0].Request.Destination).To(Equal("testhost.com"))
	Expect(*simulation.DataView.RequestResponsePairs[0].Request.Path).To(Equal("/test"))
	Expect(*simulation.DataView.RequestResponsePairs[0].Request.RequestType).To(Equal("recording"))

	Expect(simulation.DataView.RequestResponsePairs[0].Response.Status).To(Equal(200))
	Expect(simulation.DataView.RequestResponsePairs[0].Response.Body).To(Equal("test"))

	Expect(*simulation.DataView.RequestResponsePairs[1].Request.Destination).To(Equal("testhost.com"))
	Expect(*simulation.DataView.RequestResponsePairs[1].Request.Path).To(Equal("/test"))
	Expect(*simulation.DataView.RequestResponsePairs[1].Request.RequestType).To(Equal("recording"))

	Expect(simulation.DataView.RequestResponsePairs[1].Response.Status).To(Equal(200))
	Expect(simulation.DataView.RequestResponsePairs[1].Response.Body).To(Equal("test"))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:42,代码来源:hoverfly_service_test.go


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