2021-05-14 13:47:32 +02:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ansible-semaphore/semaphore/db"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetUsers(t *testing.T) {
|
|
|
|
store := createStore()
|
|
|
|
err := store.Connect()
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-15 14:40:31 +02:00
|
|
|
t.Fatal()
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = store.CreateUser(db.UserWithPwd{
|
|
|
|
Pwd: "123456",
|
|
|
|
User: db.User{
|
|
|
|
Email: "denguk@example.com",
|
|
|
|
Name: "Denis Gukov",
|
|
|
|
Username: "fiftin",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-15 14:40:31 +02:00
|
|
|
t.Fatal()
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
found, err := store.GetUsers(db.RetrieveQueryParams{})
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-15 14:40:31 +02:00
|
|
|
t.Fatal()
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(found) != 1 {
|
2021-05-15 14:40:31 +02:00
|
|
|
t.Fatal()
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetUser(t *testing.T) {
|
|
|
|
store := createStore()
|
|
|
|
err := store.Connect()
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-15 14:40:31 +02:00
|
|
|
t.Fatal()
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-15 14:40:31 +02:00
|
|
|
t.Fatal()
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
found, err := store.GetUser(usr.ID)
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-15 14:40:31 +02:00
|
|
|
t.Fatal()
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if found.Username != "fiftin" {
|
2021-05-15 14:40:31 +02:00
|
|
|
t.Fatal()
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 13:57:51 +02:00
|
|
|
err = store.DeleteUser(usr.ID)
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-15 14:40:31 +02:00
|
|
|
t.Fatal()
|
2021-05-14 13:57:51 +02:00
|
|
|
}
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|