mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-01 02:57:59 +00:00 
			
		
		
		
	postgres: replace the package lib/pq with pgx (#15343)
* WIP replacing lib/pq * change timezome param to be URI format * add changelog * add changelog for redshift * update changelog * add test for DSN style connection string * more parseurl and quoteidentify to sdk; include copyright and license * call dbutil.ParseURL instead, fix import ordering Co-authored-by: Calvin Leung Huang <1883212+calvn@users.noreply.github.com>
This commit is contained in:
		| @@ -8,8 +8,10 @@ import ( | ||||
| 	"testing" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/hashicorp/vault/sdk/database/helper/dbutil" | ||||
|  | ||||
| 	"github.com/hashicorp/vault/helper/testhelpers/postgresql" | ||||
| 	dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" | ||||
| 	"github.com/hashicorp/vault/sdk/database/dbplugin/v5" | ||||
| 	dbtesting "github.com/hashicorp/vault/sdk/database/dbplugin/v5/testing" | ||||
| 	"github.com/hashicorp/vault/sdk/helper/template" | ||||
| 	"github.com/stretchr/testify/require" | ||||
| @@ -61,6 +63,32 @@ func TestPostgreSQL_InitializeWithStringVals(t *testing.T) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestPostgreSQL_Initialize_ConnURLWithDSNFormat(t *testing.T) { | ||||
| 	cleanup, connURL := postgresql.PrepareTestContainer(t, "13.4-buster") | ||||
| 	defer cleanup() | ||||
|  | ||||
| 	dsnConnURL, err := dbutil.ParseURL(connURL) | ||||
| 	if err != nil { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| 	connectionDetails := map[string]interface{}{ | ||||
| 		"connection_url": dsnConnURL, | ||||
| 	} | ||||
|  | ||||
| 	req := dbplugin.InitializeRequest{ | ||||
| 		Config:           connectionDetails, | ||||
| 		VerifyConnection: true, | ||||
| 	} | ||||
|  | ||||
| 	db := new() | ||||
| 	dbtesting.AssertInitialize(t, db, req) | ||||
|  | ||||
| 	if !db.Initialized { | ||||
| 		t.Fatal("Database should be initialized") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestPostgreSQL_NewUser(t *testing.T) { | ||||
| 	type testCase struct { | ||||
| 		req            dbplugin.NewUserRequest | ||||
| @@ -675,7 +703,7 @@ func testCredsExist(t testing.TB, connURL, username, password string) error { | ||||
| 	t.Helper() | ||||
| 	// Log in with the new creds | ||||
| 	connURL = strings.Replace(connURL, "postgres:secret", fmt.Sprintf("%s:%s", username, password), 1) | ||||
| 	db, err := sql.Open("postgres", connURL) | ||||
| 	db, err := sql.Open("pgx", connURL) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jim Kalafut
					Jim Kalafut