From 242eeb89b007c9e229b0a7e3daf73342b71a0fdd Mon Sep 17 00:00:00 2001 From: Simon Beck Date: Fri, 3 May 2024 10:04:18 +0200 Subject: [PATCH] Fix tests --- .../functions/vshnpostgres/loadBalancer.go | 2 +- .../vshnpostgres/loadBalancer_test.go | 18 ++++++++---------- .../functions/vshnpostgres/register.go | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/pkg/comp-functions/functions/vshnpostgres/loadBalancer.go b/pkg/comp-functions/functions/vshnpostgres/loadBalancer.go index e152996e9..eab59f696 100644 --- a/pkg/comp-functions/functions/vshnpostgres/loadBalancer.go +++ b/pkg/comp-functions/functions/vshnpostgres/loadBalancer.go @@ -17,7 +17,7 @@ import ( var serviceName = "primary-service" -func AddLoadBalancerIPToConnectionDetails(ctx context.Context, svc *runtime.ServiceRuntime) *xfnproto.Result { +func AddPrimaryService(ctx context.Context, svc *runtime.ServiceRuntime) *xfnproto.Result { comp, err := getVSHNPostgreSQL(ctx, svc) diff --git a/pkg/comp-functions/functions/vshnpostgres/loadBalancer_test.go b/pkg/comp-functions/functions/vshnpostgres/loadBalancer_test.go index bfbede536..c0180ee81 100644 --- a/pkg/comp-functions/functions/vshnpostgres/loadBalancer_test.go +++ b/pkg/comp-functions/functions/vshnpostgres/loadBalancer_test.go @@ -18,13 +18,11 @@ func TestNothingToDo(t *testing.T) { svc.Config.Data["externalDatabaseConnectionsEnabled"] = "true" // When - result := AddLoadBalancerIPToConnectionDetails(ctx, svc) + result := AddPrimaryService(ctx, svc) desired := svc.GetAllDesired() - if len(desired) != 2 { - t.Fatal("Expected 2 resources in desired, got", len(desired)) - } + assert.Len(t, desired, 2) // Then assert.NotNil(t, result) @@ -42,7 +40,7 @@ func TestLoadBalancerParameterSet(t *testing.T) { svc.Config.Data["externalDatabaseConnectionsEnabled"] = "true" // When - result := AddLoadBalancerIPToConnectionDetails(ctx, svc) + result := AddPrimaryService(ctx, svc) // Then assert.NotNil(t, result) @@ -59,26 +57,26 @@ func TestLoadBalancerServiceObserverCreated(t *testing.T) { svc.Config.Data["externalDatabaseConnectionsEnabled"] = "true" // When - result := AddLoadBalancerIPToConnectionDetails(ctx, svc) + result := AddPrimaryService(ctx, svc) // Then assert.Nil(t, result) }) } -// this test normally should return Warning because it's copy of TestLoadBalancerParameterSet() -// but due to disabled LoadBalancer in config it returns Normal +// The primary-service should be deployed even if loadbalancing is disabled. +// However it should not be allowed to be set to type LoadBalancer. func TestLoadBalancerNotEnabled(t *testing.T) { ctx := context.Background() t.Run("Verify composition", func(t *testing.T) { //Given - svc := commontest.LoadRuntimeFromFile(t, "vshn-postgres/loadbalancer/01-LoadBalancerSet.yaml") + svc := commontest.LoadRuntimeFromFile(t, "vshn-postgres/loadbalancer/02-ServiceObserverPresent.yaml") svc.Config.Data["externalDatabaseConnectionsEnabled"] = "false" // When - result := AddLoadBalancerIPToConnectionDetails(ctx, svc) + result := AddPrimaryService(ctx, svc) // Then assert.Nil(t, result) diff --git a/pkg/comp-functions/functions/vshnpostgres/register.go b/pkg/comp-functions/functions/vshnpostgres/register.go index ede7c7068..5433bd2bd 100644 --- a/pkg/comp-functions/functions/vshnpostgres/register.go +++ b/pkg/comp-functions/functions/vshnpostgres/register.go @@ -51,7 +51,7 @@ func init() { }, { Name: "load-balancer", - Execute: AddLoadBalancerIPToConnectionDetails, + Execute: AddPrimaryService, }, { Name: "namespaceQuotas",