Fix the remaining `postgresql_extension` unit test.

This commit is contained in:
Sean Chittenden 2016-12-12 13:40:49 -08:00
parent daa951434f
commit c602f024f4
No known key found for this signature in database
GPG Key ID: 4EBC9DC16C2E5E16
2 changed files with 8 additions and 9 deletions

View File

@ -79,8 +79,7 @@ func resourcePostgreSQLExtensionRead(d *schema.ResourceData, meta interface{}) e
} }
defer conn.Close() defer conn.Close()
extID := d.Get(extNameAttr).(string) extID := d.Id()
var extName, extSchema string var extName, extSchema string
err = conn.QueryRow("SELECT e.extname, n.nspname FROM pg_catalog.pg_extension e, pg_catalog.pg_namespace n WHERE n.oid = e.extnamespace AND e.extname = $1", extID).Scan(&extName, &extSchema) err = conn.QueryRow("SELECT e.extname, n.nspname FROM pg_catalog.pg_extension e, pg_catalog.pg_namespace n WHERE n.oid = e.extnamespace AND e.extname = $1", extID).Scan(&extName, &extSchema)
switch { switch {
@ -106,9 +105,9 @@ func resourcePostgreSQLExtensionDelete(d *schema.ResourceData, meta interface{})
} }
defer conn.Close() defer conn.Close()
extName := d.Get(extNameAttr).(string) extID := d.Id()
query := fmt.Sprintf("DROP EXTENSION %s", pq.QuoteIdentifier(extName)) query := fmt.Sprintf("DROP EXTENSION %s", pq.QuoteIdentifier(extID))
_, err = conn.Query(query) _, err = conn.Query(query)
if err != nil { if err != nil {
return errwrap.Wrapf("Error deleting extension: {{err}}", err) return errwrap.Wrapf("Error deleting extension: {{err}}", err)
@ -141,14 +140,14 @@ func setExtSchema(conn *sql.DB, d *schema.ResourceData) error {
return nil return nil
} }
oraw, nraw := d.GetChange(extSchemaAttr) extID := d.Id()
o := oraw.(string) _, nraw := d.GetChange(extSchemaAttr)
n := nraw.(string) n := nraw.(string)
if n == "" { if n == "" {
return errors.New("Error setting extension name to an empty string") return errors.New("Error setting extension name to an empty string")
} }
query := fmt.Sprintf("ALTER EXTENSION %s SET SCHEMA %s", pq.QuoteIdentifier(o), pq.QuoteIdentifier(n)) query := fmt.Sprintf("ALTER EXTENSION %s SET SCHEMA %s", pq.QuoteIdentifier(extID), pq.QuoteIdentifier(n))
if _, err := conn.Query(query); err != nil { if _, err := conn.Query(query); err != nil {
return errwrap.Wrapf("Error updating extension SCHEMA: {{err}}", err) return errwrap.Wrapf("Error updating extension SCHEMA: {{err}}", err)
} }

View File

@ -118,8 +118,8 @@ func checkExtensionExists(client *Client, extensionName string) (bool, error) {
} }
defer conn.Close() defer conn.Close()
var _rez int var _rez bool
err = conn.QueryRow("SELECT 1 from pg_extension d WHERE extname=$1", extensionName).Scan(&_rez) err = conn.QueryRow("SELECT TRUE from pg_catalog.pg_extension d WHERE extname=$1", extensionName).Scan(&_rez)
switch { switch {
case err == sql.ErrNoRows: case err == sql.ErrNoRows:
return false, nil return false, nil