From e80143f937f8d709ee19a838879d78ed794f30a8 Mon Sep 17 00:00:00 2001 From: "oliver.michels" Date: Thu, 28 Jan 2021 14:35:01 +0100 Subject: [PATCH 1/4] terratest for azure postgresql --- modules/azure/postgresql.go | 135 ++++++++++++++++++ ...terraform_azure_postgresql_example_test.go | 32 +++++ 2 files changed, 167 insertions(+) create mode 100644 modules/azure/postgresql.go create mode 100644 test/azure/terraform_azure_postgresql_example_test.go diff --git a/modules/azure/postgresql.go b/modules/azure/postgresql.go new file mode 100644 index 000000000..4c1f5222a --- /dev/null +++ b/modules/azure/postgresql.go @@ -0,0 +1,135 @@ +package azure + +import ( + "context" + + "github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql" + "github.com/gruntwork-io/terratest/modules/testing" + "github.com/stretchr/testify/require" +) + +// GetPostgreSQLServerClientE is a helper function that will setup a postgresql server client. +func GetPostgreSQLServerClientE(subscriptionID string) (*postgresql.ServersClient, error) { + // Validate Azure subscription ID + subscriptionID, err := getTargetAzureSubscription(subscriptionID) + if err != nil { + return nil, err + } + + // Create a postgresql server client + postgresqlClient := postgresql.NewServersClient(subscriptionID) + + // Create an authorizer + authorizer, err := NewAuthorizer() + if err != nil { + return nil, err + } + + // Attach authorizer to the client + postgresqlClient.Authorizer = *authorizer + + return &postgresqlClient, nil +} + +// GetPostgresqlServer is a helper function that gets the server. +// This function would fail the test if there is an error. +func GetPostgresqlServer(t testing.TestingT, resGroupName string, serverName string, subscriptionID string) *postgresql.Server { + postgresqlServer, err := GetPostgresqlServerE(t, subscriptionID, resGroupName, serverName) + require.NoError(t, err) + + return postgresqlServer +} + +// GetPostgresqlServerE is a helper function that gets the server. +func GetPostgresqlServerE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) (*postgresql.Server, error) { + // Create a postgresql Server client + postgresqlClient, err := GetPostgreSQLServerClientE(subscriptionID) + if err != nil { + return nil, err + } + + // Get the corresponding server client + postgresqlServer, err := postgresqlClient.Get(context.Background(), resGroupName, serverName) + if err != nil { + return nil, err + } + + //Return server + return &postgresqlServer, nil +} + +// GetPostgresqlDBClientE is a helper function that will setup a postgresql DB client. +func GetPostgresqlDBClientE(subscriptionID string) (*postgresql.DatabasesClient, error) { + // Validate Azure subscription ID + subscriptionID, err := getTargetAzureSubscription(subscriptionID) + if err != nil { + return nil, err + } + + // Create a postgresql db client + postgresqlDBClient := postgresql.NewDatabasesClient(subscriptionID) + + // Create an authorizer + authorizer, err := NewAuthorizer() + if err != nil { + return nil, err + } + + // Attach authorizer to the client + postgresqlDBClient.Authorizer = *authorizer + + return &postgresqlDBClient, nil +} + +//GetPostgresqlDB is a helper function that gets the database. +// This function would fail the test if there is an error. +func GetPostgresqlDB(t testing.TestingT, resGroupName string, serverName string, dbName string, subscriptionID string) *postgresql.Database { + database, err := GetPostgresqlDBE(t, subscriptionID, resGroupName, serverName, dbName) + require.NoError(t, err) + + return database +} + +//GetPostgresqlDBE is a helper function that gets the database. +func GetPostgresqlDBE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string, dbName string) (*postgresql.Database, error) { + // Create a postgresql db client + postgresqldbClient, err := GetPostgresqlDBClientE(subscriptionID) + if err != nil { + return nil, err + } + + // Get the corresponding db client + postgresqlDb, err := postgresqldbClient.Get(context.Background(), resGroupName, serverName, dbName) + if err != nil { + return nil, err + } + + //Return DB + return &postgresqlDb, nil +} + +//ListPostgresqlDB is a helper function that gets all databases per server. +func ListPostgresqlDB(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) []postgresql.Database { + dblist, err := ListPostgresqlDBE(t, subscriptionID, resGroupName, serverName) + require.NoError(t, err) + + return dblist +} + +//ListPostgresqlDBE is a helper function that gets all databases per server. +func ListPostgresqlDBE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) ([]postgresql.Database, error) { + // Create a postgresql db client + postgresqldbClient, err := GetPostgresqlDBClientE(subscriptionID) + if err != nil { + return nil, err + } + + // Get the corresponding db client + postgresqlDbs, err := postgresqldbClient.ListByServer(context.Background(), resGroupName, serverName) + if err != nil { + return nil, err + } + + //Return DB lists + return *postgresqlDbs.Value, nil +} diff --git a/test/azure/terraform_azure_postgresql_example_test.go b/test/azure/terraform_azure_postgresql_example_test.go new file mode 100644 index 000000000..7842e6d72 --- /dev/null +++ b/test/azure/terraform_azure_postgresql_example_test.go @@ -0,0 +1,32 @@ +package test + +import ( + "os" + "testing" + + "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/stretchr/testify/assert" +) + +func TestPostgreSQLDatabase(t *testing.T) { + t.Parallel() + + terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ + TerraformDir: "../../examples/azure/terraform-azure-postgresql-example", + NoColor: true, + }) + defer terraform.Destroy(t, terraformOptions) + terraform.InitAndApply(t, terraformOptions) + subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") + + // get the actual data via terraform output + expectedServername := "terratestdevpostgresqlsrvfoo" // must match fixture + actualServername := terraform.Output(t, terraformOptions, "servername") + rgName := terraform.Output(t, terraformOptions, "rgname") + expectedSkuName := terraform.Output(t, terraformOptions, "sku_name") + actualServer := GetPostgresqlServer(t, rgName, actualServername, subscriptionID) + // Verify + assert.Equal(t, expectedServername, actualServername) + assert.Equal(t, expectedSkuName, *actualServer.Sku.Name) + +} From 6c08bddafc224cdcc4dd895617c2a0844a8dbb36 Mon Sep 17 00:00:00 2001 From: "oliver.michels" Date: Fri, 29 Jan 2021 01:26:52 +0100 Subject: [PATCH 2/4] Enable PostgreSQL testing --- .../README.md | 32 +++++++++++ .../main.tf | 53 +++++++++++++++++++ .../output.tf | 12 +++++ .../variables.tf | 5 ++ modules/azure/postgresql_test.go | 40 ++++++++++++++ ...terraform_azure_postgresql_example_test.go | 23 ++++++-- 6 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 examples/azure/terraform-azure-postgresql-example/README.md create mode 100644 examples/azure/terraform-azure-postgresql-example/main.tf create mode 100644 examples/azure/terraform-azure-postgresql-example/output.tf create mode 100644 examples/azure/terraform-azure-postgresql-example/variables.tf create mode 100644 modules/azure/postgresql_test.go diff --git a/examples/azure/terraform-azure-postgresql-example/README.md b/examples/azure/terraform-azure-postgresql-example/README.md new file mode 100644 index 000000000..825deb532 --- /dev/null +++ b/examples/azure/terraform-azure-postgresql-example/README.md @@ -0,0 +1,32 @@ +# Terraform Azure PostgreSQL DB Example + +This folder contains a Terraform module that deploys resources in [Azure](https://azure.microsoft.com/) to demonstrate how you can use Terratest to write automated tests for your Azure Terraform code. +This module deploys a database for PostgreSQL. + +- A [Azure PostgreSQL Database](https://azure.microsoft.com/services/mysql/). + +Check out [test/azure/terraform_azure_postgresqldb_example_test.go](./../../../test/azure/terraform_azure_postgresqldb_example_test.go) to see how you can write automated tests for this module and validate the configuration of the parameters and options. + +**WARNING**: This module and the automated tests for it deploy real resources into your Azure account which can cost you money. + +## Running this module manually +1. Sign up for [Azure](https://azure.microsoft.com/). +1. Configure your Azure credentials using one of the [supported methods for Azure CLI + tools](https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest) +1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. +1. Ensure [environment variables](../README.md#review-environment-variables) are available +1. Run `terraform init` +1. Run `terraform apply` +1. When you're done, run `terraform destroy`. + + +## Running automated tests against this module +1. Sign up for [Azure](https://azure.microsoft.com/) +1. Configure your Azure credentials using one of the [supported methods for Azure CLI + tools](https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest) +1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH` +1. Configure your Terratest [Go test environment](../README.md) +1. `cd test/azure` +1. `go build terraform_azure_mysqldb_example_test.go` +1. `go test -v -timeout 60m -tags azure -run TestPostgreSQLDatabase` + diff --git a/examples/azure/terraform-azure-postgresql-example/main.tf b/examples/azure/terraform-azure-postgresql-example/main.tf new file mode 100644 index 000000000..2ea97bb4b --- /dev/null +++ b/examples/azure/terraform-azure-postgresql-example/main.tf @@ -0,0 +1,53 @@ +# --------------------------------------------------------------------------------------------------------------------- +# DEPLOY AN PostgreSQL Database +# This is an example of how to deploy an Azure PostgreSQL database. +# See test/terraform_azure_example_test.go for how to write automated tests for this code. +# --------------------------------------------------------------------------------------------------------------------- + + +# --------------------------------------------------------------------------------------------------------------------- +# CONFIGURE OUR AZURE CONNECTION +# --------------------------------------------------------------------------------------------------------------------- +provider "azurerm" { + features {} +} + +# --------------------------------------------------------------------------------------------------------------------- +# DEPLOY A RESOURCE GROUP +# --------------------------------------------------------------------------------------------------------------------- +resource "azurerm_resource_group" "rg" { + name = "postgresql-rg" + location = "West Europe" +} + +# --------------------------------------------------------------------------------------------------------------------- +# DEPLOY AZURE PostgreSQL SERVER +# --------------------------------------------------------------------------------------------------------------------- +resource "azurerm_postgresql_server" "postgresqlserver" { + name = "postgresqlserver-${var.postfix}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + + sku_name = "B_Gen5_2" + + storage_mb = 5120 + backup_retention_days = 7 + geo_redundant_backup_enabled = false + auto_grow_enabled = true + + administrator_login = "pgsqladmin" + administrator_login_password = "H@Sh1CoR3!" + version = "11" + ssl_enforcement_enabled = true +} + +# --------------------------------------------------------------------------------------------------------------------- +# DEPLOY AZURE PostgreSQL Database +# --------------------------------------------------------------------------------------------------------------------- +resource "azurerm_postgresql_database" "postgresqldb" { + name = "postgresqldb" + resource_group_name = azurerm_resource_group.rg.name + server_name = azurerm_postgresql_server.postgresqlserver.name + charset = "UTF8" + collation = "English_United States.1252" +} diff --git a/examples/azure/terraform-azure-postgresql-example/output.tf b/examples/azure/terraform-azure-postgresql-example/output.tf new file mode 100644 index 000000000..c600908a5 --- /dev/null +++ b/examples/azure/terraform-azure-postgresql-example/output.tf @@ -0,0 +1,12 @@ +output "sku_name" { + value = azurerm_postgresql_server.postgresqlserver.sku_name +} + +output "servername" { + value = azurerm_postgresql_server.postgresqlserver.name + +} + +output "rgname" { + value = azurerm_resource_group.rg.name +} \ No newline at end of file diff --git a/examples/azure/terraform-azure-postgresql-example/variables.tf b/examples/azure/terraform-azure-postgresql-example/variables.tf new file mode 100644 index 000000000..1b3578984 --- /dev/null +++ b/examples/azure/terraform-azure-postgresql-example/variables.tf @@ -0,0 +1,5 @@ +variable "postfix" { + description = "A postfix string to centrally mitigate resource name collisions." + type = string + default = "resource" +} diff --git a/modules/azure/postgresql_test.go b/modules/azure/postgresql_test.go new file mode 100644 index 000000000..a81c0f373 --- /dev/null +++ b/modules/azure/postgresql_test.go @@ -0,0 +1,40 @@ +// +build azure + +// NOTE: We use build tags to differentiate azure testing because we currently do not have azure access setup for +// CircleCI. + +package azure + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +/* +The below tests are currently stubbed out, with the expectation that they will throw errors. +If/when CRUD methods are introduced for Azure PostgreSQL server and database, these tests can be extended +*/ + +func TestGetPostgreSQLServerE(t *testing.T) { + t.Parallel() + + resGroupName := "" + serverName := "" + subscriptionID := "" + + _, err := GetPostgresqlServerE(t, subscriptionID, resGroupName, serverName) + require.Error(t, err) +} + +func TestGetPostgreSQLDBE(t *testing.T) { + t.Parallel() + + resGroupName := "" + serverName := "" + subscriptionID := "" + dbName := "" + + _, err := GetPostgresqlDBE(t, subscriptionID, resGroupName, serverName, dbName) + require.Error(t, err) +} diff --git a/test/azure/terraform_azure_postgresql_example_test.go b/test/azure/terraform_azure_postgresql_example_test.go index 7842e6d72..4b7e0846b 100644 --- a/test/azure/terraform_azure_postgresql_example_test.go +++ b/test/azure/terraform_azure_postgresql_example_test.go @@ -2,8 +2,11 @@ package test import ( "os" + "strings" "testing" + "github.com/gruntwork-io/terratest/modules/azure" + "github.com/gruntwork-io/terratest/modules/random" "github.com/gruntwork-io/terratest/modules/terraform" "github.com/stretchr/testify/assert" ) @@ -11,20 +14,32 @@ import ( func TestPostgreSQLDatabase(t *testing.T) { t.Parallel() + uniquePostfix := strings.ToLower(random.UniqueId()) + + // website::tag::1:: Configure Terraform setting up a path to Terraform code. terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ TerraformDir: "../../examples/azure/terraform-azure-postgresql-example", - NoColor: true, + Vars: map[string]interface{}{ + "postfix": uniquePostfix, + }, + NoColor: true, }) + // website::tag::4:: At the end of the test, run `terraform destroy` to clean up any resources that were created defer terraform.Destroy(t, terraformOptions) + + // website::tag::2:: Run `terraform init` and `terraform apply`. Fail the test if there are any errors. terraform.InitAndApply(t, terraformOptions) + subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") - // get the actual data via terraform output - expectedServername := "terratestdevpostgresqlsrvfoo" // must match fixture + // website::tag::3:: Run `terraform output` to get the values of output variables + expectedServername := "postgresqlserver-" + uniquePostfix // see fixture actualServername := terraform.Output(t, terraformOptions, "servername") rgName := terraform.Output(t, terraformOptions, "rgname") expectedSkuName := terraform.Output(t, terraformOptions, "sku_name") - actualServer := GetPostgresqlServer(t, rgName, actualServername, subscriptionID) + + // website::tag::4:: Get the Server details and assert them against the terraform output + actualServer := azure.GetPostgresqlServer(t, rgName, actualServername, subscriptionID) // Verify assert.Equal(t, expectedServername, actualServername) assert.Equal(t, expectedSkuName, *actualServer.Sku.Name) From e1ef32ad23c8725bb59581bca4987ff0d7e5b0a3 Mon Sep 17 00:00:00 2001 From: "oliver.michels" Date: Thu, 18 Feb 2021 23:07:20 +0100 Subject: [PATCH 3/4] resolved issues from code review --- .../README.md | 5 ++- .../main.tf | 17 ++++++++-- .../output.tf | 8 ++--- .../variables.tf | 32 +++++++++++++++++++ ...terraform_azure_postgresql_example_test.go | 1 + 5 files changed, 53 insertions(+), 10 deletions(-) diff --git a/examples/azure/terraform-azure-postgresql-example/README.md b/examples/azure/terraform-azure-postgresql-example/README.md index 825deb532..6495d401f 100644 --- a/examples/azure/terraform-azure-postgresql-example/README.md +++ b/examples/azure/terraform-azure-postgresql-example/README.md @@ -3,7 +3,7 @@ This folder contains a Terraform module that deploys resources in [Azure](https://azure.microsoft.com/) to demonstrate how you can use Terratest to write automated tests for your Azure Terraform code. This module deploys a database for PostgreSQL. -- A [Azure PostgreSQL Database](https://azure.microsoft.com/services/mysql/). +- A [Azure PostgreSQL Database](https://azure.microsoft.com/services/postgresql/). Check out [test/azure/terraform_azure_postgresqldb_example_test.go](./../../../test/azure/terraform_azure_postgresqldb_example_test.go) to see how you can write automated tests for this module and validate the configuration of the parameters and options. @@ -27,6 +27,5 @@ Check out [test/azure/terraform_azure_postgresqldb_example_test.go](./../../../t 1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH` 1. Configure your Terratest [Go test environment](../README.md) 1. `cd test/azure` -1. `go build terraform_azure_mysqldb_example_test.go` +1. `go build terraform_azure_postgresql_example_test.go` 1. `go test -v -timeout 60m -tags azure -run TestPostgreSQLDatabase` - diff --git a/examples/azure/terraform-azure-postgresql-example/main.tf b/examples/azure/terraform-azure-postgresql-example/main.tf index 2ea97bb4b..8dbbdddc7 100644 --- a/examples/azure/terraform-azure-postgresql-example/main.tf +++ b/examples/azure/terraform-azure-postgresql-example/main.tf @@ -16,8 +16,8 @@ provider "azurerm" { # DEPLOY A RESOURCE GROUP # --------------------------------------------------------------------------------------------------------------------- resource "azurerm_resource_group" "rg" { - name = "postgresql-rg" - location = "West Europe" + name = "${var.resource_group_name}-${var.postfix}" + location = var.location } # --------------------------------------------------------------------------------------------------------------------- @@ -36,7 +36,7 @@ resource "azurerm_postgresql_server" "postgresqlserver" { auto_grow_enabled = true administrator_login = "pgsqladmin" - administrator_login_password = "H@Sh1CoR3!" + administrator_login_password = random_password.password.result version = "11" ssl_enforcement_enabled = true } @@ -51,3 +51,14 @@ resource "azurerm_postgresql_database" "postgresqldb" { charset = "UTF8" collation = "English_United States.1252" } + +# --------------------------------------------------------------------------------------------------------------------- +# Use a random password geneerator +# --------------------------------------------------------------------------------------------------------------------- +resource "random_password" "password" { + length = 20 + special = true + upper = true + lower = true + number = true +} diff --git a/examples/azure/terraform-azure-postgresql-example/output.tf b/examples/azure/terraform-azure-postgresql-example/output.tf index c600908a5..3d78c7b09 100644 --- a/examples/azure/terraform-azure-postgresql-example/output.tf +++ b/examples/azure/terraform-azure-postgresql-example/output.tf @@ -1,12 +1,12 @@ output "sku_name" { - value = azurerm_postgresql_server.postgresqlserver.sku_name + value = azurerm_postgresql_server.postgresqlserver.sku_name } output "servername" { - value = azurerm_postgresql_server.postgresqlserver.name - + value = azurerm_postgresql_server.postgresqlserver.name + } output "rgname" { - value = azurerm_resource_group.rg.name + value = azurerm_resource_group.rg.name } \ No newline at end of file diff --git a/examples/azure/terraform-azure-postgresql-example/variables.tf b/examples/azure/terraform-azure-postgresql-example/variables.tf index 1b3578984..787e3b2cf 100644 --- a/examples/azure/terraform-azure-postgresql-example/variables.tf +++ b/examples/azure/terraform-azure-postgresql-example/variables.tf @@ -1,3 +1,35 @@ +# --------------------------------------------------------------------------------------------------------------------- +# ENVIRONMENT VARIABLES +# Define these secrets as environment variables +# --------------------------------------------------------------------------------------------------------------------- + +# ARM_CLIENT_ID +# ARM_CLIENT_SECRET +# ARM_SUBSCRIPTION_ID +# ARM_TENANT_ID + +# --------------------------------------------------------------------------------------------------------------------- +# REQUIRED PARAMETERS +# You must provide a value for each of these parameters. +# --------------------------------------------------------------------------------------------------------------------- + +# --------------------------------------------------------------------------------------------------------------------- +# OPTIONAL PARAMETERS +# These parameters have reasonable defaults. +# --------------------------------------------------------------------------------------------------------------------- + +variable "resource_group_name" { + description = "Name for the resource group holding resources for this example" + type = string + default = "terratest-postgres-rg" +} + +variable "location" { + description = "The Azure region in which to deploy this sample" + type = string + default = "East US" +} + variable "postfix" { description = "A postfix string to centrally mitigate resource name collisions." type = string diff --git a/test/azure/terraform_azure_postgresql_example_test.go b/test/azure/terraform_azure_postgresql_example_test.go index 4b7e0846b..044152d8a 100644 --- a/test/azure/terraform_azure_postgresql_example_test.go +++ b/test/azure/terraform_azure_postgresql_example_test.go @@ -41,6 +41,7 @@ func TestPostgreSQLDatabase(t *testing.T) { // website::tag::4:: Get the Server details and assert them against the terraform output actualServer := azure.GetPostgresqlServer(t, rgName, actualServername, subscriptionID) // Verify + assert.NotNil(t, actualServer) assert.Equal(t, expectedServername, actualServername) assert.Equal(t, expectedSkuName, *actualServer.Sku.Name) From 00727ae4876bab1d5ab1fdbbcbd5ba0ed315f2e0 Mon Sep 17 00:00:00 2001 From: "oliver.michels" Date: Sat, 10 Apr 2021 21:08:25 +0200 Subject: [PATCH 4/4] all functions consistent to use PostgreSQL --- modules/azure/postgresql.go | 38 +++++++++---------- modules/azure/postgresql_test.go | 4 +- ...terraform_azure_postgresql_example_test.go | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/modules/azure/postgresql.go b/modules/azure/postgresql.go index 4c1f5222a..d9f3b47f9 100644 --- a/modules/azure/postgresql.go +++ b/modules/azure/postgresql.go @@ -31,17 +31,17 @@ func GetPostgreSQLServerClientE(subscriptionID string) (*postgresql.ServersClien return &postgresqlClient, nil } -// GetPostgresqlServer is a helper function that gets the server. +// GetPostgreSQLServer is a helper function that gets the server. // This function would fail the test if there is an error. -func GetPostgresqlServer(t testing.TestingT, resGroupName string, serverName string, subscriptionID string) *postgresql.Server { - postgresqlServer, err := GetPostgresqlServerE(t, subscriptionID, resGroupName, serverName) +func GetPostgreSQLServer(t testing.TestingT, resGroupName string, serverName string, subscriptionID string) *postgresql.Server { + postgresqlServer, err := GetPostgreSQLServerE(t, subscriptionID, resGroupName, serverName) require.NoError(t, err) return postgresqlServer } -// GetPostgresqlServerE is a helper function that gets the server. -func GetPostgresqlServerE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) (*postgresql.Server, error) { +// GetPostgreSQLServerE is a helper function that gets the server. +func GetPostgreSQLServerE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) (*postgresql.Server, error) { // Create a postgresql Server client postgresqlClient, err := GetPostgreSQLServerClientE(subscriptionID) if err != nil { @@ -58,8 +58,8 @@ func GetPostgresqlServerE(t testing.TestingT, subscriptionID string, resGroupNam return &postgresqlServer, nil } -// GetPostgresqlDBClientE is a helper function that will setup a postgresql DB client. -func GetPostgresqlDBClientE(subscriptionID string) (*postgresql.DatabasesClient, error) { +// GetPostgreSQLDBClientE is a helper function that will setup a postgresql DB client. +func GetPostgreSQLDBClientE(subscriptionID string) (*postgresql.DatabasesClient, error) { // Validate Azure subscription ID subscriptionID, err := getTargetAzureSubscription(subscriptionID) if err != nil { @@ -81,19 +81,19 @@ func GetPostgresqlDBClientE(subscriptionID string) (*postgresql.DatabasesClient, return &postgresqlDBClient, nil } -//GetPostgresqlDB is a helper function that gets the database. +//GetPostgreSQLDB is a helper function that gets the database. // This function would fail the test if there is an error. -func GetPostgresqlDB(t testing.TestingT, resGroupName string, serverName string, dbName string, subscriptionID string) *postgresql.Database { - database, err := GetPostgresqlDBE(t, subscriptionID, resGroupName, serverName, dbName) +func GetPostgreSQLDB(t testing.TestingT, resGroupName string, serverName string, dbName string, subscriptionID string) *postgresql.Database { + database, err := GetPostgreSQLDBE(t, subscriptionID, resGroupName, serverName, dbName) require.NoError(t, err) return database } -//GetPostgresqlDBE is a helper function that gets the database. -func GetPostgresqlDBE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string, dbName string) (*postgresql.Database, error) { +//GetPostgreSQLDBE is a helper function that gets the database. +func GetPostgreSQLDBE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string, dbName string) (*postgresql.Database, error) { // Create a postgresql db client - postgresqldbClient, err := GetPostgresqlDBClientE(subscriptionID) + postgresqldbClient, err := GetPostgreSQLDBClientE(subscriptionID) if err != nil { return nil, err } @@ -108,18 +108,18 @@ func GetPostgresqlDBE(t testing.TestingT, subscriptionID string, resGroupName st return &postgresqlDb, nil } -//ListPostgresqlDB is a helper function that gets all databases per server. -func ListPostgresqlDB(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) []postgresql.Database { - dblist, err := ListPostgresqlDBE(t, subscriptionID, resGroupName, serverName) +//ListPostgreSQLDB is a helper function that gets all databases per server. +func ListPostgreSQLDB(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) []postgresql.Database { + dblist, err := ListPostgreSQLDBE(t, subscriptionID, resGroupName, serverName) require.NoError(t, err) return dblist } -//ListPostgresqlDBE is a helper function that gets all databases per server. -func ListPostgresqlDBE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) ([]postgresql.Database, error) { +//ListPostgreSQLDBE is a helper function that gets all databases per server. +func ListPostgreSQLDBE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) ([]postgresql.Database, error) { // Create a postgresql db client - postgresqldbClient, err := GetPostgresqlDBClientE(subscriptionID) + postgresqldbClient, err := GetPostgreSQLDBClientE(subscriptionID) if err != nil { return nil, err } diff --git a/modules/azure/postgresql_test.go b/modules/azure/postgresql_test.go index a81c0f373..5355fd441 100644 --- a/modules/azure/postgresql_test.go +++ b/modules/azure/postgresql_test.go @@ -23,7 +23,7 @@ func TestGetPostgreSQLServerE(t *testing.T) { serverName := "" subscriptionID := "" - _, err := GetPostgresqlServerE(t, subscriptionID, resGroupName, serverName) + _, err := GetPostgreSQLServerE(t, subscriptionID, resGroupName, serverName) require.Error(t, err) } @@ -35,6 +35,6 @@ func TestGetPostgreSQLDBE(t *testing.T) { subscriptionID := "" dbName := "" - _, err := GetPostgresqlDBE(t, subscriptionID, resGroupName, serverName, dbName) + _, err := GetPostgreSQLDBE(t, subscriptionID, resGroupName, serverName, dbName) require.Error(t, err) } diff --git a/test/azure/terraform_azure_postgresql_example_test.go b/test/azure/terraform_azure_postgresql_example_test.go index 044152d8a..e272748fe 100644 --- a/test/azure/terraform_azure_postgresql_example_test.go +++ b/test/azure/terraform_azure_postgresql_example_test.go @@ -39,7 +39,7 @@ func TestPostgreSQLDatabase(t *testing.T) { expectedSkuName := terraform.Output(t, terraformOptions, "sku_name") // website::tag::4:: Get the Server details and assert them against the terraform output - actualServer := azure.GetPostgresqlServer(t, rgName, actualServername, subscriptionID) + actualServer := azure.GetPostgreSQLServer(t, rgName, actualServername, subscriptionID) // Verify assert.NotNil(t, actualServer) assert.Equal(t, expectedServername, actualServername)