mirror of
https://github.com/adnanh/webhook.git
synced 2025-10-04 13:41:03 +00:00
tests: add test for the -socket option
Refactored webhook_test so that the test HTTP requests are made using an explicitly-provided http.Client, so we can run at least one test with the server bound to a socket instead of a port number, using an http.Client whose transport has been configured with a suitable Unix-domain or Windows named pipe dialer function.
This commit is contained in:
parent
596cc5e70c
commit
c72da0b125
3 changed files with 173 additions and 85 deletions
22
testutils_windows.go
Normal file
22
testutils_windows.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/Microsoft/go-winio"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func prepareTestSocket(hookTmpl string) (socketPath string, transport *http.Transport, cleanup func(), err error) {
|
||||
socketPath = "\\\\.\\pipe\\webhook-" + hookTmpl
|
||||
transport = &http.Transport{
|
||||
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
|
||||
return winio.DialPipeContext(ctx, socketPath)
|
||||
},
|
||||
}
|
||||
|
||||
return socketPath, transport, nil, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue