Skip to content

Instantly share code, notes, and snippets.

@krancour
Created March 11, 2019 15:04
Show Gist options
  • Save krancour/d9db7348b264282e34faf7154546bbd5 to your computer and use it in GitHub Desktop.
Save krancour/d9db7348b264282e34faf7154546bbd5 to your computer and use it in GitHub Desktop.
func TestProxyWithHTTP2(t *testing.T) {
var proxyHTTP2RequestFnCalled bool
h := &httpReverseProxy{
proxyHTTP2RequestFn: func(http.ResponseWriter, *http.Request) {
// We hope this function will be called, so keep track of whether it was
proxyHTTP2RequestFnCalled = true
},
proxyHTTP1xRequestFn: func(http.ResponseWriter, *http.Request) {
// If this function was called, there is a flaw in the logic under test
assert.Fail(t, "The HTTP/1.x handler should not have been called, but was")
},
}
// Build an HTTP/2 request (r) to test with
h.Proxy(r, nil)
assert.True(t, proxyHTTP2RequestFnCalled)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment