summaryrefslogtreecommitdiffstats
path: root/models/consistency_test.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-02-27 20:42:10 -0500
committerLunny Xiao <xiaolunwen@gmail.com>2017-02-28 09:42:10 +0800
commit4b286f282a38d55b2271c43db80d3ac938746c79 (patch)
tree26995996ee01bc3e5a3224b334557b4af2433317 /models/consistency_test.go
parentcf80e191578618d94f32a0d1dece3169c4f99bf2 (diff)
downloadgitea-4b286f282a38d55b2271c43db80d3ac938746c79.tar.gz
gitea-4b286f282a38d55b2271c43db80d3ac938746c79.zip
Consistency checks for action unit tests (#1079)
Diffstat (limited to 'models/consistency_test.go')
-rw-r--r--models/consistency_test.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/models/consistency_test.go b/models/consistency_test.go
index cab8f9a782..a8de8e3c2b 100644
--- a/models/consistency_test.go
+++ b/models/consistency_test.go
@@ -6,6 +6,7 @@ package models
import (
"reflect"
+ "strings"
"testing"
"github.com/stretchr/testify/assert"
@@ -25,7 +26,8 @@ func CheckConsistencyForAll(t *testing.T) {
&PullRequest{},
&Milestone{},
&Label{},
- &Team{})
+ &Team{},
+ &Action{})
}
// CheckConsistencyFor test that all matching database entries are consistent
@@ -37,7 +39,7 @@ func CheckConsistencyFor(t *testing.T, beansToCheck ...interface{}) {
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++ {
@@ -80,6 +82,7 @@ func (user *User) CheckForConsistency(t *testing.T) {
}
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)
@@ -156,3 +159,14 @@ func (team *Team) CheckForConsistency(t *testing.T) {
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)
+}