Golang:使用 gock 模拟多个 http 请求

imm*_*eel 5 unit-testing go

我正在尝试使用 gock 模拟多个 http 请求进行单元测试,但出现此错误:

    Error:  Get https://192.64.23.33/q1/status: gock: cannot match any request
    Error:  Get https://194.55.5.6/q1/status: gock: cannot match any request
Run Code Online (Sandbox Code Playgroud)

代码:

func GetEmployee(url string, cli *http.Client) *Response {
    //Do something
    return Response
}

func company(url []string, cli *http.Client) []string {

    for employee := range url {
        resultList := GetEmployee(employee, cli)
        //Process and return an array
        return resultList
    }
}
Run Code Online (Sandbox Code Playgroud)

单元测试:

func TestCompany(t *Testing.t){
  Convey("testing function company",t,func() {
  expected := &Response: {
                Name:     "xyz",
                ID:       1",
                Status:   "active",

            }
  MockCli := &http.Client{}
  testemployees := []string{"192.64.23.33","194.55.5.6"}
  for _, testempl := range testemployees {
        gock.New(fmt.Sprintf("https://%s", testempl)).
            Get("/q1/status").
            Reply(200).
            JSON(expected) 
        gock.InterceptClient(MockCli)
        response, err = company(testemployees, MockCli)

        //some assertions
       }
    })

  }
Run Code Online (Sandbox Code Playgroud)

当我传递 testemployees := []string{"192.64.23.33","194.55.5.6"} 列表中多个元素时,单元测试失败,否则如果只有一个元素,则它会按预期通过。

如何在这里模拟多个 URL 以便 gock 可以匹配请求?