Skip to content

Commit

Permalink
Move test variables as const and var.
Browse files Browse the repository at this point in the history
  • Loading branch information
sawsa307 committed Sep 17, 2024
1 parent 08ed162 commit 08a3fef
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 43 deletions.
64 changes: 35 additions & 29 deletions pkg/i2gw/providers/gce/gateway_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,14 @@ import (
"sigs.k8s.io/gateway-api/apis/v1alpha2"
)

func Test_irToGateway(t *testing.T) {
testNamespace := "default"
testHost := "test.mydomain.com"
testServiceName := "test-service"
testGatewayName := "test-gateway"
testHTTPRouteName := "test-http-route"

gPathPrefix := gatewayv1.PathMatchPathPrefix
saTypeClientIP := "CLIENT_IP"
testCookieTTLSec := int64(10)
saTypeCookie := "GENERATED_COOKIE"
testSecurityPolicy := "test-security-policy"
const (
testGatewayName = "test-gateway"
testHTTPRouteName = "test-http-route"
testSaBackendPolicyName = testServiceName
)

testGateway := gatewayv1.Gateway{
var (
testGateway = gatewayv1.Gateway{
ObjectMeta: metav1.ObjectMeta{Name: testGatewayName, Namespace: testNamespace},
Spec: gatewayv1.GatewaySpec{
GatewayClassName: gceL7GlobalExternalManagedGatewayClass,
Expand All @@ -61,7 +55,7 @@ func Test_irToGateway(t *testing.T) {
},
}

testHTTPRoute := gatewayv1.HTTPRoute{
testHTTPRoute = gatewayv1.HTTPRoute{
ObjectMeta: metav1.ObjectMeta{Name: testHTTPRouteName, Namespace: testNamespace},
Spec: gatewayv1.HTTPRouteSpec{
CommonRouteSpec: gatewayv1.CommonRouteSpec{
Expand Down Expand Up @@ -95,8 +89,11 @@ func Test_irToGateway(t *testing.T) {
},
}

testSaBackendPolicyName := testServiceName
testSaGCPBackendPolicyCookie := gkegatewayv1.GCPBackendPolicy{
testSaGCPBackendPolicyCookie = gkegatewayv1.GCPBackendPolicy{
TypeMeta: metav1.TypeMeta{
APIVersion: "networking.gke.io/v1",
Kind: "GCPBackendPolicy",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: testSaBackendPolicyName,
Expand All @@ -115,13 +112,12 @@ func Test_irToGateway(t *testing.T) {
},
},
}
testSaGCPBackendPolicyCookie.SetGroupVersionKind(GCPBackendPolicyGVK)
testSaGCPBackendPolicyCookieUnstructured, err := i2gw.CastToUnstructured(&testSaGCPBackendPolicyCookie)
if err != nil {
t.Errorf("Failed to generate unstructured GCP Backend Policy with Cookie-based session affinity feature: %v", err)
}

testSaGCPBackendPolicyClientIP := gkegatewayv1.GCPBackendPolicy{
testSaGCPBackendPolicyClientIP = gkegatewayv1.GCPBackendPolicy{
TypeMeta: metav1.TypeMeta{
APIVersion: "networking.gke.io/v1",
Kind: "GCPBackendPolicy",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: testSaBackendPolicyName,
Expand All @@ -139,13 +135,12 @@ func Test_irToGateway(t *testing.T) {
},
},
}
testSaGCPBackendPolicyClientIP.SetGroupVersionKind(GCPBackendPolicyGVK)
testSaGCPBackendPolicyClientIPUnstructured, err := i2gw.CastToUnstructured(&testSaGCPBackendPolicyClientIP)
if err != nil {
t.Errorf("Failed to generate unstructured GCP Backend Policy with ClientIP-based session affinity feature: %v", err)
}

testSpGCPBackendPolicy := gkegatewayv1.GCPBackendPolicy{
testSpGCPBackendPolicy = gkegatewayv1.GCPBackendPolicy{
TypeMeta: metav1.TypeMeta{
APIVersion: "networking.gke.io/v1",
Kind: "GCPBackendPolicy",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: testSaBackendPolicyName,
Expand All @@ -161,11 +156,22 @@ func Test_irToGateway(t *testing.T) {
},
},
}
testSpGCPBackendPolicy.SetGroupVersionKind(GCPBackendPolicyGVK)
)

func Test_irToGateway(t *testing.T) {
testSaGCPBackendPolicyCookieUnstructured, err := i2gw.CastToUnstructured(&testSaGCPBackendPolicyCookie)
if err != nil {
t.Errorf("Failed to generate unstructured GCP Backend Policy with Cookie-based session affinity feature: %v", err)
}
testSaGCPBackendPolicyClientIPUnstructured, err := i2gw.CastToUnstructured(&testSaGCPBackendPolicyClientIP)
if err != nil {
t.Errorf("Failed to generate unstructured GCP Backend Policy with ClientIP-based session affinity feature: %v", err)
}
testSpGCPBackendPolicyUnstructured, err := i2gw.CastToUnstructured(&testSpGCPBackendPolicy)
if err != nil {
t.Errorf("Failed to generate unstructured GCP Backend Policy with Security Policy feature: %v", err)
}

testCases := []struct {
name string
ir intermediate.IR
Expand Down
33 changes: 19 additions & 14 deletions pkg/i2gw/providers/gce/ir_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,31 @@ import (
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)

func Test_convertToIR(t *testing.T) {
testNamespace := "default"
testHost := "test.mydomain.com"
testServiceName := "test-service"
testBackendConfigName := "test-backendconfig"
iPrefix := networkingv1.PathTypePrefix
implSpecificPathType := networkingv1.PathTypeImplementationSpecific
const (
testNamespace = "default"
testHost = "test.mydomain.com"
testServiceName = "test-service"
testBackendConfigName = "test-backendconfig"

saTypeClientIP = "CLIENT_IP"
saTypeCookie = "GENERATED_COOKIE"
)

gPathPrefix := gatewayv1.PathMatchPathPrefix
gExact := gatewayv1.PathMatchExact
var (
// These variables are referenced by pointers.
testSecurityPolicy = "test-security-policy"
testCookieTTLSec = int64(10)
iPrefix = networkingv1.PathTypePrefix
gPathPrefix = gatewayv1.PathMatchPathPrefix
gExact = gatewayv1.PathMatchExact
implSpecificPathType = networkingv1.PathTypeImplementationSpecific
)

func Test_convertToIR(t *testing.T) {
extIngClassIngressName := "gce-ingress-class"
intIngClassIngressName := "gce-internal-ingress-class"
noIngClassIngressName := "no-ingress-class"

saTypeClientIP := "CLIENT_IP"
testCookieTTLSec := int64(10)
saTypeCookie := "GENERATED_COOKIE"
testSecurityPolicy := "test-security-policy"

testExtIngress := getTestIngress(testNamespace, extIngClassIngressName, testServiceName, true)
testIntIngress := getTestIngress(testNamespace, intIngClassIngressName, testServiceName, false)

Expand Down

0 comments on commit 08a3fef

Please sign in to comment.