Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidswiss committed May 3, 2024
1 parent 5852f79 commit 242eeb8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/comp-functions/functions/vshnpostgres/loadBalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 8 additions & 10 deletions pkg/comp-functions/functions/vshnpostgres/loadBalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/comp-functions/functions/vshnpostgres/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func init() {
},
{
Name: "load-balancer",
Execute: AddLoadBalancerIPToConnectionDetails,
Execute: AddPrimaryService,
},
{
Name: "namespaceQuotas",
Expand Down

0 comments on commit 242eeb8

Please sign in to comment.