mirror of
https://github.com/gofiber/storage.git
synced 2025-10-04 16:22:52 +08:00
chore: update new postgres code
This commit is contained in:
@@ -53,6 +53,10 @@ func newTestStore(t testing.TB) (*Storage, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNoCreateUser(t *testing.T) {
|
func TestNoCreateUser(t *testing.T) {
|
||||||
|
testStore, err := newTestStore(t)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer testStore.Close()
|
||||||
|
|
||||||
// Create a new user
|
// Create a new user
|
||||||
// give the use usage permissions to the database (but not create)
|
// give the use usage permissions to the database (but not create)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@@ -61,10 +65,10 @@ func TestNoCreateUser(t *testing.T) {
|
|||||||
username := "testuser" + strconv.Itoa(int(time.Now().UnixNano()))
|
username := "testuser" + strconv.Itoa(int(time.Now().UnixNano()))
|
||||||
password := "testpassword"
|
password := "testpassword"
|
||||||
|
|
||||||
_, err := conn.Exec(ctx, "CREATE USER "+username+" WITH PASSWORD '"+password+"'")
|
_, err = conn.Exec(ctx, "CREATE USER "+username+" WITH PASSWORD '"+password+"'")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = conn.Exec(ctx, "GRANT CONNECT ON DATABASE "+os.Getenv("POSTGRES_DATABASE")+" TO "+username)
|
_, err = conn.Exec(ctx, "GRANT CONNECT ON DATABASE "+postgresDatabase+" TO "+username)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = conn.Exec(ctx, "GRANT USAGE ON SCHEMA public TO "+username)
|
_, err = conn.Exec(ctx, "GRANT USAGE ON SCHEMA public TO "+username)
|
||||||
@@ -183,8 +187,12 @@ func TestNoCreateUser(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
func Test_Should_Panic_On_Wrong_Schema(t *testing.T) {
|
func Test_Should_Panic_On_Wrong_Schema(t *testing.T) {
|
||||||
|
testStore, err := newTestStore(t)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer testStore.Close()
|
||||||
|
|
||||||
// Create a test table with wrong schema
|
// Create a test table with wrong schema
|
||||||
_, err := testStore.Conn().Exec(context.Background(), `
|
_, err = testStore.Conn().Exec(context.Background(), `
|
||||||
CREATE TABLE IF NOT EXISTS test_schema_table (
|
CREATE TABLE IF NOT EXISTS test_schema_table (
|
||||||
k VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT '',
|
k VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT '',
|
||||||
v BYTEA NOT NULL,
|
v BYTEA NOT NULL,
|
||||||
|
Reference in New Issue
Block a user