aboutsummaryrefslogtreecommitdiff
path: root/internal/db/org_users_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/org_users_test.go')
-rw-r--r--internal/db/org_users_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/internal/db/org_users_test.go b/internal/db/org_users_test.go
new file mode 100644
index 00000000..f5c486db
--- /dev/null
+++ b/internal/db/org_users_test.go
@@ -0,0 +1,51 @@
+// Copyright 2022 The Gogs 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 db
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ "gogs.io/gogs/internal/dbtest"
+)
+
+func TestOrgUsers(t *testing.T) {
+ if testing.Short() {
+ t.Skip()
+ }
+ t.Parallel()
+
+ tables := []interface{}{new(OrgUser)}
+ db := &orgUsers{
+ DB: dbtest.NewDB(t, "orgUsers", tables...),
+ }
+
+ for _, tc := range []struct {
+ name string
+ test func(t *testing.T, db *orgUsers)
+ }{
+ {"CountByUser", orgUsersCountByUser},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Cleanup(func() {
+ err := clearTables(t, db.DB, tables...)
+ require.NoError(t, err)
+ })
+ tc.test(t, db)
+ })
+ if t.Failed() {
+ break
+ }
+ }
+}
+
+func orgUsersCountByUser(t *testing.T, db *orgUsers) {
+ // 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)
+}