Skip to content

Commit

Permalink
Merge branch 'master' into apim-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jananivMS authored Apr 15, 2020
2 parents e55c571 + 4515608 commit 701a66b
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 1 deletion.
2 changes: 1 addition & 1 deletion controllers/postgresql_combined_controller_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

// +build all psql psqldatabase
// +build all psql

package controllers

Expand Down
73 changes: 73 additions & 0 deletions controllers/postgresqldatabase_controller_test.go
Original file line number Diff line number Diff line change
@@ -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)

}
75 changes: 75 additions & 0 deletions controllers/postgresqlfirewallrule_controller_test.go
Original file line number Diff line number Diff line change
@@ -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)

}
52 changes: 52 additions & 0 deletions controllers/postgresqlserver_controller_test.go
Original file line number Diff line number Diff line change
@@ -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)

}

0 comments on commit 701a66b

Please sign in to comment.