-
Notifications
You must be signed in to change notification settings - Fork 111
Closed
Labels
Description
AddMatch only use once in a go program?
package main
import (
"fmt"
"net/http"
"regexp"
"gopkg.in/h2non/gock.v1"
)
func test_a() {
defer gock.Off()
gock.New("http://httpbin.org").Get("/").
AddMatcher(func(req *http.Request, ereq *gock.Request) (bool, error) {
matched, err := regexp.MatchString("/aa/[A-Za-z0-9]{6}/ii/[A-Za-z0-9]{6}/calculator", req.URL.Path)
return matched && "GET" == req.Method, err
}).
Reply(204).
SetHeader("Server", "gock")
res, err := http.Get("http://httpbin.org/aa/123456/ii/123456/calculator")
if err != nil {
fmt.Errorf("Error: %s", err)
}
fmt.Printf("Status: %d\n", res.StatusCode)
fmt.Printf("Server header: %s\n", res.Header.Get("Server"))
}
func test_b() {
defer gock.Off()
gock.New("http://httpbin.org").
Get("/application").
Reply(200).
SetHeader("Server", "gockbin")
res, err := http.Get("http://httpbin.org/application")
if err != nil {
fmt.Errorf("Error: %s", err)
}
fmt.Printf("Status: %d\n", res.StatusCode)
fmt.Printf("Server header: %s\n", res.Header.Get("Server"))
}
func main() {
test_a()
test_b()
}