aboutsummaryrefslogtreecommitdiff
path: root/internal/db/org_users_test.go
diff options
context:
space:
mode:
authorJoe Chen <jc@unknwon.io>2022-11-05 13:12:53 +0800
committerGitHub <noreply@github.com>2022-11-05 13:12:53 +0800
commita66c90462da24a916ee62afcb5a1f79d06ed8399 (patch)
treeac193502864d4f9309e82adf2b883f2d6cdfe879 /internal/db/org_users_test.go
parent3af5a424f0e1afa9e77a60376bca97bc5c3b5f8b (diff)
refactor(db): migrate methods off `user.go` and `org.go` (#7219) (#7227)
Diffstat (limited to 'internal/db/org_users_test.go')
-rw-r--r--internal/db/org_users_test.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/internal/db/org_users_test.go b/internal/db/org_users_test.go
index f5c486db..ff7cd7b2 100644
--- a/internal/db/org_users_test.go
+++ b/internal/db/org_users_test.go
@@ -5,8 +5,10 @@
package db
import (
+ "context"
"testing"
+ "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gogs.io/gogs/internal/dbtest"
@@ -43,9 +45,19 @@ func TestOrgUsers(t *testing.T) {
}
func orgUsersCountByUser(t *testing.T, db *orgUsers) {
+ ctx := context.Background()
+
// TODO: Use OrgUsers.Join to replace SQL hack when the method is available.
err := db.Exec(`INSERT INTO org_user (uid, org_id) VALUES (?, ?)`, 1, 1).Error
require.NoError(t, err)
err = db.Exec(`INSERT INTO org_user (uid, org_id) VALUES (?, ?)`, 2, 1).Error
require.NoError(t, err)
+
+ got, err := db.CountByUser(ctx, 1)
+ require.NoError(t, err)
+ assert.Equal(t, int64(1), got)
+
+ got, err = db.CountByUser(ctx, 404)
+ require.NoError(t, err)
+ assert.Equal(t, int64(0), got)
}