-
Notifications
You must be signed in to change notification settings - Fork 84
router: match longest entrypoint path prefix #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,6 +241,63 @@ func TestHandleInvoke_NoEntryPoints(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestDetermineUpstreamURL_PathPrefix(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| path string | ||
| entryPoints []types.SandboxEntryPoint | ||
| wantHost string | ||
| }{ | ||
| { | ||
| name: "longest prefix wins", | ||
| path: "/api/run", | ||
| entryPoints: []types.SandboxEntryPoint{ | ||
| {Endpoint: "10.0.0.1:8080", Protocol: "HTTP", Path: "/"}, | ||
| {Endpoint: "10.0.0.2:8080", Protocol: "HTTP", Path: "/api"}, | ||
| }, | ||
| wantHost: "10.0.0.2:8080", | ||
| }, | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test only covers the boundary case when a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i agree, added a case for that. With only |
||
| name: "prefix must end on boundary", | ||
| path: "/api2/run", | ||
| entryPoints: []types.SandboxEntryPoint{ | ||
| {Endpoint: "10.0.0.1:8080", Protocol: "HTTP", Path: "/api"}, | ||
| {Endpoint: "10.0.0.2:8080", Protocol: "HTTP", Path: "/"}, | ||
| }, | ||
| wantHost: "10.0.0.2:8080", | ||
| }, | ||
| { | ||
| name: "normalizes slashes", | ||
| path: "api/run", | ||
| entryPoints: []types.SandboxEntryPoint{ | ||
| {Endpoint: "10.0.0.1:8080", Protocol: "HTTP", Path: "/api/"}, | ||
| }, | ||
| wantHost: "10.0.0.1:8080", | ||
| }, | ||
| { | ||
| name: "falls back when no prefix matches", | ||
| path: "/api2/run", | ||
| entryPoints: []types.SandboxEntryPoint{ | ||
| {Endpoint: "10.0.0.1:8080", Protocol: "HTTP", Path: "/api"}, | ||
| }, | ||
| wantHost: "10.0.0.1:8080", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| sandbox := &types.SandboxInfo{EntryPoints: tt.entryPoints} | ||
| upstreamURL, err := determineUpstreamURL(sandbox, tt.path) | ||
| if err != nil { | ||
| t.Fatalf("determineUpstreamURL returned error: %v", err) | ||
| } | ||
| if upstreamURL.Host != tt.wantHost { | ||
| t.Fatalf("expected host %s, got %s", tt.wantHost, upstreamURL.Host) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestHandleAgentInvoke(t *testing.T) { | ||
| // Set required environment variables | ||
| setupEnv() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.