Exemple #1
0
func (ms *HTTPMockService) findMatchingInteractionInScope(r *http.Request) (*Interaction, error) {
	reqToFind, err := provider.CreateRequestFromHTTPRequest(r)
	if err != nil {
		return nil, err
	}
	for _, interaction := range ms.inScopeInteractions {
		result, err := comparers.MatchRequest(interaction.Request, reqToFind)
		if err != nil {
			return nil, err
		}
		if result {
			return interaction, nil
		}
	}
	return nil, nil
}
func testCase(t *testing.T, fileName string) {
	data, err := ioutil.ReadFile("./" + fileName)
	if err != nil {
		t.Error(err)
		t.FailNow()
	}
	tc := &RequestTestCase{}
	if err := json.Unmarshal(data, tc); err != nil {
		t.Error(err)
		t.FailNow()
	}

	result, err := comparers.MatchRequest(tc.Expected, tc.Actual)
	if err != nil {
		t.Error(err)
	} else if result != tc.Match {
		t.Error(tc.Comment)
	}
}
Exemple #3
0
func (ms *HTTPMockService) findMatchingInteractionInScope(r *http.Request) (*Interaction, error) {

	for i := range ms.inScopeInteractions {
		req, err := ms.inScopeInteractions[i].ToHTTPRequest(ms.server.URL)

		if err != nil {
			return nil, err
		}

		result, err := comparers.MatchRequest(req, r)

		if err != nil {
			return nil, err
		}

		if result {
			return ms.inScopeInteractions[i], nil
		}
	}
	return nil, nil
}