mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-23 09:08:26 +01:00
Remove data generated by dao_test after the test.
This commit is contained in:
parent
43afd426bb
commit
d6bf0ea11d
@ -122,6 +122,9 @@ func ClearTable(table string) error {
|
||||
if table == models.UserTable {
|
||||
sql = fmt.Sprintf("delete from %s where user_id > 2", table)
|
||||
}
|
||||
if table == "project_metadata" { //make sure library is public
|
||||
sql = fmt.Sprintf("delete from %s where id > 1", table)
|
||||
}
|
||||
_, err := o.Raw(sql).Exec()
|
||||
return err
|
||||
}
|
||||
|
@ -157,7 +157,21 @@ func TestMain(m *testing.M) {
|
||||
func testForAll(m *testing.M) int {
|
||||
cleanByUser(username)
|
||||
|
||||
return m.Run()
|
||||
rc := m.Run()
|
||||
clearAll()
|
||||
return rc
|
||||
}
|
||||
|
||||
func clearAll() {
|
||||
tables := []string{"project_member",
|
||||
"project_metadata", "access_log", "repository", "replication_policy",
|
||||
"replication_target", "replication_job", "replication_immediate_trigger", "img_scan_job",
|
||||
"img_scan_overview", "clair_vuln_timestamp", "project", "user"}
|
||||
for _, t := range tables {
|
||||
if err := ClearTable(t); err != nil {
|
||||
log.Errorf("Failed to clear table: %s,error: %v", t, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegister(t *testing.T) {
|
||||
|
@ -40,8 +40,7 @@ func TestMemGet(t *testing.T) {
|
||||
t.Log(err)
|
||||
} else {
|
||||
assert.Equal(int(200), httpStatusCode, "httpStatusCode should be 200")
|
||||
assert.Equal(int(1), result[0].UserId, "User Id should be 1")
|
||||
assert.Equal("admin", result[0].Username, "User name should be admin")
|
||||
assert.Equal("proj_admin", result[0].Username, "User name should be proj_admin")
|
||||
}
|
||||
|
||||
//---------case 2: Response Code=401,User need to log in first.----------//
|
||||
|
@ -327,6 +327,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
apiTest := newHarborAPI()
|
||||
password := apilib.Password{OldPassword: "", NewPassword: ""}
|
||||
t.Log("Update password-case 1")
|
||||
//case 1: update user2 password with user3 auth
|
||||
code, err := apiTest.UsersUpdatePassword(testUser0002ID, password, *testUser0003Auth)
|
||||
if err != nil {
|
||||
@ -335,6 +336,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
||||
} else {
|
||||
assert.Equal(403, code, "Update user password status should be 403")
|
||||
}
|
||||
t.Log("Update password-case 2")
|
||||
//case 2: update user2 password with admin auth, but oldpassword is empty
|
||||
code, err = apiTest.UsersUpdatePassword(testUser0002ID, password, *admin)
|
||||
if err != nil {
|
||||
@ -343,6 +345,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
||||
} else {
|
||||
assert.Equal(400, code, "Update user password status should be 400")
|
||||
}
|
||||
t.Log("Update password-case 3")
|
||||
//case 3: update user2 password with admin auth, but oldpassword is wrong
|
||||
password.OldPassword = "000"
|
||||
code, err = apiTest.UsersUpdatePassword(testUser0002ID, password, *admin)
|
||||
@ -352,6 +355,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
||||
} else {
|
||||
assert.Equal(403, code, "Update user password status should be 403")
|
||||
}
|
||||
t.Log("Update password-case 4")
|
||||
//case 4: update user2 password with admin auth, but newpassword is empty
|
||||
password.OldPassword = "testUser0002"
|
||||
code, err = apiTest.UsersUpdatePassword(testUser0002ID, password, *admin)
|
||||
@ -361,6 +365,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
||||
} else {
|
||||
assert.Equal(400, code, "Update user password status should be 400")
|
||||
}
|
||||
t.Log("Update password-case 5")
|
||||
//case 5: update user2 password with admin auth, right parameters
|
||||
password.NewPassword = "TestUser0002"
|
||||
code, err = apiTest.UsersUpdatePassword(testUser0002ID, password, *admin)
|
||||
@ -383,6 +388,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
t.Log("Update password-case 6")
|
||||
//case 6: update user2 password setting the new password same as the old
|
||||
password.OldPassword = password.NewPassword
|
||||
code, err = apiTest.UsersUpdatePassword(testUser0002ID, password, *admin)
|
||||
@ -400,6 +406,7 @@ func TestUsersDelete(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
apiTest := newHarborAPI()
|
||||
|
||||
t.Log("delete user-case 1")
|
||||
//case 1:delete user without admin auth
|
||||
code, err := apiTest.UsersDelete(testUser0002ID, *testUser0003Auth)
|
||||
if err != nil {
|
||||
@ -409,6 +416,7 @@ func TestUsersDelete(t *testing.T) {
|
||||
assert.Equal(403, code, "Delete test user status should be 403")
|
||||
}
|
||||
//case 2: delete user with admin auth, user2 has already been toggled to admin, but can not delete himself
|
||||
t.Log("delete user-case 2")
|
||||
code, err = apiTest.UsersDelete(testUser0002ID, *testUser0002Auth)
|
||||
if err != nil {
|
||||
t.Error("Error occured while delete test user", err.Error())
|
||||
@ -417,6 +425,7 @@ func TestUsersDelete(t *testing.T) {
|
||||
assert.Equal(403, code, "Delete test user status should be 403")
|
||||
}
|
||||
//case 3: delete user with admin auth
|
||||
t.Log("delete user-case 3")
|
||||
code, err = apiTest.UsersDelete(testUser0002ID, *admin)
|
||||
if err != nil {
|
||||
t.Error("Error occured while delete test user", err.Error())
|
||||
@ -435,6 +444,7 @@ func TestUsersDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifiable(t *testing.T) {
|
||||
t.Log("Test modifiable.")
|
||||
assert := assert.New(t)
|
||||
base := BaseController{
|
||||
api.BaseAPI{
|
||||
|
Loading…
Reference in New Issue
Block a user