summaryrefslogtreecommitdiffstats
path: root/models/repo/repo_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/repo/repo_test.go')
-rw-r--r--models/repo/repo_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/models/repo/repo_test.go b/models/repo/repo_test.go
new file mode 100644
index 0000000000..6f48a22e49
--- /dev/null
+++ b/models/repo/repo_test.go
@@ -0,0 +1,44 @@
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package repo
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestGetRepositoryCount(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ count, err1 := GetRepositoryCount(db.DefaultContext, 10)
+ privateCount, err2 := GetPrivateRepositoryCount(&user_model.User{ID: int64(10)})
+ publicCount, err3 := GetPublicRepositoryCount(&user_model.User{ID: int64(10)})
+ assert.NoError(t, err1)
+ assert.NoError(t, err2)
+ assert.NoError(t, err3)
+ assert.Equal(t, int64(3), count)
+ assert.Equal(t, privateCount+publicCount, count)
+}
+
+func TestGetPublicRepositoryCount(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ count, err := GetPublicRepositoryCount(&user_model.User{ID: int64(10)})
+ assert.NoError(t, err)
+ assert.Equal(t, int64(1), count)
+}
+
+func TestGetPrivateRepositoryCount(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ count, err := GetPrivateRepositoryCount(&user_model.User{ID: int64(10)})
+ assert.NoError(t, err)
+ assert.Equal(t, int64(2), count)
+}