Skip to content

Commit

Permalink
linter and doc fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersonQ committed Jul 24, 2023
1 parent 55ee213 commit 17b117b
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions testing/proxytest/proxytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,19 @@ type Proxy struct {
// LocalhostURL is the server URL as "http://localhost:PORT".
LocalhostURL string

// proxiedRequests stores a copy of every request this proxy receives.
proxiedRequests []string // []*http.Request
// proxiedRequests is a "request log" for every request the proxy receives.
proxiedRequests []string
proxiedRequestsMu sync.Mutex
}

// ProxiedRequests returns a slice with each URL request the proxy received.
// ProxiedRequests returns a slice with the "request log" with every request the
// proxy received.
func (p *Proxy) ProxiedRequests() []string {
p.proxiedRequestsMu.Lock()
defer p.proxiedRequestsMu.Unlock()

rs := make([]string, len(p.proxiedRequests))
for _, r := range p.proxiedRequests {
rs = append(rs, r)
}

return rs
return append(rs, p.proxiedRequests...)
}

type Option func(o *options)
Expand Down Expand Up @@ -86,7 +83,7 @@ func New(t *testing.T, optns ...Option) *Proxy {
o(&opts)
}

l, err := net.Listen("tcp", opts.addr) //nolint:gosec // it's a test
l, err := net.Listen("tcp", opts.addr) //nolint:gosec,nolintlint // it's a test
if err != nil {
t.Fatalf("NewServer failed to create a net.Listener: %v", err)
}
Expand All @@ -95,15 +92,14 @@ func New(t *testing.T, optns ...Option) *Proxy {

s.Server = &httptest.Server{
Listener: l,
//nolint:gosec,nolintlint // it's a test
Config: &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

switch {
case opts.rewriteURL != nil:
opts.rewriteURL(r.URL)
break
case opts.rewriteHost != nil:
r.URL.Host = opts.rewriteHost(r.URL.Host)
break
}

s.proxiedRequestsMu.Lock()
Expand All @@ -121,6 +117,7 @@ func New(t *testing.T, optns ...Option) *Proxy {
_, _ = fmt.Fprint(w, msg)
return
}
defer resp.Body.Close()

w.WriteHeader(resp.StatusCode)
for k, v := range resp.Header {
Expand Down

0 comments on commit 17b117b

Please sign in to comment.