2015-10-22 01:14:02 +02:00
|
|
|
package datastore
|
2015-09-30 03:21:17 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-10-22 01:14:02 +02:00
|
|
|
"github.com/drone/drone/model"
|
2015-09-30 03:21:17 +02:00
|
|
|
"github.com/franela/goblin"
|
|
|
|
)
|
|
|
|
|
2016-03-25 21:54:16 +02:00
|
|
|
func TestRepos(t *testing.T) {
|
2015-10-22 01:14:02 +02:00
|
|
|
db := openTest()
|
2015-09-30 03:21:17 +02:00
|
|
|
defer db.Close()
|
|
|
|
|
2015-10-22 01:14:02 +02:00
|
|
|
s := From(db)
|
2015-09-30 03:21:17 +02:00
|
|
|
g := goblin.Goblin(t)
|
|
|
|
g.Describe("Repo", func() {
|
|
|
|
|
|
|
|
// before each test be sure to purge the package
|
|
|
|
// table data from the database.
|
|
|
|
g.BeforeEach(func() {
|
2015-10-03 01:16:41 +02:00
|
|
|
db.Exec("DELETE FROM builds")
|
2015-09-30 03:21:17 +02:00
|
|
|
db.Exec("DELETE FROM repos")
|
|
|
|
db.Exec("DELETE FROM users")
|
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should Set a Repo", func() {
|
2015-10-22 01:14:02 +02:00
|
|
|
repo := model.Repo{
|
2015-09-30 03:21:17 +02:00
|
|
|
UserID: 1,
|
|
|
|
FullName: "bradrydzewski/drone",
|
|
|
|
Owner: "bradrydzewski",
|
|
|
|
Name: "drone",
|
|
|
|
}
|
2016-03-25 21:54:16 +02:00
|
|
|
err1 := s.CreateRepo(&repo)
|
|
|
|
err2 := s.UpdateRepo(&repo)
|
|
|
|
getrepo, err3 := s.GetRepo(repo.ID)
|
2015-09-30 03:21:17 +02:00
|
|
|
if err3 != nil {
|
|
|
|
println("Get Repo Error")
|
|
|
|
println(err3.Error())
|
|
|
|
}
|
|
|
|
g.Assert(err1 == nil).IsTrue()
|
|
|
|
g.Assert(err2 == nil).IsTrue()
|
|
|
|
g.Assert(err3 == nil).IsTrue()
|
|
|
|
g.Assert(repo.ID).Equal(getrepo.ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should Add a Repo", func() {
|
2015-10-22 01:14:02 +02:00
|
|
|
repo := model.Repo{
|
2015-09-30 03:21:17 +02:00
|
|
|
UserID: 1,
|
|
|
|
FullName: "bradrydzewski/drone",
|
|
|
|
Owner: "bradrydzewski",
|
|
|
|
Name: "drone",
|
|
|
|
}
|
2016-03-25 21:54:16 +02:00
|
|
|
err := s.CreateRepo(&repo)
|
2015-09-30 03:21:17 +02:00
|
|
|
g.Assert(err == nil).IsTrue()
|
|
|
|
g.Assert(repo.ID != 0).IsTrue()
|
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should Get a Repo by ID", func() {
|
2015-10-22 01:14:02 +02:00
|
|
|
repo := model.Repo{
|
2015-09-30 03:21:17 +02:00
|
|
|
UserID: 1,
|
|
|
|
FullName: "bradrydzewski/drone",
|
|
|
|
Owner: "bradrydzewski",
|
|
|
|
Name: "drone",
|
|
|
|
}
|
2016-03-25 21:54:16 +02:00
|
|
|
s.CreateRepo(&repo)
|
|
|
|
getrepo, err := s.GetRepo(repo.ID)
|
2015-09-30 03:21:17 +02:00
|
|
|
g.Assert(err == nil).IsTrue()
|
|
|
|
g.Assert(repo.ID).Equal(getrepo.ID)
|
|
|
|
g.Assert(repo.UserID).Equal(getrepo.UserID)
|
|
|
|
g.Assert(repo.Owner).Equal(getrepo.Owner)
|
|
|
|
g.Assert(repo.Name).Equal(getrepo.Name)
|
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should Get a Repo by Name", func() {
|
2015-10-22 01:14:02 +02:00
|
|
|
repo := model.Repo{
|
2015-09-30 03:21:17 +02:00
|
|
|
UserID: 1,
|
|
|
|
FullName: "bradrydzewski/drone",
|
|
|
|
Owner: "bradrydzewski",
|
|
|
|
Name: "drone",
|
|
|
|
}
|
2016-03-25 21:54:16 +02:00
|
|
|
s.CreateRepo(&repo)
|
|
|
|
getrepo, err := s.GetRepoName(repo.FullName)
|
2015-09-30 03:21:17 +02:00
|
|
|
g.Assert(err == nil).IsTrue()
|
|
|
|
g.Assert(repo.ID).Equal(getrepo.ID)
|
|
|
|
g.Assert(repo.UserID).Equal(getrepo.UserID)
|
|
|
|
g.Assert(repo.Owner).Equal(getrepo.Owner)
|
|
|
|
g.Assert(repo.Name).Equal(getrepo.Name)
|
|
|
|
})
|
|
|
|
|
2015-10-22 02:17:29 +02:00
|
|
|
g.It("Should Get a Repo List", func() {
|
|
|
|
repo1 := &model.Repo{
|
|
|
|
UserID: 1,
|
|
|
|
Owner: "bradrydzewski",
|
|
|
|
Name: "drone",
|
|
|
|
FullName: "bradrydzewski/drone",
|
|
|
|
}
|
|
|
|
repo2 := &model.Repo{
|
|
|
|
UserID: 2,
|
|
|
|
Owner: "drone",
|
|
|
|
Name: "drone",
|
|
|
|
FullName: "drone/drone",
|
|
|
|
}
|
|
|
|
repo3 := &model.Repo{
|
|
|
|
UserID: 2,
|
|
|
|
Owner: "octocat",
|
|
|
|
Name: "hello-world",
|
|
|
|
FullName: "octocat/hello-world",
|
|
|
|
}
|
2016-03-25 21:54:16 +02:00
|
|
|
s.CreateRepo(repo1)
|
|
|
|
s.CreateRepo(repo2)
|
|
|
|
s.CreateRepo(repo3)
|
2015-10-22 02:17:29 +02:00
|
|
|
|
2016-03-25 21:54:16 +02:00
|
|
|
repos, err := s.GetRepoListOf([]*model.RepoLite{
|
2015-10-22 02:17:29 +02:00
|
|
|
{FullName: "bradrydzewski/drone"},
|
|
|
|
{FullName: "drone/drone"},
|
|
|
|
})
|
|
|
|
g.Assert(err == nil).IsTrue()
|
|
|
|
g.Assert(len(repos)).Equal(2)
|
|
|
|
g.Assert(repos[0].ID).Equal(repo1.ID)
|
|
|
|
g.Assert(repos[1].ID).Equal(repo2.ID)
|
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should Get a Repo List", func() {
|
|
|
|
repo1 := &model.Repo{
|
|
|
|
UserID: 1,
|
|
|
|
Owner: "bradrydzewski",
|
|
|
|
Name: "drone",
|
|
|
|
FullName: "bradrydzewski/drone",
|
|
|
|
}
|
|
|
|
repo2 := &model.Repo{
|
|
|
|
UserID: 2,
|
|
|
|
Owner: "drone",
|
|
|
|
Name: "drone",
|
|
|
|
FullName: "drone/drone",
|
|
|
|
}
|
2016-03-25 21:54:16 +02:00
|
|
|
s.CreateRepo(repo1)
|
|
|
|
s.CreateRepo(repo2)
|
2015-10-22 02:17:29 +02:00
|
|
|
|
2016-03-25 21:54:16 +02:00
|
|
|
count, err := s.GetRepoCount()
|
2015-10-22 02:17:29 +02:00
|
|
|
g.Assert(err == nil).IsTrue()
|
|
|
|
g.Assert(count).Equal(2)
|
|
|
|
})
|
2015-09-30 03:21:17 +02:00
|
|
|
|
|
|
|
g.It("Should Delete a Repo", func() {
|
2015-10-22 01:14:02 +02:00
|
|
|
repo := model.Repo{
|
2015-09-30 03:21:17 +02:00
|
|
|
UserID: 1,
|
|
|
|
FullName: "bradrydzewski/drone",
|
|
|
|
Owner: "bradrydzewski",
|
|
|
|
Name: "drone",
|
|
|
|
}
|
2016-03-25 21:54:16 +02:00
|
|
|
s.CreateRepo(&repo)
|
|
|
|
_, err1 := s.GetRepo(repo.ID)
|
|
|
|
err2 := s.DeleteRepo(&repo)
|
|
|
|
_, err3 := s.GetRepo(repo.ID)
|
2015-09-30 03:21:17 +02:00
|
|
|
g.Assert(err1 == nil).IsTrue()
|
|
|
|
g.Assert(err2 == nil).IsTrue()
|
|
|
|
g.Assert(err3 == nil).IsFalse()
|
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should Enforce Unique Repo Name", func() {
|
2015-10-22 01:14:02 +02:00
|
|
|
repo1 := model.Repo{
|
2015-09-30 03:21:17 +02:00
|
|
|
UserID: 1,
|
|
|
|
FullName: "bradrydzewski/drone",
|
|
|
|
Owner: "bradrydzewski",
|
|
|
|
Name: "drone",
|
|
|
|
}
|
2015-10-22 01:14:02 +02:00
|
|
|
repo2 := model.Repo{
|
2015-09-30 03:21:17 +02:00
|
|
|
UserID: 2,
|
|
|
|
FullName: "bradrydzewski/drone",
|
|
|
|
Owner: "bradrydzewski",
|
|
|
|
Name: "drone",
|
|
|
|
}
|
2016-03-25 21:54:16 +02:00
|
|
|
err1 := s.CreateRepo(&repo1)
|
|
|
|
err2 := s.CreateRepo(&repo2)
|
2015-09-30 03:21:17 +02:00
|
|
|
g.Assert(err1 == nil).IsTrue()
|
|
|
|
g.Assert(err2 == nil).IsFalse()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|