jjzjj

WchyContext

全部标签

unit-testing - 如何在向 API 发送 http 请求时进行模拟

我已经使用go-gin在Go中实现了一个ReSTAPI,我正在尝试测试一个如下所示的处理函数funceditNameHandler(c*gin.Context){//makeaReSTcalltoanotherservercallToAnotherServer()c.Status(200)}我想模拟callToAnotherServer方法,以便我的测试用例根本不调用第3方服务器。我的测试用例看起来像funcTestSeriveIdStatusRestorePatch(t*testing.T){//Requestbodysend:=strings.NewReader(`{"name":