diff --git a/controllers/postgresql_combined_controller_test.go b/controllers/postgresql_combined_controller_test.go index 31d2c6a12aa..9d4e1bb567f 100644 --- a/controllers/postgresql_combined_controller_test.go +++ b/controllers/postgresql_combined_controller_test.go @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -// +build all psql psqldatabase +// +build all psql package controllers diff --git a/controllers/postgresqldatabase_controller_test.go b/controllers/postgresqldatabase_controller_test.go new file mode 100644 index 00000000000..2254fee4212 --- /dev/null +++ b/controllers/postgresqldatabase_controller_test.go @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// +build all psqldatabase + +package controllers + +import ( + "context" + "testing" + + azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" + "github.com/Azure/azure-service-operator/pkg/errhelp" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +//Postgresql database controller unhappy test cases + +func TestPSQLDatabaseControllerNoResourceGroup(t *testing.T) { + t.Parallel() + defer PanicRecover(t) + ctx := context.Background() + + // Add any setup steps that needs to be executed before each test + rgName := GenerateTestResourceNameWithRandom("psqlsrv-rg", 10) + + postgreSQLServerName := GenerateTestResourceNameWithRandom("psql-srv", 10) + postgreSQLDatabaseName := GenerateTestResourceNameWithRandom("psql-db", 10) + + // Create the PostgreSQLDatabase object and expect the Reconcile to be created + postgreSQLDatabaseInstance1 := &azurev1alpha1.PostgreSQLDatabase{ + ObjectMeta: metav1.ObjectMeta{ + Name: postgreSQLDatabaseName, + Namespace: "default", + }, + Spec: azurev1alpha1.PostgreSQLDatabaseSpec{ + ResourceGroup: rgName, + Server: postgreSQLServerName, + }, + } + + EnsureInstanceWithResult(ctx, t, tc, postgreSQLDatabaseInstance1, errhelp.ResourceGroupNotFoundErrorCode, false) + EnsureDelete(ctx, t, tc, postgreSQLDatabaseInstance1) + +} + +func TestPSQLDatabaseControllerNoSever(t *testing.T) { + t.Parallel() + defer PanicRecover(t) + ctx := context.Background() + + // Add any setup steps that needs to be executed before each test + rgName := tc.resourceGroupName + + postgreSQLServerName := GenerateTestResourceNameWithRandom("psql-srv", 10) + postgreSQLDatabaseName := GenerateTestResourceNameWithRandom("psql-db", 10) + + // Create the PostgreSQLDatabase object and expect the Reconcile to be created + postgreSQLDatabaseInstance2 := &azurev1alpha1.PostgreSQLDatabase{ + ObjectMeta: metav1.ObjectMeta{ + Name: postgreSQLDatabaseName, + Namespace: "default", + }, + Spec: azurev1alpha1.PostgreSQLDatabaseSpec{ + ResourceGroup: rgName, + Server: postgreSQLServerName, + }, + } + + EnsureInstanceWithResult(ctx, t, tc, postgreSQLDatabaseInstance2, errhelp.ResourceNotFound, false) + EnsureDelete(ctx, t, tc, postgreSQLDatabaseInstance2) + +} diff --git a/controllers/postgresqlfirewallrule_controller_test.go b/controllers/postgresqlfirewallrule_controller_test.go new file mode 100644 index 00000000000..4805e8bb26e --- /dev/null +++ b/controllers/postgresqlfirewallrule_controller_test.go @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// +build all psqlfirewallrule + +package controllers + +import ( + "context" + "testing" + + azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" + "github.com/Azure/azure-service-operator/pkg/errhelp" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestPSQLFirewallRuleControllerNoResourceGroup(t *testing.T) { + t.Parallel() + defer PanicRecover(t) + ctx := context.Background() + + // Add any setup steps that needs to be executed before each test + rgName := GenerateTestResourceNameWithRandom("psqlsrv-rg", 10) + + postgreSQLServerName := GenerateTestResourceNameWithRandom("psql-srv", 10) + postgreSQLFirewallRuleName := GenerateTestResourceNameWithRandom("psql-fwrule", 10) + + // Create the PostgreSQLFirewallRule object and expect the Reconcile to be created + postgreSQLFirewallRuleInstance := &azurev1alpha1.PostgreSQLFirewallRule{ + ObjectMeta: metav1.ObjectMeta{ + Name: postgreSQLFirewallRuleName, + Namespace: "default", + }, + Spec: azurev1alpha1.PostgreSQLFirewallRuleSpec{ + ResourceGroup: rgName, + Server: postgreSQLServerName, + StartIPAddress: "0.0.0.0", + EndIPAddress: "0.0.0.0", + }, + } + + EnsureInstanceWithResult(ctx, t, tc, postgreSQLFirewallRuleInstance, errhelp.ResourceGroupNotFoundErrorCode, false) + EnsureDelete(ctx, t, tc, postgreSQLFirewallRuleInstance) + +} + +func TestPSQLFirewallRuleControllerNoServer(t *testing.T) { + t.Parallel() + defer PanicRecover(t) + ctx := context.Background() + + // Add any setup steps that needs to be executed before each test + rgName := tc.resourceGroupName + + postgreSQLServerName := GenerateTestResourceNameWithRandom("psql-srv", 10) + postgreSQLFirewallRuleName := GenerateTestResourceNameWithRandom("psql-fwrule", 10) + + // Create the PostgreSQLFirewallRule object and expect the Reconcile to be created + postgreSQLFirewallRuleInstance := &azurev1alpha1.PostgreSQLFirewallRule{ + ObjectMeta: metav1.ObjectMeta{ + Name: postgreSQLFirewallRuleName, + Namespace: "default", + }, + Spec: azurev1alpha1.PostgreSQLFirewallRuleSpec{ + ResourceGroup: rgName, + Server: postgreSQLServerName, + StartIPAddress: "0.0.0.0", + EndIPAddress: "0.0.0.0", + }, + } + + EnsureInstanceWithResult(ctx, t, tc, postgreSQLFirewallRuleInstance, errhelp.ResourceNotFound, false) + EnsureDelete(ctx, t, tc, postgreSQLFirewallRuleInstance) + +} diff --git a/controllers/postgresqlserver_controller_test.go b/controllers/postgresqlserver_controller_test.go new file mode 100644 index 00000000000..c97948d06d6 --- /dev/null +++ b/controllers/postgresqlserver_controller_test.go @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// +build all psqlserver + +package controllers + +import ( + "context" + "testing" + + azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" + "github.com/Azure/azure-service-operator/pkg/errhelp" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +//test Postgre SQL server unhappy path +func TestPSQLServerControllerNoResourceGroup(t *testing.T) { + t.Parallel() + defer PanicRecover(t) + ctx := context.Background() + + // Add any setup steps that needs to be executed before each test + rgName := GenerateTestResourceNameWithRandom("psqlsrv-rg", 10) + rgLocation := tc.resourceGroupLocation + + postgreSQLServerName := GenerateTestResourceNameWithRandom("psql-srv", 10) + + // Create the PostgreSQLServer object and expect the Reconcile to be created + postgreSQLServerInstance := &azurev1alpha1.PostgreSQLServer{ + ObjectMeta: metav1.ObjectMeta{ + Name: postgreSQLServerName, + Namespace: "default", + }, + Spec: azurev1alpha1.PostgreSQLServerSpec{ + Location: rgLocation, + ResourceGroup: rgName, + Sku: azurev1alpha1.AzureDBsSQLSku{ + Name: "B_Gen5_2", + Tier: azurev1alpha1.SkuTier("Basic"), + Family: "Gen5", + Size: "51200", + Capacity: 2, + }, + ServerVersion: azurev1alpha1.ServerVersion("10"), + SSLEnforcement: azurev1alpha1.SslEnforcementEnumEnabled, + }, + } + EnsureInstanceWithResult(ctx, t, tc, postgreSQLServerInstance, errhelp.ResourceGroupNotFoundErrorCode, false) + EnsureDelete(ctx, t, tc, postgreSQLServerInstance) + +}