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/11b54912-08d2-41f4-9323-0bf6e37dd879n%40googlegroups.com.

Reply via email to