Skip to content

Multiple mocks for the same path #54

@danny-cheung

Description

@danny-cheung
package main

import (
	"fmt"
	"gopkg.in/h2non/gock.v1"
	"net/http"
)

func main() {
	defer gock.Off()

	gock.New("https://blah.com").Path("/path").
		AddMatcher(func(request *http.Request, request2 *gock.Request) (b bool, e error) {
			fmt.Println("Matcher001")
			return false, nil
		}).
		Reply(200)

	gock.New("https://blah.com").Path("/path").
		AddMatcher(func(request *http.Request, request2 *gock.Request) (b bool, e error) {
			fmt.Println("Matcher002")
			return false, nil
		}).
		Reply(200)

	gock.New("https://blah.com").Path("/path").
		AddMatcher(func(request *http.Request, request2 *gock.Request) (b bool, e error) {
			fmt.Println("FinalMatcher")
			return true, nil
		}).
		Reply(200)

	http.Get("https://blah.com/path")
}

Expected Output:

Matcher001
Matcher002
FinalMatcher

Actual Output:

Matcher001
Matcher001
Matcher001

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions