-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Postgres in aws rds #459
Labels
Comments
Most likely, yes! Could you tell us a bit more about what changes you've added? |
I've added to following functions to modified: modules/aws/rds.go
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/service/rds"
_ "github.com/go-sql-driver/mysql"
"github.com/gruntwork-io/terratest/modules/testing"
+ _ "github.com/lib/pq"
)
// GetAddressOfRdsInstance gets the address of the given RDS Instance in the given region.
@@ -48,6 +49,36 @@ func GetPortOfRdsInstanceE(t testing.TestingT, dbInstanceID string, awsRegion st
return *dbInstance.Endpoint.Port, nil
}
+// GetWhetherSchemaExistsInRdsPostgresInstance checks whether the specified schema/table name exists in the RDS instance
+func GetWhetherSchemaExistsInRdsPostgresInstance(t testing.TestingT, dbUrl string, dbPort int64, dbUsername string, dbPassword string, expectedSchemaName string) bool {
+ output, err := GetWhetherSchemaExistsInRdsPostgresInstanceE(t, dbUrl, dbPort, dbUsername, dbPassword, expectedSchemaName)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return output
+}
+
+// GetWhetherSchemaExistsInRdsPostgresInstanceE checks whether the specified schema/table name exists in the RDS instance
+func GetWhetherSchemaExistsInRdsPostgresInstanceE(t testing.TestingT, dbUrl string, dbPort int64, dbUsername string, dbPassword string, expectedSchemaName string) (bool, error) {
+ connectionString := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s", dbUrl, dbPort, dbUsername, dbPassword, expectedSchemaName)
+
+ db, connErr := sql.Open("postgres", connectionString)
+ if connErr != nil {
+ return false, connErr
+ }
+ defer db.Close()
+ var (
+ schemaName string
+ )
+ sqlStatement := `SELECT "catalog_name" FROM "information_schema"."schemata" where catalog_name=$1`
+ row := db.QueryRow(sqlStatement, expectedSchemaName)
+ scanErr := row.Scan(&schemaName)
+ if scanErr != nil {
+ return false, scanErr
+ }
+ return true, nil
+}
+ |
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While writing some tests for setting up postgres instance in AWS I noticed that
rds.go
only currently supports mysql. As a result, I've added support for postgres to my local branch. Just wondering if there are plans to add support for postgres in future? Would it be worthwhile to create PR with the set of changes that I have made.The text was updated successfully, but these errors were encountered: