Typically http servers start a goroutine per client. If your mock server is doing that (without seeing the code, we cannot tell), a debugger won't step between the client and server goroutines. Put print statements in to tell what is actually happening. I have a little library I use constantly to debug in Go. I end up embedding in most of my applications. It turns out to be radically faster to print rather than use a debugger; and printing doesn't care how many goroutines you have going at once. https://github.com/glycerine/vprint
On Friday, March 14, 2025 at 10:47:25 PM UTC David Karr wrote: > A little while ago, I was able to write some unit tests for some code that > makes an http connection. I created a mockserver and a client using that > server. That test in that application works fine. > > I'm now trying to do basically the same thing in a different application. > I'm trying to start with just a low-level handler that gets called for > anything, and I'll iterate it into something useful. However, for some > reason my CUT (code under test) is simply not calling my mocked handler, > and I don't understand why. I must be making a simple mistake, but I'm just > not seeing it. > > My test looks like this so far (not actually testing anything yet): > > func TestProcessProjectSimple(t *testing.T) { > reader, writer, err := os.Pipe() > if err != nil { > t.Fatal(err) > } > defer reader.Close() > defer writer.Close() > > handler := func(w http.ResponseWriter, r *http.Request) { > w.WriteHeader(http.StatusOK) > } > > server := newMockServer(handler) > defer server.Close() > > scmType = Github > githubHttpClient = NewHTTPClient(server.Client(), "abc") > > processProject(writer, "projectName") > } > > func newMockServer(handlerFunc http.HandlerFunc) *httptest.Server { > return httptest.NewServer(handlerFunc) > } > > The "processProject" method makes a call like this: > > githubHttpClient.fetchGithubRepositoriesInOrg(outputFile, projectName) > > That method has a receiver definition of "(hc *HTTPClientData)" and makes > a call like this: > > resp, err := hc.client.Do(req) > When I step over that line, I'm expecting it to step into my one-line > handler defined earlier, but it does not. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/067f0ec9-ea8c-461e-bd42-da6a936a8c30n%40googlegroups.com.