Skip to content

Commit

Permalink
update based on reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
salonichf5 committed Feb 7, 2025
1 parent 2a8b719 commit 32f4173
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 221 deletions.
52 changes: 19 additions & 33 deletions internal/mode/static/nginx/config/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,20 +589,6 @@ func TestExecuteForDefaultServers(t *testing.T) {
}
}

func getHeaderMatchType(matchType string) dataplane.MatchType {
if len(matchType) == 0 {
return dataplane.MatchTypeExact
}
return dataplane.MatchType(matchType)
}

func getQueryParamMatchType(matchType string) dataplane.MatchType {
if len(matchType) == 0 {
return dataplane.MatchTypeExact
}
return dataplane.MatchType(matchType)
}

func TestCreateServers(t *testing.T) {
t.Parallel()
const (
Expand Down Expand Up @@ -724,30 +710,30 @@ func TestCreateServers(t *testing.T) {
{
Name: "Version",
Value: "V1",
Type: getHeaderMatchType(""),
Type: dataplane.MatchTypeExact,
},
{
Name: "test",
Value: "foo",
Type: getHeaderMatchType(""),
Type: dataplane.MatchTypeExact,
},
{
Name: "my-header",
Value: "my-value",
Type: getHeaderMatchType(""),
Type: dataplane.MatchTypeExact,
},
},
QueryParams: []dataplane.HTTPQueryParamMatch{
{
// query names and values should not be normalized to lowercase
Name: "GrEat",
Value: "EXAMPLE",
Type: getQueryParamMatchType(""),
Type: dataplane.MatchTypeExact,
},
{
Name: "test",
Value: "foo=bar",
Type: getQueryParamMatchType(""),
Type: dataplane.MatchTypeExact,
},
},
},
Expand Down Expand Up @@ -816,7 +802,7 @@ func TestCreateServers(t *testing.T) {
{
Name: "redirect",
Value: "this",
Type: getHeaderMatchType(""),
Type: dataplane.MatchTypeExact,
},
},
},
Expand Down Expand Up @@ -859,7 +845,7 @@ func TestCreateServers(t *testing.T) {
{
Name: "rewrite",
Value: "this",
Type: getHeaderMatchType(""),
Type: dataplane.MatchTypeExact,
},
},
},
Expand Down Expand Up @@ -899,7 +885,7 @@ func TestCreateServers(t *testing.T) {
{
Name: "filter",
Value: "this",
Type: getHeaderMatchType(""),
Type: dataplane.MatchTypeExact,
},
},
},
Expand Down Expand Up @@ -2724,17 +2710,17 @@ func TestCreateRouteMatch(t *testing.T) {
{
Name: "header-1",
Value: "val-1",
Type: getHeaderMatchType(""),
Type: dataplane.MatchTypeExact,
},
{
Name: "header-2",
Value: "val-2",
Type: getHeaderMatchType(""),
Type: dataplane.MatchTypeExact,
},
{
Name: "header-3",
Value: "val-3",
Type: getHeaderMatchType(""),
Type: dataplane.MatchTypeExact,
},
}

Expand All @@ -2750,17 +2736,17 @@ func TestCreateRouteMatch(t *testing.T) {
{
Name: "arg1",
Value: "val1",
Type: getQueryParamMatchType(""),
Type: dataplane.MatchTypeExact,
},
{
Name: "arg2",
Value: "val2=another-val",
Type: getQueryParamMatchType(""),
Type: dataplane.MatchTypeExact,
},
{
Name: "arg3",
Value: "==val3",
Type: getQueryParamMatchType(""),
Type: dataplane.MatchTypeExact,
},
}

Expand Down Expand Up @@ -2895,7 +2881,7 @@ func TestCreateQueryParamKeyValString(t *testing.T) {
input: dataplane.HTTPQueryParamMatch{
Name: "key",
Value: "value",
Type: getQueryParamMatchType(string(dataplane.MatchTypeExact)),
Type: dataplane.MatchTypeExact,
},
expected: "key=Exact=value",
},
Expand All @@ -2904,7 +2890,7 @@ func TestCreateQueryParamKeyValString(t *testing.T) {
input: dataplane.HTTPQueryParamMatch{
Name: "KeY",
Value: "vaLUe-[a-z]==",
Type: getQueryParamMatchType(string(dataplane.MatchTypeRegularExpression)),
Type: dataplane.MatchTypeRegularExpression,
},
expected: "KeY=RegularExpression=vaLUe-[a-z]==",
},
Expand All @@ -2913,7 +2899,7 @@ func TestCreateQueryParamKeyValString(t *testing.T) {
input: dataplane.HTTPQueryParamMatch{
Name: "keY",
Value: "vaLUe==",
Type: getQueryParamMatchType(""),
Type: dataplane.MatchTypeExact,
},
expected: "keY=Exact=vaLUe==",
},
Expand All @@ -2939,7 +2925,7 @@ func TestCreateHeaderKeyValString(t *testing.T) {
dataplane.HTTPHeaderMatch{
Name: "kEy",
Value: "vALUe",
Type: getHeaderMatchType(string(dataplane.MatchTypeExact)),
Type: dataplane.MatchTypeExact,
},
)

Expand All @@ -2951,7 +2937,7 @@ func TestCreateHeaderKeyValString(t *testing.T) {
dataplane.HTTPHeaderMatch{
Name: "kEy",
Value: "vALUe-[0-9]",
Type: getHeaderMatchType(string(dataplane.MatchTypeRegularExpression)),
Type: dataplane.MatchTypeRegularExpression,
},
)

Expand Down
7 changes: 4 additions & 3 deletions internal/mode/static/state/graph/grpcroute.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package graph

import (
"fmt"

"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
v1 "sigs.k8s.io/gateway-api/apis/v1"
Expand Down Expand Up @@ -225,13 +223,16 @@ func ConvertGRPCMatches(grpcMatches []v1.GRPCRouteMatch) []v1.HTTPRouteMatch {
}

func convertGRPCHeaderMatchType(matchType *v1.GRPCHeaderMatchType) *v1.HeaderMatchType {
if matchType == nil {
return nil
}
switch *matchType {
case v1.GRPCHeaderMatchExact:
return helpers.GetPointer(v1.HeaderMatchExact)
case v1.GRPCHeaderMatchRegularExpression:
return helpers.GetPointer(v1.HeaderMatchRegularExpression)
default:
panic(fmt.Sprintf("unsupported header match type: %v", matchType))
return nil
}
}

Expand Down
Loading

0 comments on commit 32f4173

Please sign in to comment.