Skip to content

Commit

Permalink
finalizing implementation and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alpacamybags118 committed Mar 2, 2021
1 parent 778206c commit 96ae641
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
124 changes: 124 additions & 0 deletions modules/aws/rds_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package aws

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetRecommendedRdsInstanceType(t *testing.T) {
type TestingScenerios struct {
name string
region string
databaseEngine string
instanceTypes []string
expected string
}
}

func TestGetRecommendedRdsInstanceTypeHappyPath(t *testing.T) {
type TestingScenerios struct {
name string
region string
databaseEngine string
instanceTypes []string
expected string
}

testingScenerios := []TestingScenerios{
{
name: "US region, mysql, first offering available",
region: "us-east-2",
databaseEngine: "mysql",
instanceTypes: []string{"db.t2.micro", "db.t3.micro"},
expected: "db.t2.micro",
},
{
name: "EU region, postgres, 2nd offering available based on region",
region: "eu-north-1",
databaseEngine: "postgres",
instanceTypes: []string{"db.t2.micro", "db.m5.large"},
expected: "db.m5.large",
},
{
name: "US region, oracle-ee, 2nd offering available based on db type",
region: "us-west-2",
databaseEngine: "oracle-ee",
instanceTypes: []string{"db.m5d.xlarge", "db.m5.large"},
expected: "db.m5.large",
},
}

for _, scenerio := range testingScenerios {
scenerio := scenerio

t.Run(scenerio.name, func(t *testing.T) {
t.Parallel()

actual, err := GetRecommendedRdsInstanceTypeE(t, scenerio.region, scenerio.databaseEngine, scenerio.instanceTypes)
assert.NoError(t, err)
assert.Equal(t, scenerio.expected, actual)
})
}
}

func TestGetRecommendedRdsInstanceTypeErrors(t *testing.T) {
type TestingScenerios struct {
name string
region string
databaseEngine string
instanceTypes []string
}

testingScenerios := []TestingScenerios{
{
name: "All empty",
region: "",
databaseEngine: "",
instanceTypes: nil,
},
{
name: "No engine or instance type",
region: "us-east-2",
databaseEngine: "",
instanceTypes: nil,
},
{
name: "No instance types",
region: "us-east-2",
databaseEngine: "mysql",
instanceTypes: nil,
},
{
name: "Invalid instance types",
region: "us-east-2",
databaseEngine: "mysql",
instanceTypes: []string{"garbage"},
},
{
name: "Region has no instance type available",
region: "eu-north-1",
databaseEngine: "mysql",
instanceTypes: []string{"db.t2.micro"},
},
{
name: "No instance type available for engine",
region: "us-east-1",
databaseEngine: "oracle-ee",
instanceTypes: []string{"db.r5d.large"},
},
}

for _, scenerio := range testingScenerios {
scenerio := scenerio

t.Run(scenerio.name, func(t *testing.T) {
t.Parallel()

_, err := GetRecommendedRdsInstanceTypeE(t, scenerio.region, scenerio.databaseEngine, scenerio.instanceTypes)
fmt.Println(err)
assert.EqualError(t, err, NoRdsInstanceTypeError{InstanceTypeOptions: scenerio.instanceTypes, DatabaseEngine: scenerio.databaseEngine}.Error())
})
}
}
2 changes: 2 additions & 0 deletions test/terraform_aws_rds_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestTerraformAwsRdsExample(t *testing.T) {
password := "password"
// Pick a random AWS region to test in. This helps ensure your code works in all regions.
awsRegion := aws.GetRandomStableRegion(t, nil, nil)
instanceType := aws.GetRecommendedRdsInstanceType(t, awsRegion, "mysql", []string{"db.t2.micro", "db.t3.micro"})

// Construct the terraform options with default retryable errors to handle the most common retryable errors in
// terraform testing.
Expand All @@ -38,6 +39,7 @@ func TestTerraformAwsRdsExample(t *testing.T) {
"engine_name": "mysql",
"major_engine_version": "5.7",
"family": "mysql5.7",
"instance_class": instanceType,
"username": username,
"password": password,
"allocated_storage": 5,
Expand Down

0 comments on commit 96ae641

Please sign in to comment.