-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
404191b
commit 8dbe9b0
Showing
1 changed file
with
29 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -932,45 +932,51 @@ func (suite *DatabaseTests) TestListUserDatasets() { | |
assert.Equal(suite.T(), "test-user-dataset-01", datasets[0].DatasetID) | ||
} | ||
|
||
func (suite *DatabaseTests) TestInsertUserInfo() { | ||
func (suite *DatabaseTests) TestUpdateUserInfo() { | ||
db, err := NewSDAdb(suite.dbConf) | ||
assert.NoError(suite.T(), err, "got (%v) when creating new connection", err) | ||
|
||
// Verify that a user can be inserted | ||
// Insert a userID | ||
var groups []string | ||
userID, name, email := "[email protected]", "Test User", "[email protected]" | ||
err = db.UpdateUserInfo(userID, name, email, groups) | ||
assert.NoError(suite.T(), err, "could not insert user info: %v", err) | ||
var exists bool | ||
err = db.DB.QueryRow("SELECT EXISTS(SELECT 1 FROM sda.userinfo WHERE id=$1)", userID).Scan(&exists) | ||
assert.NoError(suite.T(), err, "failed to verify user info existence") | ||
assert.True(suite.T(), exists, "user info was not added to the database") | ||
|
||
// Insert new information about the user | ||
groups = append(groups, "appleGroup", "bananaGroup") | ||
name = "newName" | ||
err = db.UpdateUserInfo(userID, name, email, groups) | ||
assert.NoError(suite.T(), err, "could not insert updated user info: %v", err) | ||
// Verify that the userID is connected to the details | ||
var numRows int | ||
err = db.DB.QueryRow("SELECT COUNT(*) FROM sda.userinfo WHERE id=$1", userID).Scan(&numRows) | ||
assert.NoError(suite.T(), err, "could select user info: %v", err) | ||
assert.Equal(suite.T(), 1, numRows, "there should be exactly 1 row about %v in userinfo table", userID) | ||
var name2 string | ||
err = db.DB.QueryRow("SELECT name FROM sda.userinfo WHERE id=$1", userID).Scan(&name2) | ||
assert.NoError(suite.T(), err, "could not select user info: %v", err) | ||
assert.Equal(suite.T(), name, name2, "user info table did not update correctly") | ||
} | ||
|
||
func (suite *DatabaseTests) TestUpdateUserInfo() { | ||
func (suite *DatabaseTests) TestUpdateUserInfo_newInfo() { | ||
db, err := NewSDAdb(suite.dbConf) | ||
assert.NoError(suite.T(), err, "got (%v) when creating new connection", err) | ||
|
||
// Insert a userID | ||
// Insert a user | ||
var groups []string | ||
userID, name, email := "[email protected]", "Test User", "[email protected]" | ||
err = db.UpdateUserInfo(userID, name, email, groups) | ||
assert.NoError(suite.T(), err, "could not insert user info: %v", err) | ||
// Verify that the userID is connected to the new details | ||
var exists bool | ||
err = db.DB.QueryRow("SELECT EXISTS(SELECT 1 FROM sda.userinfo WHERE id=$1)", userID).Scan(&exists) | ||
assert.NoError(suite.T(), err, "failed to verify user info existence") | ||
assert.True(suite.T(), exists, "user info was not added to the database") | ||
|
||
// Insert new information about the user and verify that there is still only 1 row, | ||
// and that this row is updated | ||
var numRows int | ||
err = db.DB.QueryRow("SELECT COUNT(*) FROM sda.userinfo WHERE id=$1", userID).Scan(&numRows) | ||
assert.NoError(suite.T(), err, "could select user info: %v", err) | ||
assert.Equal(suite.T(), 1, numRows, "there should be exactly 1 row about %v in userinfo table", userID) | ||
var name2 string | ||
var groups2 []string | ||
err = db.DB.QueryRow("SELECT name, groups FROM sda.userinfo WHERE id=$1", userID).Scan(&name2, pq.Array(&groups2)) | ||
assert.NoError(suite.T(), err, "could select user info: %v", err) | ||
assert.Equal(suite.T(), name, name2, "user info table did not update correctly") | ||
assert.Equal(suite.T(), groups, groups2, "user info table did not update correctly") | ||
assert.Equal(suite.T(), 1, numRows, "there should be exactly one row in userinfo") | ||
var dbgroups []string | ||
groups = append(groups, "appleGroup", "bananaGroup") | ||
name = "newName" | ||
err = db.UpdateUserInfo(userID, name, email, groups) | ||
assert.NoError(suite.T(), err, "could not insert updated user info: %v", err) | ||
err = db.DB.QueryRow("SELECT groups FROM sda.userinfo WHERE id=$1", userID).Scan(pq.Array(&dbgroups)) | ||
assert.NoError(suite.T(), err) | ||
assert.Equal(suite.T(), groups, dbgroups) | ||
} |