Semaphore/db/bolt/user_test.go

112 lines
1.7 KiB
Go
Raw Normal View History

package bolt
import (
"github.com/semaphoreui/semaphore/db"
"testing"
2021-05-16 23:44:42 +02:00
"time"
)
2021-05-16 23:44:42 +02:00
func TestBoltDb_UpdateProjectUser(t *testing.T) {
store := CreateTestStore()
2021-05-16 23:44:42 +02:00
usr, err := store.CreateUser(db.UserWithPwd{
Pwd: "123456",
User: db.User{
Email: "denguk@example.com",
Name: "Denis Gukov",
2021-05-16 23:44:42 +02:00
Username: "fiftin",
},
})
if err != nil {
t.Fatal(err.Error())
}
proj1, err := store.CreateProject(db.Project{
Created: time.Now(),
Name: "Test1",
2021-05-16 23:44:42 +02:00
})
if err != nil {
t.Fatal(err.Error())
}
projUser, err := store.CreateProjectUser(db.ProjectUser{
ProjectID: proj1.ID,
UserID: usr.ID,
Role: db.ProjectOwner,
2021-05-16 23:44:42 +02:00
})
if err != nil {
t.Fatal(err.Error())
}
projUser.Role = db.ProjectOwner
2021-05-16 23:44:42 +02:00
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 {
2021-05-16 23:44:42 +02:00
t.Fatal(err.Error())
}
found, err := store.GetUsers(db.RetrieveQueryParams{})
if err != nil {
2021-05-16 23:44:42 +02:00
t.Fatal(err.Error())
}
if len(found) != 1 {
2021-05-16 23:44:42 +02:00
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 {
2021-05-16 23:44:42 +02:00
t.Fatal(err.Error())
}
found, err := store.GetUser(usr.ID)
if err != nil {
2021-05-16 23:44:42 +02:00
t.Fatal(err.Error())
}
if found.Username != "fiftin" {
2021-05-16 23:44:42 +02:00
t.Fatal(err.Error())
}
err = store.DeleteUser(usr.ID)
if err != nil {
2021-05-16 23:44:42 +02:00
t.Fatal(err.Error())
}
}