mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 20:35:24 +01:00
112 lines
1.7 KiB
Go
112 lines
1.7 KiB
Go
package bolt
|
|
|
|
import (
|
|
"github.com/ansible-semaphore/semaphore/db"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestBoltDb_UpdateProjectUser(t *testing.T) {
|
|
store := CreateTestStore()
|
|
|
|
usr, err := store.CreateUser(db.UserWithPwd{
|
|
Pwd: "123456",
|
|
User: db.User{
|
|
Email: "denguk@example.com",
|
|
Name: "Denis Gukov",
|
|
Username: "fiftin",
|
|
},
|
|
})
|
|
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
proj1, err := store.CreateProject(db.Project{
|
|
Created: time.Now(),
|
|
Name: "Test1",
|
|
})
|
|
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
projUser, err := store.CreateProjectUser(db.ProjectUser{
|
|
ProjectID: proj1.ID,
|
|
UserID: usr.ID,
|
|
Admin: true,
|
|
})
|
|
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
projUser.Admin = true
|
|
err = store.UpdateProjectUser(projUser)
|
|
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
}
|
|
|
|
func TestGetUsers(t *testing.T) {
|
|
store := CreateTestStore()
|
|
|
|
_, err := store.CreateUser(db.UserWithPwd{
|
|
Pwd: "123456",
|
|
User: db.User{
|
|
Email: "denguk@example.com",
|
|
Name: "Denis Gukov",
|
|
Username: "fiftin",
|
|
},
|
|
})
|
|
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
found, err := store.GetUsers(db.RetrieveQueryParams{})
|
|
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
if len(found) != 1 {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
}
|
|
|
|
func TestGetUser(t *testing.T) {
|
|
store := CreateTestStore()
|
|
|
|
usr, err := store.CreateUser(db.UserWithPwd{
|
|
Pwd: "123456",
|
|
User: db.User{
|
|
Email: "denguk@example.com",
|
|
Name: "Denis Gukov",
|
|
Username: "fiftin",
|
|
},
|
|
})
|
|
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
found, err := store.GetUser(usr.ID)
|
|
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
if found.Username != "fiftin" {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
err = store.DeleteUser(usr.ID)
|
|
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
}
|