package models
import (
+ "strings"
"testing"
"code.gitea.io/gitea/modules/setting"
+
"github.com/stretchr/testify/assert"
)
AssertNotExistsBean(t, actionBean)
assert.NoError(t, NewRepoAction(user, repo))
AssertExistsAndLoadBean(t, actionBean)
+ CheckConsistencyFor(t, &Action{})
}
func TestRenameRepoAction(t *testing.T) {
oldRepoName := repo.Name
const newRepoName = "newRepoName"
repo.Name = newRepoName
+ repo.LowerName = strings.ToLower(newRepoName)
actionBean := &Action{
OpType: ActionRenameRepo,
AssertNotExistsBean(t, actionBean)
assert.NoError(t, RenameRepoAction(user, oldRepoName, repo))
AssertExistsAndLoadBean(t, actionBean)
+
+ _, err := x.Id(repo.ID).Cols("name", "lower_name").Update(repo)
+ assert.NoError(t, err)
+ CheckConsistencyFor(t, &Action{})
}
func TestPushCommits_ToAPIPayloadCommits(t *testing.T) {
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits))
AssertExistsAndLoadBean(t, commentBean)
AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ CheckConsistencyFor(t, &Action{})
}
func TestCommitRepoAction(t *testing.T) {
Commits: pushCommits,
}))
AssertExistsAndLoadBean(t, actionBean)
+ CheckConsistencyFor(t, &Action{})
}
func TestTransferRepoAction(t *testing.T) {
AssertNotExistsBean(t, actionBean)
assert.NoError(t, TransferRepoAction(user2, user2, repo))
AssertExistsAndLoadBean(t, actionBean)
+
+ _, err := x.Id(repo.ID).Cols("owner_id").Update(repo)
+ assert.NoError(t, err)
+ CheckConsistencyFor(t, &Action{})
}
func TestMergePullRequestAction(t *testing.T) {
AssertNotExistsBean(t, actionBean)
assert.NoError(t, MergePullRequestAction(user, repo, issue))
AssertExistsAndLoadBean(t, actionBean)
+ CheckConsistencyFor(t, &Action{})
}
func TestGetFeeds(t *testing.T) {
actions, err = GetFeeds(user, user.ID, 0, true)
assert.NoError(t, err)
- assert.Len(t, actions, 1)
- assert.Equal(t, int64(2), actions[0].ID)
- assert.Equal(t, user.ID, actions[0].UserID)
+ assert.Len(t, actions, 0)
}
import (
"reflect"
+ "strings"
"testing"
"github.com/stretchr/testify/assert"
&PullRequest{},
&Milestone{},
&Label{},
- &Team{})
+ &Team{},
+ &Action{})
}
// CheckConsistencyFor test that all matching database entries are consistent
ptrToSliceValue := reflect.New(sliceType)
ptrToSliceValue.Elem().Set(sliceValue)
- assert.NoError(t, x.Find(ptrToSliceValue.Interface()))
+ assert.NoError(t, x.Where(bean).Find(ptrToSliceValue.Interface()))
sliceValue = ptrToSliceValue.Elem()
for i := 0; i < sliceValue.Len(); i++ {
}
func (repo *Repository) CheckForConsistency(t *testing.T) {
+ assert.Equal(t, repo.LowerName, strings.ToLower(repo.Name), "repo: %+v", repo)
assertCount(t, &Star{RepoID: repo.ID}, repo.NumStars)
assertCount(t, &Watch{RepoID: repo.ID}, repo.NumWatches)
assertCount(t, &Milestone{RepoID: repo.ID}, repo.NumMilestones)
assertCount(t, &TeamUser{TeamID: team.ID}, team.NumMembers)
assertCount(t, &TeamRepo{TeamID: team.ID}, team.NumRepos)
}
+
+func (action *Action) CheckForConsistency(t *testing.T) {
+ repo := AssertExistsAndLoadBean(t, &Repository{ID: action.RepoID}).(*Repository)
+ owner := AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
+ actor := AssertExistsAndLoadBean(t, &User{ID: action.ActUserID}).(*User)
+
+ assert.Equal(t, repo.Name, action.RepoName, "action: %+v", action)
+ assert.Equal(t, repo.IsPrivate, action.IsPrivate, "action: %+v", action)
+ assert.Equal(t, owner.Name, action.RepoUserName, "action: %+v", action)
+ assert.Equal(t, actor.Name, action.ActUserName, "action: %+v", action)
+}