refactoring psql

This commit is contained in:
2023-04-27 09:18:52 +02:00
parent d56343f167
commit d196373abc
2 changed files with 120 additions and 72 deletions

View File

@@ -41,7 +41,9 @@ func generateUUIDv4() string {
}
uuid[6] = (uuid[6] & 0x0f) | 0x40
uuid[8] = (uuid[8] & 0xbf) | 0x80
return hex.EncodeToString(uuid[:4]) + "-" + hex.EncodeToString(uuid[4:6]) + "-" + hex.EncodeToString(uuid[6:8]) + "-" + hex.EncodeToString(uuid[8:10]) + "-" + hex.EncodeToString(uuid[10:])
return hex.EncodeToString(uuid[:4]) + "-" + hex.EncodeToString(uuid[4:6]) + "-" +
hex.EncodeToString(uuid[6:8]) + "-" + hex.EncodeToString(uuid[8:10]) + "-" +
hex.EncodeToString(uuid[10:])
}
func TestGetAccount(t *testing.T) {
@@ -73,7 +75,8 @@ func TestGetAccount(t *testing.T) {
if err != nil {
t.Errorf("error account data and metdata")
}
_, err = db.DbConnection.Exec("INSERT INTO accounts (id, namespace, data, metadata) VALUES ($1, $2, $3, $4)", account.ID, account.Namespace, dataJSON, dataJSON)
_, err = db.DbConnection.Exec("INSERT INTO accounts (id, namespace, data, metadata) "+
"VALUES ($1, $2, $3, $4)", account.ID, account.Namespace, dataJSON, dataJSON)
if err != nil {
t.Errorf("error in inserting a new account")
}
@@ -94,7 +97,10 @@ func TestGetAccount(t *testing.T) {
if err != nil {
t.Errorf("error account_auth localAuth")
}
_, err = db.DbConnection.Exec("INSERT INTO account_auth (account_id, username, password, email, email_validation, phone_number,phone_number_validation) VALUES ($1, $2, $3, $4, $5, $6, $7)", account.ID, localAuth.Username, localAuth.Password, localAuth.Email, localAuthJSON, localAuth.PhoneNumber, localAuthJSON)
_, err = db.DbConnection.Exec("INSERT INTO account_auth (account_id, username, password, "+
"email, email_validation, "+
"phone_number,phone_number_validation) VALUES ($1, $2, $3, $4, $5, $6, $7)", account.ID,
localAuth.Username, localAuth.Password, localAuth.Email, localAuthJSON, localAuth.PhoneNumber, localAuthJSON)
if err != nil {
fmt.Println(err)
t.Errorf("error in iserting a new account in account_auth")
@@ -242,22 +248,26 @@ func TestPostgresqlStorage_LocalAuthentication(t *testing.T) {
if err != nil {
t.Errorf("failed to create new psql connection")
}
accountByUsername, err := db.LocalAuthentication("test_namespace", "testuser", "", "")
accountByUsername, err := db.LocalAuthentication("test_namespace", "testuser",
"", "")
if err != nil {
t.Errorf("Failed LocalAuthentication based on username and namespace")
}
fmt.Println(accountByUsername)
accountByEmail, err := db.LocalAuthentication("test_namespace", "", "test@test.com", "")
accountByEmail, err := db.LocalAuthentication("test_namespace", "",
"test@test.com", "")
if err != nil {
t.Errorf("Failed LocalAuthentication based on username and namespace")
}
fmt.Println(accountByEmail)
accountByPhone, err := db.LocalAuthentication("test_namespace", "", "", "1234567890")
accountByPhone, err := db.LocalAuthentication("test_namespace", "",
"", "1234567890")
if err != nil {
t.Errorf("Failed LocalAuthentication based on username and namespace")
}
fmt.Println(accountByPhone)
accountByAll, err := db.LocalAuthentication("test_namespace", "testuser", "test@test.com", "1234567890")
accountByAll, err := db.LocalAuthentication("test_namespace", "testuser",
"test@test.com", "1234567890")
if err != nil {
t.Errorf("Failed LocalAuthentication based on username and namespace")
}