2018-02-19 22:24:10 +00:00
|
|
|
// Copyright 2018 Drone.IO Inc.
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2015-10-21 23:14:02 +00:00
|
|
|
package datastore
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-11-18 14:42:18 +00:00
|
|
|
"time"
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
"github.com/franela/goblin"
|
2021-11-13 19:18:06 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-10-12 07:25:13 +00:00
|
|
|
|
2021-09-27 17:51:55 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
2015-09-30 01:21:17 +00:00
|
|
|
)
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
func TestRepos(t *testing.T) {
|
2021-11-13 19:18:06 +00:00
|
|
|
store, closer := newTestStore(t, new(model.Repo), new(model.User), new(model.Build))
|
|
|
|
defer closer()
|
2015-09-30 01:21:17 +00: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() {
|
2021-11-13 19:18:06 +00:00
|
|
|
_, err := store.engine.Exec("DELETE FROM builds")
|
|
|
|
g.Assert(err).IsNil()
|
|
|
|
_, err = store.engine.Exec("DELETE FROM repos")
|
|
|
|
g.Assert(err).IsNil()
|
|
|
|
_, err = store.engine.Exec("DELETE FROM users")
|
|
|
|
g.Assert(err).IsNil()
|
2015-09-30 01:21:17 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should Set a Repo", func() {
|
2015-10-21 23:14:02 +00:00
|
|
|
repo := model.Repo{
|
2015-09-30 01:21:17 +00:00
|
|
|
UserID: 1,
|
2021-10-02 08:59:34 +00:00
|
|
|
FullName: "bradrydzewski/test",
|
2015-09-30 01:21:17 +00:00
|
|
|
Owner: "bradrydzewski",
|
2021-10-02 08:59:34 +00:00
|
|
|
Name: "test",
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
err1 := store.CreateRepo(&repo)
|
|
|
|
err2 := store.UpdateRepo(&repo)
|
|
|
|
getRepo, err3 := store.GetRepo(repo.ID)
|
2016-04-23 11:27:28 +00:00
|
|
|
|
2021-11-04 13:42:25 +00:00
|
|
|
g.Assert(err1).IsNil()
|
|
|
|
g.Assert(err2).IsNil()
|
|
|
|
g.Assert(err3).IsNil()
|
2021-11-13 19:18:06 +00:00
|
|
|
g.Assert(repo.ID).Equal(getRepo.ID)
|
2015-09-30 01:21:17 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should Add a Repo", func() {
|
2015-10-21 23:14:02 +00:00
|
|
|
repo := model.Repo{
|
2015-09-30 01:21:17 +00:00
|
|
|
UserID: 1,
|
2021-10-02 08:59:34 +00:00
|
|
|
FullName: "bradrydzewski/test",
|
2015-09-30 01:21:17 +00:00
|
|
|
Owner: "bradrydzewski",
|
2021-10-02 08:59:34 +00:00
|
|
|
Name: "test",
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
err := store.CreateRepo(&repo)
|
2021-11-04 13:42:25 +00:00
|
|
|
g.Assert(err).IsNil()
|
2015-09-30 01:21:17 +00:00
|
|
|
g.Assert(repo.ID != 0).IsTrue()
|
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should Get a Repo by ID", func() {
|
2015-10-21 23:14:02 +00:00
|
|
|
repo := model.Repo{
|
2015-09-30 01:21:17 +00:00
|
|
|
UserID: 1,
|
2021-10-02 08:59:34 +00:00
|
|
|
FullName: "bradrydzewski/test",
|
2015-09-30 01:21:17 +00:00
|
|
|
Owner: "bradrydzewski",
|
2021-10-02 08:59:34 +00:00
|
|
|
Name: "test",
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
g.Assert(store.CreateRepo(&repo)).IsNil()
|
|
|
|
getrepo, err := store.GetRepo(repo.ID)
|
2021-11-04 13:42:25 +00:00
|
|
|
g.Assert(err).IsNil()
|
2015-09-30 01:21:17 +00:00
|
|
|
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-21 23:14:02 +00:00
|
|
|
repo := model.Repo{
|
2015-09-30 01:21:17 +00:00
|
|
|
UserID: 1,
|
2021-10-02 08:59:34 +00:00
|
|
|
FullName: "bradrydzewski/test",
|
2015-09-30 01:21:17 +00:00
|
|
|
Owner: "bradrydzewski",
|
2021-10-02 08:59:34 +00:00
|
|
|
Name: "test",
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
g.Assert(store.CreateRepo(&repo)).IsNil()
|
|
|
|
getrepo, err := store.GetRepoName(repo.FullName)
|
2021-11-04 13:42:25 +00:00
|
|
|
g.Assert(err).IsNil()
|
2015-09-30 01:21:17 +00:00
|
|
|
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 Enforce Unique Repo Name", func() {
|
2015-10-21 23:14:02 +00:00
|
|
|
repo1 := model.Repo{
|
2015-09-30 01:21:17 +00:00
|
|
|
UserID: 1,
|
2021-10-02 08:59:34 +00:00
|
|
|
FullName: "bradrydzewski/test",
|
2015-09-30 01:21:17 +00:00
|
|
|
Owner: "bradrydzewski",
|
2021-10-02 08:59:34 +00:00
|
|
|
Name: "test",
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
2015-10-21 23:14:02 +00:00
|
|
|
repo2 := model.Repo{
|
2015-09-30 01:21:17 +00:00
|
|
|
UserID: 2,
|
2021-10-02 08:59:34 +00:00
|
|
|
FullName: "bradrydzewski/test",
|
2015-09-30 01:21:17 +00:00
|
|
|
Owner: "bradrydzewski",
|
2021-10-02 08:59:34 +00:00
|
|
|
Name: "test",
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
err1 := store.CreateRepo(&repo1)
|
|
|
|
err2 := store.CreateRepo(&repo2)
|
2021-11-04 13:42:25 +00:00
|
|
|
g.Assert(err1).IsNil()
|
2021-11-13 19:18:06 +00:00
|
|
|
g.Assert(err2 == nil).IsFalse()
|
2015-09-30 01:21:17 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2017-07-14 19:58:38 +00:00
|
|
|
|
2017-07-15 16:51:02 +00:00
|
|
|
func TestRepoList(t *testing.T) {
|
2021-11-13 19:18:06 +00:00
|
|
|
store, closer := newTestStore(t, new(model.Repo), new(model.User), new(model.Perm))
|
|
|
|
defer closer()
|
2017-07-15 16:51:02 +00:00
|
|
|
|
|
|
|
user := &model.User{
|
|
|
|
Login: "joe",
|
|
|
|
Email: "foo@bar.com",
|
|
|
|
Token: "e42080dddf012c718e476da161d21ad5",
|
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
assert.NoError(t, store.CreateUser(user))
|
2017-07-15 16:51:02 +00:00
|
|
|
|
|
|
|
repo1 := &model.Repo{
|
|
|
|
Owner: "bradrydzewski",
|
2021-10-02 08:59:34 +00:00
|
|
|
Name: "test",
|
|
|
|
FullName: "bradrydzewski/test",
|
2017-07-15 16:51:02 +00:00
|
|
|
}
|
|
|
|
repo2 := &model.Repo{
|
2021-10-02 08:59:34 +00:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
FullName: "test/test",
|
2017-07-15 16:51:02 +00:00
|
|
|
}
|
|
|
|
repo3 := &model.Repo{
|
|
|
|
Owner: "octocat",
|
|
|
|
Name: "hello-world",
|
|
|
|
FullName: "octocat/hello-world",
|
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
assert.NoError(t, store.CreateRepo(repo1))
|
|
|
|
assert.NoError(t, store.CreateRepo(repo2))
|
|
|
|
assert.NoError(t, store.CreateRepo(repo3))
|
2017-07-15 16:51:02 +00:00
|
|
|
|
2021-11-14 23:55:37 +00:00
|
|
|
for _, perm := range []*model.Perm{
|
2017-07-15 16:51:02 +00:00
|
|
|
{UserID: user.ID, Repo: repo1.FullName},
|
|
|
|
{UserID: user.ID, Repo: repo2.FullName},
|
2021-11-14 23:55:37 +00:00
|
|
|
} {
|
|
|
|
assert.NoError(t, store.PermUpsert(perm))
|
|
|
|
}
|
2017-07-15 16:51:02 +00:00
|
|
|
|
2021-11-13 19:18:06 +00:00
|
|
|
repos, err := store.RepoList(user, false)
|
2021-10-26 19:29:30 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if got, want := len(repos), 2; got != want {
|
|
|
|
t.Errorf("Want %d repositories, got %d", want, got)
|
|
|
|
}
|
|
|
|
if got, want := repos[0].ID, repo1.ID; got != want {
|
|
|
|
t.Errorf("Want repository id %d, got %d", want, got)
|
|
|
|
}
|
|
|
|
if got, want := repos[1].ID, repo2.ID; got != want {
|
|
|
|
t.Errorf("Want repository id %d, got %d", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOwnedRepoList(t *testing.T) {
|
2021-11-13 19:18:06 +00:00
|
|
|
store, closer := newTestStore(t, new(model.Repo), new(model.User), new(model.Perm))
|
|
|
|
defer closer()
|
2021-10-26 19:29:30 +00:00
|
|
|
|
|
|
|
user := &model.User{
|
|
|
|
Login: "joe",
|
|
|
|
Email: "foo@bar.com",
|
|
|
|
Token: "e42080dddf012c718e476da161d21ad5",
|
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
assert.NoError(t, store.CreateUser(user))
|
2021-10-26 19:29:30 +00:00
|
|
|
|
|
|
|
repo1 := &model.Repo{
|
|
|
|
Owner: "bradrydzewski",
|
|
|
|
Name: "test",
|
|
|
|
FullName: "bradrydzewski/test",
|
|
|
|
}
|
|
|
|
repo2 := &model.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
FullName: "test/test",
|
|
|
|
}
|
|
|
|
repo3 := &model.Repo{
|
|
|
|
Owner: "octocat",
|
|
|
|
Name: "hello-world",
|
|
|
|
FullName: "octocat/hello-world",
|
|
|
|
}
|
|
|
|
repo4 := &model.Repo{
|
|
|
|
Owner: "demo",
|
|
|
|
Name: "demo",
|
|
|
|
FullName: "demo/demo",
|
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
assert.NoError(t, store.CreateRepo(repo1))
|
|
|
|
assert.NoError(t, store.CreateRepo(repo2))
|
|
|
|
assert.NoError(t, store.CreateRepo(repo3))
|
|
|
|
assert.NoError(t, store.CreateRepo(repo4))
|
2021-10-26 19:29:30 +00:00
|
|
|
|
2021-11-14 23:55:37 +00:00
|
|
|
for _, perm := range []*model.Perm{
|
2021-10-26 19:29:30 +00:00
|
|
|
{UserID: user.ID, Repo: repo1.FullName, Push: true, Admin: false},
|
|
|
|
{UserID: user.ID, Repo: repo2.FullName, Push: false, Admin: true},
|
|
|
|
{UserID: user.ID, Repo: repo3.FullName},
|
|
|
|
{UserID: user.ID, Repo: repo4.FullName},
|
2021-11-14 23:55:37 +00:00
|
|
|
} {
|
|
|
|
assert.NoError(t, store.PermUpsert(perm))
|
|
|
|
}
|
2021-10-26 19:29:30 +00:00
|
|
|
|
2021-11-13 19:18:06 +00:00
|
|
|
repos, err := store.RepoList(user, true)
|
2017-07-15 16:51:02 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if got, want := len(repos), 2; got != want {
|
|
|
|
t.Errorf("Want %d repositories, got %d", want, got)
|
|
|
|
}
|
|
|
|
if got, want := repos[0].ID, repo1.ID; got != want {
|
|
|
|
t.Errorf("Want repository id %d, got %d", want, got)
|
|
|
|
}
|
|
|
|
if got, want := repos[1].ID, repo2.ID; got != want {
|
|
|
|
t.Errorf("Want repository id %d, got %d", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRepoCount(t *testing.T) {
|
2021-11-13 19:18:06 +00:00
|
|
|
store, closer := newTestStore(t, new(model.Repo))
|
|
|
|
defer closer()
|
2017-07-15 16:51:02 +00:00
|
|
|
|
|
|
|
repo1 := &model.Repo{
|
|
|
|
Owner: "bradrydzewski",
|
2021-10-02 08:59:34 +00:00
|
|
|
Name: "test",
|
|
|
|
FullName: "bradrydzewski/test",
|
2017-07-25 19:32:22 +00:00
|
|
|
IsActive: true,
|
2017-07-15 16:51:02 +00:00
|
|
|
}
|
|
|
|
repo2 := &model.Repo{
|
2021-10-02 08:59:34 +00:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
FullName: "test/test",
|
2017-07-25 19:32:22 +00:00
|
|
|
IsActive: true,
|
|
|
|
}
|
|
|
|
repo3 := &model.Repo{
|
2021-10-02 08:59:34 +00:00
|
|
|
Owner: "test",
|
|
|
|
Name: "test-ui",
|
|
|
|
FullName: "test/test-ui",
|
2017-07-25 19:32:22 +00:00
|
|
|
IsActive: false,
|
2017-07-15 16:51:02 +00:00
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
assert.NoError(t, store.CreateRepo(repo1))
|
|
|
|
assert.NoError(t, store.CreateRepo(repo2))
|
|
|
|
assert.NoError(t, store.CreateRepo(repo3))
|
2017-07-15 16:51:02 +00:00
|
|
|
|
2021-11-13 19:18:06 +00:00
|
|
|
count, _ := store.GetRepoCount()
|
|
|
|
if got, want := count, int64(2); got != want {
|
2017-07-15 16:51:02 +00:00
|
|
|
t.Errorf("Want %d repositories, got %d", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 19:58:38 +00:00
|
|
|
func TestRepoBatch(t *testing.T) {
|
2021-11-13 19:18:06 +00:00
|
|
|
store, closer := newTestStore(t, new(model.Repo), new(model.User), new(model.Perm))
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
if !assert.NoError(t, store.CreateRepo(&model.Repo{
|
2017-07-14 19:58:38 +00:00
|
|
|
UserID: 1,
|
|
|
|
FullName: "foo/bar",
|
|
|
|
Owner: "foo",
|
|
|
|
Name: "bar",
|
2017-07-25 19:32:22 +00:00
|
|
|
IsActive: true,
|
2021-11-13 19:18:06 +00:00
|
|
|
})) {
|
2017-07-14 19:58:38 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-14 21:13:59 +00:00
|
|
|
repos := []*model.Repo{
|
|
|
|
{
|
|
|
|
UserID: 1,
|
|
|
|
FullName: "foo/bar",
|
|
|
|
Owner: "foo",
|
|
|
|
Name: "bar",
|
|
|
|
IsActive: true,
|
2021-11-18 14:42:18 +00:00
|
|
|
Perm: &model.Perm{
|
|
|
|
UserID: 1,
|
|
|
|
Pull: true,
|
|
|
|
Push: true,
|
|
|
|
Admin: true,
|
|
|
|
Synced: time.Now().Unix(),
|
|
|
|
},
|
2021-11-14 21:13:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
UserID: 1,
|
|
|
|
FullName: "bar/baz",
|
|
|
|
Owner: "bar",
|
|
|
|
Name: "baz",
|
|
|
|
IsActive: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
UserID: 1,
|
|
|
|
FullName: "baz/qux",
|
|
|
|
Owner: "baz",
|
|
|
|
Name: "qux",
|
|
|
|
IsActive: true,
|
2017-07-14 19:58:38 +00:00
|
|
|
},
|
2021-11-14 21:13:59 +00:00
|
|
|
{
|
|
|
|
UserID: 0, // not activated repos do hot have a user id assigned
|
|
|
|
FullName: "baz/notes",
|
|
|
|
Owner: "baz",
|
|
|
|
Name: "notes",
|
|
|
|
IsActive: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if !assert.NoError(t, store.RepoBatch(repos)) {
|
2017-07-14 19:58:38 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-18 14:42:18 +00:00
|
|
|
// check DB state
|
|
|
|
perm, err := store.PermFind(&model.User{ID: 1}, repos[0])
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, perm.Admin)
|
|
|
|
|
2021-11-14 23:55:37 +00:00
|
|
|
repo := &model.Repo{
|
|
|
|
FullName: "foo/bar",
|
|
|
|
Owner: "foo",
|
|
|
|
Name: "bar",
|
2021-11-18 14:42:18 +00:00
|
|
|
Perm: &model.Perm{
|
|
|
|
UserID: 1,
|
|
|
|
Pull: true,
|
|
|
|
Push: true,
|
|
|
|
Admin: false,
|
|
|
|
Synced: time.Now().Unix(),
|
|
|
|
},
|
2021-11-14 23:55:37 +00:00
|
|
|
}
|
|
|
|
assert.NoError(t, store.RepoBatch([]*model.Repo{repo}))
|
|
|
|
assert.EqualValues(t, repos[0].ID, repo.ID)
|
2021-11-18 14:42:18 +00:00
|
|
|
|
|
|
|
// check current DB state
|
|
|
|
_, err = store.engine.ID(repo.ID).Get(repo)
|
2021-11-14 21:13:59 +00:00
|
|
|
assert.NoError(t, err)
|
2021-11-14 23:55:37 +00:00
|
|
|
assert.True(t, repo.IsActive)
|
2021-11-18 14:42:18 +00:00
|
|
|
perm, err = store.PermFind(&model.User{ID: 1}, repos[0])
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, perm.Admin)
|
2021-11-14 23:55:37 +00:00
|
|
|
|
|
|
|
allRepos := make([]*model.Repo, 0, 4)
|
|
|
|
assert.NoError(t, store.engine.Find(&allRepos))
|
2021-11-14 21:13:59 +00:00
|
|
|
assert.Len(t, allRepos, 4)
|
|
|
|
|
2021-11-13 19:18:06 +00:00
|
|
|
count, err := store.GetRepoCount()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 3, count)
|
2017-07-14 19:58:38 +00:00
|
|
|
}
|
2017-07-15 16:51:02 +00:00
|
|
|
|
|
|
|
func TestRepoCrud(t *testing.T) {
|
2021-12-11 15:03:14 +00:00
|
|
|
store, closer := newTestStore(t,
|
|
|
|
new(model.Repo),
|
|
|
|
new(model.User),
|
|
|
|
new(model.Perm),
|
|
|
|
new(model.Build),
|
|
|
|
new(model.BuildConfig),
|
|
|
|
new(model.Logs),
|
|
|
|
new(model.Proc),
|
|
|
|
new(model.File),
|
|
|
|
new(model.Secret),
|
|
|
|
new(model.Registry),
|
|
|
|
new(model.Config))
|
2021-11-13 19:18:06 +00:00
|
|
|
defer closer()
|
2017-07-15 16:51:02 +00:00
|
|
|
|
|
|
|
repo := model.Repo{
|
|
|
|
UserID: 1,
|
2021-10-02 08:59:34 +00:00
|
|
|
FullName: "bradrydzewski/test",
|
2017-07-15 16:51:02 +00:00
|
|
|
Owner: "bradrydzewski",
|
2021-10-02 08:59:34 +00:00
|
|
|
Name: "test",
|
2017-07-15 16:51:02 +00:00
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
assert.NoError(t, store.CreateRepo(&repo))
|
2021-12-11 15:03:14 +00:00
|
|
|
build := model.Build{
|
|
|
|
RepoID: repo.ID,
|
|
|
|
}
|
|
|
|
proc := model.Proc{
|
|
|
|
Name: "a proc",
|
2017-07-15 16:51:02 +00:00
|
|
|
}
|
2021-12-11 15:03:14 +00:00
|
|
|
assert.NoError(t, store.CreateBuild(&build, &proc))
|
|
|
|
|
|
|
|
// create unrelated
|
|
|
|
repoUnrelated := model.Repo{
|
|
|
|
UserID: 2,
|
|
|
|
FullName: "x/x",
|
|
|
|
Owner: "x",
|
|
|
|
Name: "x",
|
2017-07-15 16:51:02 +00:00
|
|
|
}
|
2021-12-11 15:03:14 +00:00
|
|
|
assert.NoError(t, store.CreateRepo(&repoUnrelated))
|
|
|
|
buildUnrelated := model.Build{
|
|
|
|
RepoID: repoUnrelated.ID,
|
2017-07-15 16:51:02 +00:00
|
|
|
}
|
2021-12-11 15:03:14 +00:00
|
|
|
procUnrelated := model.Proc{
|
|
|
|
Name: "a unrelated proc",
|
|
|
|
}
|
|
|
|
assert.NoError(t, store.CreateBuild(&buildUnrelated, &procUnrelated))
|
|
|
|
|
|
|
|
_, err := store.GetRepo(repo.ID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, store.DeleteRepo(&repo))
|
|
|
|
_, err = store.GetRepo(repo.ID)
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
procCount, err := store.engine.Count(new(model.Proc))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 1, procCount)
|
|
|
|
buildCount, err := store.engine.Count(new(model.Build))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 1, buildCount)
|
2017-07-15 16:51:02 +00:00
|
|
|
}
|