Add test for route building error propagation

Signed-off-by: Simon Engmann <simon.engmann@sovity.de>
This commit is contained in:
Simon Engmann 2025-01-10 12:21:18 +01:00 committed by Jan Larwig
parent ab9ce42dfc
commit ef09fb5fab
No known key found for this signature in database
GPG Key ID: C2172BFA220A037A
1 changed files with 32 additions and 0 deletions

View File

@ -383,6 +383,38 @@ var _ = Describe("Proxy Suite", func() {
)
})
Context("multiUpstreamProxy errors", func() {
type proxyErrorTableInput struct {
upstreams options.UpstreamConfig
expectedError string
}
DescribeTable("NewProxy", func(in *proxyErrorTableInput) {
sigData := &options.SignatureData{Hash: crypto.SHA256, Key: "secret"}
writer := &pagewriter.WriterFuncs{
ProxyErrorFunc: func(rw http.ResponseWriter, _ *http.Request, _ error) {
rw.WriteHeader(502)
rw.Write([]byte("Proxy Error"))
},
}
_, err := NewProxy(in.upstreams, sigData, writer)
Expect(err).To(MatchError(in.expectedError))
},
Entry("regex matcher without rewrite target", &proxyErrorTableInput{
upstreams: options.UpstreamConfig{
Upstreams: []options.Upstream{{
ID: "api",
Path: "^/api/$",
URI: "http://example.com",
}},
},
expectedError: `could not register http upstream "api": mux: path must start with a slash, got "^/api/$"`,
}),
)
})
Context("sortByPathLongest", func() {
type sortByPathLongestTableInput struct {
input []options.Upstream