2021-05-14 13:47:32 +02:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ansible-semaphore/semaphore/db"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetProjects(t *testing.T) {
|
|
|
|
store := createStore()
|
|
|
|
err := store.Connect()
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
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-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
proj1, err := store.CreateProject(db.Project{
|
|
|
|
Created: time.Now(),
|
|
|
|
Name: "Test1",
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = store.CreateProjectUser(db.ProjectUser{
|
|
|
|
ProjectID: proj1.ID,
|
|
|
|
UserID: usr.ID,
|
|
|
|
Admin: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
found, err := store.GetProjects(usr.ID)
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(found) != 1 {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetProject(t *testing.T) {
|
|
|
|
store := createStore()
|
|
|
|
err := store.Connect()
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
proj, err := store.CreateProject(db.Project{
|
|
|
|
Created: time.Now(),
|
|
|
|
Name: "Test1",
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
found, err := store.GetProject(proj.ID)
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if found.Name != "Test1" {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 13:57:51 +02:00
|
|
|
err = store.DeleteProject(proj.ID)
|
|
|
|
|
|
|
|
if err != nil {
|
2021-05-16 23:44:42 +02:00
|
|
|
t.Fatal(err.Error())
|
2021-05-14 13:57:51 +02:00
|
|
|
}
|
2021-05-14 13:47:32 +02:00
|
|
|
}
|