Skip to content

Commit

Permalink
proxyconfig: improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
liouk committed Oct 3, 2023
1 parent 2c380df commit 746414f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/controllers/proxyconfig/proxyconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ func checkProxyConfig(ctx context.Context, endpointURL *url.URL, noProxy string,

if noProxyMatchesEndpoint && withoutProxy() != nil {
if withProxy() == nil {
return fmt.Errorf("failed to reach endpoint(%q) found in NO_PROXY(%q) with error: %v", endpointURL.String(), noProxy, withoutProxy())
return fmt.Errorf("failed to reach endpoint(%q) present in NO_PROXY(%q) with error: %v", endpointURL.String(), noProxy, withoutProxy())
}
return fmt.Errorf("endpoint(%q) found in NO_PROXY(%q) is unreachable with proxy(%v) and without proxy(%v)", endpointURL.String(), noProxy, withProxy(), withoutProxy())
return fmt.Errorf("endpoint(%q) present in NO_PROXY(%q) is unreachable with proxy(%v) and without proxy(%v)", endpointURL.String(), noProxy, withProxy(), withoutProxy())
}

if !noProxyMatchesEndpoint && withProxy() != nil {
if withoutProxy() == nil {
return fmt.Errorf("failed to reach endpoint(%q) missing in NO_PROXY(%q) with error: %v", endpointURL.String(), noProxy, withProxy())
return fmt.Errorf("failed to reach endpoint(%q) not present in NO_PROXY(%q) with error: %v", endpointURL.String(), noProxy, withProxy())
}
return fmt.Errorf("endpoint(%q) is unreachable with proxy(%v) and without proxy(%v)", endpointURL.String(), withProxy(), withoutProxy())
return fmt.Errorf("endpoint(%q) not present in NO_PROXY(%q) is unreachable with proxy(%v) and without proxy(%v)", endpointURL.String(), noProxy, withProxy(), withoutProxy())
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/controllers/proxyconfig/proxyconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,26 @@ func Test_checkProxyConfig(t *testing.T) {
noProxy: "testing.com",
clientWithProxy: badHTTPClient,
clientWithoutProxy: badHTTPClient,
wantErr: fmt.Errorf("endpoint(%q) found in NO_PROXY(%q) is unreachable with proxy(%q returned 404) and without proxy(%q returned 404)", endpoint, "testing.com", endpoint, endpoint),
wantErr: fmt.Errorf("endpoint(%q) present in NO_PROXY(%q) is unreachable with proxy(%q returned 404) and without proxy(%q returned 404)", endpoint, "testing.com", endpoint, endpoint),
},
{
name: "endpoint matching noProxy is reachable with proxy",
noProxy: "proxy.testing.com",
clientWithProxy: goodHTTPClient,
clientWithoutProxy: badHTTPClient,
wantErr: fmt.Errorf("failed to reach endpoint(%q) found in NO_PROXY(%q) with error: %q returned 404", endpoint, "proxy.testing.com", endpoint),
wantErr: fmt.Errorf("failed to reach endpoint(%q) present in NO_PROXY(%q) with error: %q returned 404", endpoint, "proxy.testing.com", endpoint),
},
{
name: "endpoint not matching noProxy is reachable without proxy",
clientWithProxy: badHTTPClient,
clientWithoutProxy: goodHTTPClient,
wantErr: fmt.Errorf("failed to reach endpoint(%q) missing in NO_PROXY(\"\") with error: %q returned 404", endpoint, endpoint),
wantErr: fmt.Errorf("failed to reach endpoint(%q) not present in NO_PROXY(\"\") with error: %q returned 404", endpoint, endpoint),
},
{
name: "endpoint not matching noProxy is unreachable with/without proxy",
clientWithProxy: badHTTPClient,
clientWithoutProxy: badHTTPClient,
wantErr: fmt.Errorf("endpoint(%q) is unreachable with proxy(%q returned 404) and without proxy(%q returned 404)", endpoint, endpoint, endpoint),
wantErr: fmt.Errorf("endpoint(%q) not present in NO_PROXY(\"\") is unreachable with proxy(%q returned 404) and without proxy(%q returned 404)", endpoint, endpoint, endpoint),
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 746414f

Please sign in to comment.