Skip to content

Commit

Permalink
simplify internalizeInternalLocations
Browse files Browse the repository at this point in the history
  • Loading branch information
salonichf5 committed Jan 16, 2024
1 parent e6ff4eb commit 84f47f0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 42 deletions.
1 change: 0 additions & 1 deletion internal/mode/static/nginx/config/http/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type Location struct {
ProxyPass string
HTTPMatchVar string
ProxySetHeaders []Header
Internal bool
}

// Header defines a HTTP header to be passed to the proxied server.
Expand Down
9 changes: 2 additions & 7 deletions internal/mode/static/nginx/config/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func initializeInternalLocation(
matchRuleIdx int,
match dataplane.Match,
) (http.Location, httpMatch) {
path := createPathForMatch(pathruleIdx, matchRuleIdx)
path := fmt.Sprintf("@rule%d-route%d", pathruleIdx, matchRuleIdx)
return createMatchLocation(path), createHTTPMatch(match, path)
}

Expand Down Expand Up @@ -443,8 +443,7 @@ func createProxyPass(backendGroup dataplane.BackendGroup, filter *dataplane.HTTP

func createMatchLocation(path string) http.Location {
return http.Location{
Path: path,
Internal: true,
Path: path,
}
}

Expand Down Expand Up @@ -538,10 +537,6 @@ func createPath(rule dataplane.PathRule) string {
}
}

func createPathForMatch(ruleIdx, routeIdx int) string {
return fmt.Sprintf("@rule%d-route%d", ruleIdx, routeIdx)
}

func createDefaultRootLocation() http.Location {
return http.Location{
Path: "/",
Expand Down
35 changes: 1 addition & 34 deletions internal/mode/static/nginx/config/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,19 +554,16 @@ func TestCreateServers(t *testing.T) {
return []http.Location{
{
Path: "@rule0-route0",
Internal: true,
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: baseHeaders,
},
{
Path: "@rule0-route1",
Internal: true,
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: baseHeaders,
},
{
Path: "@rule0-route2",
Internal: true,
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: baseHeaders,
},
Expand All @@ -576,7 +573,6 @@ func TestCreateServers(t *testing.T) {
},
{
Path: "@rule1-route0",
Internal: true,
ProxyPass: "http://$test__route1_rule1$request_uri",
ProxySetHeaders: baseHeaders,
},
Expand Down Expand Up @@ -628,7 +624,6 @@ func TestCreateServers(t *testing.T) {
Body: "$scheme://foo.example.com:8080$request_uri",
Code: 302,
},
Internal: true,
},
{
Path: "/redirect-with-headers/",
Expand All @@ -653,7 +648,6 @@ func TestCreateServers(t *testing.T) {
{
Path: "@rule7-route0",
Rewrites: []string{"^/rewrite-with-headers(.*)$ /prefix-replacement$1 break"},
Internal: true,
ProxyPass: "http://test_foo_80",
ProxySetHeaders: rewriteProxySetHeaders,
},
Expand Down Expand Up @@ -682,7 +676,6 @@ func TestCreateServers(t *testing.T) {
Return: &http.Return{
Code: http.StatusInternalServerError,
},
Internal: true,
},
{
Path: "/invalid-filter-with-headers/",
Expand All @@ -701,7 +694,6 @@ func TestCreateServers(t *testing.T) {
Path: "@rule11-route0",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: baseHeaders,
Internal: true,
},
{
Path: "= /test",
Expand Down Expand Up @@ -1687,38 +1679,13 @@ func TestCreateMatchLocation(t *testing.T) {
g := NewWithT(t)

expected := http.Location{
Path: "/path",
Internal: true,
Path: "/path",
}

result := createMatchLocation("/path")
g.Expect(result).To(Equal(expected))
}

func TestCreatePathForMatch(t *testing.T) {
g := NewWithT(t)

tests := []struct {
expected string
pathType dataplane.PathType
panic bool
}{
{
expected: "@rule0-route1",
pathType: dataplane.PathTypePrefix,
},
{
expected: "@rule0-route1",
pathType: dataplane.PathTypeExact,
},
}

for _, tc := range tests {
result := createPathForMatch(0, 1)
g.Expect(result).To(Equal(tc.expected))
}
}

func TestGenerateProxySetHeaders(t *testing.T) {
tests := []struct {
filters *dataplane.HTTPFilters
Expand Down

0 comments on commit 84f47f0

Please sign in to comment.