From a66c90462da24a916ee62afcb5a1f79d06ed8399 Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sat, 5 Nov 2022 13:12:53 +0800 Subject: refactor(db): migrate methods off `user.go` and `org.go` (#7219) (#7227) --- internal/db/org_users_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'internal/db/org_users_test.go') 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) } -- cgit v1.2.3