Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Sep 12, 2024
1 parent f694a85 commit 42be084
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
26 changes: 14 additions & 12 deletions pkg/test/cel/backendtlspolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
"sigs.k8s.io/gateway-api/apis/v1beta1"
)

func TestBackendTLSPolicyValidation(t *testing.T) {
Expand All @@ -50,7 +52,7 @@ func TestBackendTLSPolicyValidation(t *testing.T) {
routeConfig: gatewayv1a3.BackendTLSPolicyValidation{
CACertificateRefs: []v1beta1.LocalObjectReference{
{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand All @@ -69,7 +71,7 @@ func TestBackendTLSPolicyValidation(t *testing.T) {
routeConfig: gatewayv1a3.BackendTLSPolicyValidation{
CACertificateRefs: []v1beta1.LocalObjectReference{
{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand All @@ -93,7 +95,7 @@ func TestBackendTLSPolicyValidation(t *testing.T) {
routeConfig: gatewayv1a3.BackendTLSPolicyValidation{
CACertificateRefs: []v1beta1.LocalObjectReference{
{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand All @@ -107,7 +109,7 @@ func TestBackendTLSPolicyValidation(t *testing.T) {
routeConfig: gatewayv1a3.BackendTLSPolicyValidation{
CACertificateRefs: []v1beta1.LocalObjectReference{
{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand All @@ -127,7 +129,7 @@ func TestBackendTLSPolicyValidation(t *testing.T) {
routeConfig: gatewayv1a3.BackendTLSPolicyValidation{
CACertificateRefs: []v1beta1.LocalObjectReference{
{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand All @@ -147,7 +149,7 @@ func TestBackendTLSPolicyValidation(t *testing.T) {
routeConfig: gatewayv1a3.BackendTLSPolicyValidation{
CACertificateRefs: []v1beta1.LocalObjectReference{
{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand All @@ -167,7 +169,7 @@ func TestBackendTLSPolicyValidation(t *testing.T) {
routeConfig: gatewayv1a3.BackendTLSPolicyValidation{
CACertificateRefs: []v1beta1.LocalObjectReference{
{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand All @@ -187,7 +189,7 @@ func TestBackendTLSPolicyValidation(t *testing.T) {
routeConfig: gatewayv1a3.BackendTLSPolicyValidation{
CACertificateRefs: []v1beta1.LocalObjectReference{
{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand All @@ -207,7 +209,7 @@ func TestBackendTLSPolicyValidation(t *testing.T) {
routeConfig: gatewayv1a3.BackendTLSPolicyValidation{
CACertificateRefs: []v1beta1.LocalObjectReference{
{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand All @@ -227,7 +229,7 @@ func TestBackendTLSPolicyValidation(t *testing.T) {
routeConfig: gatewayv1a3.BackendTLSPolicyValidation{
CACertificateRefs: []v1beta1.LocalObjectReference{
{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand All @@ -248,7 +250,7 @@ func TestBackendTLSPolicyValidation(t *testing.T) {
routeConfig: gatewayv1a3.BackendTLSPolicyValidation{
CACertificateRefs: []v1beta1.LocalObjectReference{
{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand Down
18 changes: 9 additions & 9 deletions pkg/test/cel/grpcroute_experimental_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestGRPCRequestMirrorFilterExperimental(t *testing.T) {
rules []gatewayv1.GRPCRouteRule
}{
{
name: "GRPCRoute - Invalid because both percent and fraction are specified",
name: "GRPCRoute - Invalid because both percent and fraction are specified",
wantErrors: []string{"Only one of percent or fraction may be specified in HTTPRequestMirrorFilter"},
rules: []gatewayv1.GRPCRouteRule{{
Filters: []gatewayv1.GRPCRouteFilter{{
Expand All @@ -67,15 +67,15 @@ func TestGRPCRequestMirrorFilterExperimental(t *testing.T) {
},
Percent: &percent,
Fraction: &gatewayv1.Fraction{
Numerator: 83,
Numerator: 83,
Denominator: &denominator,
},
},
}},
}},
},
{
name: "GRPCRoute - Invalid fraction - numerator greater than denominator",
name: "GRPCRoute - Invalid fraction - numerator greater than denominator",
wantErrors: []string{"numerator must be less than or equal to denominator"},
rules: []gatewayv1.GRPCRouteRule{{
Filters: []gatewayv1.GRPCRouteFilter{{
Expand All @@ -86,15 +86,15 @@ func TestGRPCRequestMirrorFilterExperimental(t *testing.T) {
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: 1001,
Numerator: 1001,
Denominator: &denominator,
},
},
}},
}},
},
{
name: "GRPCRoute - Invalid fraction - denominator is 0",
name: "GRPCRoute - Invalid fraction - denominator is 0",
wantErrors: []string{"spec.rules[0].filters[0].requestMirror.fraction.denominator in body should be greater than or equal to 1"},
rules: []gatewayv1.GRPCRouteRule{{
Filters: []gatewayv1.GRPCRouteFilter{{
Expand All @@ -105,15 +105,15 @@ func TestGRPCRequestMirrorFilterExperimental(t *testing.T) {
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: 0,
Numerator: 0,
Denominator: &bad_denominator,
},
},
}},
}},
},
{
name: "GRPCRoute - Invalid fraction - numerator is negative",
name: "GRPCRoute - Invalid fraction - numerator is negative",
wantErrors: []string{"spec.rules[0].filters[0].requestMirror.fraction.numerator in body should be greater than or equal to 0"},
rules: []gatewayv1.GRPCRouteRule{{
Filters: []gatewayv1.GRPCRouteFilter{{
Expand All @@ -124,7 +124,7 @@ func TestGRPCRequestMirrorFilterExperimental(t *testing.T) {
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: -1,
Numerator: -1,
Denominator: &denominator,
},
},
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestGRPCRequestMirrorFilterExperimental(t *testing.T) {
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: 83,
Numerator: 83,
Denominator: &denominator,
},
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/test/cel/grpcroute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
)

func TestGRPCRouteFilter(t *testing.T) {
Expand Down Expand Up @@ -121,7 +122,7 @@ func TestGRPCRouteFilter(t *testing.T) {
routeFilter: gatewayv1.GRPCRouteFilter{
Type: gatewayv1.GRPCRouteFilterExtensionRef,
ExtensionRef: &gatewayv1.LocalObjectReference{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand Down
18 changes: 9 additions & 9 deletions pkg/test/cel/httproute_experimental_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) {
rules []gatewayv1.HTTPRouteRule
}{
{
name: "HTTPRoute - Invalid because both percent and fraction are specified",
name: "HTTPRoute - Invalid because both percent and fraction are specified",
wantErrors: []string{"Only one of percent or fraction may be specified in HTTPRequestMirrorFilter"},
rules: []gatewayv1.HTTPRouteRule{{
Filters: []gatewayv1.HTTPRouteFilter{{
Expand All @@ -456,15 +456,15 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) {
},
Percent: &percent,
Fraction: &gatewayv1.Fraction{
Numerator: 83,
Numerator: 83,
Denominator: &denominator,
},
},
}},
}},
},
{
name: "HTTPRoute - Invalid fraction - numerator greater than denominator",
name: "HTTPRoute - Invalid fraction - numerator greater than denominator",
wantErrors: []string{"numerator must be less than or equal to denominator"},
rules: []gatewayv1.HTTPRouteRule{{
Filters: []gatewayv1.HTTPRouteFilter{{
Expand All @@ -475,15 +475,15 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) {
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: 1001,
Numerator: 1001,
Denominator: &denominator,
},
},
}},
}},
},
{
name: "HTTPRoute - Invalid fraction - denominator is 0",
name: "HTTPRoute - Invalid fraction - denominator is 0",
wantErrors: []string{"spec.rules[0].filters[0].requestMirror.fraction.denominator in body should be greater than or equal to 1"},
rules: []gatewayv1.HTTPRouteRule{{
Filters: []gatewayv1.HTTPRouteFilter{{
Expand All @@ -494,15 +494,15 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) {
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: 0,
Numerator: 0,
Denominator: &bad_denominator,
},
},
}},
}},
},
{
name: "HTTPRoute - Invalid fraction - numerator is negative",
name: "HTTPRoute - Invalid fraction - numerator is negative",
wantErrors: []string{"spec.rules[0].filters[0].requestMirror.fraction.numerator in body should be greater than or equal to 0"},
rules: []gatewayv1.HTTPRouteRule{{
Filters: []gatewayv1.HTTPRouteFilter{{
Expand All @@ -513,7 +513,7 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) {
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: -1,
Numerator: -1,
Denominator: &denominator,
},
},
Expand Down Expand Up @@ -546,7 +546,7 @@ func TestHTTPRequestMirrorFilterExperimental(t *testing.T) {
Port: ptrTo(gatewayv1.PortNumber(8081)),
},
Fraction: &gatewayv1.Fraction{
Numerator: 83,
Numerator: 83,
Denominator: &denominator,
},
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/test/cel/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)
Expand Down Expand Up @@ -330,7 +331,7 @@ func TestHTTPRouteFilter(t *testing.T) {
routeFilter: gatewayv1.HTTPRouteFilter{
Type: gatewayv1.HTTPRouteFilterExtensionRef,
ExtensionRef: &gatewayv1.LocalObjectReference{
Group: "group",
Group: ptr.To[gatewayv1.Group]("group"),
Kind: "kind",
Name: "name",
},
Expand Down

0 comments on commit 42be084

Please sign in to comment.