From 8c04b86f1939f193a55cb665bbe9cc0936efdded Mon Sep 17 00:00:00 2001 From: yiling Date: Mon, 25 Nov 2024 16:54:15 +0800 Subject: [PATCH 1/3] update db tests --- builder/store/database/access_token.go | 15 +- builder/store/database/access_token_test.go | 205 +++++ builder/store/database/account_metering.go | 8 +- .../store/database/account_metering_test.go | 156 ++++ builder/store/database/cluster.go | 6 + builder/store/database/cluster_test.go | 58 ++ builder/store/database/code.go | 4 + builder/store/database/code_test.go | 120 +++ builder/store/database/collection.go | 6 + builder/store/database/collection_test.go | 265 ++++++ builder/store/database/dataset.go | 16 +- builder/store/database/dataset_test.go | 223 +++++ builder/store/database/deploy_task.go | 4 + builder/store/database/deploy_task_test.go | 240 +++++ builder/store/database/discussion.go | 6 + builder/store/database/discussion_test.go | 74 ++ builder/store/database/file.go | 6 + builder/store/database/file_test.go | 85 ++ .../store/database/git_server_access_token.go | 6 + .../database/git_server_access_token_test.go | 96 ++ builder/store/database/repository.go | 8 +- builder/store/database/repository_test.go | 817 ++++++++++++++++++ common/tests/testutils.go | 99 ++- 23 files changed, 2503 insertions(+), 20 deletions(-) create mode 100644 builder/store/database/access_token_test.go create mode 100644 builder/store/database/account_metering_test.go create mode 100644 builder/store/database/cluster_test.go create mode 100644 builder/store/database/code_test.go create mode 100644 builder/store/database/collection_test.go create mode 100644 builder/store/database/dataset_test.go create mode 100644 builder/store/database/deploy_task_test.go create mode 100644 builder/store/database/discussion_test.go create mode 100644 builder/store/database/file_test.go create mode 100644 builder/store/database/git_server_access_token_test.go create mode 100644 builder/store/database/repository_test.go diff --git a/builder/store/database/access_token.go b/builder/store/database/access_token.go index ae63d318..d56a6948 100644 --- a/builder/store/database/access_token.go +++ b/builder/store/database/access_token.go @@ -29,6 +29,10 @@ type AccessTokenStore interface { FindByUser(ctx context.Context, username, app string) ([]AccessToken, error) } +func NewAccessTokenStoreWithDB(db *DB) AccessTokenStore { + return &accessTokenStoreImpl{db: db} +} + func NewAccessTokenStore() AccessTokenStore { return &accessTokenStoreImpl{ db: defaultDB, @@ -94,16 +98,15 @@ func (s *accessTokenStoreImpl) Refresh(ctx context.Context, token *AccessToken, return newToken, err } -func (s *accessTokenStoreImpl) FindByID(ctx context.Context, id int64) (token *AccessToken, err error) { - var tokens []AccessToken - err = s.db.Operator.Core. +func (s *accessTokenStoreImpl) FindByID(ctx context.Context, id int64) (*AccessToken, error) { + var token AccessToken + err := s.db.Operator.Core. NewSelect(). - Model(&tokens). + Model(&token). Relation("User"). Where("access_token.id = ?", id). Scan(ctx) - token = &tokens[0] - return + return &token, err } func (s *accessTokenStoreImpl) Delete(ctx context.Context, username, tkName, app string) (err error) { diff --git a/builder/store/database/access_token_test.go b/builder/store/database/access_token_test.go new file mode 100644 index 00000000..f19fcf39 --- /dev/null +++ b/builder/store/database/access_token_test.go @@ -0,0 +1,205 @@ +package database_test + +import ( + "context" + "testing" + "time" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestAccessTokenStore_Create(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + + ctx := context.TODO() + atStore := database.NewAccessTokenStoreWithDB(db) + + token := &database.AccessToken{ + GitID: 1234, + Name: "test-token", + Token: "abcd1234", + UserID: 1, + Application: types.AccessTokenApp("test-app"), + Permission: "read-write", + ExpiredAt: time.Now().Add(24 * time.Hour), + IsActive: true, + } + + err := atStore.Create(ctx, token) + require.Nil(t, err) + + storedToken, err := atStore.FindByID(ctx, token.ID) + require.Nil(t, err) + require.Equal(t, token.Token, storedToken.Token) + require.True(t, storedToken.IsActive) +} + +func TestAccessTokenStore_Refresh(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + + ctx := context.TODO() + atStore := database.NewAccessTokenStoreWithDB(db) + + oldToken := &database.AccessToken{ + GitID: 1234, + Name: "test-token", + Token: "abcd1234", + UserID: 1, + Application: types.AccessTokenApp("test-app"), + Permission: "read-write", + ExpiredAt: time.Now().Add(24 * time.Hour), + IsActive: true, + } + + err := atStore.Create(ctx, oldToken) + require.Nil(t, err) + + newTokenValue := "xyz7890" + newExpiredAt := time.Now().Add(48 * time.Hour) + + newToken, err := atStore.Refresh(ctx, oldToken, newTokenValue, newExpiredAt) + require.Nil(t, err) + require.NotNil(t, newToken) + require.Equal(t, newTokenValue, newToken.Token) + require.True(t, newToken.IsActive) + + // Verify old token is inactive + storedOldToken, err := atStore.FindByID(ctx, oldToken.ID) + require.Nil(t, err) + require.False(t, storedOldToken.IsActive) +} + +func TestAccessTokenStore_Delete(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + + ctx := context.TODO() + atStore := database.NewAccessTokenStoreWithDB(db) + userStore := database.NewUserStoreWithDB(db) + + user := &database.User{ + NickName: "nickname", + Email: "test-user@example.com", + Username: "username", + } + namespace := &database.Namespace{ + Path: "username", + User: *user, + } + err := userStore.Create(ctx, user, namespace) + require.Nil(t, err) + + token := &database.AccessToken{ + GitID: 1234, + Name: "delete-token", + Token: "to-delete", + UserID: user.ID, + Application: types.AccessTokenApp("test-app"), + Permission: "read-write", + IsActive: true, + } + + err = atStore.Create(ctx, token) + require.Nil(t, err) + + err = atStore.Delete(ctx, "username", "delete-token", "test-app") + require.Nil(t, err) + + _, err = atStore.FindByID(ctx, token.ID) + require.NotNil(t, err) +} + +func TestAccessTokenStore_IsExist(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + + ctx := context.TODO() + atStore := database.NewAccessTokenStoreWithDB(db) + userStore := database.NewUserStoreWithDB(db) + + user := &database.User{ + NickName: "nickname1", + Email: "test-user1@example.com", + Username: "username1", + } + namespace := &database.Namespace{ + Path: "username1", + User: *user, + } + err := userStore.Create(ctx, user, namespace) + require.Nil(t, err) + + token := &database.AccessToken{ + GitID: 1234, + Name: "exist-token", + Token: "exists", + UserID: user.ID, + Application: types.AccessTokenApp("test-app"), + IsActive: true, + } + + err = atStore.Create(ctx, token) + require.Nil(t, err) + + exists, err := atStore.IsExist(ctx, "username1", "exist-token", "test-app") + require.Nil(t, err) + require.True(t, exists) + + exists, err = atStore.IsExist(ctx, "username1", "nonexistent-token", "test-app") + require.Nil(t, err) + require.False(t, exists) +} + +func TestAccessTokenStore_FindByUID(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + + ctx := context.TODO() + atStore := database.NewAccessTokenStoreWithDB(db) + + token := &database.AccessToken{ + GitID: 1234, + Name: "uid-token", + Token: "uid1234", + UserID: 1, + Application: types.AccessTokenApp("git"), + IsActive: true, + } + + err := atStore.Create(ctx, token) + require.Nil(t, err) + + storedToken, err := atStore.FindByUID(ctx, token.UserID) + require.Nil(t, err) + require.Equal(t, token.Token, storedToken.Token) + require.True(t, storedToken.IsActive) +} + +func TestAccessTokenStore_FindByToken(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + + ctx := context.TODO() + atStore := database.NewAccessTokenStoreWithDB(db) + + token := &database.AccessToken{ + GitID: 1234, + Name: "find-token", + Token: "find-me", + UserID: 1, + Application: types.AccessTokenApp("test-app"), + IsActive: true, + } + + err := atStore.Create(ctx, token) + require.Nil(t, err) + + storedToken, err := atStore.FindByToken(ctx, "find-me", "test-app") + require.Nil(t, err) + require.Equal(t, token.Token, storedToken.Token) +} diff --git a/builder/store/database/account_metering.go b/builder/store/database/account_metering.go index 5185abf6..95b46fa9 100644 --- a/builder/store/database/account_metering.go +++ b/builder/store/database/account_metering.go @@ -16,7 +16,7 @@ type accountMeteringStoreImpl struct { type AccountMeteringStore interface { Create(ctx context.Context, input AccountMetering) error - ListByUserIDAndTime(ctx context.Context, req commonTypes.ACCT_STATEMENTS_REQ) ([]AccountMetering, int, error) + ListByUserIDAndTime(ctx context.Context, req types.ACCT_STATEMENTS_REQ) ([]AccountMetering, int, error) ListAllByUserUUID(ctx context.Context, userUUID string) ([]AccountMetering, error) } @@ -26,6 +26,12 @@ func NewAccountMeteringStore() AccountMeteringStore { } } +func NewAccountMeteringStoreWithDB(db *DB) AccountMeteringStore { + return &accountMeteringStoreImpl{ + db: db, + } +} + type AccountMetering struct { ID int64 `bun:",pk,autoincrement" json:"id"` EventUUID uuid.UUID `bun:"type:uuid,notnull" json:"event_uuid"` diff --git a/builder/store/database/account_metering_test.go b/builder/store/database/account_metering_test.go new file mode 100644 index 00000000..adb4469d --- /dev/null +++ b/builder/store/database/account_metering_test.go @@ -0,0 +1,156 @@ +package database_test + +import ( + "context" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestAccountMeteringStore_Create(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewAccountMeteringStoreWithDB(db) + am := database.AccountMetering{ + UserUUID: "foo", + Value: 12.34, + ValueType: 1, + ResourceName: "abc", + } + err := store.Create(ctx, am) + require.Nil(t, err) + amn := &database.AccountMetering{} + err = db.Core.NewSelect().Model(amn).Where("user_uuid = ?", "foo").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "foo", amn.UserUUID) + require.Equal(t, 12.34, amn.Value) + require.Equal(t, 1, amn.ValueType) + require.Equal(t, "abc", amn.ResourceName) +} + +func TestAccountMeteringStore_ListByUserIDAndTime(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewAccountMeteringStoreWithDB(db) + + dt := time.Date(2022, 11, 22, 3, 0, 0, 0, time.UTC) + ams := []database.AccountMetering{ + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r1", Scene: types.SceneSpace, CustomerID: "bar", + RecordedAt: dt.Add(-1 * time.Hour), EventUUID: uuid.New(), + }, + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r2", Scene: types.SceneSpace, CustomerID: "bar", + RecordedAt: dt.Add(-2 * time.Hour), EventUUID: uuid.New(), + }, + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r3", Scene: types.SceneSpace, CustomerID: "bar", + RecordedAt: dt.Add(1 * time.Hour), EventUUID: uuid.New(), + }, + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r4", Scene: types.SceneSpace, CustomerID: "bar", + RecordedAt: dt.Add(2 * time.Hour), EventUUID: uuid.New(), + }, + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r5", Scene: types.SceneSpace, CustomerID: "bar", + RecordedAt: dt.Add(-1 * time.Hour), EventUUID: uuid.New(), + }, + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r6", Scene: types.SceneSpace, CustomerID: "bar", + RecordedAt: dt.Add(-6 * time.Hour), EventUUID: uuid.New(), + }, + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r7", Scene: types.SceneSpace, CustomerID: "bar", + RecordedAt: dt.Add(6 * time.Hour), EventUUID: uuid.New(), + }, + { + UserUUID: "bar", Value: 12.34, ValueType: 1, + ResourceName: "r8", Scene: types.SceneSpace, CustomerID: "bar", + RecordedAt: dt.Add(-1 * time.Hour), EventUUID: uuid.New(), + }, + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r9", Scene: types.SceneMultiSync, CustomerID: "bar", + RecordedAt: dt.Add(-1 * time.Hour), EventUUID: uuid.New(), + }, + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r10", Scene: types.SceneSpace, CustomerID: "barz", + RecordedAt: dt.Add(-1 * time.Hour), EventUUID: uuid.New(), + }, + } + + for _, am := range ams { + err := store.Create(ctx, am) + require.Nil(t, err) + } + + ams, total, err := store.ListByUserIDAndTime(ctx, types.ACCT_STATEMENTS_REQ{ + UserUUID: "foo", + Scene: 11, + InstanceName: "bar", + StartTime: dt.Add(-5 * time.Hour).Format(time.RFC3339), + EndTime: dt.Add(5 * time.Hour).Format(time.RFC3339), + }) + require.Nil(t, err) + require.Equal(t, 5, total) + names := []string{} + for _, am := range ams { + names = append(names, am.ResourceName) + } + require.Equal(t, []string{"r5", "r4", "r3", "r2", "r1"}, names) +} + +func TestAccountMeteringStore_ListAllByUserUUID(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewAccountMeteringStoreWithDB(db) + ams := []database.AccountMetering{ + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r1", Scene: types.SceneSpace, CustomerID: "bar", + EventUUID: uuid.New(), + }, + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r2", Scene: types.SceneSpace, CustomerID: "bar", + EventUUID: uuid.New(), + }, + { + UserUUID: "foo", Value: 12.34, ValueType: 1, + ResourceName: "r3", Scene: types.SceneSpace, CustomerID: "bar", + EventUUID: uuid.New(), + }, + { + UserUUID: "bar", Value: 12.34, ValueType: 1, + ResourceName: "r4", Scene: types.SceneSpace, CustomerID: "bar", + EventUUID: uuid.New(), + }, + } + + for _, am := range ams { + err := store.Create(ctx, am) + require.Nil(t, err) + } + data, err := store.ListAllByUserUUID(ctx, "foo") + require.Nil(t, err) + require.Equal(t, 3, len(data)) +} diff --git a/builder/store/database/cluster.go b/builder/store/database/cluster.go index f79a3f53..0b0fb226 100644 --- a/builder/store/database/cluster.go +++ b/builder/store/database/cluster.go @@ -27,6 +27,12 @@ func NewClusterInfoStore() ClusterInfoStore { } } +func NewClusterInfoStoreWithDB(db *DB) ClusterInfoStore { + return &clusterInfoStoreImpl{ + db: db, + } +} + type ClusterInfo struct { ClusterID string `bun:",pk" json:"cluster_id"` ClusterConfig string `bun:",notnull" json:"cluster_config"` diff --git a/builder/store/database/cluster_test.go b/builder/store/database/cluster_test.go new file mode 100644 index 00000000..e44c37c0 --- /dev/null +++ b/builder/store/database/cluster_test.go @@ -0,0 +1,58 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestClusterStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewClusterInfoStoreWithDB(db) + + err := store.Add(ctx, "foo", "bar") + require.Nil(t, err) + + cfg := &database.ClusterInfo{} + err = db.Core.NewSelect().Model(cfg).Where("cluster_config=?", "foo").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "bar", cfg.Region) + + // already exist, do nothing + err = store.Add(ctx, "foo", "bar2") + require.Nil(t, err) + err = db.Core.NewSelect().Model(cfg).Where("cluster_config=?", "foo").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "bar", cfg.Region) + + err = db.Core.NewSelect().Model(cfg).Where("cluster_config=?", "foo").Scan(ctx) + require.Nil(t, err) + err = store.Update(ctx, database.ClusterInfo{ + ClusterID: cfg.ClusterID, + ClusterConfig: "foo", + Region: "bar3", + }) + require.Nil(t, err) + err = db.Core.NewSelect().Model(cfg).Where("cluster_config=?", "foo").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "bar3", cfg.Region) + + dbCluster := &database.ClusterInfo{} + err = db.Core.NewSelect().Model(dbCluster).Limit(1).Scan(ctx) + require.Nil(t, err) + info, err := store.ByClusterID(ctx, dbCluster.ClusterID) + require.Nil(t, err) + require.Equal(t, "bar3", info.Region) + + infos, err := store.List(ctx) + require.Nil(t, err) + require.Equal(t, 1, len(infos)) + require.Equal(t, "bar3", infos[0].Region) + +} diff --git a/builder/store/database/code.go b/builder/store/database/code.go index 404c3031..0189f992 100644 --- a/builder/store/database/code.go +++ b/builder/store/database/code.go @@ -30,6 +30,10 @@ func NewCodeStore() CodeStore { return &codeStoreImpl{db: defaultDB} } +func NewCodeStoreWithDB(db *DB) CodeStore { + return &codeStoreImpl{db: db} +} + type Code struct { ID int64 `bun:",pk,autoincrement" json:"id"` RepositoryID int64 `bun:",notnull" json:"repository_id"` diff --git a/builder/store/database/code_test.go b/builder/store/database/code_test.go new file mode 100644 index 00000000..a924c6a3 --- /dev/null +++ b/builder/store/database/code_test.go @@ -0,0 +1,120 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestCodeStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewCodeStoreWithDB(db) + repo, err := database.NewRepoStoreWithDB(db).CreateRepo(ctx, database.Repository{ + Path: "foo/bar", + Private: true, + }) + require.Nil(t, err) + + _, err = store.Create(ctx, database.Code{ + RepositoryID: 123, + }) + require.Nil(t, err) + + code := &database.Code{} + err = db.Core.NewSelect().Model(code).Where("repository_id=?", 123).Scan(ctx) + require.Nil(t, err) + require.Equal(t, int64(123), code.RepositoryID) + + code.RepositoryID = repo.ID + err = store.Update(ctx, *code) + require.Nil(t, err) + err = db.Core.NewSelect().Model(code).Where("repository_id=?", repo.ID).Scan(ctx) + require.Nil(t, err) + require.Equal(t, repo.ID, code.RepositoryID) + + cd, err := store.ByRepoID(ctx, repo.ID) + require.Nil(t, err) + require.Equal(t, repo.ID, cd.RepositoryID) + + cds, err := store.ByRepoIDs(ctx, []int64{repo.ID}) + require.Nil(t, err) + require.Equal(t, 1, len(cds)) + require.Equal(t, repo.ID, cds[0].RepositoryID) + + cds, total, err := store.ByUsername(ctx, "foo", 10, 1, false) + require.Nil(t, err) + require.Equal(t, 1, total) + require.Equal(t, 1, len(cds)) + require.Equal(t, repo.ID, cds[0].RepositoryID) + + cds, total, err = store.ByUsername(ctx, "foo", 10, 1, true) + require.Nil(t, err) + require.Equal(t, 0, total) + require.Equal(t, 0, len(cds)) + + cd, err = store.FindByPath(ctx, "foo", "bar") + require.Nil(t, err) + require.Equal(t, repo.ID, cd.RepositoryID) + + cds, err = store.ListByPath(ctx, []string{"foo/bar"}) + require.Nil(t, err) + require.Equal(t, 1, len(cds)) + require.Equal(t, repo.ID, cds[0].RepositoryID) + + cds, total, err = store.ByOrgPath(ctx, "foo", 10, 1, false) + require.Nil(t, err) + require.Equal(t, 1, total) + require.Equal(t, 1, len(cds)) + require.Equal(t, repo.ID, cds[0].RepositoryID) + + cds, total, err = store.ByOrgPath(ctx, "foo", 10, 1, true) + require.Nil(t, err) + require.Equal(t, 0, total) + require.Equal(t, 0, len(cds)) + +} + +func TestCodeStore_UserLikesCodes(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewCodeStoreWithDB(db) + + repo1, err := database.NewRepoStoreWithDB(db).CreateRepo(ctx, database.Repository{ + Path: "foo/bar", + GitPath: "p1", + }) + require.Nil(t, err) + repo2, err := database.NewRepoStoreWithDB(db).CreateRepo(ctx, database.Repository{ + Path: "foo/bar2", + GitPath: "p2", + }) + require.Nil(t, err) + + _, err = store.Create(ctx, database.Code{ + RepositoryID: repo1.ID, + }) + require.Nil(t, err) + _, err = store.Create(ctx, database.Code{ + RepositoryID: repo2.ID, + }) + require.Nil(t, err) + _, err = db.Core.NewInsert().Model(&database.UserLike{ + UserID: 123, + RepoID: repo2.ID, + }).Exec(ctx) + require.Nil(t, err) + + cs, total, err := store.UserLikesCodes(ctx, 123, 10, 1) + require.Nil(t, err) + require.Equal(t, 1, total) + require.Equal(t, repo2.ID, cs[0].RepositoryID) + +} diff --git a/builder/store/database/collection.go b/builder/store/database/collection.go index d7d48838..9c9457cc 100644 --- a/builder/store/database/collection.go +++ b/builder/store/database/collection.go @@ -39,6 +39,12 @@ func NewCollectionStore() CollectionStore { } } +func NewCollectionStoreWithDB(db *DB) CollectionStore { + return &collectionStoreImpl{ + db: db, + } +} + type Collection struct { ID int64 `bun:",pk,autoincrement" json:"id"` Namespace string `bun:",notnull" json:"namespace"` diff --git a/builder/store/database/collection_test.go b/builder/store/database/collection_test.go new file mode 100644 index 00000000..ad8abd39 --- /dev/null +++ b/builder/store/database/collection_test.go @@ -0,0 +1,265 @@ +package database_test + +import ( + "context" + "fmt" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestCollectionStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewCollectionStoreWithDB(db) + + _, err := store.CreateCollection(ctx, database.Collection{ + Namespace: "n", + Name: "col", + Nickname: "loc", + UserID: 123, + }) + require.Nil(t, err) + + dbc := &database.Collection{} + err = db.Core.NewSelect().Model(dbc).Where("name=?", "col").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "n", dbc.Namespace) + require.Equal(t, "loc", dbc.Nickname) + + dbc.Nickname = "lll" + _, err = store.UpdateCollection(ctx, *dbc) + require.Nil(t, err) + dbc = &database.Collection{} + err = db.Core.NewSelect().Model(dbc).Where("name=?", "col").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "lll", dbc.Nickname) + + col, err := store.FindById(ctx, dbc.ID) + require.Nil(t, err) + require.Equal(t, "n", col.Namespace) + require.Equal(t, "lll", col.Nickname) + + err = store.DeleteCollection(ctx, col.ID, 123) + require.Nil(t, err) + dbc = &database.Collection{} + err = db.Core.NewSelect().Model(dbc).Where("name=?", "col").Scan(ctx) + require.NotNil(t, err) +} + +func TestCollectionStore_CollectionRepo(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewCollectionStoreWithDB(db) + + dt := &database.Tag{} + err := db.Core.NewInsert().Model(&database.Tag{ + Name: "tag1", + Category: "task", + }).Scan(ctx, dt) + require.Nil(t, err) + tag1pk := dt.ID + + err = db.Core.NewInsert().Model(&database.Tag{ + Name: "tag2", + Category: "foo", + }).Scan(ctx, dt) + require.Nil(t, err) + tag2pk := dt.ID + + dr := &database.Repository{} + err = db.Core.NewInsert().Model(&database.Repository{ + Path: "foo/bar", + }).Scan(ctx, dr) + require.Nil(t, err) + repopk := dr.ID + + for _, tpk := range []int64{tag1pk, tag2pk} { + _, err = db.Core.NewInsert().Model(&database.RepositoryTag{ + RepositoryID: repopk, + TagID: tpk, + }).Exec(ctx) + require.Nil(t, err) + } + + col, err := store.CreateCollection(ctx, database.Collection{ + Name: "foo", + Private: false, + }) + require.Nil(t, err) + err = store.AddCollectionRepos(ctx, []database.CollectionRepository{ + {CollectionID: col.ID, RepositoryID: repopk}, + }) + require.Nil(t, err) + + col, err = store.GetCollection(ctx, col.ID) + require.Nil(t, err) + require.Equal(t, 1, len(col.Repositories)) + require.Equal(t, "foo/bar", col.Repositories[0].Path) + tags := []string{} + for _, t := range col.Repositories[0].Tags { + tags = append(tags, t.Name) + } + require.Equal(t, []string{"tag1"}, tags) + + err = store.RemoveCollectionRepos(ctx, []database.CollectionRepository{ + {CollectionID: col.ID, RepositoryID: repopk}, + }) + require.Nil(t, err) + col, err = store.GetCollection(ctx, col.ID) + require.Nil(t, err) + require.Equal(t, 0, len(col.Repositories)) + +} + +func TestCollectionStore_GetCollections(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewCollectionStoreWithDB(db) + + collections := []*database.Collection{ + {Name: "col1-1", Private: false, Likes: 20}, + {Name: "col1-2", Private: true, Likes: 40}, + {Name: "col1-3", Private: false, Likes: 50}, + {Name: "col2-1", Private: false, Likes: 30}, + } + + for _, col := range collections { + dc, err := store.CreateCollection(ctx, *col) + col.ID = dc.ID + require.Nil(t, err) + } + + names := func(cs []database.Collection) []string { + names := []string{} + for _, c := range cs { + names = append(names, c.Name) + } + return names + } + cs, total, err := store.GetCollections(ctx, &types.CollectionFilter{}, 10, 1, false) + require.Nil(t, err) + require.Equal(t, 3, total) + require.Equal(t, []string{"col1-1", "col1-3", "col2-1"}, names(cs)) + + // showPrivate param is not used here + cs, total, err = store.GetCollections(ctx, &types.CollectionFilter{}, 10, 1, true) + require.Nil(t, err) + require.Equal(t, 3, total) + require.Equal(t, []string{"col1-1", "col1-3", "col2-1"}, names(cs)) + + cs, total, err = store.GetCollections(ctx, &types.CollectionFilter{ + Search: "cOl1", + }, 10, 1, false) + require.Nil(t, err) + require.Equal(t, 2, total) + require.Equal(t, []string{"col1-1", "col1-3"}, names(cs)) + + cs, total, err = store.GetCollections(ctx, &types.CollectionFilter{ + Sort: "most_favorite", + }, 10, 1, false) + require.Nil(t, err) + require.Equal(t, 3, total) + require.Equal(t, []string{"col1-3", "col2-1", "col1-1"}, names(cs)) + + weights := []int{3, 2, 11, 7} + scores := []float64{150, 13, 12, 11} + for i, col := range collections { + + repo := &database.Repository{ + Path: fmt.Sprintf("foo/bar%d", i), + GitPath: fmt.Sprintf("foo/bar%d", i), + } + err := db.Core.NewInsert().Model(repo).Scan(ctx, repo) + require.Nil(t, err) + err = store.AddCollectionRepos(ctx, []database.CollectionRepository{ + {CollectionID: col.ID, RepositoryID: repo.ID}, + }) + require.Nil(t, err) + + _, err = db.Core.NewInsert().Model(&database.RecomOpWeight{ + RepositoryID: repo.ID, + Weight: weights[i], + }).Exec(ctx) + require.Nil(t, err) + + _, err = db.Core.NewInsert().Model(&database.RecomRepoScore{ + RepositoryID: repo.ID, + Score: scores[i], + }).Exec(ctx) + require.Nil(t, err) + + } + cs, total, err = store.GetCollections(ctx, &types.CollectionFilter{ + Sort: "trending", + }, 10, 1, false) + require.Nil(t, err) + require.Equal(t, 3, total) + require.Equal(t, []string{"col1-1", "col1-3", "col2-1"}, names(cs)) + +} + +func TestCollectionStore_ByUserLikesOrgs(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewCollectionStoreWithDB(db) + + collections := []*database.Collection{ + {Name: "col1-1", Private: false, Namespace: "ns"}, + {Name: "col1-2", Private: false, Namespace: "ns"}, + {Name: "col1-3", Private: true, Namespace: "ns2"}, + {Name: "col2-1", Private: false, Namespace: "ns"}, + } + + for _, col := range collections { + dc, err := store.CreateCollection(ctx, *col) + col.ID = dc.ID + require.Nil(t, err) + } + + _, err := db.Core.NewInsert().Model(&database.UserLike{ + UserID: 123, + CollectionID: collections[0].ID, + }).Exec(ctx) + require.Nil(t, err) + + _, err = db.Core.NewInsert().Model(&database.UserLike{ + UserID: 123, + CollectionID: collections[3].ID, + }).Exec(ctx) + require.Nil(t, err) + + cs, total, err := store.ByUserLikes(ctx, 123, 10, 1) + require.Nil(t, err) + require.Equal(t, 2, total) + names := []string{} + for _, c := range cs { + names = append(names, c.Name) + } + require.Equal(t, []string{"col1-1", "col2-1"}, names) + + cs, total, err = store.ByUserOrgs(ctx, "ns2", 10, 1, false) + require.Nil(t, err) + require.Equal(t, 1, total) + names = []string{} + for _, c := range cs { + names = append(names, c.Name) + } + require.Equal(t, []string{"col1-3"}, names) + + _, total, err = store.ByUserOrgs(ctx, "ns2", 10, 1, true) + require.Nil(t, err) + require.Equal(t, 0, total) + +} diff --git a/builder/store/database/dataset.go b/builder/store/database/dataset.go index d6c49cf3..7563da53 100644 --- a/builder/store/database/dataset.go +++ b/builder/store/database/dataset.go @@ -38,6 +38,10 @@ func NewDatasetStore() DatasetStore { return &datasetStoreImpl{db: defaultDB} } +func NewDatasetStoreWithDB(db *DB) DatasetStore { + return &datasetStoreImpl{db: db} +} + type Dataset struct { ID int64 `bun:",pk,autoincrement" json:"id"` RepositoryID int64 `bun:",notnull" json:"repository_id"` @@ -191,14 +195,16 @@ func (s *datasetStoreImpl) Delete(ctx context.Context, input Dataset) error { return nil } -func (s *datasetStoreImpl) ListByPath(ctx context.Context, paths []string) ([]Dataset, error) { - var datasets []Dataset - err := s.db.Operator.Core. +func (s *datasetStoreImpl) ListByPath(ctx context.Context, paths []string) (datasets []Dataset, err error) { + err = s.db.Operator.Core. NewSelect(). - Model(&Dataset{}). + Model(&datasets). Relation("Repository"). + Relation("Repository.Tags", func(q *bun.SelectQuery) *bun.SelectQuery { + return q.Where("category = ?", "evaluation") + }). Where("path IN (?)", bun.In(paths)). - Scan(ctx, &datasets) + Scan(ctx) if err != nil { return nil, fmt.Errorf("failed to find models by path,error: %w", err) } diff --git a/builder/store/database/dataset_test.go b/builder/store/database/dataset_test.go new file mode 100644 index 00000000..6952414f --- /dev/null +++ b/builder/store/database/dataset_test.go @@ -0,0 +1,223 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestDatasetStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewDatasetStoreWithDB(db) + _, err := store.Create(ctx, database.Dataset{ + RepositoryID: 123, + }) + require.Nil(t, err) + + ds := &database.Dataset{} + err = db.Core.NewSelect().Model(ds).Where("repository_id=?", 123).Scan(ctx) + require.Nil(t, err) + + ds.RepositoryID = 456 + err = store.Update(ctx, *ds) + require.Nil(t, err) + ds = &database.Dataset{} + err = db.Core.NewSelect().Model(ds).Where("repository_id=?", 456).Scan(ctx) + require.Nil(t, err) + + ds, err = store.ByRepoID(ctx, 456) + require.Nil(t, err) + require.Equal(t, int64(456), ds.RepositoryID) + + dss, err := store.ByRepoIDs(ctx, []int64{456}) + require.Nil(t, err) + require.Equal(t, int64(456), dss[0].RepositoryID) + + _, err = store.CreateIfNotExist(ctx, database.Dataset{ + RepositoryID: 789, + }) + require.Nil(t, err) + ds, err = store.ByRepoID(ctx, 789) + require.Nil(t, err) + require.Equal(t, int64(789), ds.RepositoryID) + + repo := &database.Repository{ + Path: "foo/bar", + GitPath: "foo/bar2", + Private: true, + } + err = db.Core.NewInsert().Model(repo).Scan(ctx, repo) + require.Nil(t, err) + ds.RepositoryID = repo.ID + err = store.Update(ctx, *ds) + require.Nil(t, err) + + dss, total, err := store.ByUsername(ctx, "foo", 10, 1, false) + require.Nil(t, err) + require.Equal(t, 1, total) + require.Equal(t, len(dss), 1) + + dss, total, err = store.ByUsername(ctx, "foo", 10, 1, true) + require.Nil(t, err) + require.Equal(t, 0, total) + require.Equal(t, len(dss), 0) + + dss, total, err = store.ByOrgPath(ctx, "foo", 10, 1, false) + require.Nil(t, err) + require.Equal(t, 1, total) + require.Equal(t, len(dss), 1) + + dss, total, err = store.ByOrgPath(ctx, "foo", 10, 1, true) + require.Nil(t, err) + require.Equal(t, 0, total) + require.Equal(t, len(dss), 0) + + ds, err = store.FindByPath(ctx, "foo", "bar") + require.Nil(t, err) + require.Equal(t, repo.ID, ds.RepositoryID) + + err = store.Delete(ctx, *ds) + require.Nil(t, err) + _, err = store.FindByPath(ctx, "foo", "bar") + require.NotNil(t, err) +} + +func TestDatasetStore_ListByPath(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewDatasetStoreWithDB(db) + + dt := &database.Tag{} + err := db.Core.NewInsert().Model(&database.Tag{ + Name: "tag1", + Category: "evaluation", + }).Scan(ctx, dt) + require.Nil(t, err) + tag1pk := dt.ID + + err = db.Core.NewInsert().Model(&database.Tag{ + Name: "tag2", + Category: "foo", + }).Scan(ctx, dt) + require.Nil(t, err) + tag2pk := dt.ID + + dr := &database.Repository{} + err = db.Core.NewInsert().Model(&database.Repository{ + Name: "repo", + Path: "foo/bar", + GitPath: "a", + }).Scan(ctx, dr) + require.Nil(t, err) + repopk := dr.ID + + for _, tpk := range []int64{tag1pk, tag2pk} { + _, err = db.Core.NewInsert().Model(&database.RepositoryTag{ + RepositoryID: repopk, + TagID: tpk, + }).Exec(ctx) + require.Nil(t, err) + } + + _, err = store.Create(ctx, database.Dataset{ + RepositoryID: repopk, + }) + require.Nil(t, err) + + dr2 := &database.Repository{} + err = db.Core.NewInsert().Model(&database.Repository{ + Name: "repo2", + Path: "bar/foo", + GitPath: "b", + }).Scan(ctx, dr2) + require.Nil(t, err) + _, err = store.Create(ctx, database.Dataset{ + RepositoryID: dr2.ID, + }) + require.Nil(t, err) + + dr3 := &database.Repository{} + err = db.Core.NewInsert().Model(&database.Repository{ + Name: "repo3", + Path: "foo/bar", + GitPath: "c", + RepositoryType: types.ModelRepo, + }).Scan(ctx, dr3) + require.Nil(t, err) + _, err = store.Create(ctx, database.Dataset{ + RepositoryID: dr3.ID, + }) + require.Nil(t, err) + + dss, err := store.ListByPath(ctx, []string{"bar/foo", "foo/bar"}) + require.Nil(t, err) + require.Equal(t, 3, len(dss)) + + tags := []string{} + for _, t := range dss[1].Repository.Tags { + tags = append(tags, t.Name) + } + require.Equal(t, []string{"tag1"}, tags) + + names := []string{} + for _, ds := range dss { + names = append(names, ds.Repository.Name) + } + require.Equal(t, []string{"repo2", "repo", "repo3"}, names) + +} + +func TestDatasetStore_UserLikesDatasets(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewDatasetStoreWithDB(db) + + repos := []*database.Repository{ + {Name: "repo1", Path: "p1", GitPath: "p1"}, + {Name: "repo2", Path: "p2", GitPath: "p2"}, + {Name: "repo3", Path: "p3", GitPath: "p3"}, + } + + for _, repo := range repos { + err := db.Core.NewInsert().Model(repo).Scan(ctx, repo) + require.Nil(t, err) + _, err = store.Create(ctx, database.Dataset{ + RepositoryID: repo.ID, + }) + require.Nil(t, err) + + } + + _, err := db.Core.NewInsert().Model(&database.UserLike{ + UserID: 123, + RepoID: repos[0].ID, + }).Exec(ctx) + require.Nil(t, err) + _, err = db.Core.NewInsert().Model(&database.UserLike{ + UserID: 123, + RepoID: repos[2].ID, + }).Exec(ctx) + require.Nil(t, err) + + dss, total, err := store.UserLikesDatasets(ctx, 123, 10, 1) + require.Nil(t, err) + require.Equal(t, 2, total) + + names := []string{} + for _, ds := range dss { + names = append(names, ds.Repository.Name) + } + require.Equal(t, []string{"repo1", "repo3"}, names) + +} diff --git a/builder/store/database/deploy_task.go b/builder/store/database/deploy_task.go index 915e80d7..27acce8d 100644 --- a/builder/store/database/deploy_task.go +++ b/builder/store/database/deploy_task.go @@ -95,6 +95,10 @@ func NewDeployTaskStore() DeployTaskStore { return &deployTaskStoreImpl{db: defaultDB} } +func NewDeployTaskStoreWithDB(db *DB) DeployTaskStore { + return &deployTaskStoreImpl{db: db} +} + func (s *deployTaskStoreImpl) CreateDeploy(ctx context.Context, deploy *Deploy) error { _, err := s.db.Core.NewInsert().Model(deploy).Exec(ctx, deploy) return err diff --git a/builder/store/database/deploy_task_test.go b/builder/store/database/deploy_task_test.go new file mode 100644 index 00000000..dbd8129f --- /dev/null +++ b/builder/store/database/deploy_task_test.go @@ -0,0 +1,240 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/deploy/common" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestDeployTaskStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewDeployTaskStoreWithDB(db) + + err := store.CreateDeploy(ctx, &database.Deploy{ + DeployName: "dp1", SvcName: "s1", + RepoID: 123, + UserID: 456, + SpaceID: 321, + Type: types.ServerlessType, + }) + require.Nil(t, err) + dp := &database.Deploy{} + err = db.Core.NewSelect().Model(dp).Where("deploy_name=?", "dp1").Scan(ctx) + require.Nil(t, err) + require.Equal(t, dp.DeployName, "dp1") + + dp, err = store.GetDeployByID(ctx, dp.ID) + require.Nil(t, err) + require.Equal(t, dp.DeployName, "dp1") + + dp.DeployName = "foo" + err = store.UpdateDeploy(ctx, dp) + require.Nil(t, err) + err = db.Core.NewSelect().Model(dp).Where("deploy_name=?", "foo").Scan(ctx) + require.Nil(t, err) + require.Equal(t, dp.DeployName, "foo") + + dp, err = store.GetDeployBySvcName(ctx, "s1") + require.Nil(t, err) + require.Equal(t, dp.DeployName, "foo") + + err = store.StopDeploy(ctx, types.ModelRepo, 123, 456, dp.ID) + require.Nil(t, err) + dp, err = store.GetDeployByID(ctx, dp.ID) + require.Nil(t, err) + require.Equal(t, dp.Status, common.Stopped) + + err = store.CreateDeploy(ctx, &database.Deploy{ + DeployName: "dp2", SvcName: "s2", + RepoID: 123, + UserID: 456, + SpaceID: 321, + }) + require.Nil(t, err) + dp, err = store.GetLatestDeployBySpaceID(ctx, 321) + require.Nil(t, err) + require.Equal(t, dp.SvcName, "s2") + + dp, err = store.GetServerlessDeployByRepID(ctx, 123) + require.Nil(t, err) + require.Equal(t, dp.SvcName, "s1") + dps, total, err := store.ListServerless(ctx, types.DeployReq{ + DeployType: types.ServerlessType, + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }) + require.Nil(t, err) + require.Equal(t, 1, total) + require.Equal(t, dps[0].SvcName, "s1") + + err = store.DeleteDeploy(ctx, types.ModelRepo, 123, 456, dp.ID) + require.Nil(t, err) + dp, err = store.GetDeployByID(ctx, dp.ID) + require.Nil(t, err) + require.Equal(t, dp.Status, common.Deleted) + +} +func TestDeployTaskStore_DeployTaskCRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewDeployTaskStoreWithDB(db) + + err := store.CreateDeployTask(ctx, &database.DeployTask{ + DeployID: 1, + Message: "foo", + }) + require.Nil(t, err) + dp := &database.DeployTask{} + err = db.Core.NewSelect().Model(dp).Where("deploy_id=?", 1).Scan(ctx) + require.Nil(t, err) + require.Equal(t, dp.Message, "foo") + + dp, err = store.GetDeployTask(ctx, dp.ID) + require.Nil(t, err) + require.Equal(t, dp.Message, "foo") + + dp.Message = "bar" + err = store.UpdateDeployTask(ctx, dp) + require.Nil(t, err) + err = db.Core.NewSelect().Model(dp).Where("deploy_id=?", 1).Scan(ctx) + require.Nil(t, err) + require.Equal(t, dp.Message, "bar") + + tasks, err := store.GetDeployTasksOfDeploy(ctx, 1) + require.Nil(t, err) + require.Equal(t, 1, len(tasks)) + require.Equal(t, "bar", tasks[0].Message) + +} + +func TestDeployTaskStore_GetNewTaskAfter(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewDeployTaskStoreWithDB(db) + + err := store.CreateDeploy(ctx, &database.Deploy{SvcName: "svc"}) + require.Nil(t, err) + dp, err := store.GetDeployBySvcName(ctx, "svc") + require.Nil(t, err) + + tasks := []*database.DeployTask{ + {TaskType: 0, Status: 0, Message: "t1"}, + {TaskType: 0, Status: 1, Message: "t2"}, + {TaskType: 0, Status: 2, Message: "t3"}, + {TaskType: 0, Status: 3, Message: "t4"}, + {TaskType: 1, Status: 0, Message: "t5"}, + {TaskType: 1, Status: 1, Message: "t6"}, + {TaskType: 1, Status: 2, Message: "t7"}, + {TaskType: 1, Status: 3, Message: "t8"}, + } + + for _, tk := range tasks { + tk.DeployID = dp.ID + err = store.CreateDeployTask(ctx, tk) + require.Nil(t, err) + } + + for _, c := range []struct { + current int64 + expected string + err bool + }{ + {0, "t1", false}, + {tasks[0].ID, "t2", false}, + {tasks[1].ID, "t5", false}, + {tasks[2].ID, "t5", false}, + {tasks[3].ID, "t5", false}, + {tasks[4].ID, "t6", false}, + {tasks[5].ID, "t8", false}, + {tasks[6].ID, "t8", false}, + {tasks[7].ID, "t8", true}, + } { + tk, err := store.GetNewTaskAfter(ctx, c.current) + if c.err { + require.NotNil(t, err) + } else { + require.Nil(t, err) + require.Equal(t, c.expected, tk.Message) + } + } + + first, err := store.GetNewTaskFirst(ctx) + require.Nil(t, err) + require.Equal(t, "t1", first.Message) + +} + +func TestDeployTaskStore_UpdateInTx(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewDeployTaskStoreWithDB(db) + err := store.CreateDeploy(ctx, &database.Deploy{ + SvcName: "svc", + GitPath: "test", + GitBranch: "test", + Endpoint: "test", + Env: "test", + }) + require.Nil(t, err) + dp, err := store.GetDeployBySvcName(ctx, "svc") + require.Nil(t, err) + + tasks := []*database.DeployTask{ + {TaskType: 3, Status: 1, Message: "t1"}, + {TaskType: 3, Status: 2, Message: "t2"}, + } + + for _, tk := range tasks { + tk.DeployID = dp.ID + err = store.CreateDeployTask(ctx, tk) + require.Nil(t, err) + } + tasks[0].Message = "t1new" + tasks[0].TaskType = 1 + tasks[0].Status = 3 + tasks[1].Message = "t2new" + tasks[1].TaskType = 1 + tasks[1].Status = 3 + + dp.GitPath = "foo/bar" + dp.GitBranch = "new" + dp.Endpoint = "eee" + dp.Env = "env" + err = store.UpdateInTx(ctx, []string{"git_path", "git_branch"}, []string{"message"}, dp, tasks...) + require.Nil(t, err) + + dp, err = store.GetDeployBySvcName(ctx, "svc") + require.Nil(t, err) + require.Equal(t, "foo/bar", dp.GitPath) + require.Equal(t, "new", dp.GitBranch) + require.Equal(t, "test", dp.Endpoint) + require.Equal(t, "test", dp.Env) + + tasks, err = store.GetDeployTasksOfDeploy(ctx, dp.ID) + require.Nil(t, err) + messages := []string{} + types := []int{} + for _, t := range tasks { + messages = append(messages, t.Message) + types = append(types, t.TaskType) + } + require.ElementsMatch(t, []string{"t1new", "t2new"}, messages) + require.ElementsMatch(t, []int{3, 3}, types) + +} diff --git a/builder/store/database/discussion.go b/builder/store/database/discussion.go index fb8c7d92..fc058409 100644 --- a/builder/store/database/discussion.go +++ b/builder/store/database/discussion.go @@ -56,6 +56,12 @@ func NewDiscussionStore() DiscussionStore { } } +func NewDiscussionStoreWithDB(db *DB) DiscussionStore { + return &discussionStoreImpl{ + db: db, + } +} + func (s *discussionStoreImpl) Create(ctx context.Context, discussion Discussion) (*Discussion, error) { _, err := s.db.Core.NewInsert().Model(&discussion).Exec(ctx) if err != nil { diff --git a/builder/store/database/discussion_test.go b/builder/store/database/discussion_test.go new file mode 100644 index 00000000..6f4f4b09 --- /dev/null +++ b/builder/store/database/discussion_test.go @@ -0,0 +1,74 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestDiscussionStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewDiscussionStoreWithDB(db) + _, err := store.Create(ctx, database.Discussion{ + Title: "dis", + DiscussionableType: "zzz", + DiscussionableID: 123, + }) + require.Nil(t, err) + ds := &database.Discussion{} + err = db.Core.NewSelect().Model(ds).Where("title=?", "dis").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "dis", ds.Title) + + ds, err = store.FindByID(ctx, ds.ID) + require.Nil(t, err) + require.Equal(t, "dis", ds.Title) + + err = store.UpdateByID(ctx, ds.ID, "foo") + require.Nil(t, err) + ds, err = store.FindByID(ctx, ds.ID) + require.Nil(t, err) + require.Equal(t, "foo", ds.Title) + + dss, err := store.FindByDiscussionableID(ctx, "zzz", 123) + require.Nil(t, err) + require.Equal(t, 1, len(dss)) + dss, err = store.FindByDiscussionableID(ctx, "zzz", 456) + require.Nil(t, err) + require.Equal(t, 0, len(dss)) + + err = store.DeleteByID(ctx, ds.ID) + require.Nil(t, err) + _, err = store.FindByID(ctx, ds.ID) + require.NotNil(t, err) + + _, err = store.CreateComment(ctx, database.Comment{ + Content: "foobar", + }) + require.Nil(t, err) + cm := &database.Comment{} + err = db.Core.NewSelect().Model(cm).Where("content=?", "foobar").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "foobar", cm.Content) + + cm, err = store.FindCommentByID(ctx, cm.ID) + require.Nil(t, err) + require.Equal(t, "foobar", cm.Content) + + err = store.UpdateComment(ctx, cm.ID, "barfoo") + require.Nil(t, err) + cm, err = store.FindCommentByID(ctx, cm.ID) + require.Nil(t, err) + require.Equal(t, "barfoo", cm.Content) + + err = store.DeleteComment(ctx, cm.ID) + require.Nil(t, err) + _, err = store.FindCommentByID(ctx, cm.ID) + require.NotNil(t, err) +} diff --git a/builder/store/database/file.go b/builder/store/database/file.go index 0278a516..d1480ed6 100644 --- a/builder/store/database/file.go +++ b/builder/store/database/file.go @@ -13,6 +13,12 @@ type FileStore interface { BatchCreate(ctx context.Context, files []File) error } +func NewFileStoreWithDB(db *DB) FileStore { + return &fileStoreImpl{ + db: db, + } +} + func NewFileStore() FileStore { return &fileStoreImpl{ db: defaultDB, diff --git a/builder/store/database/file_test.go b/builder/store/database/file_test.go new file mode 100644 index 00000000..938ada72 --- /dev/null +++ b/builder/store/database/file_test.go @@ -0,0 +1,85 @@ +package database_test + +import ( + "context" + "testing" + "time" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestFileStore_FindByParentPath(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + fs := database.NewFileStoreWithDB(db) + + // Create a repository + rs := database.NewRepoStoreWithDB(db) + repo, err := rs.CreateRepo(ctx, database.Repository{ + Name: "test-repo", + Path: "test-path", + }) + require.Nil(t, err) + + // Insert files with the same parent path + files := []database.File{ + {Name: "file1", Path: "test-path/file1", ParentPath: "test-path", RepositoryID: repo.ID}, + {Name: "file2", Path: "test-path/file2", ParentPath: "test-path", RepositoryID: repo.ID}, + } + err = fs.BatchCreate(ctx, files) + require.Nil(t, err) + + // Query files by parent path + result, err := fs.FindByParentPath(ctx, repo.ID, "test-path") + require.Nil(t, err) + require.Equal(t, 2, len(result)) + + names := []string{} + for _, f := range result { + names = append(names, f.Name) + } + require.ElementsMatch(t, []string{"file1", "file2"}, names) +} + +func TestFileStore_BatchCreate(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + fs := database.NewFileStoreWithDB(db) + + // Create a repository + rs := database.NewRepoStoreWithDB(db) + repo, err := rs.CreateRepo(ctx, database.Repository{ + Name: "test-repo", + Path: "test-path", + }) + require.Nil(t, err) + + // Insert multiple files + files := []database.File{ + {Name: "file1", Path: "test-path/file1", ParentPath: "test-path", RepositoryID: repo.ID}, + {Name: "file2", Path: "test-path/file2", ParentPath: "test-path", RepositoryID: repo.ID}, + } + err = fs.BatchCreate(ctx, files) + require.Nil(t, err) + + // Validate files are inserted correctly + result, err := fs.FindByParentPath(ctx, repo.ID, "test-path") + require.Nil(t, err) + require.Equal(t, 2, len(result)) + + names := []string{} + for _, f := range result { + names = append(names, f.Name) + } + require.ElementsMatch(t, []string{"file1", "file2"}, names) +} diff --git a/builder/store/database/git_server_access_token.go b/builder/store/database/git_server_access_token.go index b2e8fcd9..356ea5b2 100644 --- a/builder/store/database/git_server_access_token.go +++ b/builder/store/database/git_server_access_token.go @@ -12,6 +12,12 @@ type GitServerAccessTokenStore interface { FindByType(ctx context.Context, serverType string) ([]GitServerAccessToken, error) } +func NewGitServerAccessTokenStoreWithDB(db *DB) GitServerAccessTokenStore { + return &gitServerAccessTokenStoreImpl{ + db: db, + } +} + func NewGitServerAccessTokenStore() GitServerAccessTokenStore { return &gitServerAccessTokenStoreImpl{ db: defaultDB, diff --git a/builder/store/database/git_server_access_token_test.go b/builder/store/database/git_server_access_token_test.go new file mode 100644 index 00000000..3ca163fc --- /dev/null +++ b/builder/store/database/git_server_access_token_test.go @@ -0,0 +1,96 @@ +package database_test + +import ( + "context" + "testing" + "time" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestGitServerAccessTokenStore_Create(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + store := database.NewGitServerAccessTokenStoreWithDB(db) + + token := &database.GitServerAccessToken{ + Token: "test-token", + ServerType: database.MirrorServer, + } + + createdToken, err := store.Create(ctx, token) + require.Nil(t, err) + require.NotNil(t, createdToken) + require.Equal(t, "test-token", createdToken.Token) + require.Equal(t, database.MirrorServer, createdToken.ServerType) +} + +func TestGitServerAccessTokenStore_Index(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + store := database.NewGitServerAccessTokenStoreWithDB(db) + + // Insert multiple tokens + tokens := []*database.GitServerAccessToken{ + {Token: "token1", ServerType: database.MirrorServer}, + {Token: "token2", ServerType: database.GitServer}, + } + for _, token := range tokens { + _, err := store.Create(ctx, token) + require.Nil(t, err) + } + + // Fetch all tokens + allTokens, err := store.Index(ctx) + require.Nil(t, err) + require.Equal(t, len(tokens), len(allTokens)) + + tokensMap := make(map[string]database.GitServerType) + for _, token := range allTokens { + tokensMap[token.Token] = token.ServerType + } + require.Equal(t, database.MirrorServer, tokensMap["token1"]) + require.Equal(t, database.GitServer, tokensMap["token2"]) +} + +func TestGitServerAccessTokenStore_FindByType(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + store := database.NewGitServerAccessTokenStoreWithDB(db) + + // Insert tokens with different server types + tokens := []*database.GitServerAccessToken{ + {Token: "token1", ServerType: database.MirrorServer}, + {Token: "token2", ServerType: database.GitServer}, + {Token: "token3", ServerType: database.MirrorServer}, + } + for _, token := range tokens { + _, err := store.Create(ctx, token) + require.Nil(t, err) + } + + // Fetch tokens by server type + mirrorTokens, err := store.FindByType(ctx, string(database.MirrorServer)) + require.Nil(t, err) + require.Equal(t, 2, len(mirrorTokens)) + require.ElementsMatch(t, []string{"token1", "token3"}, []string{mirrorTokens[0].Token, mirrorTokens[1].Token}) + + gitTokens, err := store.FindByType(ctx, string(database.GitServer)) + require.Nil(t, err) + require.Equal(t, 1, len(gitTokens)) + require.Equal(t, "token2", gitTokens[0].Token) +} diff --git a/builder/store/database/repository.go b/builder/store/database/repository.go index ef41e916..e929d22c 100644 --- a/builder/store/database/repository.go +++ b/builder/store/database/repository.go @@ -566,10 +566,10 @@ func (s *repoStoreImpl) BatchCreateRepoTags(ctx context.Context, repoTags []Repo } func (s *repoStoreImpl) DeleteAllFiles(ctx context.Context, repoID int64) error { - err := s.db.Operator.Core.NewDelete(). + _, err := s.db.Operator.Core.NewDelete(). Model(&File{}). Where("repository_id = ?", repoID). - Scan(ctx) + Exec(ctx) if err != nil { return err } @@ -578,10 +578,10 @@ func (s *repoStoreImpl) DeleteAllFiles(ctx context.Context, repoID int64) error } func (s *repoStoreImpl) DeleteAllTags(ctx context.Context, repoID int64) error { - err := s.db.Operator.Core.NewDelete(). + _, err := s.db.Operator.Core.NewDelete(). Model(&RepositoryTag{}). Where("repository_id = ?", repoID). - Scan(ctx) + Exec(ctx) if err != nil { return err } diff --git a/builder/store/database/repository_test.go b/builder/store/database/repository_test.go new file mode 100644 index 00000000..45d8db5c --- /dev/null +++ b/builder/store/database/repository_test.go @@ -0,0 +1,817 @@ +package database_test + +import ( + "context" + "fmt" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestRepoStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + + _, err := store.CreateRepo(ctx, database.Repository{ + Name: "repo1", + UserID: 123, + GitPath: "foos_u/bar", + }) + require.Nil(t, err) + + rp := &database.Repository{} + err = db.Core.NewSelect().Model(rp).Where("user_id=?", 123).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "repo1", rp.Name) + + rp, err = store.FindById(ctx, rp.ID) + require.Nil(t, err) + require.Equal(t, "repo1", rp.Name) + + rps, err := store.FindByIds(ctx, []int64{rp.ID}) + require.Nil(t, err) + require.Equal(t, 1, len(rps)) + require.Equal(t, "repo1", rps[0].Name) + + rps, err = store.All(ctx) + require.Nil(t, err) + require.Equal(t, 1, len(rps)) + require.Equal(t, "repo1", rps[0].Name) + + rp, err = store.Find(ctx, "u", "foO", "bAr") + require.Nil(t, err) + require.Equal(t, "repo1", rp.Name) + + exist, err := store.Exists(ctx, "foO", "u", "bar") + require.Nil(t, err) + require.True(t, exist) + + rp, err = store.FindByPath(ctx, "foO", "u", "bAr") + require.Nil(t, err) + require.Equal(t, "repo1", rp.Name) + + rp, err = store.FindByGitPath(ctx, "foos_u/bAr") + require.Nil(t, err) + require.Equal(t, "repo1", rp.Name) + + rps, err = store.FindByGitPaths(ctx, []string{"foos_u/bAr"}) + require.Nil(t, err) + require.Equal(t, 1, len(rps)) + require.Equal(t, "repo1", rps[0].Name) + + rpsp, err := store.ByUser(ctx, 123) + require.Nil(t, err) + require.Equal(t, 1, len(rpsp)) + require.Equal(t, "repo1", rpsp[0].Name) + rpsp, err = store.ByUser(ctx, 125) + require.Nil(t, err) + require.Equal(t, 0, len(rpsp)) + + rpn := *rp + rpn.Name = "repo1-new" + _, err = store.UpdateRepo(ctx, rpn) + require.Nil(t, err) + err = db.Core.NewSelect().Model(rp).Where("user_id=?", 123).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "repo1-new", rp.Name) + + err = store.DeleteRepo(ctx, database.Repository{ + ID: rp.ID, + }) + require.Nil(t, err) + err = db.Core.NewSelect().Model(rp).Where("user_id=?", 123).Scan(ctx) + require.NotNil(t, err) + + _, err = store.UpdateOrCreateRepo(ctx, database.Repository{ + Name: "repo3", + UserID: 231, + Path: "bars_u/bar", + RepositoryType: types.CodeRepo, + }) + require.Nil(t, err) + rp = &database.Repository{} + err = db.Core.NewSelect().Model(rp).Where("user_id=?", 231).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "repo3", rp.Name) + + _, err = store.UpdateOrCreateRepo(ctx, database.Repository{ + Name: "repo3n", + UserID: 231, + Path: "bars_u/bar", + RepositoryType: types.CodeRepo, + }) + require.Nil(t, err) + rp = &database.Repository{} + err = db.Core.NewSelect().Model(rp).Where("user_id=?", 231).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "repo3n", rp.Name) + + cnt, err := store.CountByRepoType(ctx, types.CodeRepo) + require.Nil(t, err) + require.Equal(t, 1, cnt) + +} + +func TestRepoStore_UpdateRepoFileDownloads(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + + repo, err := store.CreateRepo(ctx, database.Repository{ + Name: "repo1", + UserID: 123, + GitPath: "foos_u/bar", + }) + require.Nil(t, err) + + dt := time.Date(2022, 12, 11, 0, 0, 0, 0, time.UTC) + dw := &database.RepositoryDownload{} + // create + err = store.UpdateRepoFileDownloads(ctx, repo, dt, 111) + require.Nil(t, err) + err = db.Core.NewSelect().Model(dw).Where("repository_id = ?", repo.ID).Scan(ctx) + require.Nil(t, err) + require.Equal(t, 111, int(dw.ClickDownloadCount)) + err = db.Core.NewSelect().Model(repo).Where("user_id=?", 123).Scan(ctx) + require.Nil(t, err) + require.Equal(t, 111, int(repo.DownloadCount)) + + // update + err = store.UpdateRepoFileDownloads(ctx, repo, dt, 5) + require.Nil(t, err) + err = db.Core.NewSelect().Model(dw).Where("repository_id = ?", repo.ID).Scan(ctx) + require.Nil(t, err) + require.Equal(t, 116, int(dw.ClickDownloadCount)) + err = db.Core.NewSelect().Model(repo).Where("user_id=?", 123).Scan(ctx) + require.Nil(t, err) + require.Equal(t, 116, int(repo.DownloadCount)) + +} + +func TestRepoStore_UpdateRepoCloneDownloads(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + + repo, err := store.CreateRepo(ctx, database.Repository{ + Name: "repo1", + UserID: 123, + GitPath: "foos_u/bar", + }) + require.Nil(t, err) + + dt := time.Date(2022, 12, 11, 0, 0, 0, 0, time.UTC) + dw := &database.RepositoryDownload{} + // create + err = store.UpdateRepoCloneDownloads(ctx, repo, dt, 111) + require.Nil(t, err) + err = db.Core.NewSelect().Model(dw).Where("repository_id = ?", repo.ID).Scan(ctx) + require.Nil(t, err) + require.Equal(t, 111, int(dw.CloneCount)) + err = db.Core.NewSelect().Model(repo).Where("user_id=?", 123).Scan(ctx) + require.Nil(t, err) + require.Equal(t, 111, int(repo.DownloadCount)) + + // update + err = store.UpdateRepoCloneDownloads(ctx, repo, dt, 5) + require.Nil(t, err) + err = db.Core.NewSelect().Model(dw).Where("repository_id = ?", repo.ID).Scan(ctx) + require.Nil(t, err) + // clone count will be override, not add to previous + require.Equal(t, 5, int(dw.CloneCount)) + err = db.Core.NewSelect().Model(repo).Where("user_id=?", 123).Scan(ctx) + require.Nil(t, err) + require.Equal(t, 5, int(repo.DownloadCount)) + +} + +func TestRepoStore_Tags(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + repo, err := store.CreateRepo(ctx, database.Repository{ + Name: "repo1", + UserID: 123, + }) + require.Nil(t, err) + + tag := &database.Tag{ + Name: "tg", + Category: "foo", + } + _, err = db.Core.NewInsert().Model(tag).Exec(ctx, tag) + require.Nil(t, err) + tag2 := &database.Tag{ + Name: "tg2", + Category: "bar", + } + _, err = db.Core.NewInsert().Model(tag2).Exec(ctx, tag2) + require.Nil(t, err) + + rtags := []database.RepositoryTag{ + {TagID: tag.ID, RepositoryID: repo.ID, Count: 1}, + {TagID: tag2.ID, RepositoryID: repo.ID, Count: 1}, + } + err = store.BatchCreateRepoTags(ctx, rtags) + require.Nil(t, err) + + tags, err := store.Tags(ctx, repo.ID) + require.Nil(t, err) + require.Equal(t, 2, len(tags)) + require.Equal(t, tags[0].Name, "tg") + require.Equal(t, tags[1].Name, "tg2") + + tags, err = store.TagsWithCategory(ctx, repo.ID, "foo") + require.Nil(t, err) + require.Equal(t, 1, len(tags)) + require.Equal(t, tags[0].Name, "tg") + + ids, err := store.TagIDs(ctx, repo.ID, "foo") + require.Nil(t, err) + require.Equal(t, []int64{tag.ID}, ids) +} + +func TestRepoStore_SetUpdateTimeByPath(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + repo, err := store.CreateRepo(ctx, database.Repository{ + Name: "repo1", + UserID: 123, + GitPath: "foos_u/bar", + }) + require.Nil(t, err) + + dt := time.Date(2022, 12, 6, 1, 2, 0, 0, time.UTC) + err = store.SetUpdateTimeByPath(ctx, "foo", "u", "bar", dt) + require.Nil(t, err) + + err = db.Core.NewSelect().Model(repo).WherePK().Scan(ctx) + require.Nil(t, err) + require.Equal(t, dt, repo.UpdatedAt) + +} + +func TestRepoStore_PublicToUserSimple(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + // insert a new repo + rs := database.NewRepoStoreWithDB(db) + userName := "user_name_" + uuid.NewString() + repoName := "repo_name_" + uuid.NewString() + repo, err := rs.CreateRepo(ctx, database.Repository{ + UserID: 1, + Path: fmt.Sprintf("%s/%s", userName, repoName), + GitPath: fmt.Sprintf("datasets_%s/%s", userName, repoName), + Name: repoName, + DefaultBranch: "main", + Nickname: "ww", + Description: "ww", + Private: false, + RepositoryType: types.DatasetRepo, + }) + require.Empty(t, err) + require.NotNil(t, repo) + + ts := database.NewTagStoreWithDB(db) + var tags []*database.Tag + tags = append(tags, &database.Tag{ + Name: "tag_" + uuid.NewString(), + Category: "evaluation", + Group: "", + Scope: database.DatasetTagScope, + BuiltIn: true, + ShowName: "", + }) + tags = append(tags, &database.Tag{ + Name: "tag_" + uuid.NewString(), + Category: "runtime_framework", + Group: "", + Scope: database.DatasetTagScope, + BuiltIn: true, + ShowName: "", + }) + t1, err := ts.FindOrCreate(ctx, *tags[0]) + require.Nil(t, err) + t2, err := ts.FindOrCreate(ctx, *tags[1]) + require.Nil(t, err) + err = ts.UpsertRepoTags(ctx, repo.ID, []int64{}, []int64{t1.ID, t2.ID}) + require.Nil(t, err) + var tagsfilter []types.TagReq + tagsfilter = append(tagsfilter, types.TagReq{ + Name: tags[0].Name, + Category: tags[0].Category, + }) + filter := &types.RepoFilter{ + Tags: tagsfilter, + Sort: "recently_update", + } + // case 1: one tag + repos, _, err := rs.PublicToUser(ctx, repo.RepositoryType, []int64{1}, filter, 20, 1) + require.Nil(t, err) + require.NotNil(t, repos) + + tagsfilter = append(tagsfilter, types.TagReq{ + Name: tags[1].Name, + Category: tags[1].Category, + }) + filter = &types.RepoFilter{ + Tags: tagsfilter, + Sort: "recently_update", + } + // case 2: two tag + repos, _, err = rs.PublicToUser(ctx, repo.RepositoryType, []int64{1}, filter, 20, 1) + require.Nil(t, err) + require.Nil(t, repos) +} + +func TestRepoStore_PublicToUser(t *testing.T) { + + cases := []struct { + admin bool + repoType types.RepositoryType + source string + search string + tags []types.TagReq + sort string + expected []string + }{ + { + admin: false, repoType: types.CodeRepo, + expected: []string{"rp1", "rp2", "rp4", "rp5", "rp6"}, + }, + { + admin: false, repoType: types.CodeRepo, source: string(types.HuggingfaceSource), + expected: []string{"rp2"}, + }, + { + admin: true, repoType: types.CodeRepo, + expected: []string{"rp1", "rp2", "rp4", "rp5", "rp6"}, + }, + { + admin: false, repoType: types.CodeRepo, search: "rp4", + expected: []string{"rp4", "rp6"}, + }, + { + admin: false, repoType: types.CodeRepo, sort: "most_download", + expected: []string{"rp1", "rp2", "rp4", "rp5", "rp6"}, + }, + { + admin: false, repoType: types.CodeRepo, sort: "trending", + expected: []string{"rp1", "rp2", "rp4", "rp5", "rp6"}, + }, + { + admin: false, repoType: types.CodeRepo, tags: []types.TagReq{{Name: "foo"}}, + expected: []string{"rp4"}, + }, + } + + for _, c := range cases { + t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + + repos := []*database.Repository{ + { + Name: "rp1", Path: "rp1", UserID: 123, RepositoryType: types.CodeRepo, + DownloadCount: 10, + }, + { + Name: "rp2", Path: "rp2", UserID: 123, RepositoryType: types.CodeRepo, + Private: true, Source: types.HuggingfaceSource, + DownloadCount: 10, + }, + { + Name: "rp3", Path: "rp3", UserID: 456, RepositoryType: types.CodeRepo, + Private: true, + DownloadCount: 15, + }, + { + Name: "rp4", Path: "rp4", UserID: 456, RepositoryType: types.CodeRepo, + Private: false, Tags: []database.Tag{{Name: "foo"}}, + DownloadCount: 10, + }, + { + Name: "rp5", Path: "rp5", UserID: 789, RepositoryType: types.CodeRepo, + Private: false, Tags: []database.Tag{{Name: "bar"}}, + DownloadCount: 10, + }, + { + Name: "rp6", Path: "rp6", UserID: 789, RepositoryType: types.CodeRepo, + Private: false, Description: "rp4desc", + DownloadCount: 10, + }, + } + + for _, repo := range repos { + repo.GitPath = repo.Path + rn, err := store.CreateRepo(ctx, *repo) + require.Nil(t, err) + for _, tag := range repo.Tags { + _, err = db.Core.NewInsert().Model(&tag).Exec(ctx, &tag) + require.Nil(t, err) + rtags := []database.RepositoryTag{ + {TagID: tag.ID, RepositoryID: rn.ID, Count: 1}, + } + err = store.BatchCreateRepoTags(ctx, rtags) + require.Nil(t, err) + } + } + + rs, count, err := store.PublicToUser(ctx, c.repoType, []int64{123}, &types.RepoFilter{ + Tags: c.tags, + Sort: c.sort, + Search: c.search, + Source: c.source, + }, 10, 1) + require.Nil(t, err) + names := []string{} + for _, r := range rs { + names = append(names, r.Name) + } + require.Equal(t, len(c.expected), count) + require.Equal(t, c.expected, names) + + }) + } +} + +func TestRepoStore_IsMirrorRepo(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + rn, err := store.CreateRepo(ctx, database.Repository{ + GitPath: "codes_ns/n", + }) + require.Nil(t, err) + mi := &database.Mirror{RepositoryID: rn.ID} + _, err = db.Core.NewInsert().Model(mi).Exec(ctx) + require.Nil(t, err) + m, err := store.IsMirrorRepo(ctx, types.CodeRepo, "ns", "n") + require.Nil(t, err) + require.True(t, m) + m, err = store.IsMirrorRepo(ctx, types.CodeRepo, "ns", "n2") + require.NotNil(t, err) + require.False(t, m) + +} + +func TestRepoStore_WithMirror(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + rn, err := store.CreateRepo(ctx, database.Repository{ + GitPath: "codes_ns/n", + }) + require.Nil(t, err) + mi := &database.Mirror{RepositoryID: rn.ID} + _, err = db.Core.NewInsert().Model(mi).Exec(ctx) + require.Nil(t, err) + _, err = store.CreateRepo(ctx, database.Repository{ + GitPath: "codes_ns2/n", + Path: "zzz", + }) + require.Nil(t, err) + rs, count, err := store.WithMirror(ctx, 10, 1) + require.Nil(t, err) + require.Equal(t, 1, count) + require.Equal(t, "codes_ns/n", rs[0].GitPath) + +} + +func TestRepoStore_ListRepoPublicToUserByRepoIDs(t *testing.T) { + + cases := []struct { + admin bool + repoType types.RepositoryType + search string + sort string + expected []string + }{ + { + admin: false, repoType: types.CodeRepo, + expected: []string{"rp1", "rp2", "rp4", "rp5", "rp6"}, + }, + { + admin: true, repoType: types.CodeRepo, + expected: []string{"rp1", "rp2", "rp4", "rp5", "rp6"}, + }, + { + admin: false, repoType: types.CodeRepo, search: "rp4", + expected: []string{"rp4", "rp6"}, + }, + { + admin: false, repoType: types.CodeRepo, sort: "most_download", + expected: []string{"rp1", "rp2", "rp4", "rp5", "rp6"}, + }, + { + admin: false, repoType: types.CodeRepo, sort: "trending", + expected: []string{"rp1", "rp2", "rp4", "rp5", "rp6"}, + }, + } + + for _, c := range cases { + t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + + repos := []*database.Repository{ + { + Name: "rp1", Path: "rp1", UserID: 123, RepositoryType: types.CodeRepo, + DownloadCount: 10, + }, + { + Name: "rp2", Path: "rp2", UserID: 123, RepositoryType: types.CodeRepo, + Private: true, + DownloadCount: 10, + }, + { + Name: "rp3", Path: "rp3", UserID: 456, RepositoryType: types.CodeRepo, + Private: true, + DownloadCount: 15, + }, + { + Name: "rp4", Path: "rp4", UserID: 456, RepositoryType: types.CodeRepo, + Private: false, Tags: []database.Tag{{Name: "foo"}}, + DownloadCount: 10, + }, + { + Name: "rp5", Path: "rp5", UserID: 789, RepositoryType: types.CodeRepo, + Private: false, Tags: []database.Tag{{Name: "bar"}}, + DownloadCount: 10, + }, + { + Name: "rp6", Path: "rp6", UserID: 789, RepositoryType: types.CodeRepo, + Private: false, Description: "rp4desc", + DownloadCount: 10, + }, + } + + rids := []int64{} + for _, repo := range repos { + repo.GitPath = repo.Path + rn, err := store.CreateRepo(ctx, *repo) + require.Nil(t, err) + rids = append(rids, rn.ID) + for _, tag := range repo.Tags { + _, err = db.Core.NewInsert().Model(&tag).Exec(ctx, &tag) + require.Nil(t, err) + rtags := []database.RepositoryTag{ + {TagID: tag.ID, RepositoryID: rn.ID, Count: 1}, + } + err = store.BatchCreateRepoTags(ctx, rtags) + require.Nil(t, err) + } + } + + rs, count, err := store.ListRepoPublicToUserByRepoIDs(ctx, c.repoType, 123, c.search, c.sort, 10, 1, rids) + require.Nil(t, err) + names := []string{} + for _, r := range rs { + names = append(names, r.Name) + } + require.Equal(t, len(c.expected), count) + require.Equal(t, c.expected, names) + + }) + } +} + +func TestRepoStore_CleanRelationsByRepoID(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + rn, err := store.CreateRepo(ctx, database.Repository{ + GitPath: "codes_ns/n", + }) + require.Nil(t, err) + + _, err = db.Core.NewInsert().Model(&database.RepositoriesRuntimeFramework{ + RepoID: rn.ID, + }).Exec(ctx) + require.Nil(t, err) + _, err = db.Core.NewInsert().Model(&database.UserLike{ + RepoID: rn.ID, + }).Exec(ctx) + require.Nil(t, err) + count, err := db.Core.NewSelect().Model(&database.RepositoriesRuntimeFramework{}).Where("repo_id=?", rn.ID).Count(ctx) + require.Nil(t, err) + require.Equal(t, 1, count) + count, err = db.Core.NewSelect().Model(&database.UserLike{}).Where("repo_id=?", rn.ID).Count(ctx) + require.Nil(t, err) + require.Equal(t, 1, count) + + err = store.CleanRelationsByRepoID(ctx, rn.ID) + require.Nil(t, err) + + count, err = db.Core.NewSelect().Model(&database.RepositoriesRuntimeFramework{}).Where("repo_id=?", rn.ID).Count(ctx) + require.Nil(t, err) + require.Equal(t, 0, count) + count, err = db.Core.NewSelect().Model(&database.UserLike{}).Where("repo_id=?", rn.ID).Count(ctx) + require.Nil(t, err) + require.Equal(t, 0, count) + +} + +func TestRepoStore_DeleteAllFiles(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + + _, err := db.Core.NewInsert().Model(&database.File{RepositoryID: 123}).Exec(ctx) + require.Nil(t, err) + err = store.DeleteAllFiles(ctx, 123) + require.Nil(t, err) + count, err := db.Core.NewSelect().Model(&database.File{}).Where("repository_id = ?", 123).Count(ctx) + require.Nil(t, err) + require.Equal(t, 0, count) +} + +func TestRepoStore_DeleteAllTags(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + + _, err := db.Core.NewInsert().Model(&database.RepositoryTag{RepositoryID: 123}).Exec(ctx) + require.Nil(t, err) + err = store.DeleteAllTags(ctx, 123) + require.Nil(t, err) + count, err := db.Core.NewSelect().Model(&database.RepositoryTag{}).Where("repository_id = ?", 123).Count(ctx) + require.Nil(t, err) + require.Equal(t, 0, count) +} + +func TestRepoStore_UpdateLicenseByTag(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + rn, err := store.CreateRepo(ctx, database.Repository{ + GitPath: "codes_ns/n", + License: "foo", + }) + require.Nil(t, err) + tag := &database.Tag{ + Category: "license", + Name: "MIT", + } + _, err = db.Core.NewInsert().Model(tag).Exec(ctx, tag) + require.Nil(t, err) + rtags := []database.RepositoryTag{ + {TagID: tag.ID, RepositoryID: rn.ID, Count: 1}, + } + err = store.BatchCreateRepoTags(ctx, rtags) + require.Nil(t, err) + + err = store.UpdateLicenseByTag(ctx, rn.ID) + require.Nil(t, err) + + rn, err = store.FindById(ctx, rn.ID) + require.Nil(t, err) + require.Equal(t, "MIT", rn.License) +} + +func TestRepoStore_GetRepoRuntimeByID(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + repo, err := store.CreateRepo(ctx, database.Repository{ + Path: "codes_ns/n", + License: "foo", + RepositoryType: types.ModelRepo, + }) + require.Nil(t, err) + + rf := &database.RepositoriesRuntimeFramework{ + RepoID: repo.ID, + RuntimeFrameworkID: 999, + } + _, err = db.Core.NewInsert().Model(rf).Exec(ctx, rf) + require.Nil(t, err) + + rs, err := store.GetRepoWithRuntimeByID(ctx, rf.RuntimeFrameworkID, []string{"codes_ns/n"}) + require.Nil(t, err) + require.Equal(t, 1, len(rs)) + + rs, err = store.GetRepoWithoutRuntimeByID(ctx, rf.RuntimeFrameworkID, []string{"codes_ns/n"}) + require.Nil(t, err) + require.Equal(t, 0, len(rs)) + +} + +func TestRepoStore_BatchMethods(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoStoreWithDB(db) + + repos := []*database.Repository{ + { + Name: "rp1", Path: "rp1", UserID: 123, RepositoryType: types.CodeRepo, + SensitiveCheckStatus: types.SensitiveCheckPending, + Source: types.HuggingfaceSource, + }, + { + Name: "rp2", Path: "rp2", UserID: 123, RepositoryType: types.CodeRepo, + SensitiveCheckStatus: types.SensitiveCheckPending, + Source: types.HuggingfaceSource, + }, + { + Name: "rp3", Path: "rp3", UserID: 123, RepositoryType: types.CodeRepo, + SensitiveCheckStatus: types.SensitiveCheckPending, + Source: types.HuggingfaceSource, + }, + { + Name: "rp4", Path: "rp4", UserID: 456, RepositoryType: types.CodeRepo, + SensitiveCheckStatus: types.SensitiveCheckPass, + Source: types.HuggingfaceSource, + }, + { + Name: "rp5", Path: "rp5", UserID: 456, RepositoryType: types.DatasetRepo, + SensitiveCheckStatus: types.SensitiveCheckPending, + }, + } + + names := func(rs []database.Repository) []string { + names := []string{} + for _, r := range rs { + names = append(names, r.Name) + } + return names + } + + rids := []int64{} + for _, repo := range repos { + repo.GitPath = repo.Path + rn, err := store.CreateRepo(ctx, *repo) + require.Nil(t, err) + rids = append(rids, rn.ID) + } + rs, err := store.BatchGet(ctx, types.CodeRepo, 0, 10) + require.Nil(t, err) + require.Equal(t, len(rs), 3) + require.Equal(t, []string{"rp1", "rp2", "rp3"}, names(rs)) + + rs, err = store.BatchGet(ctx, types.CodeRepo, rids[1], 10) + require.Nil(t, err) + require.Equal(t, len(rs), 1) + require.Equal(t, []string{"rp3"}, names(rs)) + + rs, err = store.BatchGet(ctx, types.CodeRepo, 0, 1) + require.Nil(t, err) + require.Equal(t, len(rs), 1) + require.Equal(t, []string{"rp1"}, names(rs)) + + rs, err = store.FindWithBatch(ctx, 2, 1) + require.Nil(t, err) + require.Equal(t, len(rs), 2) + require.Equal(t, []string{"rp3", "rp2"}, names(rs)) + + rs, err = store.ByUser(ctx, 123) + require.Nil(t, err) + require.Equal(t, len(rs), 3) + require.ElementsMatch(t, []string{"rp1", "rp2", "rp3"}, names(rs)) + + rs, err = store.FindByRepoSourceWithBatch(ctx, types.HuggingfaceSource, 2, 1) + require.Nil(t, err) + require.Equal(t, len(rs), 2) + require.Equal(t, []string{"rp2", "rp1"}, names(rs)) +} diff --git a/common/tests/testutils.go b/common/tests/testutils.go index a5d6c6f6..55f8a553 100644 --- a/common/tests/testutils.go +++ b/common/tests/testutils.go @@ -5,9 +5,11 @@ import ( "database/sql" "fmt" "os" + "sync" "time" "github.com/DATA-DOG/go-txdb" + "github.com/google/uuid" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/postgres" "github.com/testcontainers/testcontainers-go/wait" @@ -47,6 +49,24 @@ func newBun(ctx context.Context, config database.DBConfig, useTxdb bool) (bunDB return } +var chMu sync.Mutex + +func chProjectRoot() { + chMu.Lock() + defer chMu.Unlock() + for { + _, err := os.Stat("builder/store/database/migrations") + if err != nil { + err = os.Chdir("../") + if err != nil { + panic(err) + } + continue + } + return + } +} + // Init a test db, must call `defer db.Close()` in the test func InitTestDB() *database.DB { ctx := context.TODO() @@ -60,7 +80,10 @@ func InitTestDB() *database.DB { }, ) - pc, err := postgres.Run(ctx, "docker.io/postgres:14-alpine", reuse, postgres.WithDatabase("csghub_test"), + pc, err := postgres.Run(ctx, + "postgres:15.7", + reuse, + postgres.WithDatabase("csghub_test"), testcontainers.WithWaitStrategy( wait.ForLog("database system is ready to accept connections"). WithOccurrence(2). @@ -74,9 +97,7 @@ func InitTestDB() *database.DB { if err != nil { panic(err) } - - // switch to project root, so migrations can work correctly - _ = os.Chdir("../../../") + chProjectRoot() bdb, err := newBun(ctx, database.DBConfig{ Dialect: database.DialectPostgres, DSN: dsn + "sslmode=disable", @@ -122,3 +143,73 @@ func InitTestDB() *database.DB { BunDB: bdb, } } + +// Create a random test postgres Database without txdb, +// this method is *MUCH SLOWER* than TestDB, use it only when you need to testing concurrent +// transaction execution(e.g., test concurrent select for update locks). +func InitTransactionTestDB() *database.DB { + ctx := context.TODO() + cname := "csghub_test_tx_" + uuid.New().String() + // reuse the container, so we don't need to recreate the db for each test + // https://github.com/testcontainers/testcontainers-go/issues/2726 + reuse := testcontainers.CustomizeRequestOption( + func(req *testcontainers.GenericContainerRequest) error { + req.Reuse = true + req.Name = cname + return nil + }, + ) + + pc, err := postgres.Run(ctx, "postgres:15.7", reuse, postgres.WithDatabase(cname), + testcontainers.WithWaitStrategy( + wait.ForLog("database system is ready to accept connections"). + WithOccurrence(2). + WithStartupTimeout(5*time.Second))) + if err != nil { + panic(err) + } + + // testcontainers will create a random dsn eachtime + dsn, err := pc.ConnectionString(ctx) + if err != nil { + panic(err) + } + + chProjectRoot() + + bdb, err := newBun(ctx, database.DBConfig{ + Dialect: database.DialectPostgres, + DSN: dsn + "sslmode=disable", + }, false) + if err != nil { + panic(err) + } + defer bdb.Close() + bdb.AddQueryHook(bundebug.NewQueryHook( + bundebug.WithEnabled(false), + + bundebug.FromEnv("BUNDEBUG"), + )) + + migrator := migrate.NewMigrator(bdb, migrations.Migrations) + err = migrator.Init(ctx) + if err != nil { + panic(err) + } + _, err = migrator.Migrate(ctx) + if err != nil { + panic(err) + } + bdb, err = newBun(ctx, database.DBConfig{ + Dialect: database.DialectPostgres, + DSN: dsn + "sslmode=disable", + }, false) + if err != nil { + panic(err) + } + + return &database.DB{ + Operator: database.Operator{Core: bdb}, + BunDB: bdb, + } +} From 66c16f2b4f0184fc553484c767ec5c6e655ce538 Mon Sep 17 00:00:00 2001 From: yiling Date: Mon, 25 Nov 2024 17:29:31 +0800 Subject: [PATCH 2/3] fix existing failed tests and add more tests --- .mockery.yaml | 62 + .../builder/git/gitserver/mock_GitServer.go | 2131 +++++++++++ .../git/membership/mock_GitMemerShip.go | 242 ++ .../builder/rpc/mock_UserSvcClient.go | 216 ++ .../builder/sensitive/mock_Green2022Client.go | 196 + .../builder/sensitive/mock_GreenClient.go | 95 + .../database/mock_AccountMeteringStore.go | 211 ++ .../store/database/mock_DatasetStore.go | 692 ++++ .../store/database/mock_LLMConfigStore.go | 95 + .../store/database/mock_MemberStore.go | 322 ++ .../store/database/mock_MirrorStore.go | 1128 ++++++ .../builder/store/database/mock_ModelStore.go | 875 +++++ .../store/database/mock_NamespaceStore.go | 151 + .../builder/store/database/mock_OrgStore.go | 411 ++ .../database/mock_PromptConversationStore.go | 452 +++ .../store/database/mock_PromptPrefixStore.go | 95 + .../store/database/mock_PromptStore.go | 506 +++ .../builder/store/database/mock_RepoStore.go | 2128 +++++++++++ .../store/database/mock_SpaceResourceStore.go | 437 +++ .../builder/store/database/mock_TagStore.go | 1232 ++++++ .../store/database/mock_UserLikesStore.go | 344 ++ .../builder/store/database/mock_UserStore.go | 814 ++++ .../component/mock_RepoComponent.go | 3373 +++++++++++++++++ .../user/component/mock_MemberComponent.go | 522 +++ builder/git/file_test.go | 59 +- builder/sensitive/aliyun_green.go | 98 +- builder/sensitive/aliyun_green_test.go | 176 +- common/tests/stores.go | 88 + common/utils/common/sync_version_test.go | 12 +- component/code.go | 6 +- component/dataset.go | 8 +- component/model.go | 8 +- component/model_test.go | 103 +- component/prompt.go | 207 +- component/prompt_test.go | 1206 +++++- component/recom_test.go | 32 +- component/repo.go | 72 +- component/space.go | 4 +- component/tagparser/contentparser_test.go | 55 +- go.mod | 2 + go.sum | 5 + moderation/checker/init.go | 2 +- moderation/component/repo.go | 2 +- moderation/handler/sensitive.go | 2 +- 44 files changed, 18380 insertions(+), 497 deletions(-) create mode 100644 .mockery.yaml create mode 100644 _mocks/opencsg.com/csghub-server/builder/git/gitserver/mock_GitServer.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/git/membership/mock_GitMemerShip.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/rpc/mock_UserSvcClient.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/sensitive/mock_Green2022Client.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/sensitive/mock_GreenClient.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountMeteringStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_DatasetStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_LLMConfigStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_MemberStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_ModelStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_NamespaceStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_OrgStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptConversationStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptPrefixStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceResourceStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_TagStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_UserLikesStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_UserStore.go create mode 100644 _mocks/opencsg.com/csghub-server/component/mock_RepoComponent.go create mode 100644 _mocks/opencsg.com/csghub-server/user/component/mock_MemberComponent.go create mode 100644 common/tests/stores.go diff --git a/.mockery.yaml b/.mockery.yaml new file mode 100644 index 00000000..d44e4206 --- /dev/null +++ b/.mockery.yaml @@ -0,0 +1,62 @@ +with-expecter: true +dir: "_mocks/{{.PackagePath}}" +packages: + opencsg.com/csghub-server/component: + config: + interfaces: + RepoComponent: + opencsg.com/csghub-server/user/component: + config: + interfaces: + MemberComponent: + opencsg.com/csghub-server/builder/store/database: + config: + interfaces: + UserStore: + NamespaceStore: + LicenseStore: + MirrorStore: + RepoStore: + OrgStore: + MemberStore: + ModelStore: + SpaceResourceStore: + TagStore: + DatasetStore: + PromptConversationStore: + PromptPrefixStore: + LLMConfigStore: + PromptStore: + UserLikesStore: + AccountStatementStore: + AccountOrderStore: + AccountPriceStore: + AccountBillStore: + AccountEventStore: + AccountMeteringStore: + AccountPresentStore: + opencsg.com/csghub-server/builder/rpc: + config: + interfaces: + UserSvcClient: + opencsg.com/csghub-server/builder/sensitive: + config: + interfaces: + GreenClient: + Green2022Client: + opencsg.com/csghub-server/builder/git/gitserver: + config: + interfaces: + GitServer: + opencsg.com/csghub-server/builder/git/membership: + config: + interfaces: + GitMemerShip: + opencsg.com/csghub-server/builder/rsa: + config: + interfaces: + KeysReader: + opencsg.com/csghub-server/mirror/cache: + config: + interfaces: + Cache: diff --git a/_mocks/opencsg.com/csghub-server/builder/git/gitserver/mock_GitServer.go b/_mocks/opencsg.com/csghub-server/builder/git/gitserver/mock_GitServer.go new file mode 100644 index 00000000..31b4ba06 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/git/gitserver/mock_GitServer.go @@ -0,0 +1,2131 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package gitserver + +import ( + context "context" + + gitserver "opencsg.com/csghub-server/builder/git/gitserver" + database "opencsg.com/csghub-server/builder/store/database" + + io "io" + + mock "github.com/stretchr/testify/mock" + + types "opencsg.com/csghub-server/common/types" +) + +// MockGitServer is an autogenerated mock type for the GitServer type +type MockGitServer struct { + mock.Mock +} + +type MockGitServer_Expecter struct { + mock *mock.Mock +} + +func (_m *MockGitServer) EXPECT() *MockGitServer_Expecter { + return &MockGitServer_Expecter{mock: &_m.Mock} +} + +// CreateMirrorRepo provides a mock function with given fields: ctx, req +func (_m *MockGitServer) CreateMirrorRepo(ctx context.Context, req gitserver.CreateMirrorRepoReq) (int64, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for CreateMirrorRepo") + } + + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.CreateMirrorRepoReq) (int64, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.CreateMirrorRepoReq) int64); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Get(0).(int64) + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.CreateMirrorRepoReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_CreateMirrorRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateMirrorRepo' +type MockGitServer_CreateMirrorRepo_Call struct { + *mock.Call +} + +// CreateMirrorRepo is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.CreateMirrorRepoReq +func (_e *MockGitServer_Expecter) CreateMirrorRepo(ctx interface{}, req interface{}) *MockGitServer_CreateMirrorRepo_Call { + return &MockGitServer_CreateMirrorRepo_Call{Call: _e.mock.On("CreateMirrorRepo", ctx, req)} +} + +func (_c *MockGitServer_CreateMirrorRepo_Call) Run(run func(ctx context.Context, req gitserver.CreateMirrorRepoReq)) *MockGitServer_CreateMirrorRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.CreateMirrorRepoReq)) + }) + return _c +} + +func (_c *MockGitServer_CreateMirrorRepo_Call) Return(_a0 int64, _a1 error) *MockGitServer_CreateMirrorRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_CreateMirrorRepo_Call) RunAndReturn(run func(context.Context, gitserver.CreateMirrorRepoReq) (int64, error)) *MockGitServer_CreateMirrorRepo_Call { + _c.Call.Return(run) + return _c +} + +// CreateOrganization provides a mock function with given fields: req, orgOwner +func (_m *MockGitServer) CreateOrganization(req *types.CreateOrgReq, orgOwner database.User) (*database.Organization, error) { + ret := _m.Called(req, orgOwner) + + if len(ret) == 0 { + panic("no return value specified for CreateOrganization") + } + + var r0 *database.Organization + var r1 error + if rf, ok := ret.Get(0).(func(*types.CreateOrgReq, database.User) (*database.Organization, error)); ok { + return rf(req, orgOwner) + } + if rf, ok := ret.Get(0).(func(*types.CreateOrgReq, database.User) *database.Organization); ok { + r0 = rf(req, orgOwner) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Organization) + } + } + + if rf, ok := ret.Get(1).(func(*types.CreateOrgReq, database.User) error); ok { + r1 = rf(req, orgOwner) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_CreateOrganization_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateOrganization' +type MockGitServer_CreateOrganization_Call struct { + *mock.Call +} + +// CreateOrganization is a helper method to define mock.On call +// - req *types.CreateOrgReq +// - orgOwner database.User +func (_e *MockGitServer_Expecter) CreateOrganization(req interface{}, orgOwner interface{}) *MockGitServer_CreateOrganization_Call { + return &MockGitServer_CreateOrganization_Call{Call: _e.mock.On("CreateOrganization", req, orgOwner)} +} + +func (_c *MockGitServer_CreateOrganization_Call) Run(run func(req *types.CreateOrgReq, orgOwner database.User)) *MockGitServer_CreateOrganization_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*types.CreateOrgReq), args[1].(database.User)) + }) + return _c +} + +func (_c *MockGitServer_CreateOrganization_Call) Return(_a0 *database.Organization, _a1 error) *MockGitServer_CreateOrganization_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_CreateOrganization_Call) RunAndReturn(run func(*types.CreateOrgReq, database.User) (*database.Organization, error)) *MockGitServer_CreateOrganization_Call { + _c.Call.Return(run) + return _c +} + +// CreateRepo provides a mock function with given fields: ctx, req +func (_m *MockGitServer) CreateRepo(ctx context.Context, req gitserver.CreateRepoReq) (*gitserver.CreateRepoResp, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for CreateRepo") + } + + var r0 *gitserver.CreateRepoResp + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.CreateRepoReq) (*gitserver.CreateRepoResp, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.CreateRepoReq) *gitserver.CreateRepoResp); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gitserver.CreateRepoResp) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.CreateRepoReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_CreateRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRepo' +type MockGitServer_CreateRepo_Call struct { + *mock.Call +} + +// CreateRepo is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.CreateRepoReq +func (_e *MockGitServer_Expecter) CreateRepo(ctx interface{}, req interface{}) *MockGitServer_CreateRepo_Call { + return &MockGitServer_CreateRepo_Call{Call: _e.mock.On("CreateRepo", ctx, req)} +} + +func (_c *MockGitServer_CreateRepo_Call) Run(run func(ctx context.Context, req gitserver.CreateRepoReq)) *MockGitServer_CreateRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.CreateRepoReq)) + }) + return _c +} + +func (_c *MockGitServer_CreateRepo_Call) Return(_a0 *gitserver.CreateRepoResp, _a1 error) *MockGitServer_CreateRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_CreateRepo_Call) RunAndReturn(run func(context.Context, gitserver.CreateRepoReq) (*gitserver.CreateRepoResp, error)) *MockGitServer_CreateRepo_Call { + _c.Call.Return(run) + return _c +} + +// CreateRepoFile provides a mock function with given fields: req +func (_m *MockGitServer) CreateRepoFile(req *types.CreateFileReq) error { + ret := _m.Called(req) + + if len(ret) == 0 { + panic("no return value specified for CreateRepoFile") + } + + var r0 error + if rf, ok := ret.Get(0).(func(*types.CreateFileReq) error); ok { + r0 = rf(req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_CreateRepoFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRepoFile' +type MockGitServer_CreateRepoFile_Call struct { + *mock.Call +} + +// CreateRepoFile is a helper method to define mock.On call +// - req *types.CreateFileReq +func (_e *MockGitServer_Expecter) CreateRepoFile(req interface{}) *MockGitServer_CreateRepoFile_Call { + return &MockGitServer_CreateRepoFile_Call{Call: _e.mock.On("CreateRepoFile", req)} +} + +func (_c *MockGitServer_CreateRepoFile_Call) Run(run func(req *types.CreateFileReq)) *MockGitServer_CreateRepoFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*types.CreateFileReq)) + }) + return _c +} + +func (_c *MockGitServer_CreateRepoFile_Call) Return(err error) *MockGitServer_CreateRepoFile_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockGitServer_CreateRepoFile_Call) RunAndReturn(run func(*types.CreateFileReq) error) *MockGitServer_CreateRepoFile_Call { + _c.Call.Return(run) + return _c +} + +// CreateSSHKey provides a mock function with given fields: _a0 +func (_m *MockGitServer) CreateSSHKey(_a0 *types.CreateSSHKeyRequest) (*database.SSHKey, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for CreateSSHKey") + } + + var r0 *database.SSHKey + var r1 error + if rf, ok := ret.Get(0).(func(*types.CreateSSHKeyRequest) (*database.SSHKey, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(*types.CreateSSHKeyRequest) *database.SSHKey); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SSHKey) + } + } + + if rf, ok := ret.Get(1).(func(*types.CreateSSHKeyRequest) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_CreateSSHKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateSSHKey' +type MockGitServer_CreateSSHKey_Call struct { + *mock.Call +} + +// CreateSSHKey is a helper method to define mock.On call +// - _a0 *types.CreateSSHKeyRequest +func (_e *MockGitServer_Expecter) CreateSSHKey(_a0 interface{}) *MockGitServer_CreateSSHKey_Call { + return &MockGitServer_CreateSSHKey_Call{Call: _e.mock.On("CreateSSHKey", _a0)} +} + +func (_c *MockGitServer_CreateSSHKey_Call) Run(run func(_a0 *types.CreateSSHKeyRequest)) *MockGitServer_CreateSSHKey_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*types.CreateSSHKeyRequest)) + }) + return _c +} + +func (_c *MockGitServer_CreateSSHKey_Call) Return(_a0 *database.SSHKey, _a1 error) *MockGitServer_CreateSSHKey_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_CreateSSHKey_Call) RunAndReturn(run func(*types.CreateSSHKeyRequest) (*database.SSHKey, error)) *MockGitServer_CreateSSHKey_Call { + _c.Call.Return(run) + return _c +} + +// CreateUser provides a mock function with given fields: _a0 +func (_m *MockGitServer) CreateUser(_a0 gitserver.CreateUserRequest) (*gitserver.CreateUserResponse, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for CreateUser") + } + + var r0 *gitserver.CreateUserResponse + var r1 error + if rf, ok := ret.Get(0).(func(gitserver.CreateUserRequest) (*gitserver.CreateUserResponse, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(gitserver.CreateUserRequest) *gitserver.CreateUserResponse); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gitserver.CreateUserResponse) + } + } + + if rf, ok := ret.Get(1).(func(gitserver.CreateUserRequest) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_CreateUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateUser' +type MockGitServer_CreateUser_Call struct { + *mock.Call +} + +// CreateUser is a helper method to define mock.On call +// - _a0 gitserver.CreateUserRequest +func (_e *MockGitServer_Expecter) CreateUser(_a0 interface{}) *MockGitServer_CreateUser_Call { + return &MockGitServer_CreateUser_Call{Call: _e.mock.On("CreateUser", _a0)} +} + +func (_c *MockGitServer_CreateUser_Call) Run(run func(_a0 gitserver.CreateUserRequest)) *MockGitServer_CreateUser_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(gitserver.CreateUserRequest)) + }) + return _c +} + +func (_c *MockGitServer_CreateUser_Call) Return(_a0 *gitserver.CreateUserResponse, _a1 error) *MockGitServer_CreateUser_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_CreateUser_Call) RunAndReturn(run func(gitserver.CreateUserRequest) (*gitserver.CreateUserResponse, error)) *MockGitServer_CreateUser_Call { + _c.Call.Return(run) + return _c +} + +// CreateUserToken provides a mock function with given fields: _a0 +func (_m *MockGitServer) CreateUserToken(_a0 *types.CreateUserTokenRequest) (*database.AccessToken, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for CreateUserToken") + } + + var r0 *database.AccessToken + var r1 error + if rf, ok := ret.Get(0).(func(*types.CreateUserTokenRequest) (*database.AccessToken, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(*types.CreateUserTokenRequest) *database.AccessToken); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.AccessToken) + } + } + + if rf, ok := ret.Get(1).(func(*types.CreateUserTokenRequest) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_CreateUserToken_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateUserToken' +type MockGitServer_CreateUserToken_Call struct { + *mock.Call +} + +// CreateUserToken is a helper method to define mock.On call +// - _a0 *types.CreateUserTokenRequest +func (_e *MockGitServer_Expecter) CreateUserToken(_a0 interface{}) *MockGitServer_CreateUserToken_Call { + return &MockGitServer_CreateUserToken_Call{Call: _e.mock.On("CreateUserToken", _a0)} +} + +func (_c *MockGitServer_CreateUserToken_Call) Run(run func(_a0 *types.CreateUserTokenRequest)) *MockGitServer_CreateUserToken_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*types.CreateUserTokenRequest)) + }) + return _c +} + +func (_c *MockGitServer_CreateUserToken_Call) Return(_a0 *database.AccessToken, _a1 error) *MockGitServer_CreateUserToken_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_CreateUserToken_Call) RunAndReturn(run func(*types.CreateUserTokenRequest) (*database.AccessToken, error)) *MockGitServer_CreateUserToken_Call { + _c.Call.Return(run) + return _c +} + +// DeleteOrganization provides a mock function with given fields: _a0 +func (_m *MockGitServer) DeleteOrganization(_a0 string) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for DeleteOrganization") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_DeleteOrganization_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteOrganization' +type MockGitServer_DeleteOrganization_Call struct { + *mock.Call +} + +// DeleteOrganization is a helper method to define mock.On call +// - _a0 string +func (_e *MockGitServer_Expecter) DeleteOrganization(_a0 interface{}) *MockGitServer_DeleteOrganization_Call { + return &MockGitServer_DeleteOrganization_Call{Call: _e.mock.On("DeleteOrganization", _a0)} +} + +func (_c *MockGitServer_DeleteOrganization_Call) Run(run func(_a0 string)) *MockGitServer_DeleteOrganization_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockGitServer_DeleteOrganization_Call) Return(_a0 error) *MockGitServer_DeleteOrganization_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitServer_DeleteOrganization_Call) RunAndReturn(run func(string) error) *MockGitServer_DeleteOrganization_Call { + _c.Call.Return(run) + return _c +} + +// DeleteRepo provides a mock function with given fields: ctx, req +func (_m *MockGitServer) DeleteRepo(ctx context.Context, req gitserver.DeleteRepoReq) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for DeleteRepo") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.DeleteRepoReq) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_DeleteRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteRepo' +type MockGitServer_DeleteRepo_Call struct { + *mock.Call +} + +// DeleteRepo is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.DeleteRepoReq +func (_e *MockGitServer_Expecter) DeleteRepo(ctx interface{}, req interface{}) *MockGitServer_DeleteRepo_Call { + return &MockGitServer_DeleteRepo_Call{Call: _e.mock.On("DeleteRepo", ctx, req)} +} + +func (_c *MockGitServer_DeleteRepo_Call) Run(run func(ctx context.Context, req gitserver.DeleteRepoReq)) *MockGitServer_DeleteRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.DeleteRepoReq)) + }) + return _c +} + +func (_c *MockGitServer_DeleteRepo_Call) Return(_a0 error) *MockGitServer_DeleteRepo_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitServer_DeleteRepo_Call) RunAndReturn(run func(context.Context, gitserver.DeleteRepoReq) error) *MockGitServer_DeleteRepo_Call { + _c.Call.Return(run) + return _c +} + +// DeleteRepoFile provides a mock function with given fields: req +func (_m *MockGitServer) DeleteRepoFile(req *types.DeleteFileReq) error { + ret := _m.Called(req) + + if len(ret) == 0 { + panic("no return value specified for DeleteRepoFile") + } + + var r0 error + if rf, ok := ret.Get(0).(func(*types.DeleteFileReq) error); ok { + r0 = rf(req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_DeleteRepoFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteRepoFile' +type MockGitServer_DeleteRepoFile_Call struct { + *mock.Call +} + +// DeleteRepoFile is a helper method to define mock.On call +// - req *types.DeleteFileReq +func (_e *MockGitServer_Expecter) DeleteRepoFile(req interface{}) *MockGitServer_DeleteRepoFile_Call { + return &MockGitServer_DeleteRepoFile_Call{Call: _e.mock.On("DeleteRepoFile", req)} +} + +func (_c *MockGitServer_DeleteRepoFile_Call) Run(run func(req *types.DeleteFileReq)) *MockGitServer_DeleteRepoFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*types.DeleteFileReq)) + }) + return _c +} + +func (_c *MockGitServer_DeleteRepoFile_Call) Return(err error) *MockGitServer_DeleteRepoFile_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockGitServer_DeleteRepoFile_Call) RunAndReturn(run func(*types.DeleteFileReq) error) *MockGitServer_DeleteRepoFile_Call { + _c.Call.Return(run) + return _c +} + +// DeleteSSHKey provides a mock function with given fields: _a0 +func (_m *MockGitServer) DeleteSSHKey(_a0 int) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for DeleteSSHKey") + } + + var r0 error + if rf, ok := ret.Get(0).(func(int) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_DeleteSSHKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteSSHKey' +type MockGitServer_DeleteSSHKey_Call struct { + *mock.Call +} + +// DeleteSSHKey is a helper method to define mock.On call +// - _a0 int +func (_e *MockGitServer_Expecter) DeleteSSHKey(_a0 interface{}) *MockGitServer_DeleteSSHKey_Call { + return &MockGitServer_DeleteSSHKey_Call{Call: _e.mock.On("DeleteSSHKey", _a0)} +} + +func (_c *MockGitServer_DeleteSSHKey_Call) Run(run func(_a0 int)) *MockGitServer_DeleteSSHKey_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *MockGitServer_DeleteSSHKey_Call) Return(_a0 error) *MockGitServer_DeleteSSHKey_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitServer_DeleteSSHKey_Call) RunAndReturn(run func(int) error) *MockGitServer_DeleteSSHKey_Call { + _c.Call.Return(run) + return _c +} + +// DeleteUserToken provides a mock function with given fields: _a0 +func (_m *MockGitServer) DeleteUserToken(_a0 *types.DeleteUserTokenRequest) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for DeleteUserToken") + } + + var r0 error + if rf, ok := ret.Get(0).(func(*types.DeleteUserTokenRequest) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_DeleteUserToken_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteUserToken' +type MockGitServer_DeleteUserToken_Call struct { + *mock.Call +} + +// DeleteUserToken is a helper method to define mock.On call +// - _a0 *types.DeleteUserTokenRequest +func (_e *MockGitServer_Expecter) DeleteUserToken(_a0 interface{}) *MockGitServer_DeleteUserToken_Call { + return &MockGitServer_DeleteUserToken_Call{Call: _e.mock.On("DeleteUserToken", _a0)} +} + +func (_c *MockGitServer_DeleteUserToken_Call) Run(run func(_a0 *types.DeleteUserTokenRequest)) *MockGitServer_DeleteUserToken_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*types.DeleteUserTokenRequest)) + }) + return _c +} + +func (_c *MockGitServer_DeleteUserToken_Call) Return(_a0 error) *MockGitServer_DeleteUserToken_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitServer_DeleteUserToken_Call) RunAndReturn(run func(*types.DeleteUserTokenRequest) error) *MockGitServer_DeleteUserToken_Call { + _c.Call.Return(run) + return _c +} + +// FixOrganization provides a mock function with given fields: req, orgOwner +func (_m *MockGitServer) FixOrganization(req *types.CreateOrgReq, orgOwner database.User) error { + ret := _m.Called(req, orgOwner) + + if len(ret) == 0 { + panic("no return value specified for FixOrganization") + } + + var r0 error + if rf, ok := ret.Get(0).(func(*types.CreateOrgReq, database.User) error); ok { + r0 = rf(req, orgOwner) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_FixOrganization_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FixOrganization' +type MockGitServer_FixOrganization_Call struct { + *mock.Call +} + +// FixOrganization is a helper method to define mock.On call +// - req *types.CreateOrgReq +// - orgOwner database.User +func (_e *MockGitServer_Expecter) FixOrganization(req interface{}, orgOwner interface{}) *MockGitServer_FixOrganization_Call { + return &MockGitServer_FixOrganization_Call{Call: _e.mock.On("FixOrganization", req, orgOwner)} +} + +func (_c *MockGitServer_FixOrganization_Call) Run(run func(req *types.CreateOrgReq, orgOwner database.User)) *MockGitServer_FixOrganization_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*types.CreateOrgReq), args[1].(database.User)) + }) + return _c +} + +func (_c *MockGitServer_FixOrganization_Call) Return(_a0 error) *MockGitServer_FixOrganization_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitServer_FixOrganization_Call) RunAndReturn(run func(*types.CreateOrgReq, database.User) error) *MockGitServer_FixOrganization_Call { + _c.Call.Return(run) + return _c +} + +// FixUserData provides a mock function with given fields: ctx, userName +func (_m *MockGitServer) FixUserData(ctx context.Context, userName string) error { + ret := _m.Called(ctx, userName) + + if len(ret) == 0 { + panic("no return value specified for FixUserData") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, userName) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_FixUserData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FixUserData' +type MockGitServer_FixUserData_Call struct { + *mock.Call +} + +// FixUserData is a helper method to define mock.On call +// - ctx context.Context +// - userName string +func (_e *MockGitServer_Expecter) FixUserData(ctx interface{}, userName interface{}) *MockGitServer_FixUserData_Call { + return &MockGitServer_FixUserData_Call{Call: _e.mock.On("FixUserData", ctx, userName)} +} + +func (_c *MockGitServer_FixUserData_Call) Run(run func(ctx context.Context, userName string)) *MockGitServer_FixUserData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockGitServer_FixUserData_Call) Return(_a0 error) *MockGitServer_FixUserData_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitServer_FixUserData_Call) RunAndReturn(run func(context.Context, string) error) *MockGitServer_FixUserData_Call { + _c.Call.Return(run) + return _c +} + +// GetCommitDiff provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetCommitDiff(ctx context.Context, req gitserver.GetRepoLastCommitReq) ([]byte, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetCommitDiff") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoLastCommitReq) ([]byte, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoLastCommitReq) []byte); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoLastCommitReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetCommitDiff_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCommitDiff' +type MockGitServer_GetCommitDiff_Call struct { + *mock.Call +} + +// GetCommitDiff is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoLastCommitReq +func (_e *MockGitServer_Expecter) GetCommitDiff(ctx interface{}, req interface{}) *MockGitServer_GetCommitDiff_Call { + return &MockGitServer_GetCommitDiff_Call{Call: _e.mock.On("GetCommitDiff", ctx, req)} +} + +func (_c *MockGitServer_GetCommitDiff_Call) Run(run func(ctx context.Context, req gitserver.GetRepoLastCommitReq)) *MockGitServer_GetCommitDiff_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoLastCommitReq)) + }) + return _c +} + +func (_c *MockGitServer_GetCommitDiff_Call) Return(_a0 []byte, _a1 error) *MockGitServer_GetCommitDiff_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetCommitDiff_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoLastCommitReq) ([]byte, error)) *MockGitServer_GetCommitDiff_Call { + _c.Call.Return(run) + return _c +} + +// GetDiffBetweenTwoCommits provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetDiffBetweenTwoCommits(ctx context.Context, req gitserver.GetDiffBetweenTwoCommitsReq) (*types.GiteaCallbackPushReq, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetDiffBetweenTwoCommits") + } + + var r0 *types.GiteaCallbackPushReq + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetDiffBetweenTwoCommitsReq) (*types.GiteaCallbackPushReq, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetDiffBetweenTwoCommitsReq) *types.GiteaCallbackPushReq); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.GiteaCallbackPushReq) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetDiffBetweenTwoCommitsReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetDiffBetweenTwoCommits_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDiffBetweenTwoCommits' +type MockGitServer_GetDiffBetweenTwoCommits_Call struct { + *mock.Call +} + +// GetDiffBetweenTwoCommits is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetDiffBetweenTwoCommitsReq +func (_e *MockGitServer_Expecter) GetDiffBetweenTwoCommits(ctx interface{}, req interface{}) *MockGitServer_GetDiffBetweenTwoCommits_Call { + return &MockGitServer_GetDiffBetweenTwoCommits_Call{Call: _e.mock.On("GetDiffBetweenTwoCommits", ctx, req)} +} + +func (_c *MockGitServer_GetDiffBetweenTwoCommits_Call) Run(run func(ctx context.Context, req gitserver.GetDiffBetweenTwoCommitsReq)) *MockGitServer_GetDiffBetweenTwoCommits_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetDiffBetweenTwoCommitsReq)) + }) + return _c +} + +func (_c *MockGitServer_GetDiffBetweenTwoCommits_Call) Return(_a0 *types.GiteaCallbackPushReq, _a1 error) *MockGitServer_GetDiffBetweenTwoCommits_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetDiffBetweenTwoCommits_Call) RunAndReturn(run func(context.Context, gitserver.GetDiffBetweenTwoCommitsReq) (*types.GiteaCallbackPushReq, error)) *MockGitServer_GetDiffBetweenTwoCommits_Call { + _c.Call.Return(run) + return _c +} + +// GetMirrorTaskInfo provides a mock function with given fields: ctx, taskId +func (_m *MockGitServer) GetMirrorTaskInfo(ctx context.Context, taskId int64) (*gitserver.MirrorTaskInfo, error) { + ret := _m.Called(ctx, taskId) + + if len(ret) == 0 { + panic("no return value specified for GetMirrorTaskInfo") + } + + var r0 *gitserver.MirrorTaskInfo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*gitserver.MirrorTaskInfo, error)); ok { + return rf(ctx, taskId) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *gitserver.MirrorTaskInfo); ok { + r0 = rf(ctx, taskId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gitserver.MirrorTaskInfo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, taskId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetMirrorTaskInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMirrorTaskInfo' +type MockGitServer_GetMirrorTaskInfo_Call struct { + *mock.Call +} + +// GetMirrorTaskInfo is a helper method to define mock.On call +// - ctx context.Context +// - taskId int64 +func (_e *MockGitServer_Expecter) GetMirrorTaskInfo(ctx interface{}, taskId interface{}) *MockGitServer_GetMirrorTaskInfo_Call { + return &MockGitServer_GetMirrorTaskInfo_Call{Call: _e.mock.On("GetMirrorTaskInfo", ctx, taskId)} +} + +func (_c *MockGitServer_GetMirrorTaskInfo_Call) Run(run func(ctx context.Context, taskId int64)) *MockGitServer_GetMirrorTaskInfo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockGitServer_GetMirrorTaskInfo_Call) Return(_a0 *gitserver.MirrorTaskInfo, _a1 error) *MockGitServer_GetMirrorTaskInfo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetMirrorTaskInfo_Call) RunAndReturn(run func(context.Context, int64) (*gitserver.MirrorTaskInfo, error)) *MockGitServer_GetMirrorTaskInfo_Call { + _c.Call.Return(run) + return _c +} + +// GetRepo provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetRepo(ctx context.Context, req gitserver.GetRepoReq) (*gitserver.CreateRepoResp, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetRepo") + } + + var r0 *gitserver.CreateRepoResp + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoReq) (*gitserver.CreateRepoResp, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoReq) *gitserver.CreateRepoResp); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gitserver.CreateRepoResp) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepo' +type MockGitServer_GetRepo_Call struct { + *mock.Call +} + +// GetRepo is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoReq +func (_e *MockGitServer_Expecter) GetRepo(ctx interface{}, req interface{}) *MockGitServer_GetRepo_Call { + return &MockGitServer_GetRepo_Call{Call: _e.mock.On("GetRepo", ctx, req)} +} + +func (_c *MockGitServer_GetRepo_Call) Run(run func(ctx context.Context, req gitserver.GetRepoReq)) *MockGitServer_GetRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoReq)) + }) + return _c +} + +func (_c *MockGitServer_GetRepo_Call) Return(_a0 *gitserver.CreateRepoResp, _a1 error) *MockGitServer_GetRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetRepo_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoReq) (*gitserver.CreateRepoResp, error)) *MockGitServer_GetRepo_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoAllFiles provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetRepoAllFiles(ctx context.Context, req gitserver.GetRepoAllFilesReq) ([]*types.File, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetRepoAllFiles") + } + + var r0 []*types.File + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoAllFilesReq) ([]*types.File, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoAllFilesReq) []*types.File); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*types.File) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoAllFilesReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetRepoAllFiles_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoAllFiles' +type MockGitServer_GetRepoAllFiles_Call struct { + *mock.Call +} + +// GetRepoAllFiles is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoAllFilesReq +func (_e *MockGitServer_Expecter) GetRepoAllFiles(ctx interface{}, req interface{}) *MockGitServer_GetRepoAllFiles_Call { + return &MockGitServer_GetRepoAllFiles_Call{Call: _e.mock.On("GetRepoAllFiles", ctx, req)} +} + +func (_c *MockGitServer_GetRepoAllFiles_Call) Run(run func(ctx context.Context, req gitserver.GetRepoAllFilesReq)) *MockGitServer_GetRepoAllFiles_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoAllFilesReq)) + }) + return _c +} + +func (_c *MockGitServer_GetRepoAllFiles_Call) Return(_a0 []*types.File, _a1 error) *MockGitServer_GetRepoAllFiles_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetRepoAllFiles_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoAllFilesReq) ([]*types.File, error)) *MockGitServer_GetRepoAllFiles_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoAllLfsPointers provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetRepoAllLfsPointers(ctx context.Context, req gitserver.GetRepoAllFilesReq) ([]*types.LFSPointer, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetRepoAllLfsPointers") + } + + var r0 []*types.LFSPointer + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoAllFilesReq) ([]*types.LFSPointer, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoAllFilesReq) []*types.LFSPointer); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*types.LFSPointer) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoAllFilesReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetRepoAllLfsPointers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoAllLfsPointers' +type MockGitServer_GetRepoAllLfsPointers_Call struct { + *mock.Call +} + +// GetRepoAllLfsPointers is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoAllFilesReq +func (_e *MockGitServer_Expecter) GetRepoAllLfsPointers(ctx interface{}, req interface{}) *MockGitServer_GetRepoAllLfsPointers_Call { + return &MockGitServer_GetRepoAllLfsPointers_Call{Call: _e.mock.On("GetRepoAllLfsPointers", ctx, req)} +} + +func (_c *MockGitServer_GetRepoAllLfsPointers_Call) Run(run func(ctx context.Context, req gitserver.GetRepoAllFilesReq)) *MockGitServer_GetRepoAllLfsPointers_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoAllFilesReq)) + }) + return _c +} + +func (_c *MockGitServer_GetRepoAllLfsPointers_Call) Return(_a0 []*types.LFSPointer, _a1 error) *MockGitServer_GetRepoAllLfsPointers_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetRepoAllLfsPointers_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoAllFilesReq) ([]*types.LFSPointer, error)) *MockGitServer_GetRepoAllLfsPointers_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoBranches provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetRepoBranches(ctx context.Context, req gitserver.GetBranchesReq) ([]types.Branch, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetRepoBranches") + } + + var r0 []types.Branch + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetBranchesReq) ([]types.Branch, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetBranchesReq) []types.Branch); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Branch) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetBranchesReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetRepoBranches_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoBranches' +type MockGitServer_GetRepoBranches_Call struct { + *mock.Call +} + +// GetRepoBranches is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetBranchesReq +func (_e *MockGitServer_Expecter) GetRepoBranches(ctx interface{}, req interface{}) *MockGitServer_GetRepoBranches_Call { + return &MockGitServer_GetRepoBranches_Call{Call: _e.mock.On("GetRepoBranches", ctx, req)} +} + +func (_c *MockGitServer_GetRepoBranches_Call) Run(run func(ctx context.Context, req gitserver.GetBranchesReq)) *MockGitServer_GetRepoBranches_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetBranchesReq)) + }) + return _c +} + +func (_c *MockGitServer_GetRepoBranches_Call) Return(_a0 []types.Branch, _a1 error) *MockGitServer_GetRepoBranches_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetRepoBranches_Call) RunAndReturn(run func(context.Context, gitserver.GetBranchesReq) ([]types.Branch, error)) *MockGitServer_GetRepoBranches_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoCommits provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetRepoCommits(ctx context.Context, req gitserver.GetRepoCommitsReq) ([]types.Commit, *types.RepoPageOpts, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetRepoCommits") + } + + var r0 []types.Commit + var r1 *types.RepoPageOpts + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoCommitsReq) ([]types.Commit, *types.RepoPageOpts, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoCommitsReq) []types.Commit); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Commit) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoCommitsReq) *types.RepoPageOpts); ok { + r1 = rf(ctx, req) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*types.RepoPageOpts) + } + } + + if rf, ok := ret.Get(2).(func(context.Context, gitserver.GetRepoCommitsReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockGitServer_GetRepoCommits_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoCommits' +type MockGitServer_GetRepoCommits_Call struct { + *mock.Call +} + +// GetRepoCommits is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoCommitsReq +func (_e *MockGitServer_Expecter) GetRepoCommits(ctx interface{}, req interface{}) *MockGitServer_GetRepoCommits_Call { + return &MockGitServer_GetRepoCommits_Call{Call: _e.mock.On("GetRepoCommits", ctx, req)} +} + +func (_c *MockGitServer_GetRepoCommits_Call) Run(run func(ctx context.Context, req gitserver.GetRepoCommitsReq)) *MockGitServer_GetRepoCommits_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoCommitsReq)) + }) + return _c +} + +func (_c *MockGitServer_GetRepoCommits_Call) Return(_a0 []types.Commit, _a1 *types.RepoPageOpts, _a2 error) *MockGitServer_GetRepoCommits_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockGitServer_GetRepoCommits_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoCommitsReq) ([]types.Commit, *types.RepoPageOpts, error)) *MockGitServer_GetRepoCommits_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoFileContents provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetRepoFileContents(ctx context.Context, req gitserver.GetRepoInfoByPathReq) (*types.File, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetRepoFileContents") + } + + var r0 *types.File + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoInfoByPathReq) (*types.File, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoInfoByPathReq) *types.File); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.File) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoInfoByPathReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetRepoFileContents_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoFileContents' +type MockGitServer_GetRepoFileContents_Call struct { + *mock.Call +} + +// GetRepoFileContents is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoInfoByPathReq +func (_e *MockGitServer_Expecter) GetRepoFileContents(ctx interface{}, req interface{}) *MockGitServer_GetRepoFileContents_Call { + return &MockGitServer_GetRepoFileContents_Call{Call: _e.mock.On("GetRepoFileContents", ctx, req)} +} + +func (_c *MockGitServer_GetRepoFileContents_Call) Run(run func(ctx context.Context, req gitserver.GetRepoInfoByPathReq)) *MockGitServer_GetRepoFileContents_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoInfoByPathReq)) + }) + return _c +} + +func (_c *MockGitServer_GetRepoFileContents_Call) Return(_a0 *types.File, _a1 error) *MockGitServer_GetRepoFileContents_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetRepoFileContents_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoInfoByPathReq) (*types.File, error)) *MockGitServer_GetRepoFileContents_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoFileRaw provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetRepoFileRaw(ctx context.Context, req gitserver.GetRepoInfoByPathReq) (string, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetRepoFileRaw") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoInfoByPathReq) (string, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoInfoByPathReq) string); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoInfoByPathReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetRepoFileRaw_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoFileRaw' +type MockGitServer_GetRepoFileRaw_Call struct { + *mock.Call +} + +// GetRepoFileRaw is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoInfoByPathReq +func (_e *MockGitServer_Expecter) GetRepoFileRaw(ctx interface{}, req interface{}) *MockGitServer_GetRepoFileRaw_Call { + return &MockGitServer_GetRepoFileRaw_Call{Call: _e.mock.On("GetRepoFileRaw", ctx, req)} +} + +func (_c *MockGitServer_GetRepoFileRaw_Call) Run(run func(ctx context.Context, req gitserver.GetRepoInfoByPathReq)) *MockGitServer_GetRepoFileRaw_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoInfoByPathReq)) + }) + return _c +} + +func (_c *MockGitServer_GetRepoFileRaw_Call) Return(_a0 string, _a1 error) *MockGitServer_GetRepoFileRaw_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetRepoFileRaw_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoInfoByPathReq) (string, error)) *MockGitServer_GetRepoFileRaw_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoFileReader provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetRepoFileReader(ctx context.Context, req gitserver.GetRepoInfoByPathReq) (io.ReadCloser, int64, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetRepoFileReader") + } + + var r0 io.ReadCloser + var r1 int64 + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoInfoByPathReq) (io.ReadCloser, int64, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoInfoByPathReq) io.ReadCloser); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(io.ReadCloser) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoInfoByPathReq) int64); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int64) + } + + if rf, ok := ret.Get(2).(func(context.Context, gitserver.GetRepoInfoByPathReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockGitServer_GetRepoFileReader_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoFileReader' +type MockGitServer_GetRepoFileReader_Call struct { + *mock.Call +} + +// GetRepoFileReader is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoInfoByPathReq +func (_e *MockGitServer_Expecter) GetRepoFileReader(ctx interface{}, req interface{}) *MockGitServer_GetRepoFileReader_Call { + return &MockGitServer_GetRepoFileReader_Call{Call: _e.mock.On("GetRepoFileReader", ctx, req)} +} + +func (_c *MockGitServer_GetRepoFileReader_Call) Run(run func(ctx context.Context, req gitserver.GetRepoInfoByPathReq)) *MockGitServer_GetRepoFileReader_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoInfoByPathReq)) + }) + return _c +} + +func (_c *MockGitServer_GetRepoFileReader_Call) Return(_a0 io.ReadCloser, _a1 int64, _a2 error) *MockGitServer_GetRepoFileReader_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockGitServer_GetRepoFileReader_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoInfoByPathReq) (io.ReadCloser, int64, error)) *MockGitServer_GetRepoFileReader_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoFileTree provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetRepoFileTree(ctx context.Context, req gitserver.GetRepoInfoByPathReq) ([]*types.File, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetRepoFileTree") + } + + var r0 []*types.File + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoInfoByPathReq) ([]*types.File, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoInfoByPathReq) []*types.File); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*types.File) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoInfoByPathReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetRepoFileTree_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoFileTree' +type MockGitServer_GetRepoFileTree_Call struct { + *mock.Call +} + +// GetRepoFileTree is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoInfoByPathReq +func (_e *MockGitServer_Expecter) GetRepoFileTree(ctx interface{}, req interface{}) *MockGitServer_GetRepoFileTree_Call { + return &MockGitServer_GetRepoFileTree_Call{Call: _e.mock.On("GetRepoFileTree", ctx, req)} +} + +func (_c *MockGitServer_GetRepoFileTree_Call) Run(run func(ctx context.Context, req gitserver.GetRepoInfoByPathReq)) *MockGitServer_GetRepoFileTree_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoInfoByPathReq)) + }) + return _c +} + +func (_c *MockGitServer_GetRepoFileTree_Call) Return(_a0 []*types.File, _a1 error) *MockGitServer_GetRepoFileTree_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetRepoFileTree_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoInfoByPathReq) ([]*types.File, error)) *MockGitServer_GetRepoFileTree_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoLastCommit provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetRepoLastCommit(ctx context.Context, req gitserver.GetRepoLastCommitReq) (*types.Commit, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetRepoLastCommit") + } + + var r0 *types.Commit + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoLastCommitReq) (*types.Commit, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoLastCommitReq) *types.Commit); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Commit) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoLastCommitReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetRepoLastCommit_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoLastCommit' +type MockGitServer_GetRepoLastCommit_Call struct { + *mock.Call +} + +// GetRepoLastCommit is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoLastCommitReq +func (_e *MockGitServer_Expecter) GetRepoLastCommit(ctx interface{}, req interface{}) *MockGitServer_GetRepoLastCommit_Call { + return &MockGitServer_GetRepoLastCommit_Call{Call: _e.mock.On("GetRepoLastCommit", ctx, req)} +} + +func (_c *MockGitServer_GetRepoLastCommit_Call) Run(run func(ctx context.Context, req gitserver.GetRepoLastCommitReq)) *MockGitServer_GetRepoLastCommit_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoLastCommitReq)) + }) + return _c +} + +func (_c *MockGitServer_GetRepoLastCommit_Call) Return(_a0 *types.Commit, _a1 error) *MockGitServer_GetRepoLastCommit_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetRepoLastCommit_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoLastCommitReq) (*types.Commit, error)) *MockGitServer_GetRepoLastCommit_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoLfsFileRaw provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetRepoLfsFileRaw(ctx context.Context, req gitserver.GetRepoInfoByPathReq) (io.ReadCloser, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetRepoLfsFileRaw") + } + + var r0 io.ReadCloser + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoInfoByPathReq) (io.ReadCloser, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoInfoByPathReq) io.ReadCloser); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(io.ReadCloser) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoInfoByPathReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetRepoLfsFileRaw_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoLfsFileRaw' +type MockGitServer_GetRepoLfsFileRaw_Call struct { + *mock.Call +} + +// GetRepoLfsFileRaw is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoInfoByPathReq +func (_e *MockGitServer_Expecter) GetRepoLfsFileRaw(ctx interface{}, req interface{}) *MockGitServer_GetRepoLfsFileRaw_Call { + return &MockGitServer_GetRepoLfsFileRaw_Call{Call: _e.mock.On("GetRepoLfsFileRaw", ctx, req)} +} + +func (_c *MockGitServer_GetRepoLfsFileRaw_Call) Run(run func(ctx context.Context, req gitserver.GetRepoInfoByPathReq)) *MockGitServer_GetRepoLfsFileRaw_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoInfoByPathReq)) + }) + return _c +} + +func (_c *MockGitServer_GetRepoLfsFileRaw_Call) Return(_a0 io.ReadCloser, _a1 error) *MockGitServer_GetRepoLfsFileRaw_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetRepoLfsFileRaw_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoInfoByPathReq) (io.ReadCloser, error)) *MockGitServer_GetRepoLfsFileRaw_Call { + _c.Call.Return(run) + return _c +} + +// GetSingleCommit provides a mock function with given fields: ctx, req +func (_m *MockGitServer) GetSingleCommit(ctx context.Context, req gitserver.GetRepoLastCommitReq) (*types.CommitResponse, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetSingleCommit") + } + + var r0 *types.CommitResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoLastCommitReq) (*types.CommitResponse, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.GetRepoLastCommitReq) *types.CommitResponse); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.CommitResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.GetRepoLastCommitReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_GetSingleCommit_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSingleCommit' +type MockGitServer_GetSingleCommit_Call struct { + *mock.Call +} + +// GetSingleCommit is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.GetRepoLastCommitReq +func (_e *MockGitServer_Expecter) GetSingleCommit(ctx interface{}, req interface{}) *MockGitServer_GetSingleCommit_Call { + return &MockGitServer_GetSingleCommit_Call{Call: _e.mock.On("GetSingleCommit", ctx, req)} +} + +func (_c *MockGitServer_GetSingleCommit_Call) Run(run func(ctx context.Context, req gitserver.GetRepoLastCommitReq)) *MockGitServer_GetSingleCommit_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.GetRepoLastCommitReq)) + }) + return _c +} + +func (_c *MockGitServer_GetSingleCommit_Call) Return(_a0 *types.CommitResponse, _a1 error) *MockGitServer_GetSingleCommit_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_GetSingleCommit_Call) RunAndReturn(run func(context.Context, gitserver.GetRepoLastCommitReq) (*types.CommitResponse, error)) *MockGitServer_GetSingleCommit_Call { + _c.Call.Return(run) + return _c +} + +// InfoRefsResponse provides a mock function with given fields: ctx, req +func (_m *MockGitServer) InfoRefsResponse(ctx context.Context, req gitserver.InfoRefsReq) (io.Reader, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for InfoRefsResponse") + } + + var r0 io.Reader + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.InfoRefsReq) (io.Reader, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.InfoRefsReq) io.Reader); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(io.Reader) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.InfoRefsReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_InfoRefsResponse_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'InfoRefsResponse' +type MockGitServer_InfoRefsResponse_Call struct { + *mock.Call +} + +// InfoRefsResponse is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.InfoRefsReq +func (_e *MockGitServer_Expecter) InfoRefsResponse(ctx interface{}, req interface{}) *MockGitServer_InfoRefsResponse_Call { + return &MockGitServer_InfoRefsResponse_Call{Call: _e.mock.On("InfoRefsResponse", ctx, req)} +} + +func (_c *MockGitServer_InfoRefsResponse_Call) Run(run func(ctx context.Context, req gitserver.InfoRefsReq)) *MockGitServer_InfoRefsResponse_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.InfoRefsReq)) + }) + return _c +} + +func (_c *MockGitServer_InfoRefsResponse_Call) Return(_a0 io.Reader, _a1 error) *MockGitServer_InfoRefsResponse_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_InfoRefsResponse_Call) RunAndReturn(run func(context.Context, gitserver.InfoRefsReq) (io.Reader, error)) *MockGitServer_InfoRefsResponse_Call { + _c.Call.Return(run) + return _c +} + +// MirrorSync provides a mock function with given fields: ctx, req +func (_m *MockGitServer) MirrorSync(ctx context.Context, req gitserver.MirrorSyncReq) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for MirrorSync") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.MirrorSyncReq) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_MirrorSync_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MirrorSync' +type MockGitServer_MirrorSync_Call struct { + *mock.Call +} + +// MirrorSync is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.MirrorSyncReq +func (_e *MockGitServer_Expecter) MirrorSync(ctx interface{}, req interface{}) *MockGitServer_MirrorSync_Call { + return &MockGitServer_MirrorSync_Call{Call: _e.mock.On("MirrorSync", ctx, req)} +} + +func (_c *MockGitServer_MirrorSync_Call) Run(run func(ctx context.Context, req gitserver.MirrorSyncReq)) *MockGitServer_MirrorSync_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.MirrorSyncReq)) + }) + return _c +} + +func (_c *MockGitServer_MirrorSync_Call) Return(_a0 error) *MockGitServer_MirrorSync_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitServer_MirrorSync_Call) RunAndReturn(run func(context.Context, gitserver.MirrorSyncReq) error) *MockGitServer_MirrorSync_Call { + _c.Call.Return(run) + return _c +} + +// ReceivePack provides a mock function with given fields: ctx, req +func (_m *MockGitServer) ReceivePack(ctx context.Context, req gitserver.ReceivePackReq) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for ReceivePack") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.ReceivePackReq) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_ReceivePack_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReceivePack' +type MockGitServer_ReceivePack_Call struct { + *mock.Call +} + +// ReceivePack is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.ReceivePackReq +func (_e *MockGitServer_Expecter) ReceivePack(ctx interface{}, req interface{}) *MockGitServer_ReceivePack_Call { + return &MockGitServer_ReceivePack_Call{Call: _e.mock.On("ReceivePack", ctx, req)} +} + +func (_c *MockGitServer_ReceivePack_Call) Run(run func(ctx context.Context, req gitserver.ReceivePackReq)) *MockGitServer_ReceivePack_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.ReceivePackReq)) + }) + return _c +} + +func (_c *MockGitServer_ReceivePack_Call) Return(_a0 error) *MockGitServer_ReceivePack_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitServer_ReceivePack_Call) RunAndReturn(run func(context.Context, gitserver.ReceivePackReq) error) *MockGitServer_ReceivePack_Call { + _c.Call.Return(run) + return _c +} + +// UpdateOrganization provides a mock function with given fields: _a0, _a1 +func (_m *MockGitServer) UpdateOrganization(_a0 *types.EditOrgReq, _a1 *database.Organization) (*database.Organization, error) { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for UpdateOrganization") + } + + var r0 *database.Organization + var r1 error + if rf, ok := ret.Get(0).(func(*types.EditOrgReq, *database.Organization) (*database.Organization, error)); ok { + return rf(_a0, _a1) + } + if rf, ok := ret.Get(0).(func(*types.EditOrgReq, *database.Organization) *database.Organization); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Organization) + } + } + + if rf, ok := ret.Get(1).(func(*types.EditOrgReq, *database.Organization) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_UpdateOrganization_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateOrganization' +type MockGitServer_UpdateOrganization_Call struct { + *mock.Call +} + +// UpdateOrganization is a helper method to define mock.On call +// - _a0 *types.EditOrgReq +// - _a1 *database.Organization +func (_e *MockGitServer_Expecter) UpdateOrganization(_a0 interface{}, _a1 interface{}) *MockGitServer_UpdateOrganization_Call { + return &MockGitServer_UpdateOrganization_Call{Call: _e.mock.On("UpdateOrganization", _a0, _a1)} +} + +func (_c *MockGitServer_UpdateOrganization_Call) Run(run func(_a0 *types.EditOrgReq, _a1 *database.Organization)) *MockGitServer_UpdateOrganization_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*types.EditOrgReq), args[1].(*database.Organization)) + }) + return _c +} + +func (_c *MockGitServer_UpdateOrganization_Call) Return(_a0 *database.Organization, _a1 error) *MockGitServer_UpdateOrganization_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_UpdateOrganization_Call) RunAndReturn(run func(*types.EditOrgReq, *database.Organization) (*database.Organization, error)) *MockGitServer_UpdateOrganization_Call { + _c.Call.Return(run) + return _c +} + +// UpdateRepo provides a mock function with given fields: ctx, req +func (_m *MockGitServer) UpdateRepo(ctx context.Context, req gitserver.UpdateRepoReq) (*gitserver.CreateRepoResp, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for UpdateRepo") + } + + var r0 *gitserver.CreateRepoResp + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.UpdateRepoReq) (*gitserver.CreateRepoResp, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, gitserver.UpdateRepoReq) *gitserver.CreateRepoResp); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gitserver.CreateRepoResp) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, gitserver.UpdateRepoReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_UpdateRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateRepo' +type MockGitServer_UpdateRepo_Call struct { + *mock.Call +} + +// UpdateRepo is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.UpdateRepoReq +func (_e *MockGitServer_Expecter) UpdateRepo(ctx interface{}, req interface{}) *MockGitServer_UpdateRepo_Call { + return &MockGitServer_UpdateRepo_Call{Call: _e.mock.On("UpdateRepo", ctx, req)} +} + +func (_c *MockGitServer_UpdateRepo_Call) Run(run func(ctx context.Context, req gitserver.UpdateRepoReq)) *MockGitServer_UpdateRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.UpdateRepoReq)) + }) + return _c +} + +func (_c *MockGitServer_UpdateRepo_Call) Return(_a0 *gitserver.CreateRepoResp, _a1 error) *MockGitServer_UpdateRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_UpdateRepo_Call) RunAndReturn(run func(context.Context, gitserver.UpdateRepoReq) (*gitserver.CreateRepoResp, error)) *MockGitServer_UpdateRepo_Call { + _c.Call.Return(run) + return _c +} + +// UpdateRepoFile provides a mock function with given fields: req +func (_m *MockGitServer) UpdateRepoFile(req *types.UpdateFileReq) error { + ret := _m.Called(req) + + if len(ret) == 0 { + panic("no return value specified for UpdateRepoFile") + } + + var r0 error + if rf, ok := ret.Get(0).(func(*types.UpdateFileReq) error); ok { + r0 = rf(req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_UpdateRepoFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateRepoFile' +type MockGitServer_UpdateRepoFile_Call struct { + *mock.Call +} + +// UpdateRepoFile is a helper method to define mock.On call +// - req *types.UpdateFileReq +func (_e *MockGitServer_Expecter) UpdateRepoFile(req interface{}) *MockGitServer_UpdateRepoFile_Call { + return &MockGitServer_UpdateRepoFile_Call{Call: _e.mock.On("UpdateRepoFile", req)} +} + +func (_c *MockGitServer_UpdateRepoFile_Call) Run(run func(req *types.UpdateFileReq)) *MockGitServer_UpdateRepoFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*types.UpdateFileReq)) + }) + return _c +} + +func (_c *MockGitServer_UpdateRepoFile_Call) Return(err error) *MockGitServer_UpdateRepoFile_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockGitServer_UpdateRepoFile_Call) RunAndReturn(run func(*types.UpdateFileReq) error) *MockGitServer_UpdateRepoFile_Call { + _c.Call.Return(run) + return _c +} + +// UpdateUser provides a mock function with given fields: _a0, _a1 +func (_m *MockGitServer) UpdateUser(_a0 *types.UpdateUserRequest, _a1 *database.User) (*database.User, error) { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for UpdateUser") + } + + var r0 *database.User + var r1 error + if rf, ok := ret.Get(0).(func(*types.UpdateUserRequest, *database.User) (*database.User, error)); ok { + return rf(_a0, _a1) + } + if rf, ok := ret.Get(0).(func(*types.UpdateUserRequest, *database.User) *database.User); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.User) + } + } + + if rf, ok := ret.Get(1).(func(*types.UpdateUserRequest, *database.User) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServer_UpdateUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateUser' +type MockGitServer_UpdateUser_Call struct { + *mock.Call +} + +// UpdateUser is a helper method to define mock.On call +// - _a0 *types.UpdateUserRequest +// - _a1 *database.User +func (_e *MockGitServer_Expecter) UpdateUser(_a0 interface{}, _a1 interface{}) *MockGitServer_UpdateUser_Call { + return &MockGitServer_UpdateUser_Call{Call: _e.mock.On("UpdateUser", _a0, _a1)} +} + +func (_c *MockGitServer_UpdateUser_Call) Run(run func(_a0 *types.UpdateUserRequest, _a1 *database.User)) *MockGitServer_UpdateUser_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*types.UpdateUserRequest), args[1].(*database.User)) + }) + return _c +} + +func (_c *MockGitServer_UpdateUser_Call) Return(_a0 *database.User, _a1 error) *MockGitServer_UpdateUser_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServer_UpdateUser_Call) RunAndReturn(run func(*types.UpdateUserRequest, *database.User) (*database.User, error)) *MockGitServer_UpdateUser_Call { + _c.Call.Return(run) + return _c +} + +// UpdateUserV2 provides a mock function with given fields: _a0 +func (_m *MockGitServer) UpdateUserV2(_a0 gitserver.UpdateUserRequest) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for UpdateUserV2") + } + + var r0 error + if rf, ok := ret.Get(0).(func(gitserver.UpdateUserRequest) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_UpdateUserV2_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateUserV2' +type MockGitServer_UpdateUserV2_Call struct { + *mock.Call +} + +// UpdateUserV2 is a helper method to define mock.On call +// - _a0 gitserver.UpdateUserRequest +func (_e *MockGitServer_Expecter) UpdateUserV2(_a0 interface{}) *MockGitServer_UpdateUserV2_Call { + return &MockGitServer_UpdateUserV2_Call{Call: _e.mock.On("UpdateUserV2", _a0)} +} + +func (_c *MockGitServer_UpdateUserV2_Call) Run(run func(_a0 gitserver.UpdateUserRequest)) *MockGitServer_UpdateUserV2_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(gitserver.UpdateUserRequest)) + }) + return _c +} + +func (_c *MockGitServer_UpdateUserV2_Call) Return(_a0 error) *MockGitServer_UpdateUserV2_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitServer_UpdateUserV2_Call) RunAndReturn(run func(gitserver.UpdateUserRequest) error) *MockGitServer_UpdateUserV2_Call { + _c.Call.Return(run) + return _c +} + +// UploadPack provides a mock function with given fields: ctx, req +func (_m *MockGitServer) UploadPack(ctx context.Context, req gitserver.UploadPackReq) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for UploadPack") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, gitserver.UploadPackReq) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitServer_UploadPack_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UploadPack' +type MockGitServer_UploadPack_Call struct { + *mock.Call +} + +// UploadPack is a helper method to define mock.On call +// - ctx context.Context +// - req gitserver.UploadPackReq +func (_e *MockGitServer_Expecter) UploadPack(ctx interface{}, req interface{}) *MockGitServer_UploadPack_Call { + return &MockGitServer_UploadPack_Call{Call: _e.mock.On("UploadPack", ctx, req)} +} + +func (_c *MockGitServer_UploadPack_Call) Run(run func(ctx context.Context, req gitserver.UploadPackReq)) *MockGitServer_UploadPack_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(gitserver.UploadPackReq)) + }) + return _c +} + +func (_c *MockGitServer_UploadPack_Call) Return(_a0 error) *MockGitServer_UploadPack_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitServer_UploadPack_Call) RunAndReturn(run func(context.Context, gitserver.UploadPackReq) error) *MockGitServer_UploadPack_Call { + _c.Call.Return(run) + return _c +} + +// NewMockGitServer creates a new instance of MockGitServer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockGitServer(t interface { + mock.TestingT + Cleanup(func()) +}) *MockGitServer { + mock := &MockGitServer{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/git/membership/mock_GitMemerShip.go b/_mocks/opencsg.com/csghub-server/builder/git/membership/mock_GitMemerShip.go new file mode 100644 index 00000000..00c051a1 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/git/membership/mock_GitMemerShip.go @@ -0,0 +1,242 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package membership + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + membership "opencsg.com/csghub-server/builder/git/membership" +) + +// MockGitMemerShip is an autogenerated mock type for the GitMemerShip type +type MockGitMemerShip struct { + mock.Mock +} + +type MockGitMemerShip_Expecter struct { + mock *mock.Mock +} + +func (_m *MockGitMemerShip) EXPECT() *MockGitMemerShip_Expecter { + return &MockGitMemerShip_Expecter{mock: &_m.Mock} +} + +// AddMember provides a mock function with given fields: ctx, org, user, role +func (_m *MockGitMemerShip) AddMember(ctx context.Context, org string, user string, role membership.Role) error { + ret := _m.Called(ctx, org, user, role) + + if len(ret) == 0 { + panic("no return value specified for AddMember") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, membership.Role) error); ok { + r0 = rf(ctx, org, user, role) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitMemerShip_AddMember_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddMember' +type MockGitMemerShip_AddMember_Call struct { + *mock.Call +} + +// AddMember is a helper method to define mock.On call +// - ctx context.Context +// - org string +// - user string +// - role membership.Role +func (_e *MockGitMemerShip_Expecter) AddMember(ctx interface{}, org interface{}, user interface{}, role interface{}) *MockGitMemerShip_AddMember_Call { + return &MockGitMemerShip_AddMember_Call{Call: _e.mock.On("AddMember", ctx, org, user, role)} +} + +func (_c *MockGitMemerShip_AddMember_Call) Run(run func(ctx context.Context, org string, user string, role membership.Role)) *MockGitMemerShip_AddMember_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(membership.Role)) + }) + return _c +} + +func (_c *MockGitMemerShip_AddMember_Call) Return(_a0 error) *MockGitMemerShip_AddMember_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitMemerShip_AddMember_Call) RunAndReturn(run func(context.Context, string, string, membership.Role) error) *MockGitMemerShip_AddMember_Call { + _c.Call.Return(run) + return _c +} + +// AddRoles provides a mock function with given fields: ctx, org, roles +func (_m *MockGitMemerShip) AddRoles(ctx context.Context, org string, roles []membership.Role) error { + ret := _m.Called(ctx, org, roles) + + if len(ret) == 0 { + panic("no return value specified for AddRoles") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, []membership.Role) error); ok { + r0 = rf(ctx, org, roles) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitMemerShip_AddRoles_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddRoles' +type MockGitMemerShip_AddRoles_Call struct { + *mock.Call +} + +// AddRoles is a helper method to define mock.On call +// - ctx context.Context +// - org string +// - roles []membership.Role +func (_e *MockGitMemerShip_Expecter) AddRoles(ctx interface{}, org interface{}, roles interface{}) *MockGitMemerShip_AddRoles_Call { + return &MockGitMemerShip_AddRoles_Call{Call: _e.mock.On("AddRoles", ctx, org, roles)} +} + +func (_c *MockGitMemerShip_AddRoles_Call) Run(run func(ctx context.Context, org string, roles []membership.Role)) *MockGitMemerShip_AddRoles_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].([]membership.Role)) + }) + return _c +} + +func (_c *MockGitMemerShip_AddRoles_Call) Return(_a0 error) *MockGitMemerShip_AddRoles_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitMemerShip_AddRoles_Call) RunAndReturn(run func(context.Context, string, []membership.Role) error) *MockGitMemerShip_AddRoles_Call { + _c.Call.Return(run) + return _c +} + +// IsRole provides a mock function with given fields: ctx, org, user, role +func (_m *MockGitMemerShip) IsRole(ctx context.Context, org string, user string, role membership.Role) (bool, error) { + ret := _m.Called(ctx, org, user, role) + + if len(ret) == 0 { + panic("no return value specified for IsRole") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, membership.Role) (bool, error)); ok { + return rf(ctx, org, user, role) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, membership.Role) bool); ok { + r0 = rf(ctx, org, user, role) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, membership.Role) error); ok { + r1 = rf(ctx, org, user, role) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitMemerShip_IsRole_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsRole' +type MockGitMemerShip_IsRole_Call struct { + *mock.Call +} + +// IsRole is a helper method to define mock.On call +// - ctx context.Context +// - org string +// - user string +// - role membership.Role +func (_e *MockGitMemerShip_Expecter) IsRole(ctx interface{}, org interface{}, user interface{}, role interface{}) *MockGitMemerShip_IsRole_Call { + return &MockGitMemerShip_IsRole_Call{Call: _e.mock.On("IsRole", ctx, org, user, role)} +} + +func (_c *MockGitMemerShip_IsRole_Call) Run(run func(ctx context.Context, org string, user string, role membership.Role)) *MockGitMemerShip_IsRole_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(membership.Role)) + }) + return _c +} + +func (_c *MockGitMemerShip_IsRole_Call) Return(_a0 bool, _a1 error) *MockGitMemerShip_IsRole_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitMemerShip_IsRole_Call) RunAndReturn(run func(context.Context, string, string, membership.Role) (bool, error)) *MockGitMemerShip_IsRole_Call { + _c.Call.Return(run) + return _c +} + +// RemoveMember provides a mock function with given fields: ctx, org, user, role +func (_m *MockGitMemerShip) RemoveMember(ctx context.Context, org string, user string, role membership.Role) error { + ret := _m.Called(ctx, org, user, role) + + if len(ret) == 0 { + panic("no return value specified for RemoveMember") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, membership.Role) error); ok { + r0 = rf(ctx, org, user, role) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockGitMemerShip_RemoveMember_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveMember' +type MockGitMemerShip_RemoveMember_Call struct { + *mock.Call +} + +// RemoveMember is a helper method to define mock.On call +// - ctx context.Context +// - org string +// - user string +// - role membership.Role +func (_e *MockGitMemerShip_Expecter) RemoveMember(ctx interface{}, org interface{}, user interface{}, role interface{}) *MockGitMemerShip_RemoveMember_Call { + return &MockGitMemerShip_RemoveMember_Call{Call: _e.mock.On("RemoveMember", ctx, org, user, role)} +} + +func (_c *MockGitMemerShip_RemoveMember_Call) Run(run func(ctx context.Context, org string, user string, role membership.Role)) *MockGitMemerShip_RemoveMember_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(membership.Role)) + }) + return _c +} + +func (_c *MockGitMemerShip_RemoveMember_Call) Return(_a0 error) *MockGitMemerShip_RemoveMember_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGitMemerShip_RemoveMember_Call) RunAndReturn(run func(context.Context, string, string, membership.Role) error) *MockGitMemerShip_RemoveMember_Call { + _c.Call.Return(run) + return _c +} + +// NewMockGitMemerShip creates a new instance of MockGitMemerShip. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockGitMemerShip(t interface { + mock.TestingT + Cleanup(func()) +}) *MockGitMemerShip { + mock := &MockGitMemerShip{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/rpc/mock_UserSvcClient.go b/_mocks/opencsg.com/csghub-server/builder/rpc/mock_UserSvcClient.go new file mode 100644 index 00000000..5a7be599 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/rpc/mock_UserSvcClient.go @@ -0,0 +1,216 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package rpc + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + membership "opencsg.com/csghub-server/builder/git/membership" + + rpc "opencsg.com/csghub-server/builder/rpc" +) + +// MockUserSvcClient is an autogenerated mock type for the UserSvcClient type +type MockUserSvcClient struct { + mock.Mock +} + +type MockUserSvcClient_Expecter struct { + mock *mock.Mock +} + +func (_m *MockUserSvcClient) EXPECT() *MockUserSvcClient_Expecter { + return &MockUserSvcClient_Expecter{mock: &_m.Mock} +} + +// GetMemberRole provides a mock function with given fields: ctx, orgName, userName +func (_m *MockUserSvcClient) GetMemberRole(ctx context.Context, orgName string, userName string) (membership.Role, error) { + ret := _m.Called(ctx, orgName, userName) + + if len(ret) == 0 { + panic("no return value specified for GetMemberRole") + } + + var r0 membership.Role + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (membership.Role, error)); ok { + return rf(ctx, orgName, userName) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) membership.Role); ok { + r0 = rf(ctx, orgName, userName) + } else { + r0 = ret.Get(0).(membership.Role) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, orgName, userName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserSvcClient_GetMemberRole_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMemberRole' +type MockUserSvcClient_GetMemberRole_Call struct { + *mock.Call +} + +// GetMemberRole is a helper method to define mock.On call +// - ctx context.Context +// - orgName string +// - userName string +func (_e *MockUserSvcClient_Expecter) GetMemberRole(ctx interface{}, orgName interface{}, userName interface{}) *MockUserSvcClient_GetMemberRole_Call { + return &MockUserSvcClient_GetMemberRole_Call{Call: _e.mock.On("GetMemberRole", ctx, orgName, userName)} +} + +func (_c *MockUserSvcClient_GetMemberRole_Call) Run(run func(ctx context.Context, orgName string, userName string)) *MockUserSvcClient_GetMemberRole_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockUserSvcClient_GetMemberRole_Call) Return(_a0 membership.Role, _a1 error) *MockUserSvcClient_GetMemberRole_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockUserSvcClient_GetMemberRole_Call) RunAndReturn(run func(context.Context, string, string) (membership.Role, error)) *MockUserSvcClient_GetMemberRole_Call { + _c.Call.Return(run) + return _c +} + +// GetNameSpaceInfo provides a mock function with given fields: ctx, path +func (_m *MockUserSvcClient) GetNameSpaceInfo(ctx context.Context, path string) (*rpc.Namespace, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for GetNameSpaceInfo") + } + + var r0 *rpc.Namespace + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*rpc.Namespace, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *rpc.Namespace); ok { + r0 = rf(ctx, path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*rpc.Namespace) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserSvcClient_GetNameSpaceInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNameSpaceInfo' +type MockUserSvcClient_GetNameSpaceInfo_Call struct { + *mock.Call +} + +// GetNameSpaceInfo is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *MockUserSvcClient_Expecter) GetNameSpaceInfo(ctx interface{}, path interface{}) *MockUserSvcClient_GetNameSpaceInfo_Call { + return &MockUserSvcClient_GetNameSpaceInfo_Call{Call: _e.mock.On("GetNameSpaceInfo", ctx, path)} +} + +func (_c *MockUserSvcClient_GetNameSpaceInfo_Call) Run(run func(ctx context.Context, path string)) *MockUserSvcClient_GetNameSpaceInfo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockUserSvcClient_GetNameSpaceInfo_Call) Return(_a0 *rpc.Namespace, _a1 error) *MockUserSvcClient_GetNameSpaceInfo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockUserSvcClient_GetNameSpaceInfo_Call) RunAndReturn(run func(context.Context, string) (*rpc.Namespace, error)) *MockUserSvcClient_GetNameSpaceInfo_Call { + _c.Call.Return(run) + return _c +} + +// GetUserInfo provides a mock function with given fields: ctx, userName, visitorName +func (_m *MockUserSvcClient) GetUserInfo(ctx context.Context, userName string, visitorName string) (*rpc.User, error) { + ret := _m.Called(ctx, userName, visitorName) + + if len(ret) == 0 { + panic("no return value specified for GetUserInfo") + } + + var r0 *rpc.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*rpc.User, error)); ok { + return rf(ctx, userName, visitorName) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) *rpc.User); ok { + r0 = rf(ctx, userName, visitorName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*rpc.User) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, userName, visitorName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserSvcClient_GetUserInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserInfo' +type MockUserSvcClient_GetUserInfo_Call struct { + *mock.Call +} + +// GetUserInfo is a helper method to define mock.On call +// - ctx context.Context +// - userName string +// - visitorName string +func (_e *MockUserSvcClient_Expecter) GetUserInfo(ctx interface{}, userName interface{}, visitorName interface{}) *MockUserSvcClient_GetUserInfo_Call { + return &MockUserSvcClient_GetUserInfo_Call{Call: _e.mock.On("GetUserInfo", ctx, userName, visitorName)} +} + +func (_c *MockUserSvcClient_GetUserInfo_Call) Run(run func(ctx context.Context, userName string, visitorName string)) *MockUserSvcClient_GetUserInfo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockUserSvcClient_GetUserInfo_Call) Return(_a0 *rpc.User, _a1 error) *MockUserSvcClient_GetUserInfo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockUserSvcClient_GetUserInfo_Call) RunAndReturn(run func(context.Context, string, string) (*rpc.User, error)) *MockUserSvcClient_GetUserInfo_Call { + _c.Call.Return(run) + return _c +} + +// NewMockUserSvcClient creates a new instance of MockUserSvcClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockUserSvcClient(t interface { + mock.TestingT + Cleanup(func()) +}) *MockUserSvcClient { + mock := &MockUserSvcClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_Green2022Client.go b/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_Green2022Client.go new file mode 100644 index 00000000..e9b8f697 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_Green2022Client.go @@ -0,0 +1,196 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package sensitive + +import ( + client "github.com/alibabacloud-go/green-20220302/client" + mock "github.com/stretchr/testify/mock" +) + +// MockGreen2022Client is an autogenerated mock type for the Green2022Client type +type MockGreen2022Client struct { + mock.Mock +} + +type MockGreen2022Client_Expecter struct { + mock *mock.Mock +} + +func (_m *MockGreen2022Client) EXPECT() *MockGreen2022Client_Expecter { + return &MockGreen2022Client_Expecter{mock: &_m.Mock} +} + +// GetRegionId provides a mock function with given fields: +func (_m *MockGreen2022Client) GetRegionId() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetRegionId") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// MockGreen2022Client_GetRegionId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRegionId' +type MockGreen2022Client_GetRegionId_Call struct { + *mock.Call +} + +// GetRegionId is a helper method to define mock.On call +func (_e *MockGreen2022Client_Expecter) GetRegionId() *MockGreen2022Client_GetRegionId_Call { + return &MockGreen2022Client_GetRegionId_Call{Call: _e.mock.On("GetRegionId")} +} + +func (_c *MockGreen2022Client_GetRegionId_Call) Run(run func()) *MockGreen2022Client_GetRegionId_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockGreen2022Client_GetRegionId_Call) Return(_a0 string) *MockGreen2022Client_GetRegionId_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockGreen2022Client_GetRegionId_Call) RunAndReturn(run func() string) *MockGreen2022Client_GetRegionId_Call { + _c.Call.Return(run) + return _c +} + +// ImageModeration provides a mock function with given fields: request +func (_m *MockGreen2022Client) ImageModeration(request *client.ImageModerationRequest) (*client.ImageModerationResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for ImageModeration") + } + + var r0 *client.ImageModerationResponse + var r1 error + if rf, ok := ret.Get(0).(func(*client.ImageModerationRequest) (*client.ImageModerationResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*client.ImageModerationRequest) *client.ImageModerationResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*client.ImageModerationResponse) + } + } + + if rf, ok := ret.Get(1).(func(*client.ImageModerationRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGreen2022Client_ImageModeration_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ImageModeration' +type MockGreen2022Client_ImageModeration_Call struct { + *mock.Call +} + +// ImageModeration is a helper method to define mock.On call +// - request *client.ImageModerationRequest +func (_e *MockGreen2022Client_Expecter) ImageModeration(request interface{}) *MockGreen2022Client_ImageModeration_Call { + return &MockGreen2022Client_ImageModeration_Call{Call: _e.mock.On("ImageModeration", request)} +} + +func (_c *MockGreen2022Client_ImageModeration_Call) Run(run func(request *client.ImageModerationRequest)) *MockGreen2022Client_ImageModeration_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*client.ImageModerationRequest)) + }) + return _c +} + +func (_c *MockGreen2022Client_ImageModeration_Call) Return(_result *client.ImageModerationResponse, _err error) *MockGreen2022Client_ImageModeration_Call { + _c.Call.Return(_result, _err) + return _c +} + +func (_c *MockGreen2022Client_ImageModeration_Call) RunAndReturn(run func(*client.ImageModerationRequest) (*client.ImageModerationResponse, error)) *MockGreen2022Client_ImageModeration_Call { + _c.Call.Return(run) + return _c +} + +// TextModeration provides a mock function with given fields: request +func (_m *MockGreen2022Client) TextModeration(request *client.TextModerationRequest) (*client.TextModerationResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for TextModeration") + } + + var r0 *client.TextModerationResponse + var r1 error + if rf, ok := ret.Get(0).(func(*client.TextModerationRequest) (*client.TextModerationResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*client.TextModerationRequest) *client.TextModerationResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*client.TextModerationResponse) + } + } + + if rf, ok := ret.Get(1).(func(*client.TextModerationRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGreen2022Client_TextModeration_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TextModeration' +type MockGreen2022Client_TextModeration_Call struct { + *mock.Call +} + +// TextModeration is a helper method to define mock.On call +// - request *client.TextModerationRequest +func (_e *MockGreen2022Client_Expecter) TextModeration(request interface{}) *MockGreen2022Client_TextModeration_Call { + return &MockGreen2022Client_TextModeration_Call{Call: _e.mock.On("TextModeration", request)} +} + +func (_c *MockGreen2022Client_TextModeration_Call) Run(run func(request *client.TextModerationRequest)) *MockGreen2022Client_TextModeration_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*client.TextModerationRequest)) + }) + return _c +} + +func (_c *MockGreen2022Client_TextModeration_Call) Return(_result *client.TextModerationResponse, _err error) *MockGreen2022Client_TextModeration_Call { + _c.Call.Return(_result, _err) + return _c +} + +func (_c *MockGreen2022Client_TextModeration_Call) RunAndReturn(run func(*client.TextModerationRequest) (*client.TextModerationResponse, error)) *MockGreen2022Client_TextModeration_Call { + _c.Call.Return(run) + return _c +} + +// NewMockGreen2022Client creates a new instance of MockGreen2022Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockGreen2022Client(t interface { + mock.TestingT + Cleanup(func()) +}) *MockGreen2022Client { + mock := &MockGreen2022Client{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_GreenClient.go b/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_GreenClient.go new file mode 100644 index 00000000..5913e09e --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_GreenClient.go @@ -0,0 +1,95 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package sensitive + +import ( + green "github.com/aliyun/alibaba-cloud-sdk-go/services/green" + mock "github.com/stretchr/testify/mock" + + sensitive "opencsg.com/csghub-server/builder/sensitive" +) + +// MockGreenClient is an autogenerated mock type for the GreenClient type +type MockGreenClient struct { + mock.Mock +} + +type MockGreenClient_Expecter struct { + mock *mock.Mock +} + +func (_m *MockGreenClient) EXPECT() *MockGreenClient_Expecter { + return &MockGreenClient_Expecter{mock: &_m.Mock} +} + +// TextScan provides a mock function with given fields: request +func (_m *MockGreenClient) TextScan(request *green.TextScanRequest) (*sensitive.TextScanResponse, error) { + ret := _m.Called(request) + + if len(ret) == 0 { + panic("no return value specified for TextScan") + } + + var r0 *sensitive.TextScanResponse + var r1 error + if rf, ok := ret.Get(0).(func(*green.TextScanRequest) (*sensitive.TextScanResponse, error)); ok { + return rf(request) + } + if rf, ok := ret.Get(0).(func(*green.TextScanRequest) *sensitive.TextScanResponse); ok { + r0 = rf(request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*sensitive.TextScanResponse) + } + } + + if rf, ok := ret.Get(1).(func(*green.TextScanRequest) error); ok { + r1 = rf(request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGreenClient_TextScan_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TextScan' +type MockGreenClient_TextScan_Call struct { + *mock.Call +} + +// TextScan is a helper method to define mock.On call +// - request *green.TextScanRequest +func (_e *MockGreenClient_Expecter) TextScan(request interface{}) *MockGreenClient_TextScan_Call { + return &MockGreenClient_TextScan_Call{Call: _e.mock.On("TextScan", request)} +} + +func (_c *MockGreenClient_TextScan_Call) Run(run func(request *green.TextScanRequest)) *MockGreenClient_TextScan_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*green.TextScanRequest)) + }) + return _c +} + +func (_c *MockGreenClient_TextScan_Call) Return(response *sensitive.TextScanResponse, err error) *MockGreenClient_TextScan_Call { + _c.Call.Return(response, err) + return _c +} + +func (_c *MockGreenClient_TextScan_Call) RunAndReturn(run func(*green.TextScanRequest) (*sensitive.TextScanResponse, error)) *MockGreenClient_TextScan_Call { + _c.Call.Return(run) + return _c +} + +// NewMockGreenClient creates a new instance of MockGreenClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockGreenClient(t interface { + mock.TestingT + Cleanup(func()) +}) *MockGreenClient { + mock := &MockGreenClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountMeteringStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountMeteringStore.go new file mode 100644 index 00000000..d5c9a8cd --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountMeteringStore.go @@ -0,0 +1,211 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" + + types "opencsg.com/csghub-server/common/types" +) + +// MockAccountMeteringStore is an autogenerated mock type for the AccountMeteringStore type +type MockAccountMeteringStore struct { + mock.Mock +} + +type MockAccountMeteringStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockAccountMeteringStore) EXPECT() *MockAccountMeteringStore_Expecter { + return &MockAccountMeteringStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, input +func (_m *MockAccountMeteringStore) Create(ctx context.Context, input database.AccountMetering) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.AccountMetering) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockAccountMeteringStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockAccountMeteringStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - input database.AccountMetering +func (_e *MockAccountMeteringStore_Expecter) Create(ctx interface{}, input interface{}) *MockAccountMeteringStore_Create_Call { + return &MockAccountMeteringStore_Create_Call{Call: _e.mock.On("Create", ctx, input)} +} + +func (_c *MockAccountMeteringStore_Create_Call) Run(run func(ctx context.Context, input database.AccountMetering)) *MockAccountMeteringStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.AccountMetering)) + }) + return _c +} + +func (_c *MockAccountMeteringStore_Create_Call) Return(_a0 error) *MockAccountMeteringStore_Create_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockAccountMeteringStore_Create_Call) RunAndReturn(run func(context.Context, database.AccountMetering) error) *MockAccountMeteringStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// ListAllByUserUUID provides a mock function with given fields: ctx, userUUID +func (_m *MockAccountMeteringStore) ListAllByUserUUID(ctx context.Context, userUUID string) ([]database.AccountMetering, error) { + ret := _m.Called(ctx, userUUID) + + if len(ret) == 0 { + panic("no return value specified for ListAllByUserUUID") + } + + var r0 []database.AccountMetering + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]database.AccountMetering, error)); ok { + return rf(ctx, userUUID) + } + if rf, ok := ret.Get(0).(func(context.Context, string) []database.AccountMetering); ok { + r0 = rf(ctx, userUUID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.AccountMetering) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, userUUID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockAccountMeteringStore_ListAllByUserUUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAllByUserUUID' +type MockAccountMeteringStore_ListAllByUserUUID_Call struct { + *mock.Call +} + +// ListAllByUserUUID is a helper method to define mock.On call +// - ctx context.Context +// - userUUID string +func (_e *MockAccountMeteringStore_Expecter) ListAllByUserUUID(ctx interface{}, userUUID interface{}) *MockAccountMeteringStore_ListAllByUserUUID_Call { + return &MockAccountMeteringStore_ListAllByUserUUID_Call{Call: _e.mock.On("ListAllByUserUUID", ctx, userUUID)} +} + +func (_c *MockAccountMeteringStore_ListAllByUserUUID_Call) Run(run func(ctx context.Context, userUUID string)) *MockAccountMeteringStore_ListAllByUserUUID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockAccountMeteringStore_ListAllByUserUUID_Call) Return(_a0 []database.AccountMetering, _a1 error) *MockAccountMeteringStore_ListAllByUserUUID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockAccountMeteringStore_ListAllByUserUUID_Call) RunAndReturn(run func(context.Context, string) ([]database.AccountMetering, error)) *MockAccountMeteringStore_ListAllByUserUUID_Call { + _c.Call.Return(run) + return _c +} + +// ListByUserIDAndTime provides a mock function with given fields: ctx, req +func (_m *MockAccountMeteringStore) ListByUserIDAndTime(ctx context.Context, req types.ACCT_STATEMENTS_REQ) ([]database.AccountMetering, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for ListByUserIDAndTime") + } + + var r0 []database.AccountMetering + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, types.ACCT_STATEMENTS_REQ) ([]database.AccountMetering, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.ACCT_STATEMENTS_REQ) []database.AccountMetering); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.AccountMetering) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.ACCT_STATEMENTS_REQ) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, types.ACCT_STATEMENTS_REQ) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockAccountMeteringStore_ListByUserIDAndTime_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByUserIDAndTime' +type MockAccountMeteringStore_ListByUserIDAndTime_Call struct { + *mock.Call +} + +// ListByUserIDAndTime is a helper method to define mock.On call +// - ctx context.Context +// - req types.ACCT_STATEMENTS_REQ +func (_e *MockAccountMeteringStore_Expecter) ListByUserIDAndTime(ctx interface{}, req interface{}) *MockAccountMeteringStore_ListByUserIDAndTime_Call { + return &MockAccountMeteringStore_ListByUserIDAndTime_Call{Call: _e.mock.On("ListByUserIDAndTime", ctx, req)} +} + +func (_c *MockAccountMeteringStore_ListByUserIDAndTime_Call) Run(run func(ctx context.Context, req types.ACCT_STATEMENTS_REQ)) *MockAccountMeteringStore_ListByUserIDAndTime_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.ACCT_STATEMENTS_REQ)) + }) + return _c +} + +func (_c *MockAccountMeteringStore_ListByUserIDAndTime_Call) Return(_a0 []database.AccountMetering, _a1 int, _a2 error) *MockAccountMeteringStore_ListByUserIDAndTime_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockAccountMeteringStore_ListByUserIDAndTime_Call) RunAndReturn(run func(context.Context, types.ACCT_STATEMENTS_REQ) ([]database.AccountMetering, int, error)) *MockAccountMeteringStore_ListByUserIDAndTime_Call { + _c.Call.Return(run) + return _c +} + +// NewMockAccountMeteringStore creates a new instance of MockAccountMeteringStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockAccountMeteringStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockAccountMeteringStore { + mock := &MockAccountMeteringStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DatasetStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DatasetStore.go new file mode 100644 index 00000000..b6ba3745 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DatasetStore.go @@ -0,0 +1,692 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockDatasetStore is an autogenerated mock type for the DatasetStore type +type MockDatasetStore struct { + mock.Mock +} + +type MockDatasetStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockDatasetStore) EXPECT() *MockDatasetStore_Expecter { + return &MockDatasetStore_Expecter{mock: &_m.Mock} +} + +// ByOrgPath provides a mock function with given fields: ctx, namespace, per, page, onlyPublic +func (_m *MockDatasetStore) ByOrgPath(ctx context.Context, namespace string, per int, page int, onlyPublic bool) ([]database.Dataset, int, error) { + ret := _m.Called(ctx, namespace, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByOrgPath") + } + + var r0 []database.Dataset + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Dataset, int, error)); ok { + return rf(ctx, namespace, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Dataset); ok { + r0 = rf(ctx, namespace, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Dataset) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockDatasetStore_ByOrgPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByOrgPath' +type MockDatasetStore_ByOrgPath_Call struct { + *mock.Call +} + +// ByOrgPath is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockDatasetStore_Expecter) ByOrgPath(ctx interface{}, namespace interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockDatasetStore_ByOrgPath_Call { + return &MockDatasetStore_ByOrgPath_Call{Call: _e.mock.On("ByOrgPath", ctx, namespace, per, page, onlyPublic)} +} + +func (_c *MockDatasetStore_ByOrgPath_Call) Run(run func(ctx context.Context, namespace string, per int, page int, onlyPublic bool)) *MockDatasetStore_ByOrgPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockDatasetStore_ByOrgPath_Call) Return(datasets []database.Dataset, total int, err error) *MockDatasetStore_ByOrgPath_Call { + _c.Call.Return(datasets, total, err) + return _c +} + +func (_c *MockDatasetStore_ByOrgPath_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Dataset, int, error)) *MockDatasetStore_ByOrgPath_Call { + _c.Call.Return(run) + return _c +} + +// ByRepoID provides a mock function with given fields: ctx, repoID +func (_m *MockDatasetStore) ByRepoID(ctx context.Context, repoID int64) (*database.Dataset, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for ByRepoID") + } + + var r0 *database.Dataset + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Dataset, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Dataset); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Dataset) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDatasetStore_ByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByRepoID' +type MockDatasetStore_ByRepoID_Call struct { + *mock.Call +} + +// ByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockDatasetStore_Expecter) ByRepoID(ctx interface{}, repoID interface{}) *MockDatasetStore_ByRepoID_Call { + return &MockDatasetStore_ByRepoID_Call{Call: _e.mock.On("ByRepoID", ctx, repoID)} +} + +func (_c *MockDatasetStore_ByRepoID_Call) Run(run func(ctx context.Context, repoID int64)) *MockDatasetStore_ByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDatasetStore_ByRepoID_Call) Return(_a0 *database.Dataset, _a1 error) *MockDatasetStore_ByRepoID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDatasetStore_ByRepoID_Call) RunAndReturn(run func(context.Context, int64) (*database.Dataset, error)) *MockDatasetStore_ByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// ByRepoIDs provides a mock function with given fields: ctx, repoIDs +func (_m *MockDatasetStore) ByRepoIDs(ctx context.Context, repoIDs []int64) ([]database.Dataset, error) { + ret := _m.Called(ctx, repoIDs) + + if len(ret) == 0 { + panic("no return value specified for ByRepoIDs") + } + + var r0 []database.Dataset + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []int64) ([]database.Dataset, error)); ok { + return rf(ctx, repoIDs) + } + if rf, ok := ret.Get(0).(func(context.Context, []int64) []database.Dataset); ok { + r0 = rf(ctx, repoIDs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Dataset) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []int64) error); ok { + r1 = rf(ctx, repoIDs) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDatasetStore_ByRepoIDs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByRepoIDs' +type MockDatasetStore_ByRepoIDs_Call struct { + *mock.Call +} + +// ByRepoIDs is a helper method to define mock.On call +// - ctx context.Context +// - repoIDs []int64 +func (_e *MockDatasetStore_Expecter) ByRepoIDs(ctx interface{}, repoIDs interface{}) *MockDatasetStore_ByRepoIDs_Call { + return &MockDatasetStore_ByRepoIDs_Call{Call: _e.mock.On("ByRepoIDs", ctx, repoIDs)} +} + +func (_c *MockDatasetStore_ByRepoIDs_Call) Run(run func(ctx context.Context, repoIDs []int64)) *MockDatasetStore_ByRepoIDs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]int64)) + }) + return _c +} + +func (_c *MockDatasetStore_ByRepoIDs_Call) Return(datasets []database.Dataset, err error) *MockDatasetStore_ByRepoIDs_Call { + _c.Call.Return(datasets, err) + return _c +} + +func (_c *MockDatasetStore_ByRepoIDs_Call) RunAndReturn(run func(context.Context, []int64) ([]database.Dataset, error)) *MockDatasetStore_ByRepoIDs_Call { + _c.Call.Return(run) + return _c +} + +// ByUsername provides a mock function with given fields: ctx, username, per, page, onlyPublic +func (_m *MockDatasetStore) ByUsername(ctx context.Context, username string, per int, page int, onlyPublic bool) ([]database.Dataset, int, error) { + ret := _m.Called(ctx, username, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByUsername") + } + + var r0 []database.Dataset + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Dataset, int, error)); ok { + return rf(ctx, username, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Dataset); ok { + r0 = rf(ctx, username, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Dataset) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, username, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, username, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockDatasetStore_ByUsername_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByUsername' +type MockDatasetStore_ByUsername_Call struct { + *mock.Call +} + +// ByUsername is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockDatasetStore_Expecter) ByUsername(ctx interface{}, username interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockDatasetStore_ByUsername_Call { + return &MockDatasetStore_ByUsername_Call{Call: _e.mock.On("ByUsername", ctx, username, per, page, onlyPublic)} +} + +func (_c *MockDatasetStore_ByUsername_Call) Run(run func(ctx context.Context, username string, per int, page int, onlyPublic bool)) *MockDatasetStore_ByUsername_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockDatasetStore_ByUsername_Call) Return(datasets []database.Dataset, total int, err error) *MockDatasetStore_ByUsername_Call { + _c.Call.Return(datasets, total, err) + return _c +} + +func (_c *MockDatasetStore_ByUsername_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Dataset, int, error)) *MockDatasetStore_ByUsername_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, input +func (_m *MockDatasetStore) Create(ctx context.Context, input database.Dataset) (*database.Dataset, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.Dataset + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Dataset) (*database.Dataset, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Dataset) *database.Dataset); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Dataset) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Dataset) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDatasetStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockDatasetStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - input database.Dataset +func (_e *MockDatasetStore_Expecter) Create(ctx interface{}, input interface{}) *MockDatasetStore_Create_Call { + return &MockDatasetStore_Create_Call{Call: _e.mock.On("Create", ctx, input)} +} + +func (_c *MockDatasetStore_Create_Call) Run(run func(ctx context.Context, input database.Dataset)) *MockDatasetStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Dataset)) + }) + return _c +} + +func (_c *MockDatasetStore_Create_Call) Return(_a0 *database.Dataset, _a1 error) *MockDatasetStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDatasetStore_Create_Call) RunAndReturn(run func(context.Context, database.Dataset) (*database.Dataset, error)) *MockDatasetStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// CreateIfNotExist provides a mock function with given fields: ctx, input +func (_m *MockDatasetStore) CreateIfNotExist(ctx context.Context, input database.Dataset) (*database.Dataset, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for CreateIfNotExist") + } + + var r0 *database.Dataset + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Dataset) (*database.Dataset, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Dataset) *database.Dataset); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Dataset) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Dataset) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDatasetStore_CreateIfNotExist_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateIfNotExist' +type MockDatasetStore_CreateIfNotExist_Call struct { + *mock.Call +} + +// CreateIfNotExist is a helper method to define mock.On call +// - ctx context.Context +// - input database.Dataset +func (_e *MockDatasetStore_Expecter) CreateIfNotExist(ctx interface{}, input interface{}) *MockDatasetStore_CreateIfNotExist_Call { + return &MockDatasetStore_CreateIfNotExist_Call{Call: _e.mock.On("CreateIfNotExist", ctx, input)} +} + +func (_c *MockDatasetStore_CreateIfNotExist_Call) Run(run func(ctx context.Context, input database.Dataset)) *MockDatasetStore_CreateIfNotExist_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Dataset)) + }) + return _c +} + +func (_c *MockDatasetStore_CreateIfNotExist_Call) Return(_a0 *database.Dataset, _a1 error) *MockDatasetStore_CreateIfNotExist_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDatasetStore_CreateIfNotExist_Call) RunAndReturn(run func(context.Context, database.Dataset) (*database.Dataset, error)) *MockDatasetStore_CreateIfNotExist_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, input +func (_m *MockDatasetStore) Delete(ctx context.Context, input database.Dataset) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.Dataset) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDatasetStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockDatasetStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - input database.Dataset +func (_e *MockDatasetStore_Expecter) Delete(ctx interface{}, input interface{}) *MockDatasetStore_Delete_Call { + return &MockDatasetStore_Delete_Call{Call: _e.mock.On("Delete", ctx, input)} +} + +func (_c *MockDatasetStore_Delete_Call) Run(run func(ctx context.Context, input database.Dataset)) *MockDatasetStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Dataset)) + }) + return _c +} + +func (_c *MockDatasetStore_Delete_Call) Return(_a0 error) *MockDatasetStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDatasetStore_Delete_Call) RunAndReturn(run func(context.Context, database.Dataset) error) *MockDatasetStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindByPath provides a mock function with given fields: ctx, namespace, repoPath +func (_m *MockDatasetStore) FindByPath(ctx context.Context, namespace string, repoPath string) (*database.Dataset, error) { + ret := _m.Called(ctx, namespace, repoPath) + + if len(ret) == 0 { + panic("no return value specified for FindByPath") + } + + var r0 *database.Dataset + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*database.Dataset, error)); ok { + return rf(ctx, namespace, repoPath) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) *database.Dataset); ok { + r0 = rf(ctx, namespace, repoPath) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Dataset) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, namespace, repoPath) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDatasetStore_FindByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByPath' +type MockDatasetStore_FindByPath_Call struct { + *mock.Call +} + +// FindByPath is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - repoPath string +func (_e *MockDatasetStore_Expecter) FindByPath(ctx interface{}, namespace interface{}, repoPath interface{}) *MockDatasetStore_FindByPath_Call { + return &MockDatasetStore_FindByPath_Call{Call: _e.mock.On("FindByPath", ctx, namespace, repoPath)} +} + +func (_c *MockDatasetStore_FindByPath_Call) Run(run func(ctx context.Context, namespace string, repoPath string)) *MockDatasetStore_FindByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockDatasetStore_FindByPath_Call) Return(dataset *database.Dataset, err error) *MockDatasetStore_FindByPath_Call { + _c.Call.Return(dataset, err) + return _c +} + +func (_c *MockDatasetStore_FindByPath_Call) RunAndReturn(run func(context.Context, string, string) (*database.Dataset, error)) *MockDatasetStore_FindByPath_Call { + _c.Call.Return(run) + return _c +} + +// ListByPath provides a mock function with given fields: ctx, paths +func (_m *MockDatasetStore) ListByPath(ctx context.Context, paths []string) ([]database.Dataset, error) { + ret := _m.Called(ctx, paths) + + if len(ret) == 0 { + panic("no return value specified for ListByPath") + } + + var r0 []database.Dataset + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []string) ([]database.Dataset, error)); ok { + return rf(ctx, paths) + } + if rf, ok := ret.Get(0).(func(context.Context, []string) []database.Dataset); ok { + r0 = rf(ctx, paths) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Dataset) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok { + r1 = rf(ctx, paths) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDatasetStore_ListByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByPath' +type MockDatasetStore_ListByPath_Call struct { + *mock.Call +} + +// ListByPath is a helper method to define mock.On call +// - ctx context.Context +// - paths []string +func (_e *MockDatasetStore_Expecter) ListByPath(ctx interface{}, paths interface{}) *MockDatasetStore_ListByPath_Call { + return &MockDatasetStore_ListByPath_Call{Call: _e.mock.On("ListByPath", ctx, paths)} +} + +func (_c *MockDatasetStore_ListByPath_Call) Run(run func(ctx context.Context, paths []string)) *MockDatasetStore_ListByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]string)) + }) + return _c +} + +func (_c *MockDatasetStore_ListByPath_Call) Return(_a0 []database.Dataset, _a1 error) *MockDatasetStore_ListByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDatasetStore_ListByPath_Call) RunAndReturn(run func(context.Context, []string) ([]database.Dataset, error)) *MockDatasetStore_ListByPath_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, input +func (_m *MockDatasetStore) Update(ctx context.Context, input database.Dataset) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.Dataset) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDatasetStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockDatasetStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - input database.Dataset +func (_e *MockDatasetStore_Expecter) Update(ctx interface{}, input interface{}) *MockDatasetStore_Update_Call { + return &MockDatasetStore_Update_Call{Call: _e.mock.On("Update", ctx, input)} +} + +func (_c *MockDatasetStore_Update_Call) Run(run func(ctx context.Context, input database.Dataset)) *MockDatasetStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Dataset)) + }) + return _c +} + +func (_c *MockDatasetStore_Update_Call) Return(err error) *MockDatasetStore_Update_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockDatasetStore_Update_Call) RunAndReturn(run func(context.Context, database.Dataset) error) *MockDatasetStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// UserLikesDatasets provides a mock function with given fields: ctx, userID, per, page +func (_m *MockDatasetStore) UserLikesDatasets(ctx context.Context, userID int64, per int, page int) ([]database.Dataset, int, error) { + ret := _m.Called(ctx, userID, per, page) + + if len(ret) == 0 { + panic("no return value specified for UserLikesDatasets") + } + + var r0 []database.Dataset + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) ([]database.Dataset, int, error)); ok { + return rf(ctx, userID, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) []database.Dataset); ok { + r0 = rf(ctx, userID, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Dataset) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int, int) int); ok { + r1 = rf(ctx, userID, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, int64, int, int) error); ok { + r2 = rf(ctx, userID, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockDatasetStore_UserLikesDatasets_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UserLikesDatasets' +type MockDatasetStore_UserLikesDatasets_Call struct { + *mock.Call +} + +// UserLikesDatasets is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +// - per int +// - page int +func (_e *MockDatasetStore_Expecter) UserLikesDatasets(ctx interface{}, userID interface{}, per interface{}, page interface{}) *MockDatasetStore_UserLikesDatasets_Call { + return &MockDatasetStore_UserLikesDatasets_Call{Call: _e.mock.On("UserLikesDatasets", ctx, userID, per, page)} +} + +func (_c *MockDatasetStore_UserLikesDatasets_Call) Run(run func(ctx context.Context, userID int64, per int, page int)) *MockDatasetStore_UserLikesDatasets_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockDatasetStore_UserLikesDatasets_Call) Return(datasets []database.Dataset, total int, err error) *MockDatasetStore_UserLikesDatasets_Call { + _c.Call.Return(datasets, total, err) + return _c +} + +func (_c *MockDatasetStore_UserLikesDatasets_Call) RunAndReturn(run func(context.Context, int64, int, int) ([]database.Dataset, int, error)) *MockDatasetStore_UserLikesDatasets_Call { + _c.Call.Return(run) + return _c +} + +// NewMockDatasetStore creates a new instance of MockDatasetStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockDatasetStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockDatasetStore { + mock := &MockDatasetStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LLMConfigStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LLMConfigStore.go new file mode 100644 index 00000000..a92a1623 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LLMConfigStore.go @@ -0,0 +1,95 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockLLMConfigStore is an autogenerated mock type for the LLMConfigStore type +type MockLLMConfigStore struct { + mock.Mock +} + +type MockLLMConfigStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockLLMConfigStore) EXPECT() *MockLLMConfigStore_Expecter { + return &MockLLMConfigStore_Expecter{mock: &_m.Mock} +} + +// GetOptimization provides a mock function with given fields: ctx +func (_m *MockLLMConfigStore) GetOptimization(ctx context.Context) (*database.LLMConfig, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetOptimization") + } + + var r0 *database.LLMConfig + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*database.LLMConfig, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *database.LLMConfig); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.LLMConfig) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockLLMConfigStore_GetOptimization_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetOptimization' +type MockLLMConfigStore_GetOptimization_Call struct { + *mock.Call +} + +// GetOptimization is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockLLMConfigStore_Expecter) GetOptimization(ctx interface{}) *MockLLMConfigStore_GetOptimization_Call { + return &MockLLMConfigStore_GetOptimization_Call{Call: _e.mock.On("GetOptimization", ctx)} +} + +func (_c *MockLLMConfigStore_GetOptimization_Call) Run(run func(ctx context.Context)) *MockLLMConfigStore_GetOptimization_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockLLMConfigStore_GetOptimization_Call) Return(_a0 *database.LLMConfig, _a1 error) *MockLLMConfigStore_GetOptimization_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockLLMConfigStore_GetOptimization_Call) RunAndReturn(run func(context.Context) (*database.LLMConfig, error)) *MockLLMConfigStore_GetOptimization_Call { + _c.Call.Return(run) + return _c +} + +// NewMockLLMConfigStore creates a new instance of MockLLMConfigStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockLLMConfigStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockLLMConfigStore { + mock := &MockLLMConfigStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MemberStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MemberStore.go new file mode 100644 index 00000000..1a5564b0 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MemberStore.go @@ -0,0 +1,322 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockMemberStore is an autogenerated mock type for the MemberStore type +type MockMemberStore struct { + mock.Mock +} + +type MockMemberStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockMemberStore) EXPECT() *MockMemberStore_Expecter { + return &MockMemberStore_Expecter{mock: &_m.Mock} +} + +// Add provides a mock function with given fields: ctx, orgID, userID, role +func (_m *MockMemberStore) Add(ctx context.Context, orgID int64, userID int64, role string) error { + ret := _m.Called(ctx, orgID, userID, role) + + if len(ret) == 0 { + panic("no return value specified for Add") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64, string) error); ok { + r0 = rf(ctx, orgID, userID, role) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMemberStore_Add_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Add' +type MockMemberStore_Add_Call struct { + *mock.Call +} + +// Add is a helper method to define mock.On call +// - ctx context.Context +// - orgID int64 +// - userID int64 +// - role string +func (_e *MockMemberStore_Expecter) Add(ctx interface{}, orgID interface{}, userID interface{}, role interface{}) *MockMemberStore_Add_Call { + return &MockMemberStore_Add_Call{Call: _e.mock.On("Add", ctx, orgID, userID, role)} +} + +func (_c *MockMemberStore_Add_Call) Run(run func(ctx context.Context, orgID int64, userID int64, role string)) *MockMemberStore_Add_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64), args[3].(string)) + }) + return _c +} + +func (_c *MockMemberStore_Add_Call) Return(_a0 error) *MockMemberStore_Add_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMemberStore_Add_Call) RunAndReturn(run func(context.Context, int64, int64, string) error) *MockMemberStore_Add_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, orgID, userID, role +func (_m *MockMemberStore) Delete(ctx context.Context, orgID int64, userID int64, role string) error { + ret := _m.Called(ctx, orgID, userID, role) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64, string) error); ok { + r0 = rf(ctx, orgID, userID, role) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMemberStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockMemberStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - orgID int64 +// - userID int64 +// - role string +func (_e *MockMemberStore_Expecter) Delete(ctx interface{}, orgID interface{}, userID interface{}, role interface{}) *MockMemberStore_Delete_Call { + return &MockMemberStore_Delete_Call{Call: _e.mock.On("Delete", ctx, orgID, userID, role)} +} + +func (_c *MockMemberStore_Delete_Call) Run(run func(ctx context.Context, orgID int64, userID int64, role string)) *MockMemberStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64), args[3].(string)) + }) + return _c +} + +func (_c *MockMemberStore_Delete_Call) Return(_a0 error) *MockMemberStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMemberStore_Delete_Call) RunAndReturn(run func(context.Context, int64, int64, string) error) *MockMemberStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// Find provides a mock function with given fields: ctx, orgID, userID +func (_m *MockMemberStore) Find(ctx context.Context, orgID int64, userID int64) (*database.Member, error) { + ret := _m.Called(ctx, orgID, userID) + + if len(ret) == 0 { + panic("no return value specified for Find") + } + + var r0 *database.Member + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64) (*database.Member, error)); ok { + return rf(ctx, orgID, userID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int64) *database.Member); ok { + r0 = rf(ctx, orgID, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Member) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int64) error); ok { + r1 = rf(ctx, orgID, userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMemberStore_Find_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Find' +type MockMemberStore_Find_Call struct { + *mock.Call +} + +// Find is a helper method to define mock.On call +// - ctx context.Context +// - orgID int64 +// - userID int64 +func (_e *MockMemberStore_Expecter) Find(ctx interface{}, orgID interface{}, userID interface{}) *MockMemberStore_Find_Call { + return &MockMemberStore_Find_Call{Call: _e.mock.On("Find", ctx, orgID, userID)} +} + +func (_c *MockMemberStore_Find_Call) Run(run func(ctx context.Context, orgID int64, userID int64)) *MockMemberStore_Find_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64)) + }) + return _c +} + +func (_c *MockMemberStore_Find_Call) Return(_a0 *database.Member, _a1 error) *MockMemberStore_Find_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMemberStore_Find_Call) RunAndReturn(run func(context.Context, int64, int64) (*database.Member, error)) *MockMemberStore_Find_Call { + _c.Call.Return(run) + return _c +} + +// OrganizationMembers provides a mock function with given fields: ctx, orgID, pageSize, page +func (_m *MockMemberStore) OrganizationMembers(ctx context.Context, orgID int64, pageSize int, page int) ([]database.Member, int, error) { + ret := _m.Called(ctx, orgID, pageSize, page) + + if len(ret) == 0 { + panic("no return value specified for OrganizationMembers") + } + + var r0 []database.Member + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) ([]database.Member, int, error)); ok { + return rf(ctx, orgID, pageSize, page) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) []database.Member); ok { + r0 = rf(ctx, orgID, pageSize, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Member) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int, int) int); ok { + r1 = rf(ctx, orgID, pageSize, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, int64, int, int) error); ok { + r2 = rf(ctx, orgID, pageSize, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockMemberStore_OrganizationMembers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OrganizationMembers' +type MockMemberStore_OrganizationMembers_Call struct { + *mock.Call +} + +// OrganizationMembers is a helper method to define mock.On call +// - ctx context.Context +// - orgID int64 +// - pageSize int +// - page int +func (_e *MockMemberStore_Expecter) OrganizationMembers(ctx interface{}, orgID interface{}, pageSize interface{}, page interface{}) *MockMemberStore_OrganizationMembers_Call { + return &MockMemberStore_OrganizationMembers_Call{Call: _e.mock.On("OrganizationMembers", ctx, orgID, pageSize, page)} +} + +func (_c *MockMemberStore_OrganizationMembers_Call) Run(run func(ctx context.Context, orgID int64, pageSize int, page int)) *MockMemberStore_OrganizationMembers_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockMemberStore_OrganizationMembers_Call) Return(_a0 []database.Member, _a1 int, _a2 error) *MockMemberStore_OrganizationMembers_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockMemberStore_OrganizationMembers_Call) RunAndReturn(run func(context.Context, int64, int, int) ([]database.Member, int, error)) *MockMemberStore_OrganizationMembers_Call { + _c.Call.Return(run) + return _c +} + +// UserMembers provides a mock function with given fields: ctx, userID +func (_m *MockMemberStore) UserMembers(ctx context.Context, userID int64) ([]database.Member, error) { + ret := _m.Called(ctx, userID) + + if len(ret) == 0 { + panic("no return value specified for UserMembers") + } + + var r0 []database.Member + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.Member, error)); ok { + return rf(ctx, userID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.Member); ok { + r0 = rf(ctx, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Member) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMemberStore_UserMembers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UserMembers' +type MockMemberStore_UserMembers_Call struct { + *mock.Call +} + +// UserMembers is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +func (_e *MockMemberStore_Expecter) UserMembers(ctx interface{}, userID interface{}) *MockMemberStore_UserMembers_Call { + return &MockMemberStore_UserMembers_Call{Call: _e.mock.On("UserMembers", ctx, userID)} +} + +func (_c *MockMemberStore_UserMembers_Call) Run(run func(ctx context.Context, userID int64)) *MockMemberStore_UserMembers_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockMemberStore_UserMembers_Call) Return(_a0 []database.Member, _a1 error) *MockMemberStore_UserMembers_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMemberStore_UserMembers_Call) RunAndReturn(run func(context.Context, int64) ([]database.Member, error)) *MockMemberStore_UserMembers_Call { + _c.Call.Return(run) + return _c +} + +// NewMockMemberStore creates a new instance of MockMemberStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockMemberStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockMemberStore { + mock := &MockMemberStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorStore.go new file mode 100644 index 00000000..1daf5c96 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorStore.go @@ -0,0 +1,1128 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" + + types "opencsg.com/csghub-server/common/types" +) + +// MockMirrorStore is an autogenerated mock type for the MirrorStore type +type MockMirrorStore struct { + mock.Mock +} + +type MockMirrorStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockMirrorStore) EXPECT() *MockMirrorStore_Expecter { + return &MockMirrorStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, mirror +func (_m *MockMirrorStore) Create(ctx context.Context, mirror *database.Mirror) (*database.Mirror, error) { + ret := _m.Called(ctx, mirror) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Mirror) (*database.Mirror, error)); ok { + return rf(ctx, mirror) + } + if rf, ok := ret.Get(0).(func(context.Context, *database.Mirror) *database.Mirror); ok { + r0 = rf(ctx, mirror) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *database.Mirror) error); ok { + r1 = rf(ctx, mirror) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockMirrorStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - mirror *database.Mirror +func (_e *MockMirrorStore_Expecter) Create(ctx interface{}, mirror interface{}) *MockMirrorStore_Create_Call { + return &MockMirrorStore_Create_Call{Call: _e.mock.On("Create", ctx, mirror)} +} + +func (_c *MockMirrorStore_Create_Call) Run(run func(ctx context.Context, mirror *database.Mirror)) *MockMirrorStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Mirror)) + }) + return _c +} + +func (_c *MockMirrorStore_Create_Call) Return(_a0 *database.Mirror, _a1 error) *MockMirrorStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_Create_Call) RunAndReturn(run func(context.Context, *database.Mirror) (*database.Mirror, error)) *MockMirrorStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, mirror +func (_m *MockMirrorStore) Delete(ctx context.Context, mirror *database.Mirror) error { + ret := _m.Called(ctx, mirror) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Mirror) error); ok { + r0 = rf(ctx, mirror) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMirrorStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockMirrorStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - mirror *database.Mirror +func (_e *MockMirrorStore_Expecter) Delete(ctx interface{}, mirror interface{}) *MockMirrorStore_Delete_Call { + return &MockMirrorStore_Delete_Call{Call: _e.mock.On("Delete", ctx, mirror)} +} + +func (_c *MockMirrorStore_Delete_Call) Run(run func(ctx context.Context, mirror *database.Mirror)) *MockMirrorStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Mirror)) + }) + return _c +} + +func (_c *MockMirrorStore_Delete_Call) Return(err error) *MockMirrorStore_Delete_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockMirrorStore_Delete_Call) RunAndReturn(run func(context.Context, *database.Mirror) error) *MockMirrorStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindByID provides a mock function with given fields: ctx, ID +func (_m *MockMirrorStore) FindByID(ctx context.Context, ID int64) (*database.Mirror, error) { + ret := _m.Called(ctx, ID) + + if len(ret) == 0 { + panic("no return value specified for FindByID") + } + + var r0 *database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Mirror, error)); ok { + return rf(ctx, ID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Mirror); ok { + r0 = rf(ctx, ID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, ID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_FindByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByID' +type MockMirrorStore_FindByID_Call struct { + *mock.Call +} + +// FindByID is a helper method to define mock.On call +// - ctx context.Context +// - ID int64 +func (_e *MockMirrorStore_Expecter) FindByID(ctx interface{}, ID interface{}) *MockMirrorStore_FindByID_Call { + return &MockMirrorStore_FindByID_Call{Call: _e.mock.On("FindByID", ctx, ID)} +} + +func (_c *MockMirrorStore_FindByID_Call) Run(run func(ctx context.Context, ID int64)) *MockMirrorStore_FindByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockMirrorStore_FindByID_Call) Return(_a0 *database.Mirror, _a1 error) *MockMirrorStore_FindByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_FindByID_Call) RunAndReturn(run func(context.Context, int64) (*database.Mirror, error)) *MockMirrorStore_FindByID_Call { + _c.Call.Return(run) + return _c +} + +// FindByRepoID provides a mock function with given fields: ctx, repoID +func (_m *MockMirrorStore) FindByRepoID(ctx context.Context, repoID int64) (*database.Mirror, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for FindByRepoID") + } + + var r0 *database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Mirror, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Mirror); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_FindByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByRepoID' +type MockMirrorStore_FindByRepoID_Call struct { + *mock.Call +} + +// FindByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockMirrorStore_Expecter) FindByRepoID(ctx interface{}, repoID interface{}) *MockMirrorStore_FindByRepoID_Call { + return &MockMirrorStore_FindByRepoID_Call{Call: _e.mock.On("FindByRepoID", ctx, repoID)} +} + +func (_c *MockMirrorStore_FindByRepoID_Call) Run(run func(ctx context.Context, repoID int64)) *MockMirrorStore_FindByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockMirrorStore_FindByRepoID_Call) Return(_a0 *database.Mirror, _a1 error) *MockMirrorStore_FindByRepoID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_FindByRepoID_Call) RunAndReturn(run func(context.Context, int64) (*database.Mirror, error)) *MockMirrorStore_FindByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// FindByRepoPath provides a mock function with given fields: ctx, repoType, namespace, name +func (_m *MockMirrorStore) FindByRepoPath(ctx context.Context, repoType types.RepositoryType, namespace string, name string) (*database.Mirror, error) { + ret := _m.Called(ctx, repoType, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for FindByRepoPath") + } + + var r0 *database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) (*database.Mirror, error)); ok { + return rf(ctx, repoType, namespace, name) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) *database.Mirror); ok { + r0 = rf(ctx, repoType, namespace, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string) error); ok { + r1 = rf(ctx, repoType, namespace, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_FindByRepoPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByRepoPath' +type MockMirrorStore_FindByRepoPath_Call struct { + *mock.Call +} + +// FindByRepoPath is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +func (_e *MockMirrorStore_Expecter) FindByRepoPath(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}) *MockMirrorStore_FindByRepoPath_Call { + return &MockMirrorStore_FindByRepoPath_Call{Call: _e.mock.On("FindByRepoPath", ctx, repoType, namespace, name)} +} + +func (_c *MockMirrorStore_FindByRepoPath_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string)) *MockMirrorStore_FindByRepoPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockMirrorStore_FindByRepoPath_Call) Return(_a0 *database.Mirror, _a1 error) *MockMirrorStore_FindByRepoPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_FindByRepoPath_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string) (*database.Mirror, error)) *MockMirrorStore_FindByRepoPath_Call { + _c.Call.Return(run) + return _c +} + +// FindWithMapping provides a mock function with given fields: ctx, repoType, namespace, name, mapping +func (_m *MockMirrorStore) FindWithMapping(ctx context.Context, repoType types.RepositoryType, namespace string, name string, mapping types.Mapping) (*database.Mirror, error) { + ret := _m.Called(ctx, repoType, namespace, name, mapping) + + if len(ret) == 0 { + panic("no return value specified for FindWithMapping") + } + + var r0 *database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, types.Mapping) (*database.Mirror, error)); ok { + return rf(ctx, repoType, namespace, name, mapping) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, types.Mapping) *database.Mirror); ok { + r0 = rf(ctx, repoType, namespace, name, mapping) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string, types.Mapping) error); ok { + r1 = rf(ctx, repoType, namespace, name, mapping) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_FindWithMapping_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindWithMapping' +type MockMirrorStore_FindWithMapping_Call struct { + *mock.Call +} + +// FindWithMapping is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - mapping types.Mapping +func (_e *MockMirrorStore_Expecter) FindWithMapping(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, mapping interface{}) *MockMirrorStore_FindWithMapping_Call { + return &MockMirrorStore_FindWithMapping_Call{Call: _e.mock.On("FindWithMapping", ctx, repoType, namespace, name, mapping)} +} + +func (_c *MockMirrorStore_FindWithMapping_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, mapping types.Mapping)) *MockMirrorStore_FindWithMapping_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(types.Mapping)) + }) + return _c +} + +func (_c *MockMirrorStore_FindWithMapping_Call) Return(_a0 *database.Mirror, _a1 error) *MockMirrorStore_FindWithMapping_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_FindWithMapping_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, types.Mapping) (*database.Mirror, error)) *MockMirrorStore_FindWithMapping_Call { + _c.Call.Return(run) + return _c +} + +// Finished provides a mock function with given fields: ctx +func (_m *MockMirrorStore) Finished(ctx context.Context) ([]database.Mirror, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Finished") + } + + var r0 []database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.Mirror, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.Mirror); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_Finished_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Finished' +type MockMirrorStore_Finished_Call struct { + *mock.Call +} + +// Finished is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockMirrorStore_Expecter) Finished(ctx interface{}) *MockMirrorStore_Finished_Call { + return &MockMirrorStore_Finished_Call{Call: _e.mock.On("Finished", ctx)} +} + +func (_c *MockMirrorStore_Finished_Call) Run(run func(ctx context.Context)) *MockMirrorStore_Finished_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockMirrorStore_Finished_Call) Return(_a0 []database.Mirror, _a1 error) *MockMirrorStore_Finished_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_Finished_Call) RunAndReturn(run func(context.Context) ([]database.Mirror, error)) *MockMirrorStore_Finished_Call { + _c.Call.Return(run) + return _c +} + +// IndexWithPagination provides a mock function with given fields: ctx, per, page +func (_m *MockMirrorStore) IndexWithPagination(ctx context.Context, per int, page int) ([]database.Mirror, int, error) { + ret := _m.Called(ctx, per, page) + + if len(ret) == 0 { + panic("no return value specified for IndexWithPagination") + } + + var r0 []database.Mirror + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, int, int) ([]database.Mirror, int, error)); ok { + return rf(ctx, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, int, int) []database.Mirror); ok { + r0 = rf(ctx, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int, int) int); ok { + r1 = rf(ctx, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, int, int) error); ok { + r2 = rf(ctx, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockMirrorStore_IndexWithPagination_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IndexWithPagination' +type MockMirrorStore_IndexWithPagination_Call struct { + *mock.Call +} + +// IndexWithPagination is a helper method to define mock.On call +// - ctx context.Context +// - per int +// - page int +func (_e *MockMirrorStore_Expecter) IndexWithPagination(ctx interface{}, per interface{}, page interface{}) *MockMirrorStore_IndexWithPagination_Call { + return &MockMirrorStore_IndexWithPagination_Call{Call: _e.mock.On("IndexWithPagination", ctx, per, page)} +} + +func (_c *MockMirrorStore_IndexWithPagination_Call) Run(run func(ctx context.Context, per int, page int)) *MockMirrorStore_IndexWithPagination_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int), args[2].(int)) + }) + return _c +} + +func (_c *MockMirrorStore_IndexWithPagination_Call) Return(mirrors []database.Mirror, count int, err error) *MockMirrorStore_IndexWithPagination_Call { + _c.Call.Return(mirrors, count, err) + return _c +} + +func (_c *MockMirrorStore_IndexWithPagination_Call) RunAndReturn(run func(context.Context, int, int) ([]database.Mirror, int, error)) *MockMirrorStore_IndexWithPagination_Call { + _c.Call.Return(run) + return _c +} + +// IsExist provides a mock function with given fields: ctx, repoID +func (_m *MockMirrorStore) IsExist(ctx context.Context, repoID int64) (bool, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for IsExist") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (bool, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) bool); ok { + r0 = rf(ctx, repoID) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_IsExist_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsExist' +type MockMirrorStore_IsExist_Call struct { + *mock.Call +} + +// IsExist is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockMirrorStore_Expecter) IsExist(ctx interface{}, repoID interface{}) *MockMirrorStore_IsExist_Call { + return &MockMirrorStore_IsExist_Call{Call: _e.mock.On("IsExist", ctx, repoID)} +} + +func (_c *MockMirrorStore_IsExist_Call) Run(run func(ctx context.Context, repoID int64)) *MockMirrorStore_IsExist_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockMirrorStore_IsExist_Call) Return(exists bool, err error) *MockMirrorStore_IsExist_Call { + _c.Call.Return(exists, err) + return _c +} + +func (_c *MockMirrorStore_IsExist_Call) RunAndReturn(run func(context.Context, int64) (bool, error)) *MockMirrorStore_IsExist_Call { + _c.Call.Return(run) + return _c +} + +// IsRepoExist provides a mock function with given fields: ctx, repoType, namespace, name +func (_m *MockMirrorStore) IsRepoExist(ctx context.Context, repoType types.RepositoryType, namespace string, name string) (bool, error) { + ret := _m.Called(ctx, repoType, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for IsRepoExist") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) (bool, error)); ok { + return rf(ctx, repoType, namespace, name) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) bool); ok { + r0 = rf(ctx, repoType, namespace, name) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string) error); ok { + r1 = rf(ctx, repoType, namespace, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_IsRepoExist_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsRepoExist' +type MockMirrorStore_IsRepoExist_Call struct { + *mock.Call +} + +// IsRepoExist is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +func (_e *MockMirrorStore_Expecter) IsRepoExist(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}) *MockMirrorStore_IsRepoExist_Call { + return &MockMirrorStore_IsRepoExist_Call{Call: _e.mock.On("IsRepoExist", ctx, repoType, namespace, name)} +} + +func (_c *MockMirrorStore_IsRepoExist_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string)) *MockMirrorStore_IsRepoExist_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockMirrorStore_IsRepoExist_Call) Return(exists bool, err error) *MockMirrorStore_IsRepoExist_Call { + _c.Call.Return(exists, err) + return _c +} + +func (_c *MockMirrorStore_IsRepoExist_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string) (bool, error)) *MockMirrorStore_IsRepoExist_Call { + _c.Call.Return(run) + return _c +} + +// NoPushMirror provides a mock function with given fields: ctx +func (_m *MockMirrorStore) NoPushMirror(ctx context.Context) ([]database.Mirror, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for NoPushMirror") + } + + var r0 []database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.Mirror, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.Mirror); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_NoPushMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NoPushMirror' +type MockMirrorStore_NoPushMirror_Call struct { + *mock.Call +} + +// NoPushMirror is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockMirrorStore_Expecter) NoPushMirror(ctx interface{}) *MockMirrorStore_NoPushMirror_Call { + return &MockMirrorStore_NoPushMirror_Call{Call: _e.mock.On("NoPushMirror", ctx)} +} + +func (_c *MockMirrorStore_NoPushMirror_Call) Run(run func(ctx context.Context)) *MockMirrorStore_NoPushMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockMirrorStore_NoPushMirror_Call) Return(_a0 []database.Mirror, _a1 error) *MockMirrorStore_NoPushMirror_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_NoPushMirror_Call) RunAndReturn(run func(context.Context) ([]database.Mirror, error)) *MockMirrorStore_NoPushMirror_Call { + _c.Call.Return(run) + return _c +} + +// PushedMirror provides a mock function with given fields: ctx +func (_m *MockMirrorStore) PushedMirror(ctx context.Context) ([]database.Mirror, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for PushedMirror") + } + + var r0 []database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.Mirror, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.Mirror); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_PushedMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PushedMirror' +type MockMirrorStore_PushedMirror_Call struct { + *mock.Call +} + +// PushedMirror is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockMirrorStore_Expecter) PushedMirror(ctx interface{}) *MockMirrorStore_PushedMirror_Call { + return &MockMirrorStore_PushedMirror_Call{Call: _e.mock.On("PushedMirror", ctx)} +} + +func (_c *MockMirrorStore_PushedMirror_Call) Run(run func(ctx context.Context)) *MockMirrorStore_PushedMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockMirrorStore_PushedMirror_Call) Return(_a0 []database.Mirror, _a1 error) *MockMirrorStore_PushedMirror_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_PushedMirror_Call) RunAndReturn(run func(context.Context) ([]database.Mirror, error)) *MockMirrorStore_PushedMirror_Call { + _c.Call.Return(run) + return _c +} + +// ToSyncLfs provides a mock function with given fields: ctx +func (_m *MockMirrorStore) ToSyncLfs(ctx context.Context) ([]database.Mirror, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ToSyncLfs") + } + + var r0 []database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.Mirror, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.Mirror); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_ToSyncLfs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ToSyncLfs' +type MockMirrorStore_ToSyncLfs_Call struct { + *mock.Call +} + +// ToSyncLfs is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockMirrorStore_Expecter) ToSyncLfs(ctx interface{}) *MockMirrorStore_ToSyncLfs_Call { + return &MockMirrorStore_ToSyncLfs_Call{Call: _e.mock.On("ToSyncLfs", ctx)} +} + +func (_c *MockMirrorStore_ToSyncLfs_Call) Run(run func(ctx context.Context)) *MockMirrorStore_ToSyncLfs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockMirrorStore_ToSyncLfs_Call) Return(_a0 []database.Mirror, _a1 error) *MockMirrorStore_ToSyncLfs_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_ToSyncLfs_Call) RunAndReturn(run func(context.Context) ([]database.Mirror, error)) *MockMirrorStore_ToSyncLfs_Call { + _c.Call.Return(run) + return _c +} + +// ToSyncRepo provides a mock function with given fields: ctx +func (_m *MockMirrorStore) ToSyncRepo(ctx context.Context) ([]database.Mirror, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ToSyncRepo") + } + + var r0 []database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.Mirror, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.Mirror); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_ToSyncRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ToSyncRepo' +type MockMirrorStore_ToSyncRepo_Call struct { + *mock.Call +} + +// ToSyncRepo is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockMirrorStore_Expecter) ToSyncRepo(ctx interface{}) *MockMirrorStore_ToSyncRepo_Call { + return &MockMirrorStore_ToSyncRepo_Call{Call: _e.mock.On("ToSyncRepo", ctx)} +} + +func (_c *MockMirrorStore_ToSyncRepo_Call) Run(run func(ctx context.Context)) *MockMirrorStore_ToSyncRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockMirrorStore_ToSyncRepo_Call) Return(_a0 []database.Mirror, _a1 error) *MockMirrorStore_ToSyncRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_ToSyncRepo_Call) RunAndReturn(run func(context.Context) ([]database.Mirror, error)) *MockMirrorStore_ToSyncRepo_Call { + _c.Call.Return(run) + return _c +} + +// Unfinished provides a mock function with given fields: ctx +func (_m *MockMirrorStore) Unfinished(ctx context.Context) ([]database.Mirror, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Unfinished") + } + + var r0 []database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.Mirror, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.Mirror); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_Unfinished_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Unfinished' +type MockMirrorStore_Unfinished_Call struct { + *mock.Call +} + +// Unfinished is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockMirrorStore_Expecter) Unfinished(ctx interface{}) *MockMirrorStore_Unfinished_Call { + return &MockMirrorStore_Unfinished_Call{Call: _e.mock.On("Unfinished", ctx)} +} + +func (_c *MockMirrorStore_Unfinished_Call) Run(run func(ctx context.Context)) *MockMirrorStore_Unfinished_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockMirrorStore_Unfinished_Call) Return(_a0 []database.Mirror, _a1 error) *MockMirrorStore_Unfinished_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_Unfinished_Call) RunAndReturn(run func(context.Context) ([]database.Mirror, error)) *MockMirrorStore_Unfinished_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, mirror +func (_m *MockMirrorStore) Update(ctx context.Context, mirror *database.Mirror) error { + ret := _m.Called(ctx, mirror) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Mirror) error); ok { + r0 = rf(ctx, mirror) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMirrorStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockMirrorStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - mirror *database.Mirror +func (_e *MockMirrorStore_Expecter) Update(ctx interface{}, mirror interface{}) *MockMirrorStore_Update_Call { + return &MockMirrorStore_Update_Call{Call: _e.mock.On("Update", ctx, mirror)} +} + +func (_c *MockMirrorStore_Update_Call) Run(run func(ctx context.Context, mirror *database.Mirror)) *MockMirrorStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Mirror)) + }) + return _c +} + +func (_c *MockMirrorStore_Update_Call) Return(err error) *MockMirrorStore_Update_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockMirrorStore_Update_Call) RunAndReturn(run func(context.Context, *database.Mirror) error) *MockMirrorStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// UpdateMirrorAndRepository provides a mock function with given fields: ctx, mirror, repo +func (_m *MockMirrorStore) UpdateMirrorAndRepository(ctx context.Context, mirror *database.Mirror, repo *database.Repository) error { + ret := _m.Called(ctx, mirror, repo) + + if len(ret) == 0 { + panic("no return value specified for UpdateMirrorAndRepository") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Mirror, *database.Repository) error); ok { + r0 = rf(ctx, mirror, repo) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMirrorStore_UpdateMirrorAndRepository_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateMirrorAndRepository' +type MockMirrorStore_UpdateMirrorAndRepository_Call struct { + *mock.Call +} + +// UpdateMirrorAndRepository is a helper method to define mock.On call +// - ctx context.Context +// - mirror *database.Mirror +// - repo *database.Repository +func (_e *MockMirrorStore_Expecter) UpdateMirrorAndRepository(ctx interface{}, mirror interface{}, repo interface{}) *MockMirrorStore_UpdateMirrorAndRepository_Call { + return &MockMirrorStore_UpdateMirrorAndRepository_Call{Call: _e.mock.On("UpdateMirrorAndRepository", ctx, mirror, repo)} +} + +func (_c *MockMirrorStore_UpdateMirrorAndRepository_Call) Run(run func(ctx context.Context, mirror *database.Mirror, repo *database.Repository)) *MockMirrorStore_UpdateMirrorAndRepository_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Mirror), args[2].(*database.Repository)) + }) + return _c +} + +func (_c *MockMirrorStore_UpdateMirrorAndRepository_Call) Return(_a0 error) *MockMirrorStore_UpdateMirrorAndRepository_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMirrorStore_UpdateMirrorAndRepository_Call) RunAndReturn(run func(context.Context, *database.Mirror, *database.Repository) error) *MockMirrorStore_UpdateMirrorAndRepository_Call { + _c.Call.Return(run) + return _c +} + +// WithPagination provides a mock function with given fields: ctx +func (_m *MockMirrorStore) WithPagination(ctx context.Context) ([]database.Mirror, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for WithPagination") + } + + var r0 []database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.Mirror, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.Mirror); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_WithPagination_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPagination' +type MockMirrorStore_WithPagination_Call struct { + *mock.Call +} + +// WithPagination is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockMirrorStore_Expecter) WithPagination(ctx interface{}) *MockMirrorStore_WithPagination_Call { + return &MockMirrorStore_WithPagination_Call{Call: _e.mock.On("WithPagination", ctx)} +} + +func (_c *MockMirrorStore_WithPagination_Call) Run(run func(ctx context.Context)) *MockMirrorStore_WithPagination_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockMirrorStore_WithPagination_Call) Return(_a0 []database.Mirror, _a1 error) *MockMirrorStore_WithPagination_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_WithPagination_Call) RunAndReturn(run func(context.Context) ([]database.Mirror, error)) *MockMirrorStore_WithPagination_Call { + _c.Call.Return(run) + return _c +} + +// WithPaginationWithRepository provides a mock function with given fields: ctx +func (_m *MockMirrorStore) WithPaginationWithRepository(ctx context.Context) ([]database.Mirror, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for WithPaginationWithRepository") + } + + var r0 []database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.Mirror, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.Mirror); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorStore_WithPaginationWithRepository_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPaginationWithRepository' +type MockMirrorStore_WithPaginationWithRepository_Call struct { + *mock.Call +} + +// WithPaginationWithRepository is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockMirrorStore_Expecter) WithPaginationWithRepository(ctx interface{}) *MockMirrorStore_WithPaginationWithRepository_Call { + return &MockMirrorStore_WithPaginationWithRepository_Call{Call: _e.mock.On("WithPaginationWithRepository", ctx)} +} + +func (_c *MockMirrorStore_WithPaginationWithRepository_Call) Run(run func(ctx context.Context)) *MockMirrorStore_WithPaginationWithRepository_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockMirrorStore_WithPaginationWithRepository_Call) Return(_a0 []database.Mirror, _a1 error) *MockMirrorStore_WithPaginationWithRepository_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorStore_WithPaginationWithRepository_Call) RunAndReturn(run func(context.Context) ([]database.Mirror, error)) *MockMirrorStore_WithPaginationWithRepository_Call { + _c.Call.Return(run) + return _c +} + +// NewMockMirrorStore creates a new instance of MockMirrorStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockMirrorStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockMirrorStore { + mock := &MockMirrorStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ModelStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ModelStore.go new file mode 100644 index 00000000..1a8d68a9 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ModelStore.go @@ -0,0 +1,875 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockModelStore is an autogenerated mock type for the ModelStore type +type MockModelStore struct { + mock.Mock +} + +type MockModelStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockModelStore) EXPECT() *MockModelStore_Expecter { + return &MockModelStore_Expecter{mock: &_m.Mock} +} + +// ByID provides a mock function with given fields: ctx, id +func (_m *MockModelStore) ByID(ctx context.Context, id int64) (*database.Model, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for ByID") + } + + var r0 *database.Model + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Model, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Model); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelStore_ByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByID' +type MockModelStore_ByID_Call struct { + *mock.Call +} + +// ByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockModelStore_Expecter) ByID(ctx interface{}, id interface{}) *MockModelStore_ByID_Call { + return &MockModelStore_ByID_Call{Call: _e.mock.On("ByID", ctx, id)} +} + +func (_c *MockModelStore_ByID_Call) Run(run func(ctx context.Context, id int64)) *MockModelStore_ByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockModelStore_ByID_Call) Return(_a0 *database.Model, _a1 error) *MockModelStore_ByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelStore_ByID_Call) RunAndReturn(run func(context.Context, int64) (*database.Model, error)) *MockModelStore_ByID_Call { + _c.Call.Return(run) + return _c +} + +// ByOrgPath provides a mock function with given fields: ctx, namespace, per, page, onlyPublic +func (_m *MockModelStore) ByOrgPath(ctx context.Context, namespace string, per int, page int, onlyPublic bool) ([]database.Model, int, error) { + ret := _m.Called(ctx, namespace, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByOrgPath") + } + + var r0 []database.Model + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Model, int, error)); ok { + return rf(ctx, namespace, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Model); ok { + r0 = rf(ctx, namespace, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockModelStore_ByOrgPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByOrgPath' +type MockModelStore_ByOrgPath_Call struct { + *mock.Call +} + +// ByOrgPath is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockModelStore_Expecter) ByOrgPath(ctx interface{}, namespace interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockModelStore_ByOrgPath_Call { + return &MockModelStore_ByOrgPath_Call{Call: _e.mock.On("ByOrgPath", ctx, namespace, per, page, onlyPublic)} +} + +func (_c *MockModelStore_ByOrgPath_Call) Run(run func(ctx context.Context, namespace string, per int, page int, onlyPublic bool)) *MockModelStore_ByOrgPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockModelStore_ByOrgPath_Call) Return(models []database.Model, total int, err error) *MockModelStore_ByOrgPath_Call { + _c.Call.Return(models, total, err) + return _c +} + +func (_c *MockModelStore_ByOrgPath_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Model, int, error)) *MockModelStore_ByOrgPath_Call { + _c.Call.Return(run) + return _c +} + +// ByRepoID provides a mock function with given fields: ctx, repoID +func (_m *MockModelStore) ByRepoID(ctx context.Context, repoID int64) (*database.Model, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for ByRepoID") + } + + var r0 *database.Model + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Model, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Model); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelStore_ByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByRepoID' +type MockModelStore_ByRepoID_Call struct { + *mock.Call +} + +// ByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockModelStore_Expecter) ByRepoID(ctx interface{}, repoID interface{}) *MockModelStore_ByRepoID_Call { + return &MockModelStore_ByRepoID_Call{Call: _e.mock.On("ByRepoID", ctx, repoID)} +} + +func (_c *MockModelStore_ByRepoID_Call) Run(run func(ctx context.Context, repoID int64)) *MockModelStore_ByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockModelStore_ByRepoID_Call) Return(_a0 *database.Model, _a1 error) *MockModelStore_ByRepoID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelStore_ByRepoID_Call) RunAndReturn(run func(context.Context, int64) (*database.Model, error)) *MockModelStore_ByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// ByRepoIDs provides a mock function with given fields: ctx, repoIDs +func (_m *MockModelStore) ByRepoIDs(ctx context.Context, repoIDs []int64) ([]database.Model, error) { + ret := _m.Called(ctx, repoIDs) + + if len(ret) == 0 { + panic("no return value specified for ByRepoIDs") + } + + var r0 []database.Model + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []int64) ([]database.Model, error)); ok { + return rf(ctx, repoIDs) + } + if rf, ok := ret.Get(0).(func(context.Context, []int64) []database.Model); ok { + r0 = rf(ctx, repoIDs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []int64) error); ok { + r1 = rf(ctx, repoIDs) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelStore_ByRepoIDs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByRepoIDs' +type MockModelStore_ByRepoIDs_Call struct { + *mock.Call +} + +// ByRepoIDs is a helper method to define mock.On call +// - ctx context.Context +// - repoIDs []int64 +func (_e *MockModelStore_Expecter) ByRepoIDs(ctx interface{}, repoIDs interface{}) *MockModelStore_ByRepoIDs_Call { + return &MockModelStore_ByRepoIDs_Call{Call: _e.mock.On("ByRepoIDs", ctx, repoIDs)} +} + +func (_c *MockModelStore_ByRepoIDs_Call) Run(run func(ctx context.Context, repoIDs []int64)) *MockModelStore_ByRepoIDs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]int64)) + }) + return _c +} + +func (_c *MockModelStore_ByRepoIDs_Call) Return(models []database.Model, err error) *MockModelStore_ByRepoIDs_Call { + _c.Call.Return(models, err) + return _c +} + +func (_c *MockModelStore_ByRepoIDs_Call) RunAndReturn(run func(context.Context, []int64) ([]database.Model, error)) *MockModelStore_ByRepoIDs_Call { + _c.Call.Return(run) + return _c +} + +// ByUsername provides a mock function with given fields: ctx, username, per, page, onlyPublic +func (_m *MockModelStore) ByUsername(ctx context.Context, username string, per int, page int, onlyPublic bool) ([]database.Model, int, error) { + ret := _m.Called(ctx, username, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByUsername") + } + + var r0 []database.Model + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Model, int, error)); ok { + return rf(ctx, username, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Model); ok { + r0 = rf(ctx, username, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, username, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, username, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockModelStore_ByUsername_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByUsername' +type MockModelStore_ByUsername_Call struct { + *mock.Call +} + +// ByUsername is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockModelStore_Expecter) ByUsername(ctx interface{}, username interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockModelStore_ByUsername_Call { + return &MockModelStore_ByUsername_Call{Call: _e.mock.On("ByUsername", ctx, username, per, page, onlyPublic)} +} + +func (_c *MockModelStore_ByUsername_Call) Run(run func(ctx context.Context, username string, per int, page int, onlyPublic bool)) *MockModelStore_ByUsername_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockModelStore_ByUsername_Call) Return(models []database.Model, total int, err error) *MockModelStore_ByUsername_Call { + _c.Call.Return(models, total, err) + return _c +} + +func (_c *MockModelStore_ByUsername_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Model, int, error)) *MockModelStore_ByUsername_Call { + _c.Call.Return(run) + return _c +} + +// Count provides a mock function with given fields: ctx +func (_m *MockModelStore) Count(ctx context.Context) (int, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Count") + } + + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (int, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) int); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelStore_Count_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Count' +type MockModelStore_Count_Call struct { + *mock.Call +} + +// Count is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockModelStore_Expecter) Count(ctx interface{}) *MockModelStore_Count_Call { + return &MockModelStore_Count_Call{Call: _e.mock.On("Count", ctx)} +} + +func (_c *MockModelStore_Count_Call) Run(run func(ctx context.Context)) *MockModelStore_Count_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockModelStore_Count_Call) Return(count int, err error) *MockModelStore_Count_Call { + _c.Call.Return(count, err) + return _c +} + +func (_c *MockModelStore_Count_Call) RunAndReturn(run func(context.Context) (int, error)) *MockModelStore_Count_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, input +func (_m *MockModelStore) Create(ctx context.Context, input database.Model) (*database.Model, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.Model + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Model) (*database.Model, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Model) *database.Model); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Model) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockModelStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - input database.Model +func (_e *MockModelStore_Expecter) Create(ctx interface{}, input interface{}) *MockModelStore_Create_Call { + return &MockModelStore_Create_Call{Call: _e.mock.On("Create", ctx, input)} +} + +func (_c *MockModelStore_Create_Call) Run(run func(ctx context.Context, input database.Model)) *MockModelStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Model)) + }) + return _c +} + +func (_c *MockModelStore_Create_Call) Return(_a0 *database.Model, _a1 error) *MockModelStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelStore_Create_Call) RunAndReturn(run func(context.Context, database.Model) (*database.Model, error)) *MockModelStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// CreateIfNotExist provides a mock function with given fields: ctx, input +func (_m *MockModelStore) CreateIfNotExist(ctx context.Context, input database.Model) (*database.Model, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for CreateIfNotExist") + } + + var r0 *database.Model + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Model) (*database.Model, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Model) *database.Model); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Model) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelStore_CreateIfNotExist_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateIfNotExist' +type MockModelStore_CreateIfNotExist_Call struct { + *mock.Call +} + +// CreateIfNotExist is a helper method to define mock.On call +// - ctx context.Context +// - input database.Model +func (_e *MockModelStore_Expecter) CreateIfNotExist(ctx interface{}, input interface{}) *MockModelStore_CreateIfNotExist_Call { + return &MockModelStore_CreateIfNotExist_Call{Call: _e.mock.On("CreateIfNotExist", ctx, input)} +} + +func (_c *MockModelStore_CreateIfNotExist_Call) Run(run func(ctx context.Context, input database.Model)) *MockModelStore_CreateIfNotExist_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Model)) + }) + return _c +} + +func (_c *MockModelStore_CreateIfNotExist_Call) Return(_a0 *database.Model, _a1 error) *MockModelStore_CreateIfNotExist_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelStore_CreateIfNotExist_Call) RunAndReturn(run func(context.Context, database.Model) (*database.Model, error)) *MockModelStore_CreateIfNotExist_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, input +func (_m *MockModelStore) Delete(ctx context.Context, input database.Model) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.Model) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockModelStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockModelStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - input database.Model +func (_e *MockModelStore_Expecter) Delete(ctx interface{}, input interface{}) *MockModelStore_Delete_Call { + return &MockModelStore_Delete_Call{Call: _e.mock.On("Delete", ctx, input)} +} + +func (_c *MockModelStore_Delete_Call) Run(run func(ctx context.Context, input database.Model)) *MockModelStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Model)) + }) + return _c +} + +func (_c *MockModelStore_Delete_Call) Return(_a0 error) *MockModelStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockModelStore_Delete_Call) RunAndReturn(run func(context.Context, database.Model) error) *MockModelStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindByPath provides a mock function with given fields: ctx, namespace, name +func (_m *MockModelStore) FindByPath(ctx context.Context, namespace string, name string) (*database.Model, error) { + ret := _m.Called(ctx, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for FindByPath") + } + + var r0 *database.Model + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*database.Model, error)); ok { + return rf(ctx, namespace, name) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) *database.Model); ok { + r0 = rf(ctx, namespace, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, namespace, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelStore_FindByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByPath' +type MockModelStore_FindByPath_Call struct { + *mock.Call +} + +// FindByPath is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +func (_e *MockModelStore_Expecter) FindByPath(ctx interface{}, namespace interface{}, name interface{}) *MockModelStore_FindByPath_Call { + return &MockModelStore_FindByPath_Call{Call: _e.mock.On("FindByPath", ctx, namespace, name)} +} + +func (_c *MockModelStore_FindByPath_Call) Run(run func(ctx context.Context, namespace string, name string)) *MockModelStore_FindByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockModelStore_FindByPath_Call) Return(_a0 *database.Model, _a1 error) *MockModelStore_FindByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelStore_FindByPath_Call) RunAndReturn(run func(context.Context, string, string) (*database.Model, error)) *MockModelStore_FindByPath_Call { + _c.Call.Return(run) + return _c +} + +// ListByPath provides a mock function with given fields: ctx, paths +func (_m *MockModelStore) ListByPath(ctx context.Context, paths []string) ([]database.Model, error) { + ret := _m.Called(ctx, paths) + + if len(ret) == 0 { + panic("no return value specified for ListByPath") + } + + var r0 []database.Model + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []string) ([]database.Model, error)); ok { + return rf(ctx, paths) + } + if rf, ok := ret.Get(0).(func(context.Context, []string) []database.Model); ok { + r0 = rf(ctx, paths) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok { + r1 = rf(ctx, paths) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelStore_ListByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByPath' +type MockModelStore_ListByPath_Call struct { + *mock.Call +} + +// ListByPath is a helper method to define mock.On call +// - ctx context.Context +// - paths []string +func (_e *MockModelStore_Expecter) ListByPath(ctx interface{}, paths interface{}) *MockModelStore_ListByPath_Call { + return &MockModelStore_ListByPath_Call{Call: _e.mock.On("ListByPath", ctx, paths)} +} + +func (_c *MockModelStore_ListByPath_Call) Run(run func(ctx context.Context, paths []string)) *MockModelStore_ListByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]string)) + }) + return _c +} + +func (_c *MockModelStore_ListByPath_Call) Return(_a0 []database.Model, _a1 error) *MockModelStore_ListByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelStore_ListByPath_Call) RunAndReturn(run func(context.Context, []string) ([]database.Model, error)) *MockModelStore_ListByPath_Call { + _c.Call.Return(run) + return _c +} + +// PublicCount provides a mock function with given fields: ctx +func (_m *MockModelStore) PublicCount(ctx context.Context) (int, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for PublicCount") + } + + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (int, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) int); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelStore_PublicCount_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublicCount' +type MockModelStore_PublicCount_Call struct { + *mock.Call +} + +// PublicCount is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockModelStore_Expecter) PublicCount(ctx interface{}) *MockModelStore_PublicCount_Call { + return &MockModelStore_PublicCount_Call{Call: _e.mock.On("PublicCount", ctx)} +} + +func (_c *MockModelStore_PublicCount_Call) Run(run func(ctx context.Context)) *MockModelStore_PublicCount_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockModelStore_PublicCount_Call) Return(count int, err error) *MockModelStore_PublicCount_Call { + _c.Call.Return(count, err) + return _c +} + +func (_c *MockModelStore_PublicCount_Call) RunAndReturn(run func(context.Context) (int, error)) *MockModelStore_PublicCount_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, input +func (_m *MockModelStore) Update(ctx context.Context, input database.Model) (*database.Model, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 *database.Model + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Model) (*database.Model, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Model) *database.Model); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Model) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModelStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockModelStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - input database.Model +func (_e *MockModelStore_Expecter) Update(ctx interface{}, input interface{}) *MockModelStore_Update_Call { + return &MockModelStore_Update_Call{Call: _e.mock.On("Update", ctx, input)} +} + +func (_c *MockModelStore_Update_Call) Run(run func(ctx context.Context, input database.Model)) *MockModelStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Model)) + }) + return _c +} + +func (_c *MockModelStore_Update_Call) Return(_a0 *database.Model, _a1 error) *MockModelStore_Update_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModelStore_Update_Call) RunAndReturn(run func(context.Context, database.Model) (*database.Model, error)) *MockModelStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// UserLikesModels provides a mock function with given fields: ctx, userID, per, page +func (_m *MockModelStore) UserLikesModels(ctx context.Context, userID int64, per int, page int) ([]database.Model, int, error) { + ret := _m.Called(ctx, userID, per, page) + + if len(ret) == 0 { + panic("no return value specified for UserLikesModels") + } + + var r0 []database.Model + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) ([]database.Model, int, error)); ok { + return rf(ctx, userID, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) []database.Model); ok { + r0 = rf(ctx, userID, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Model) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int, int) int); ok { + r1 = rf(ctx, userID, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, int64, int, int) error); ok { + r2 = rf(ctx, userID, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockModelStore_UserLikesModels_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UserLikesModels' +type MockModelStore_UserLikesModels_Call struct { + *mock.Call +} + +// UserLikesModels is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +// - per int +// - page int +func (_e *MockModelStore_Expecter) UserLikesModels(ctx interface{}, userID interface{}, per interface{}, page interface{}) *MockModelStore_UserLikesModels_Call { + return &MockModelStore_UserLikesModels_Call{Call: _e.mock.On("UserLikesModels", ctx, userID, per, page)} +} + +func (_c *MockModelStore_UserLikesModels_Call) Run(run func(ctx context.Context, userID int64, per int, page int)) *MockModelStore_UserLikesModels_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockModelStore_UserLikesModels_Call) Return(models []database.Model, total int, err error) *MockModelStore_UserLikesModels_Call { + _c.Call.Return(models, total, err) + return _c +} + +func (_c *MockModelStore_UserLikesModels_Call) RunAndReturn(run func(context.Context, int64, int, int) ([]database.Model, int, error)) *MockModelStore_UserLikesModels_Call { + _c.Call.Return(run) + return _c +} + +// NewMockModelStore creates a new instance of MockModelStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockModelStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockModelStore { + mock := &MockModelStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_NamespaceStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_NamespaceStore.go new file mode 100644 index 00000000..0e1250ff --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_NamespaceStore.go @@ -0,0 +1,151 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockNamespaceStore is an autogenerated mock type for the NamespaceStore type +type MockNamespaceStore struct { + mock.Mock +} + +type MockNamespaceStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockNamespaceStore) EXPECT() *MockNamespaceStore_Expecter { + return &MockNamespaceStore_Expecter{mock: &_m.Mock} +} + +// Exists provides a mock function with given fields: ctx, path +func (_m *MockNamespaceStore) Exists(ctx context.Context, path string) (bool, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for Exists") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (bool, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) bool); ok { + r0 = rf(ctx, path) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockNamespaceStore_Exists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Exists' +type MockNamespaceStore_Exists_Call struct { + *mock.Call +} + +// Exists is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *MockNamespaceStore_Expecter) Exists(ctx interface{}, path interface{}) *MockNamespaceStore_Exists_Call { + return &MockNamespaceStore_Exists_Call{Call: _e.mock.On("Exists", ctx, path)} +} + +func (_c *MockNamespaceStore_Exists_Call) Run(run func(ctx context.Context, path string)) *MockNamespaceStore_Exists_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockNamespaceStore_Exists_Call) Return(exists bool, err error) *MockNamespaceStore_Exists_Call { + _c.Call.Return(exists, err) + return _c +} + +func (_c *MockNamespaceStore_Exists_Call) RunAndReturn(run func(context.Context, string) (bool, error)) *MockNamespaceStore_Exists_Call { + _c.Call.Return(run) + return _c +} + +// FindByPath provides a mock function with given fields: ctx, path +func (_m *MockNamespaceStore) FindByPath(ctx context.Context, path string) (database.Namespace, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for FindByPath") + } + + var r0 database.Namespace + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (database.Namespace, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) database.Namespace); ok { + r0 = rf(ctx, path) + } else { + r0 = ret.Get(0).(database.Namespace) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockNamespaceStore_FindByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByPath' +type MockNamespaceStore_FindByPath_Call struct { + *mock.Call +} + +// FindByPath is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *MockNamespaceStore_Expecter) FindByPath(ctx interface{}, path interface{}) *MockNamespaceStore_FindByPath_Call { + return &MockNamespaceStore_FindByPath_Call{Call: _e.mock.On("FindByPath", ctx, path)} +} + +func (_c *MockNamespaceStore_FindByPath_Call) Run(run func(ctx context.Context, path string)) *MockNamespaceStore_FindByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockNamespaceStore_FindByPath_Call) Return(namespace database.Namespace, err error) *MockNamespaceStore_FindByPath_Call { + _c.Call.Return(namespace, err) + return _c +} + +func (_c *MockNamespaceStore_FindByPath_Call) RunAndReturn(run func(context.Context, string) (database.Namespace, error)) *MockNamespaceStore_FindByPath_Call { + _c.Call.Return(run) + return _c +} + +// NewMockNamespaceStore creates a new instance of MockNamespaceStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockNamespaceStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockNamespaceStore { + mock := &MockNamespaceStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_OrgStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_OrgStore.go new file mode 100644 index 00000000..0827a6b5 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_OrgStore.go @@ -0,0 +1,411 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockOrgStore is an autogenerated mock type for the OrgStore type +type MockOrgStore struct { + mock.Mock +} + +type MockOrgStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockOrgStore) EXPECT() *MockOrgStore_Expecter { + return &MockOrgStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, org, namepace +func (_m *MockOrgStore) Create(ctx context.Context, org *database.Organization, namepace *database.Namespace) error { + ret := _m.Called(ctx, org, namepace) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Organization, *database.Namespace) error); ok { + r0 = rf(ctx, org, namepace) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockOrgStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockOrgStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - org *database.Organization +// - namepace *database.Namespace +func (_e *MockOrgStore_Expecter) Create(ctx interface{}, org interface{}, namepace interface{}) *MockOrgStore_Create_Call { + return &MockOrgStore_Create_Call{Call: _e.mock.On("Create", ctx, org, namepace)} +} + +func (_c *MockOrgStore_Create_Call) Run(run func(ctx context.Context, org *database.Organization, namepace *database.Namespace)) *MockOrgStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Organization), args[2].(*database.Namespace)) + }) + return _c +} + +func (_c *MockOrgStore_Create_Call) Return(err error) *MockOrgStore_Create_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockOrgStore_Create_Call) RunAndReturn(run func(context.Context, *database.Organization, *database.Namespace) error) *MockOrgStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, path +func (_m *MockOrgStore) Delete(ctx context.Context, path string) error { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, path) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockOrgStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockOrgStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *MockOrgStore_Expecter) Delete(ctx interface{}, path interface{}) *MockOrgStore_Delete_Call { + return &MockOrgStore_Delete_Call{Call: _e.mock.On("Delete", ctx, path)} +} + +func (_c *MockOrgStore_Delete_Call) Run(run func(ctx context.Context, path string)) *MockOrgStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockOrgStore_Delete_Call) Return(err error) *MockOrgStore_Delete_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockOrgStore_Delete_Call) RunAndReturn(run func(context.Context, string) error) *MockOrgStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// Exists provides a mock function with given fields: ctx, path +func (_m *MockOrgStore) Exists(ctx context.Context, path string) (bool, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for Exists") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (bool, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) bool); ok { + r0 = rf(ctx, path) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockOrgStore_Exists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Exists' +type MockOrgStore_Exists_Call struct { + *mock.Call +} + +// Exists is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *MockOrgStore_Expecter) Exists(ctx interface{}, path interface{}) *MockOrgStore_Exists_Call { + return &MockOrgStore_Exists_Call{Call: _e.mock.On("Exists", ctx, path)} +} + +func (_c *MockOrgStore_Exists_Call) Run(run func(ctx context.Context, path string)) *MockOrgStore_Exists_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockOrgStore_Exists_Call) Return(exists bool, err error) *MockOrgStore_Exists_Call { + _c.Call.Return(exists, err) + return _c +} + +func (_c *MockOrgStore_Exists_Call) RunAndReturn(run func(context.Context, string) (bool, error)) *MockOrgStore_Exists_Call { + _c.Call.Return(run) + return _c +} + +// FindByPath provides a mock function with given fields: ctx, path +func (_m *MockOrgStore) FindByPath(ctx context.Context, path string) (database.Organization, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for FindByPath") + } + + var r0 database.Organization + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (database.Organization, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) database.Organization); ok { + r0 = rf(ctx, path) + } else { + r0 = ret.Get(0).(database.Organization) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockOrgStore_FindByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByPath' +type MockOrgStore_FindByPath_Call struct { + *mock.Call +} + +// FindByPath is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *MockOrgStore_Expecter) FindByPath(ctx interface{}, path interface{}) *MockOrgStore_FindByPath_Call { + return &MockOrgStore_FindByPath_Call{Call: _e.mock.On("FindByPath", ctx, path)} +} + +func (_c *MockOrgStore_FindByPath_Call) Run(run func(ctx context.Context, path string)) *MockOrgStore_FindByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockOrgStore_FindByPath_Call) Return(org database.Organization, err error) *MockOrgStore_FindByPath_Call { + _c.Call.Return(org, err) + return _c +} + +func (_c *MockOrgStore_FindByPath_Call) RunAndReturn(run func(context.Context, string) (database.Organization, error)) *MockOrgStore_FindByPath_Call { + _c.Call.Return(run) + return _c +} + +// GetUserBelongOrgs provides a mock function with given fields: ctx, userID +func (_m *MockOrgStore) GetUserBelongOrgs(ctx context.Context, userID int64) ([]database.Organization, error) { + ret := _m.Called(ctx, userID) + + if len(ret) == 0 { + panic("no return value specified for GetUserBelongOrgs") + } + + var r0 []database.Organization + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.Organization, error)); ok { + return rf(ctx, userID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.Organization); ok { + r0 = rf(ctx, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Organization) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockOrgStore_GetUserBelongOrgs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserBelongOrgs' +type MockOrgStore_GetUserBelongOrgs_Call struct { + *mock.Call +} + +// GetUserBelongOrgs is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +func (_e *MockOrgStore_Expecter) GetUserBelongOrgs(ctx interface{}, userID interface{}) *MockOrgStore_GetUserBelongOrgs_Call { + return &MockOrgStore_GetUserBelongOrgs_Call{Call: _e.mock.On("GetUserBelongOrgs", ctx, userID)} +} + +func (_c *MockOrgStore_GetUserBelongOrgs_Call) Run(run func(ctx context.Context, userID int64)) *MockOrgStore_GetUserBelongOrgs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockOrgStore_GetUserBelongOrgs_Call) Return(orgs []database.Organization, err error) *MockOrgStore_GetUserBelongOrgs_Call { + _c.Call.Return(orgs, err) + return _c +} + +func (_c *MockOrgStore_GetUserBelongOrgs_Call) RunAndReturn(run func(context.Context, int64) ([]database.Organization, error)) *MockOrgStore_GetUserBelongOrgs_Call { + _c.Call.Return(run) + return _c +} + +// GetUserOwnOrgs provides a mock function with given fields: ctx, username +func (_m *MockOrgStore) GetUserOwnOrgs(ctx context.Context, username string) ([]database.Organization, error) { + ret := _m.Called(ctx, username) + + if len(ret) == 0 { + panic("no return value specified for GetUserOwnOrgs") + } + + var r0 []database.Organization + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]database.Organization, error)); ok { + return rf(ctx, username) + } + if rf, ok := ret.Get(0).(func(context.Context, string) []database.Organization); ok { + r0 = rf(ctx, username) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Organization) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockOrgStore_GetUserOwnOrgs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserOwnOrgs' +type MockOrgStore_GetUserOwnOrgs_Call struct { + *mock.Call +} + +// GetUserOwnOrgs is a helper method to define mock.On call +// - ctx context.Context +// - username string +func (_e *MockOrgStore_Expecter) GetUserOwnOrgs(ctx interface{}, username interface{}) *MockOrgStore_GetUserOwnOrgs_Call { + return &MockOrgStore_GetUserOwnOrgs_Call{Call: _e.mock.On("GetUserOwnOrgs", ctx, username)} +} + +func (_c *MockOrgStore_GetUserOwnOrgs_Call) Run(run func(ctx context.Context, username string)) *MockOrgStore_GetUserOwnOrgs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockOrgStore_GetUserOwnOrgs_Call) Return(orgs []database.Organization, err error) *MockOrgStore_GetUserOwnOrgs_Call { + _c.Call.Return(orgs, err) + return _c +} + +func (_c *MockOrgStore_GetUserOwnOrgs_Call) RunAndReturn(run func(context.Context, string) ([]database.Organization, error)) *MockOrgStore_GetUserOwnOrgs_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, org +func (_m *MockOrgStore) Update(ctx context.Context, org *database.Organization) error { + ret := _m.Called(ctx, org) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Organization) error); ok { + r0 = rf(ctx, org) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockOrgStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockOrgStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - org *database.Organization +func (_e *MockOrgStore_Expecter) Update(ctx interface{}, org interface{}) *MockOrgStore_Update_Call { + return &MockOrgStore_Update_Call{Call: _e.mock.On("Update", ctx, org)} +} + +func (_c *MockOrgStore_Update_Call) Run(run func(ctx context.Context, org *database.Organization)) *MockOrgStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Organization)) + }) + return _c +} + +func (_c *MockOrgStore_Update_Call) Return(err error) *MockOrgStore_Update_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockOrgStore_Update_Call) RunAndReturn(run func(context.Context, *database.Organization) error) *MockOrgStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockOrgStore creates a new instance of MockOrgStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockOrgStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockOrgStore { + mock := &MockOrgStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptConversationStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptConversationStore.go new file mode 100644 index 00000000..c561bdf9 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptConversationStore.go @@ -0,0 +1,452 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockPromptConversationStore is an autogenerated mock type for the PromptConversationStore type +type MockPromptConversationStore struct { + mock.Mock +} + +type MockPromptConversationStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockPromptConversationStore) EXPECT() *MockPromptConversationStore_Expecter { + return &MockPromptConversationStore_Expecter{mock: &_m.Mock} +} + +// CreateConversation provides a mock function with given fields: ctx, conversation +func (_m *MockPromptConversationStore) CreateConversation(ctx context.Context, conversation database.PromptConversation) error { + ret := _m.Called(ctx, conversation) + + if len(ret) == 0 { + panic("no return value specified for CreateConversation") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.PromptConversation) error); ok { + r0 = rf(ctx, conversation) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockPromptConversationStore_CreateConversation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateConversation' +type MockPromptConversationStore_CreateConversation_Call struct { + *mock.Call +} + +// CreateConversation is a helper method to define mock.On call +// - ctx context.Context +// - conversation database.PromptConversation +func (_e *MockPromptConversationStore_Expecter) CreateConversation(ctx interface{}, conversation interface{}) *MockPromptConversationStore_CreateConversation_Call { + return &MockPromptConversationStore_CreateConversation_Call{Call: _e.mock.On("CreateConversation", ctx, conversation)} +} + +func (_c *MockPromptConversationStore_CreateConversation_Call) Run(run func(ctx context.Context, conversation database.PromptConversation)) *MockPromptConversationStore_CreateConversation_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.PromptConversation)) + }) + return _c +} + +func (_c *MockPromptConversationStore_CreateConversation_Call) Return(_a0 error) *MockPromptConversationStore_CreateConversation_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPromptConversationStore_CreateConversation_Call) RunAndReturn(run func(context.Context, database.PromptConversation) error) *MockPromptConversationStore_CreateConversation_Call { + _c.Call.Return(run) + return _c +} + +// DeleteConversationsByID provides a mock function with given fields: ctx, userID, uuid +func (_m *MockPromptConversationStore) DeleteConversationsByID(ctx context.Context, userID int64, uuid string) error { + ret := _m.Called(ctx, userID, uuid) + + if len(ret) == 0 { + panic("no return value specified for DeleteConversationsByID") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) error); ok { + r0 = rf(ctx, userID, uuid) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockPromptConversationStore_DeleteConversationsByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteConversationsByID' +type MockPromptConversationStore_DeleteConversationsByID_Call struct { + *mock.Call +} + +// DeleteConversationsByID is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +// - uuid string +func (_e *MockPromptConversationStore_Expecter) DeleteConversationsByID(ctx interface{}, userID interface{}, uuid interface{}) *MockPromptConversationStore_DeleteConversationsByID_Call { + return &MockPromptConversationStore_DeleteConversationsByID_Call{Call: _e.mock.On("DeleteConversationsByID", ctx, userID, uuid)} +} + +func (_c *MockPromptConversationStore_DeleteConversationsByID_Call) Run(run func(ctx context.Context, userID int64, uuid string)) *MockPromptConversationStore_DeleteConversationsByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockPromptConversationStore_DeleteConversationsByID_Call) Return(_a0 error) *MockPromptConversationStore_DeleteConversationsByID_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPromptConversationStore_DeleteConversationsByID_Call) RunAndReturn(run func(context.Context, int64, string) error) *MockPromptConversationStore_DeleteConversationsByID_Call { + _c.Call.Return(run) + return _c +} + +// FindConversationsByUserID provides a mock function with given fields: ctx, userID +func (_m *MockPromptConversationStore) FindConversationsByUserID(ctx context.Context, userID int64) ([]database.PromptConversation, error) { + ret := _m.Called(ctx, userID) + + if len(ret) == 0 { + panic("no return value specified for FindConversationsByUserID") + } + + var r0 []database.PromptConversation + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.PromptConversation, error)); ok { + return rf(ctx, userID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.PromptConversation); ok { + r0 = rf(ctx, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.PromptConversation) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockPromptConversationStore_FindConversationsByUserID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindConversationsByUserID' +type MockPromptConversationStore_FindConversationsByUserID_Call struct { + *mock.Call +} + +// FindConversationsByUserID is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +func (_e *MockPromptConversationStore_Expecter) FindConversationsByUserID(ctx interface{}, userID interface{}) *MockPromptConversationStore_FindConversationsByUserID_Call { + return &MockPromptConversationStore_FindConversationsByUserID_Call{Call: _e.mock.On("FindConversationsByUserID", ctx, userID)} +} + +func (_c *MockPromptConversationStore_FindConversationsByUserID_Call) Run(run func(ctx context.Context, userID int64)) *MockPromptConversationStore_FindConversationsByUserID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockPromptConversationStore_FindConversationsByUserID_Call) Return(_a0 []database.PromptConversation, _a1 error) *MockPromptConversationStore_FindConversationsByUserID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPromptConversationStore_FindConversationsByUserID_Call) RunAndReturn(run func(context.Context, int64) ([]database.PromptConversation, error)) *MockPromptConversationStore_FindConversationsByUserID_Call { + _c.Call.Return(run) + return _c +} + +// GetConversationByID provides a mock function with given fields: ctx, userID, uuid, hasDetail +func (_m *MockPromptConversationStore) GetConversationByID(ctx context.Context, userID int64, uuid string, hasDetail bool) (*database.PromptConversation, error) { + ret := _m.Called(ctx, userID, uuid, hasDetail) + + if len(ret) == 0 { + panic("no return value specified for GetConversationByID") + } + + var r0 *database.PromptConversation + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string, bool) (*database.PromptConversation, error)); ok { + return rf(ctx, userID, uuid, hasDetail) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, string, bool) *database.PromptConversation); ok { + r0 = rf(ctx, userID, uuid, hasDetail) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.PromptConversation) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, string, bool) error); ok { + r1 = rf(ctx, userID, uuid, hasDetail) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockPromptConversationStore_GetConversationByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetConversationByID' +type MockPromptConversationStore_GetConversationByID_Call struct { + *mock.Call +} + +// GetConversationByID is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +// - uuid string +// - hasDetail bool +func (_e *MockPromptConversationStore_Expecter) GetConversationByID(ctx interface{}, userID interface{}, uuid interface{}, hasDetail interface{}) *MockPromptConversationStore_GetConversationByID_Call { + return &MockPromptConversationStore_GetConversationByID_Call{Call: _e.mock.On("GetConversationByID", ctx, userID, uuid, hasDetail)} +} + +func (_c *MockPromptConversationStore_GetConversationByID_Call) Run(run func(ctx context.Context, userID int64, uuid string, hasDetail bool)) *MockPromptConversationStore_GetConversationByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string), args[3].(bool)) + }) + return _c +} + +func (_c *MockPromptConversationStore_GetConversationByID_Call) Return(_a0 *database.PromptConversation, _a1 error) *MockPromptConversationStore_GetConversationByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPromptConversationStore_GetConversationByID_Call) RunAndReturn(run func(context.Context, int64, string, bool) (*database.PromptConversation, error)) *MockPromptConversationStore_GetConversationByID_Call { + _c.Call.Return(run) + return _c +} + +// HateMessageByID provides a mock function with given fields: ctx, id +func (_m *MockPromptConversationStore) HateMessageByID(ctx context.Context, id int64) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for HateMessageByID") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockPromptConversationStore_HateMessageByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HateMessageByID' +type MockPromptConversationStore_HateMessageByID_Call struct { + *mock.Call +} + +// HateMessageByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockPromptConversationStore_Expecter) HateMessageByID(ctx interface{}, id interface{}) *MockPromptConversationStore_HateMessageByID_Call { + return &MockPromptConversationStore_HateMessageByID_Call{Call: _e.mock.On("HateMessageByID", ctx, id)} +} + +func (_c *MockPromptConversationStore_HateMessageByID_Call) Run(run func(ctx context.Context, id int64)) *MockPromptConversationStore_HateMessageByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockPromptConversationStore_HateMessageByID_Call) Return(_a0 error) *MockPromptConversationStore_HateMessageByID_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPromptConversationStore_HateMessageByID_Call) RunAndReturn(run func(context.Context, int64) error) *MockPromptConversationStore_HateMessageByID_Call { + _c.Call.Return(run) + return _c +} + +// LikeMessageByID provides a mock function with given fields: ctx, id +func (_m *MockPromptConversationStore) LikeMessageByID(ctx context.Context, id int64) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for LikeMessageByID") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockPromptConversationStore_LikeMessageByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LikeMessageByID' +type MockPromptConversationStore_LikeMessageByID_Call struct { + *mock.Call +} + +// LikeMessageByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockPromptConversationStore_Expecter) LikeMessageByID(ctx interface{}, id interface{}) *MockPromptConversationStore_LikeMessageByID_Call { + return &MockPromptConversationStore_LikeMessageByID_Call{Call: _e.mock.On("LikeMessageByID", ctx, id)} +} + +func (_c *MockPromptConversationStore_LikeMessageByID_Call) Run(run func(ctx context.Context, id int64)) *MockPromptConversationStore_LikeMessageByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockPromptConversationStore_LikeMessageByID_Call) Return(_a0 error) *MockPromptConversationStore_LikeMessageByID_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPromptConversationStore_LikeMessageByID_Call) RunAndReturn(run func(context.Context, int64) error) *MockPromptConversationStore_LikeMessageByID_Call { + _c.Call.Return(run) + return _c +} + +// SaveConversationMessage provides a mock function with given fields: ctx, message +func (_m *MockPromptConversationStore) SaveConversationMessage(ctx context.Context, message database.PromptConversationMessage) (*database.PromptConversationMessage, error) { + ret := _m.Called(ctx, message) + + if len(ret) == 0 { + panic("no return value specified for SaveConversationMessage") + } + + var r0 *database.PromptConversationMessage + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.PromptConversationMessage) (*database.PromptConversationMessage, error)); ok { + return rf(ctx, message) + } + if rf, ok := ret.Get(0).(func(context.Context, database.PromptConversationMessage) *database.PromptConversationMessage); ok { + r0 = rf(ctx, message) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.PromptConversationMessage) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.PromptConversationMessage) error); ok { + r1 = rf(ctx, message) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockPromptConversationStore_SaveConversationMessage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveConversationMessage' +type MockPromptConversationStore_SaveConversationMessage_Call struct { + *mock.Call +} + +// SaveConversationMessage is a helper method to define mock.On call +// - ctx context.Context +// - message database.PromptConversationMessage +func (_e *MockPromptConversationStore_Expecter) SaveConversationMessage(ctx interface{}, message interface{}) *MockPromptConversationStore_SaveConversationMessage_Call { + return &MockPromptConversationStore_SaveConversationMessage_Call{Call: _e.mock.On("SaveConversationMessage", ctx, message)} +} + +func (_c *MockPromptConversationStore_SaveConversationMessage_Call) Run(run func(ctx context.Context, message database.PromptConversationMessage)) *MockPromptConversationStore_SaveConversationMessage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.PromptConversationMessage)) + }) + return _c +} + +func (_c *MockPromptConversationStore_SaveConversationMessage_Call) Return(_a0 *database.PromptConversationMessage, _a1 error) *MockPromptConversationStore_SaveConversationMessage_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPromptConversationStore_SaveConversationMessage_Call) RunAndReturn(run func(context.Context, database.PromptConversationMessage) (*database.PromptConversationMessage, error)) *MockPromptConversationStore_SaveConversationMessage_Call { + _c.Call.Return(run) + return _c +} + +// UpdateConversation provides a mock function with given fields: ctx, conversation +func (_m *MockPromptConversationStore) UpdateConversation(ctx context.Context, conversation database.PromptConversation) error { + ret := _m.Called(ctx, conversation) + + if len(ret) == 0 { + panic("no return value specified for UpdateConversation") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.PromptConversation) error); ok { + r0 = rf(ctx, conversation) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockPromptConversationStore_UpdateConversation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateConversation' +type MockPromptConversationStore_UpdateConversation_Call struct { + *mock.Call +} + +// UpdateConversation is a helper method to define mock.On call +// - ctx context.Context +// - conversation database.PromptConversation +func (_e *MockPromptConversationStore_Expecter) UpdateConversation(ctx interface{}, conversation interface{}) *MockPromptConversationStore_UpdateConversation_Call { + return &MockPromptConversationStore_UpdateConversation_Call{Call: _e.mock.On("UpdateConversation", ctx, conversation)} +} + +func (_c *MockPromptConversationStore_UpdateConversation_Call) Run(run func(ctx context.Context, conversation database.PromptConversation)) *MockPromptConversationStore_UpdateConversation_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.PromptConversation)) + }) + return _c +} + +func (_c *MockPromptConversationStore_UpdateConversation_Call) Return(_a0 error) *MockPromptConversationStore_UpdateConversation_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPromptConversationStore_UpdateConversation_Call) RunAndReturn(run func(context.Context, database.PromptConversation) error) *MockPromptConversationStore_UpdateConversation_Call { + _c.Call.Return(run) + return _c +} + +// NewMockPromptConversationStore creates a new instance of MockPromptConversationStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockPromptConversationStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockPromptConversationStore { + mock := &MockPromptConversationStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptPrefixStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptPrefixStore.go new file mode 100644 index 00000000..15f164b4 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptPrefixStore.go @@ -0,0 +1,95 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockPromptPrefixStore is an autogenerated mock type for the PromptPrefixStore type +type MockPromptPrefixStore struct { + mock.Mock +} + +type MockPromptPrefixStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockPromptPrefixStore) EXPECT() *MockPromptPrefixStore_Expecter { + return &MockPromptPrefixStore_Expecter{mock: &_m.Mock} +} + +// Get provides a mock function with given fields: ctx +func (_m *MockPromptPrefixStore) Get(ctx context.Context) (*database.PromptPrefix, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 *database.PromptPrefix + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*database.PromptPrefix, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *database.PromptPrefix); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.PromptPrefix) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockPromptPrefixStore_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type MockPromptPrefixStore_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockPromptPrefixStore_Expecter) Get(ctx interface{}) *MockPromptPrefixStore_Get_Call { + return &MockPromptPrefixStore_Get_Call{Call: _e.mock.On("Get", ctx)} +} + +func (_c *MockPromptPrefixStore_Get_Call) Run(run func(ctx context.Context)) *MockPromptPrefixStore_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockPromptPrefixStore_Get_Call) Return(_a0 *database.PromptPrefix, _a1 error) *MockPromptPrefixStore_Get_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPromptPrefixStore_Get_Call) RunAndReturn(run func(context.Context) (*database.PromptPrefix, error)) *MockPromptPrefixStore_Get_Call { + _c.Call.Return(run) + return _c +} + +// NewMockPromptPrefixStore creates a new instance of MockPromptPrefixStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockPromptPrefixStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockPromptPrefixStore { + mock := &MockPromptPrefixStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptStore.go new file mode 100644 index 00000000..68c5c51a --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptStore.go @@ -0,0 +1,506 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockPromptStore is an autogenerated mock type for the PromptStore type +type MockPromptStore struct { + mock.Mock +} + +type MockPromptStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockPromptStore) EXPECT() *MockPromptStore_Expecter { + return &MockPromptStore_Expecter{mock: &_m.Mock} +} + +// ByOrgPath provides a mock function with given fields: ctx, namespace, per, page, onlyPublic +func (_m *MockPromptStore) ByOrgPath(ctx context.Context, namespace string, per int, page int, onlyPublic bool) ([]database.Prompt, int, error) { + ret := _m.Called(ctx, namespace, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByOrgPath") + } + + var r0 []database.Prompt + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Prompt, int, error)); ok { + return rf(ctx, namespace, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Prompt); ok { + r0 = rf(ctx, namespace, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Prompt) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockPromptStore_ByOrgPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByOrgPath' +type MockPromptStore_ByOrgPath_Call struct { + *mock.Call +} + +// ByOrgPath is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockPromptStore_Expecter) ByOrgPath(ctx interface{}, namespace interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockPromptStore_ByOrgPath_Call { + return &MockPromptStore_ByOrgPath_Call{Call: _e.mock.On("ByOrgPath", ctx, namespace, per, page, onlyPublic)} +} + +func (_c *MockPromptStore_ByOrgPath_Call) Run(run func(ctx context.Context, namespace string, per int, page int, onlyPublic bool)) *MockPromptStore_ByOrgPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockPromptStore_ByOrgPath_Call) Return(prompts []database.Prompt, total int, err error) *MockPromptStore_ByOrgPath_Call { + _c.Call.Return(prompts, total, err) + return _c +} + +func (_c *MockPromptStore_ByOrgPath_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Prompt, int, error)) *MockPromptStore_ByOrgPath_Call { + _c.Call.Return(run) + return _c +} + +// ByRepoID provides a mock function with given fields: ctx, repoID +func (_m *MockPromptStore) ByRepoID(ctx context.Context, repoID int64) (*database.Prompt, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for ByRepoID") + } + + var r0 *database.Prompt + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Prompt, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Prompt); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Prompt) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockPromptStore_ByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByRepoID' +type MockPromptStore_ByRepoID_Call struct { + *mock.Call +} + +// ByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockPromptStore_Expecter) ByRepoID(ctx interface{}, repoID interface{}) *MockPromptStore_ByRepoID_Call { + return &MockPromptStore_ByRepoID_Call{Call: _e.mock.On("ByRepoID", ctx, repoID)} +} + +func (_c *MockPromptStore_ByRepoID_Call) Run(run func(ctx context.Context, repoID int64)) *MockPromptStore_ByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockPromptStore_ByRepoID_Call) Return(_a0 *database.Prompt, _a1 error) *MockPromptStore_ByRepoID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPromptStore_ByRepoID_Call) RunAndReturn(run func(context.Context, int64) (*database.Prompt, error)) *MockPromptStore_ByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// ByRepoIDs provides a mock function with given fields: ctx, repoIDs +func (_m *MockPromptStore) ByRepoIDs(ctx context.Context, repoIDs []int64) ([]database.Prompt, error) { + ret := _m.Called(ctx, repoIDs) + + if len(ret) == 0 { + panic("no return value specified for ByRepoIDs") + } + + var r0 []database.Prompt + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []int64) ([]database.Prompt, error)); ok { + return rf(ctx, repoIDs) + } + if rf, ok := ret.Get(0).(func(context.Context, []int64) []database.Prompt); ok { + r0 = rf(ctx, repoIDs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Prompt) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []int64) error); ok { + r1 = rf(ctx, repoIDs) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockPromptStore_ByRepoIDs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByRepoIDs' +type MockPromptStore_ByRepoIDs_Call struct { + *mock.Call +} + +// ByRepoIDs is a helper method to define mock.On call +// - ctx context.Context +// - repoIDs []int64 +func (_e *MockPromptStore_Expecter) ByRepoIDs(ctx interface{}, repoIDs interface{}) *MockPromptStore_ByRepoIDs_Call { + return &MockPromptStore_ByRepoIDs_Call{Call: _e.mock.On("ByRepoIDs", ctx, repoIDs)} +} + +func (_c *MockPromptStore_ByRepoIDs_Call) Run(run func(ctx context.Context, repoIDs []int64)) *MockPromptStore_ByRepoIDs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]int64)) + }) + return _c +} + +func (_c *MockPromptStore_ByRepoIDs_Call) Return(prompts []database.Prompt, err error) *MockPromptStore_ByRepoIDs_Call { + _c.Call.Return(prompts, err) + return _c +} + +func (_c *MockPromptStore_ByRepoIDs_Call) RunAndReturn(run func(context.Context, []int64) ([]database.Prompt, error)) *MockPromptStore_ByRepoIDs_Call { + _c.Call.Return(run) + return _c +} + +// ByUsername provides a mock function with given fields: ctx, username, per, page, onlyPublic +func (_m *MockPromptStore) ByUsername(ctx context.Context, username string, per int, page int, onlyPublic bool) ([]database.Prompt, int, error) { + ret := _m.Called(ctx, username, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByUsername") + } + + var r0 []database.Prompt + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Prompt, int, error)); ok { + return rf(ctx, username, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Prompt); ok { + r0 = rf(ctx, username, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Prompt) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, username, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, username, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockPromptStore_ByUsername_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByUsername' +type MockPromptStore_ByUsername_Call struct { + *mock.Call +} + +// ByUsername is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockPromptStore_Expecter) ByUsername(ctx interface{}, username interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockPromptStore_ByUsername_Call { + return &MockPromptStore_ByUsername_Call{Call: _e.mock.On("ByUsername", ctx, username, per, page, onlyPublic)} +} + +func (_c *MockPromptStore_ByUsername_Call) Run(run func(ctx context.Context, username string, per int, page int, onlyPublic bool)) *MockPromptStore_ByUsername_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockPromptStore_ByUsername_Call) Return(prompts []database.Prompt, total int, err error) *MockPromptStore_ByUsername_Call { + _c.Call.Return(prompts, total, err) + return _c +} + +func (_c *MockPromptStore_ByUsername_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Prompt, int, error)) *MockPromptStore_ByUsername_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, input +func (_m *MockPromptStore) Create(ctx context.Context, input database.Prompt) (*database.Prompt, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.Prompt + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Prompt) (*database.Prompt, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Prompt) *database.Prompt); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Prompt) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Prompt) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockPromptStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockPromptStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - input database.Prompt +func (_e *MockPromptStore_Expecter) Create(ctx interface{}, input interface{}) *MockPromptStore_Create_Call { + return &MockPromptStore_Create_Call{Call: _e.mock.On("Create", ctx, input)} +} + +func (_c *MockPromptStore_Create_Call) Run(run func(ctx context.Context, input database.Prompt)) *MockPromptStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Prompt)) + }) + return _c +} + +func (_c *MockPromptStore_Create_Call) Return(_a0 *database.Prompt, _a1 error) *MockPromptStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPromptStore_Create_Call) RunAndReturn(run func(context.Context, database.Prompt) (*database.Prompt, error)) *MockPromptStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, input +func (_m *MockPromptStore) Delete(ctx context.Context, input database.Prompt) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.Prompt) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockPromptStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockPromptStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - input database.Prompt +func (_e *MockPromptStore_Expecter) Delete(ctx interface{}, input interface{}) *MockPromptStore_Delete_Call { + return &MockPromptStore_Delete_Call{Call: _e.mock.On("Delete", ctx, input)} +} + +func (_c *MockPromptStore_Delete_Call) Run(run func(ctx context.Context, input database.Prompt)) *MockPromptStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Prompt)) + }) + return _c +} + +func (_c *MockPromptStore_Delete_Call) Return(_a0 error) *MockPromptStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPromptStore_Delete_Call) RunAndReturn(run func(context.Context, database.Prompt) error) *MockPromptStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindByPath provides a mock function with given fields: ctx, namespace, repoPath +func (_m *MockPromptStore) FindByPath(ctx context.Context, namespace string, repoPath string) (*database.Prompt, error) { + ret := _m.Called(ctx, namespace, repoPath) + + if len(ret) == 0 { + panic("no return value specified for FindByPath") + } + + var r0 *database.Prompt + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*database.Prompt, error)); ok { + return rf(ctx, namespace, repoPath) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) *database.Prompt); ok { + r0 = rf(ctx, namespace, repoPath) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Prompt) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, namespace, repoPath) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockPromptStore_FindByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByPath' +type MockPromptStore_FindByPath_Call struct { + *mock.Call +} + +// FindByPath is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - repoPath string +func (_e *MockPromptStore_Expecter) FindByPath(ctx interface{}, namespace interface{}, repoPath interface{}) *MockPromptStore_FindByPath_Call { + return &MockPromptStore_FindByPath_Call{Call: _e.mock.On("FindByPath", ctx, namespace, repoPath)} +} + +func (_c *MockPromptStore_FindByPath_Call) Run(run func(ctx context.Context, namespace string, repoPath string)) *MockPromptStore_FindByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockPromptStore_FindByPath_Call) Return(_a0 *database.Prompt, _a1 error) *MockPromptStore_FindByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockPromptStore_FindByPath_Call) RunAndReturn(run func(context.Context, string, string) (*database.Prompt, error)) *MockPromptStore_FindByPath_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, input +func (_m *MockPromptStore) Update(ctx context.Context, input database.Prompt) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.Prompt) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockPromptStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockPromptStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - input database.Prompt +func (_e *MockPromptStore_Expecter) Update(ctx interface{}, input interface{}) *MockPromptStore_Update_Call { + return &MockPromptStore_Update_Call{Call: _e.mock.On("Update", ctx, input)} +} + +func (_c *MockPromptStore_Update_Call) Run(run func(ctx context.Context, input database.Prompt)) *MockPromptStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Prompt)) + }) + return _c +} + +func (_c *MockPromptStore_Update_Call) Return(err error) *MockPromptStore_Update_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockPromptStore_Update_Call) RunAndReturn(run func(context.Context, database.Prompt) error) *MockPromptStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockPromptStore creates a new instance of MockPromptStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockPromptStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockPromptStore { + mock := &MockPromptStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoStore.go new file mode 100644 index 00000000..298c3f48 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoStore.go @@ -0,0 +1,2128 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + bun "github.com/uptrace/bun" + + database "opencsg.com/csghub-server/builder/store/database" + + mock "github.com/stretchr/testify/mock" + + time "time" + + types "opencsg.com/csghub-server/common/types" +) + +// MockRepoStore is an autogenerated mock type for the RepoStore type +type MockRepoStore struct { + mock.Mock +} + +type MockRepoStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRepoStore) EXPECT() *MockRepoStore_Expecter { + return &MockRepoStore_Expecter{mock: &_m.Mock} +} + +// All provides a mock function with given fields: ctx +func (_m *MockRepoStore) All(ctx context.Context) ([]*database.Repository, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for All") + } + + var r0 []*database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]*database.Repository, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []*database.Repository); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_All_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'All' +type MockRepoStore_All_Call struct { + *mock.Call +} + +// All is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockRepoStore_Expecter) All(ctx interface{}) *MockRepoStore_All_Call { + return &MockRepoStore_All_Call{Call: _e.mock.On("All", ctx)} +} + +func (_c *MockRepoStore_All_Call) Run(run func(ctx context.Context)) *MockRepoStore_All_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockRepoStore_All_Call) Return(_a0 []*database.Repository, _a1 error) *MockRepoStore_All_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_All_Call) RunAndReturn(run func(context.Context) ([]*database.Repository, error)) *MockRepoStore_All_Call { + _c.Call.Return(run) + return _c +} + +// BatchCreateRepoTags provides a mock function with given fields: ctx, repoTags +func (_m *MockRepoStore) BatchCreateRepoTags(ctx context.Context, repoTags []database.RepositoryTag) error { + ret := _m.Called(ctx, repoTags) + + if len(ret) == 0 { + panic("no return value specified for BatchCreateRepoTags") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []database.RepositoryTag) error); ok { + r0 = rf(ctx, repoTags) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoStore_BatchCreateRepoTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchCreateRepoTags' +type MockRepoStore_BatchCreateRepoTags_Call struct { + *mock.Call +} + +// BatchCreateRepoTags is a helper method to define mock.On call +// - ctx context.Context +// - repoTags []database.RepositoryTag +func (_e *MockRepoStore_Expecter) BatchCreateRepoTags(ctx interface{}, repoTags interface{}) *MockRepoStore_BatchCreateRepoTags_Call { + return &MockRepoStore_BatchCreateRepoTags_Call{Call: _e.mock.On("BatchCreateRepoTags", ctx, repoTags)} +} + +func (_c *MockRepoStore_BatchCreateRepoTags_Call) Run(run func(ctx context.Context, repoTags []database.RepositoryTag)) *MockRepoStore_BatchCreateRepoTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]database.RepositoryTag)) + }) + return _c +} + +func (_c *MockRepoStore_BatchCreateRepoTags_Call) Return(_a0 error) *MockRepoStore_BatchCreateRepoTags_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoStore_BatchCreateRepoTags_Call) RunAndReturn(run func(context.Context, []database.RepositoryTag) error) *MockRepoStore_BatchCreateRepoTags_Call { + _c.Call.Return(run) + return _c +} + +// BatchGet provides a mock function with given fields: ctx, repoType, lastRepoID, batch +func (_m *MockRepoStore) BatchGet(ctx context.Context, repoType types.RepositoryType, lastRepoID int64, batch int) ([]database.Repository, error) { + ret := _m.Called(ctx, repoType, lastRepoID, batch) + + if len(ret) == 0 { + panic("no return value specified for BatchGet") + } + + var r0 []database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, int64, int) ([]database.Repository, error)); ok { + return rf(ctx, repoType, lastRepoID, batch) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, int64, int) []database.Repository); ok { + r0 = rf(ctx, repoType, lastRepoID, batch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, int64, int) error); ok { + r1 = rf(ctx, repoType, lastRepoID, batch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_BatchGet_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchGet' +type MockRepoStore_BatchGet_Call struct { + *mock.Call +} + +// BatchGet is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - lastRepoID int64 +// - batch int +func (_e *MockRepoStore_Expecter) BatchGet(ctx interface{}, repoType interface{}, lastRepoID interface{}, batch interface{}) *MockRepoStore_BatchGet_Call { + return &MockRepoStore_BatchGet_Call{Call: _e.mock.On("BatchGet", ctx, repoType, lastRepoID, batch)} +} + +func (_c *MockRepoStore_BatchGet_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, lastRepoID int64, batch int)) *MockRepoStore_BatchGet_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(int64), args[3].(int)) + }) + return _c +} + +func (_c *MockRepoStore_BatchGet_Call) Return(_a0 []database.Repository, _a1 error) *MockRepoStore_BatchGet_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_BatchGet_Call) RunAndReturn(run func(context.Context, types.RepositoryType, int64, int) ([]database.Repository, error)) *MockRepoStore_BatchGet_Call { + _c.Call.Return(run) + return _c +} + +// ByUser provides a mock function with given fields: ctx, userID +func (_m *MockRepoStore) ByUser(ctx context.Context, userID int64) ([]database.Repository, error) { + ret := _m.Called(ctx, userID) + + if len(ret) == 0 { + panic("no return value specified for ByUser") + } + + var r0 []database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.Repository, error)); ok { + return rf(ctx, userID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.Repository); ok { + r0 = rf(ctx, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_ByUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByUser' +type MockRepoStore_ByUser_Call struct { + *mock.Call +} + +// ByUser is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +func (_e *MockRepoStore_Expecter) ByUser(ctx interface{}, userID interface{}) *MockRepoStore_ByUser_Call { + return &MockRepoStore_ByUser_Call{Call: _e.mock.On("ByUser", ctx, userID)} +} + +func (_c *MockRepoStore_ByUser_Call) Run(run func(ctx context.Context, userID int64)) *MockRepoStore_ByUser_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepoStore_ByUser_Call) Return(_a0 []database.Repository, _a1 error) *MockRepoStore_ByUser_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_ByUser_Call) RunAndReturn(run func(context.Context, int64) ([]database.Repository, error)) *MockRepoStore_ByUser_Call { + _c.Call.Return(run) + return _c +} + +// CleanRelationsByRepoID provides a mock function with given fields: ctx, repoId +func (_m *MockRepoStore) CleanRelationsByRepoID(ctx context.Context, repoId int64) error { + ret := _m.Called(ctx, repoId) + + if len(ret) == 0 { + panic("no return value specified for CleanRelationsByRepoID") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, repoId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoStore_CleanRelationsByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CleanRelationsByRepoID' +type MockRepoStore_CleanRelationsByRepoID_Call struct { + *mock.Call +} + +// CleanRelationsByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - repoId int64 +func (_e *MockRepoStore_Expecter) CleanRelationsByRepoID(ctx interface{}, repoId interface{}) *MockRepoStore_CleanRelationsByRepoID_Call { + return &MockRepoStore_CleanRelationsByRepoID_Call{Call: _e.mock.On("CleanRelationsByRepoID", ctx, repoId)} +} + +func (_c *MockRepoStore_CleanRelationsByRepoID_Call) Run(run func(ctx context.Context, repoId int64)) *MockRepoStore_CleanRelationsByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepoStore_CleanRelationsByRepoID_Call) Return(_a0 error) *MockRepoStore_CleanRelationsByRepoID_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoStore_CleanRelationsByRepoID_Call) RunAndReturn(run func(context.Context, int64) error) *MockRepoStore_CleanRelationsByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// CountByRepoType provides a mock function with given fields: ctx, repoType +func (_m *MockRepoStore) CountByRepoType(ctx context.Context, repoType types.RepositoryType) (int, error) { + ret := _m.Called(ctx, repoType) + + if len(ret) == 0 { + panic("no return value specified for CountByRepoType") + } + + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType) (int, error)); ok { + return rf(ctx, repoType) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType) int); ok { + r0 = rf(ctx, repoType) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType) error); ok { + r1 = rf(ctx, repoType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_CountByRepoType_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CountByRepoType' +type MockRepoStore_CountByRepoType_Call struct { + *mock.Call +} + +// CountByRepoType is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +func (_e *MockRepoStore_Expecter) CountByRepoType(ctx interface{}, repoType interface{}) *MockRepoStore_CountByRepoType_Call { + return &MockRepoStore_CountByRepoType_Call{Call: _e.mock.On("CountByRepoType", ctx, repoType)} +} + +func (_c *MockRepoStore_CountByRepoType_Call) Run(run func(ctx context.Context, repoType types.RepositoryType)) *MockRepoStore_CountByRepoType_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType)) + }) + return _c +} + +func (_c *MockRepoStore_CountByRepoType_Call) Return(_a0 int, _a1 error) *MockRepoStore_CountByRepoType_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_CountByRepoType_Call) RunAndReturn(run func(context.Context, types.RepositoryType) (int, error)) *MockRepoStore_CountByRepoType_Call { + _c.Call.Return(run) + return _c +} + +// CreateRepo provides a mock function with given fields: ctx, input +func (_m *MockRepoStore) CreateRepo(ctx context.Context, input database.Repository) (*database.Repository, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for CreateRepo") + } + + var r0 *database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Repository) (*database.Repository, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Repository) *database.Repository); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Repository) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_CreateRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRepo' +type MockRepoStore_CreateRepo_Call struct { + *mock.Call +} + +// CreateRepo is a helper method to define mock.On call +// - ctx context.Context +// - input database.Repository +func (_e *MockRepoStore_Expecter) CreateRepo(ctx interface{}, input interface{}) *MockRepoStore_CreateRepo_Call { + return &MockRepoStore_CreateRepo_Call{Call: _e.mock.On("CreateRepo", ctx, input)} +} + +func (_c *MockRepoStore_CreateRepo_Call) Run(run func(ctx context.Context, input database.Repository)) *MockRepoStore_CreateRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Repository)) + }) + return _c +} + +func (_c *MockRepoStore_CreateRepo_Call) Return(_a0 *database.Repository, _a1 error) *MockRepoStore_CreateRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_CreateRepo_Call) RunAndReturn(run func(context.Context, database.Repository) (*database.Repository, error)) *MockRepoStore_CreateRepo_Call { + _c.Call.Return(run) + return _c +} + +// CreateRepoTx provides a mock function with given fields: ctx, tx, input +func (_m *MockRepoStore) CreateRepoTx(ctx context.Context, tx bun.Tx, input database.Repository) (*database.Repository, error) { + ret := _m.Called(ctx, tx, input) + + if len(ret) == 0 { + panic("no return value specified for CreateRepoTx") + } + + var r0 *database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, bun.Tx, database.Repository) (*database.Repository, error)); ok { + return rf(ctx, tx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, bun.Tx, database.Repository) *database.Repository); ok { + r0 = rf(ctx, tx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, bun.Tx, database.Repository) error); ok { + r1 = rf(ctx, tx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_CreateRepoTx_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRepoTx' +type MockRepoStore_CreateRepoTx_Call struct { + *mock.Call +} + +// CreateRepoTx is a helper method to define mock.On call +// - ctx context.Context +// - tx bun.Tx +// - input database.Repository +func (_e *MockRepoStore_Expecter) CreateRepoTx(ctx interface{}, tx interface{}, input interface{}) *MockRepoStore_CreateRepoTx_Call { + return &MockRepoStore_CreateRepoTx_Call{Call: _e.mock.On("CreateRepoTx", ctx, tx, input)} +} + +func (_c *MockRepoStore_CreateRepoTx_Call) Run(run func(ctx context.Context, tx bun.Tx, input database.Repository)) *MockRepoStore_CreateRepoTx_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(bun.Tx), args[2].(database.Repository)) + }) + return _c +} + +func (_c *MockRepoStore_CreateRepoTx_Call) Return(_a0 *database.Repository, _a1 error) *MockRepoStore_CreateRepoTx_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_CreateRepoTx_Call) RunAndReturn(run func(context.Context, bun.Tx, database.Repository) (*database.Repository, error)) *MockRepoStore_CreateRepoTx_Call { + _c.Call.Return(run) + return _c +} + +// DeleteAllFiles provides a mock function with given fields: ctx, repoID +func (_m *MockRepoStore) DeleteAllFiles(ctx context.Context, repoID int64) error { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for DeleteAllFiles") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, repoID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoStore_DeleteAllFiles_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllFiles' +type MockRepoStore_DeleteAllFiles_Call struct { + *mock.Call +} + +// DeleteAllFiles is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockRepoStore_Expecter) DeleteAllFiles(ctx interface{}, repoID interface{}) *MockRepoStore_DeleteAllFiles_Call { + return &MockRepoStore_DeleteAllFiles_Call{Call: _e.mock.On("DeleteAllFiles", ctx, repoID)} +} + +func (_c *MockRepoStore_DeleteAllFiles_Call) Run(run func(ctx context.Context, repoID int64)) *MockRepoStore_DeleteAllFiles_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepoStore_DeleteAllFiles_Call) Return(_a0 error) *MockRepoStore_DeleteAllFiles_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoStore_DeleteAllFiles_Call) RunAndReturn(run func(context.Context, int64) error) *MockRepoStore_DeleteAllFiles_Call { + _c.Call.Return(run) + return _c +} + +// DeleteAllTags provides a mock function with given fields: ctx, repoID +func (_m *MockRepoStore) DeleteAllTags(ctx context.Context, repoID int64) error { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for DeleteAllTags") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, repoID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoStore_DeleteAllTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAllTags' +type MockRepoStore_DeleteAllTags_Call struct { + *mock.Call +} + +// DeleteAllTags is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockRepoStore_Expecter) DeleteAllTags(ctx interface{}, repoID interface{}) *MockRepoStore_DeleteAllTags_Call { + return &MockRepoStore_DeleteAllTags_Call{Call: _e.mock.On("DeleteAllTags", ctx, repoID)} +} + +func (_c *MockRepoStore_DeleteAllTags_Call) Run(run func(ctx context.Context, repoID int64)) *MockRepoStore_DeleteAllTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepoStore_DeleteAllTags_Call) Return(_a0 error) *MockRepoStore_DeleteAllTags_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoStore_DeleteAllTags_Call) RunAndReturn(run func(context.Context, int64) error) *MockRepoStore_DeleteAllTags_Call { + _c.Call.Return(run) + return _c +} + +// DeleteRepo provides a mock function with given fields: ctx, input +func (_m *MockRepoStore) DeleteRepo(ctx context.Context, input database.Repository) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for DeleteRepo") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.Repository) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoStore_DeleteRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteRepo' +type MockRepoStore_DeleteRepo_Call struct { + *mock.Call +} + +// DeleteRepo is a helper method to define mock.On call +// - ctx context.Context +// - input database.Repository +func (_e *MockRepoStore_Expecter) DeleteRepo(ctx interface{}, input interface{}) *MockRepoStore_DeleteRepo_Call { + return &MockRepoStore_DeleteRepo_Call{Call: _e.mock.On("DeleteRepo", ctx, input)} +} + +func (_c *MockRepoStore_DeleteRepo_Call) Run(run func(ctx context.Context, input database.Repository)) *MockRepoStore_DeleteRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Repository)) + }) + return _c +} + +func (_c *MockRepoStore_DeleteRepo_Call) Return(_a0 error) *MockRepoStore_DeleteRepo_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoStore_DeleteRepo_Call) RunAndReturn(run func(context.Context, database.Repository) error) *MockRepoStore_DeleteRepo_Call { + _c.Call.Return(run) + return _c +} + +// Exists provides a mock function with given fields: ctx, repoType, namespace, name +func (_m *MockRepoStore) Exists(ctx context.Context, repoType types.RepositoryType, namespace string, name string) (bool, error) { + ret := _m.Called(ctx, repoType, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for Exists") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) (bool, error)); ok { + return rf(ctx, repoType, namespace, name) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) bool); ok { + r0 = rf(ctx, repoType, namespace, name) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string) error); ok { + r1 = rf(ctx, repoType, namespace, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_Exists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Exists' +type MockRepoStore_Exists_Call struct { + *mock.Call +} + +// Exists is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +func (_e *MockRepoStore_Expecter) Exists(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}) *MockRepoStore_Exists_Call { + return &MockRepoStore_Exists_Call{Call: _e.mock.On("Exists", ctx, repoType, namespace, name)} +} + +func (_c *MockRepoStore_Exists_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string)) *MockRepoStore_Exists_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockRepoStore_Exists_Call) Return(_a0 bool, _a1 error) *MockRepoStore_Exists_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_Exists_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string) (bool, error)) *MockRepoStore_Exists_Call { + _c.Call.Return(run) + return _c +} + +// Find provides a mock function with given fields: ctx, owner, repoType, repoName +func (_m *MockRepoStore) Find(ctx context.Context, owner string, repoType string, repoName string) (*database.Repository, error) { + ret := _m.Called(ctx, owner, repoType, repoName) + + if len(ret) == 0 { + panic("no return value specified for Find") + } + + var r0 *database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) (*database.Repository, error)); ok { + return rf(ctx, owner, repoType, repoName) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *database.Repository); ok { + r0 = rf(ctx, owner, repoType, repoName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { + r1 = rf(ctx, owner, repoType, repoName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_Find_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Find' +type MockRepoStore_Find_Call struct { + *mock.Call +} + +// Find is a helper method to define mock.On call +// - ctx context.Context +// - owner string +// - repoType string +// - repoName string +func (_e *MockRepoStore_Expecter) Find(ctx interface{}, owner interface{}, repoType interface{}, repoName interface{}) *MockRepoStore_Find_Call { + return &MockRepoStore_Find_Call{Call: _e.mock.On("Find", ctx, owner, repoType, repoName)} +} + +func (_c *MockRepoStore_Find_Call) Run(run func(ctx context.Context, owner string, repoType string, repoName string)) *MockRepoStore_Find_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockRepoStore_Find_Call) Return(_a0 *database.Repository, _a1 error) *MockRepoStore_Find_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_Find_Call) RunAndReturn(run func(context.Context, string, string, string) (*database.Repository, error)) *MockRepoStore_Find_Call { + _c.Call.Return(run) + return _c +} + +// FindByGitPath provides a mock function with given fields: ctx, path +func (_m *MockRepoStore) FindByGitPath(ctx context.Context, path string) (*database.Repository, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for FindByGitPath") + } + + var r0 *database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.Repository, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.Repository); ok { + r0 = rf(ctx, path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_FindByGitPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByGitPath' +type MockRepoStore_FindByGitPath_Call struct { + *mock.Call +} + +// FindByGitPath is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *MockRepoStore_Expecter) FindByGitPath(ctx interface{}, path interface{}) *MockRepoStore_FindByGitPath_Call { + return &MockRepoStore_FindByGitPath_Call{Call: _e.mock.On("FindByGitPath", ctx, path)} +} + +func (_c *MockRepoStore_FindByGitPath_Call) Run(run func(ctx context.Context, path string)) *MockRepoStore_FindByGitPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockRepoStore_FindByGitPath_Call) Return(_a0 *database.Repository, _a1 error) *MockRepoStore_FindByGitPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_FindByGitPath_Call) RunAndReturn(run func(context.Context, string) (*database.Repository, error)) *MockRepoStore_FindByGitPath_Call { + _c.Call.Return(run) + return _c +} + +// FindByGitPaths provides a mock function with given fields: ctx, paths, opts +func (_m *MockRepoStore) FindByGitPaths(ctx context.Context, paths []string, opts ...database.SelectOption) ([]*database.Repository, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, paths) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for FindByGitPaths") + } + + var r0 []*database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []string, ...database.SelectOption) ([]*database.Repository, error)); ok { + return rf(ctx, paths, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, []string, ...database.SelectOption) []*database.Repository); ok { + r0 = rf(ctx, paths, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []string, ...database.SelectOption) error); ok { + r1 = rf(ctx, paths, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_FindByGitPaths_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByGitPaths' +type MockRepoStore_FindByGitPaths_Call struct { + *mock.Call +} + +// FindByGitPaths is a helper method to define mock.On call +// - ctx context.Context +// - paths []string +// - opts ...database.SelectOption +func (_e *MockRepoStore_Expecter) FindByGitPaths(ctx interface{}, paths interface{}, opts ...interface{}) *MockRepoStore_FindByGitPaths_Call { + return &MockRepoStore_FindByGitPaths_Call{Call: _e.mock.On("FindByGitPaths", + append([]interface{}{ctx, paths}, opts...)...)} +} + +func (_c *MockRepoStore_FindByGitPaths_Call) Run(run func(ctx context.Context, paths []string, opts ...database.SelectOption)) *MockRepoStore_FindByGitPaths_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]database.SelectOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(database.SelectOption) + } + } + run(args[0].(context.Context), args[1].([]string), variadicArgs...) + }) + return _c +} + +func (_c *MockRepoStore_FindByGitPaths_Call) Return(_a0 []*database.Repository, _a1 error) *MockRepoStore_FindByGitPaths_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_FindByGitPaths_Call) RunAndReturn(run func(context.Context, []string, ...database.SelectOption) ([]*database.Repository, error)) *MockRepoStore_FindByGitPaths_Call { + _c.Call.Return(run) + return _c +} + +// FindById provides a mock function with given fields: ctx, id +func (_m *MockRepoStore) FindById(ctx context.Context, id int64) (*database.Repository, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for FindById") + } + + var r0 *database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Repository, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Repository); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_FindById_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindById' +type MockRepoStore_FindById_Call struct { + *mock.Call +} + +// FindById is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockRepoStore_Expecter) FindById(ctx interface{}, id interface{}) *MockRepoStore_FindById_Call { + return &MockRepoStore_FindById_Call{Call: _e.mock.On("FindById", ctx, id)} +} + +func (_c *MockRepoStore_FindById_Call) Run(run func(ctx context.Context, id int64)) *MockRepoStore_FindById_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepoStore_FindById_Call) Return(_a0 *database.Repository, _a1 error) *MockRepoStore_FindById_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_FindById_Call) RunAndReturn(run func(context.Context, int64) (*database.Repository, error)) *MockRepoStore_FindById_Call { + _c.Call.Return(run) + return _c +} + +// FindByIds provides a mock function with given fields: ctx, ids, opts +func (_m *MockRepoStore) FindByIds(ctx context.Context, ids []int64, opts ...database.SelectOption) ([]*database.Repository, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, ids) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for FindByIds") + } + + var r0 []*database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []int64, ...database.SelectOption) ([]*database.Repository, error)); ok { + return rf(ctx, ids, opts...) + } + if rf, ok := ret.Get(0).(func(context.Context, []int64, ...database.SelectOption) []*database.Repository); ok { + r0 = rf(ctx, ids, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []int64, ...database.SelectOption) error); ok { + r1 = rf(ctx, ids, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_FindByIds_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByIds' +type MockRepoStore_FindByIds_Call struct { + *mock.Call +} + +// FindByIds is a helper method to define mock.On call +// - ctx context.Context +// - ids []int64 +// - opts ...database.SelectOption +func (_e *MockRepoStore_Expecter) FindByIds(ctx interface{}, ids interface{}, opts ...interface{}) *MockRepoStore_FindByIds_Call { + return &MockRepoStore_FindByIds_Call{Call: _e.mock.On("FindByIds", + append([]interface{}{ctx, ids}, opts...)...)} +} + +func (_c *MockRepoStore_FindByIds_Call) Run(run func(ctx context.Context, ids []int64, opts ...database.SelectOption)) *MockRepoStore_FindByIds_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]database.SelectOption, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(database.SelectOption) + } + } + run(args[0].(context.Context), args[1].([]int64), variadicArgs...) + }) + return _c +} + +func (_c *MockRepoStore_FindByIds_Call) Return(_a0 []*database.Repository, _a1 error) *MockRepoStore_FindByIds_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_FindByIds_Call) RunAndReturn(run func(context.Context, []int64, ...database.SelectOption) ([]*database.Repository, error)) *MockRepoStore_FindByIds_Call { + _c.Call.Return(run) + return _c +} + +// FindByPath provides a mock function with given fields: ctx, repoType, namespace, name +func (_m *MockRepoStore) FindByPath(ctx context.Context, repoType types.RepositoryType, namespace string, name string) (*database.Repository, error) { + ret := _m.Called(ctx, repoType, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for FindByPath") + } + + var r0 *database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) (*database.Repository, error)); ok { + return rf(ctx, repoType, namespace, name) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) *database.Repository); ok { + r0 = rf(ctx, repoType, namespace, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string) error); ok { + r1 = rf(ctx, repoType, namespace, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_FindByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByPath' +type MockRepoStore_FindByPath_Call struct { + *mock.Call +} + +// FindByPath is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +func (_e *MockRepoStore_Expecter) FindByPath(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}) *MockRepoStore_FindByPath_Call { + return &MockRepoStore_FindByPath_Call{Call: _e.mock.On("FindByPath", ctx, repoType, namespace, name)} +} + +func (_c *MockRepoStore_FindByPath_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string)) *MockRepoStore_FindByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockRepoStore_FindByPath_Call) Return(_a0 *database.Repository, _a1 error) *MockRepoStore_FindByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_FindByPath_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string) (*database.Repository, error)) *MockRepoStore_FindByPath_Call { + _c.Call.Return(run) + return _c +} + +// FindByRepoSourceWithBatch provides a mock function with given fields: ctx, repoSource, batchSize, batch +func (_m *MockRepoStore) FindByRepoSourceWithBatch(ctx context.Context, repoSource types.RepositorySource, batchSize int, batch int) ([]database.Repository, error) { + ret := _m.Called(ctx, repoSource, batchSize, batch) + + if len(ret) == 0 { + panic("no return value specified for FindByRepoSourceWithBatch") + } + + var r0 []database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositorySource, int, int) ([]database.Repository, error)); ok { + return rf(ctx, repoSource, batchSize, batch) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositorySource, int, int) []database.Repository); ok { + r0 = rf(ctx, repoSource, batchSize, batch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositorySource, int, int) error); ok { + r1 = rf(ctx, repoSource, batchSize, batch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_FindByRepoSourceWithBatch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByRepoSourceWithBatch' +type MockRepoStore_FindByRepoSourceWithBatch_Call struct { + *mock.Call +} + +// FindByRepoSourceWithBatch is a helper method to define mock.On call +// - ctx context.Context +// - repoSource types.RepositorySource +// - batchSize int +// - batch int +func (_e *MockRepoStore_Expecter) FindByRepoSourceWithBatch(ctx interface{}, repoSource interface{}, batchSize interface{}, batch interface{}) *MockRepoStore_FindByRepoSourceWithBatch_Call { + return &MockRepoStore_FindByRepoSourceWithBatch_Call{Call: _e.mock.On("FindByRepoSourceWithBatch", ctx, repoSource, batchSize, batch)} +} + +func (_c *MockRepoStore_FindByRepoSourceWithBatch_Call) Run(run func(ctx context.Context, repoSource types.RepositorySource, batchSize int, batch int)) *MockRepoStore_FindByRepoSourceWithBatch_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositorySource), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockRepoStore_FindByRepoSourceWithBatch_Call) Return(_a0 []database.Repository, _a1 error) *MockRepoStore_FindByRepoSourceWithBatch_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_FindByRepoSourceWithBatch_Call) RunAndReturn(run func(context.Context, types.RepositorySource, int, int) ([]database.Repository, error)) *MockRepoStore_FindByRepoSourceWithBatch_Call { + _c.Call.Return(run) + return _c +} + +// FindWithBatch provides a mock function with given fields: ctx, batchSize, batch +func (_m *MockRepoStore) FindWithBatch(ctx context.Context, batchSize int, batch int) ([]database.Repository, error) { + ret := _m.Called(ctx, batchSize, batch) + + if len(ret) == 0 { + panic("no return value specified for FindWithBatch") + } + + var r0 []database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int, int) ([]database.Repository, error)); ok { + return rf(ctx, batchSize, batch) + } + if rf, ok := ret.Get(0).(func(context.Context, int, int) []database.Repository); ok { + r0 = rf(ctx, batchSize, batch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int, int) error); ok { + r1 = rf(ctx, batchSize, batch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_FindWithBatch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindWithBatch' +type MockRepoStore_FindWithBatch_Call struct { + *mock.Call +} + +// FindWithBatch is a helper method to define mock.On call +// - ctx context.Context +// - batchSize int +// - batch int +func (_e *MockRepoStore_Expecter) FindWithBatch(ctx interface{}, batchSize interface{}, batch interface{}) *MockRepoStore_FindWithBatch_Call { + return &MockRepoStore_FindWithBatch_Call{Call: _e.mock.On("FindWithBatch", ctx, batchSize, batch)} +} + +func (_c *MockRepoStore_FindWithBatch_Call) Run(run func(ctx context.Context, batchSize int, batch int)) *MockRepoStore_FindWithBatch_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int), args[2].(int)) + }) + return _c +} + +func (_c *MockRepoStore_FindWithBatch_Call) Return(_a0 []database.Repository, _a1 error) *MockRepoStore_FindWithBatch_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_FindWithBatch_Call) RunAndReturn(run func(context.Context, int, int) ([]database.Repository, error)) *MockRepoStore_FindWithBatch_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoWithRuntimeByID provides a mock function with given fields: ctx, rfID, paths +func (_m *MockRepoStore) GetRepoWithRuntimeByID(ctx context.Context, rfID int64, paths []string) ([]database.Repository, error) { + ret := _m.Called(ctx, rfID, paths) + + if len(ret) == 0 { + panic("no return value specified for GetRepoWithRuntimeByID") + } + + var r0 []database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, []string) ([]database.Repository, error)); ok { + return rf(ctx, rfID, paths) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, []string) []database.Repository); ok { + r0 = rf(ctx, rfID, paths) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, []string) error); ok { + r1 = rf(ctx, rfID, paths) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_GetRepoWithRuntimeByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoWithRuntimeByID' +type MockRepoStore_GetRepoWithRuntimeByID_Call struct { + *mock.Call +} + +// GetRepoWithRuntimeByID is a helper method to define mock.On call +// - ctx context.Context +// - rfID int64 +// - paths []string +func (_e *MockRepoStore_Expecter) GetRepoWithRuntimeByID(ctx interface{}, rfID interface{}, paths interface{}) *MockRepoStore_GetRepoWithRuntimeByID_Call { + return &MockRepoStore_GetRepoWithRuntimeByID_Call{Call: _e.mock.On("GetRepoWithRuntimeByID", ctx, rfID, paths)} +} + +func (_c *MockRepoStore_GetRepoWithRuntimeByID_Call) Run(run func(ctx context.Context, rfID int64, paths []string)) *MockRepoStore_GetRepoWithRuntimeByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].([]string)) + }) + return _c +} + +func (_c *MockRepoStore_GetRepoWithRuntimeByID_Call) Return(_a0 []database.Repository, _a1 error) *MockRepoStore_GetRepoWithRuntimeByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_GetRepoWithRuntimeByID_Call) RunAndReturn(run func(context.Context, int64, []string) ([]database.Repository, error)) *MockRepoStore_GetRepoWithRuntimeByID_Call { + _c.Call.Return(run) + return _c +} + +// GetRepoWithoutRuntimeByID provides a mock function with given fields: ctx, rfID, paths +func (_m *MockRepoStore) GetRepoWithoutRuntimeByID(ctx context.Context, rfID int64, paths []string) ([]database.Repository, error) { + ret := _m.Called(ctx, rfID, paths) + + if len(ret) == 0 { + panic("no return value specified for GetRepoWithoutRuntimeByID") + } + + var r0 []database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, []string) ([]database.Repository, error)); ok { + return rf(ctx, rfID, paths) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, []string) []database.Repository); ok { + r0 = rf(ctx, rfID, paths) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, []string) error); ok { + r1 = rf(ctx, rfID, paths) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_GetRepoWithoutRuntimeByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRepoWithoutRuntimeByID' +type MockRepoStore_GetRepoWithoutRuntimeByID_Call struct { + *mock.Call +} + +// GetRepoWithoutRuntimeByID is a helper method to define mock.On call +// - ctx context.Context +// - rfID int64 +// - paths []string +func (_e *MockRepoStore_Expecter) GetRepoWithoutRuntimeByID(ctx interface{}, rfID interface{}, paths interface{}) *MockRepoStore_GetRepoWithoutRuntimeByID_Call { + return &MockRepoStore_GetRepoWithoutRuntimeByID_Call{Call: _e.mock.On("GetRepoWithoutRuntimeByID", ctx, rfID, paths)} +} + +func (_c *MockRepoStore_GetRepoWithoutRuntimeByID_Call) Run(run func(ctx context.Context, rfID int64, paths []string)) *MockRepoStore_GetRepoWithoutRuntimeByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].([]string)) + }) + return _c +} + +func (_c *MockRepoStore_GetRepoWithoutRuntimeByID_Call) Return(_a0 []database.Repository, _a1 error) *MockRepoStore_GetRepoWithoutRuntimeByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_GetRepoWithoutRuntimeByID_Call) RunAndReturn(run func(context.Context, int64, []string) ([]database.Repository, error)) *MockRepoStore_GetRepoWithoutRuntimeByID_Call { + _c.Call.Return(run) + return _c +} + +// IsMirrorRepo provides a mock function with given fields: ctx, repoType, namespace, name +func (_m *MockRepoStore) IsMirrorRepo(ctx context.Context, repoType types.RepositoryType, namespace string, name string) (bool, error) { + ret := _m.Called(ctx, repoType, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for IsMirrorRepo") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) (bool, error)); ok { + return rf(ctx, repoType, namespace, name) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) bool); ok { + r0 = rf(ctx, repoType, namespace, name) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string) error); ok { + r1 = rf(ctx, repoType, namespace, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_IsMirrorRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsMirrorRepo' +type MockRepoStore_IsMirrorRepo_Call struct { + *mock.Call +} + +// IsMirrorRepo is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +func (_e *MockRepoStore_Expecter) IsMirrorRepo(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}) *MockRepoStore_IsMirrorRepo_Call { + return &MockRepoStore_IsMirrorRepo_Call{Call: _e.mock.On("IsMirrorRepo", ctx, repoType, namespace, name)} +} + +func (_c *MockRepoStore_IsMirrorRepo_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string)) *MockRepoStore_IsMirrorRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockRepoStore_IsMirrorRepo_Call) Return(_a0 bool, _a1 error) *MockRepoStore_IsMirrorRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_IsMirrorRepo_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string) (bool, error)) *MockRepoStore_IsMirrorRepo_Call { + _c.Call.Return(run) + return _c +} + +// ListRepoPublicToUserByRepoIDs provides a mock function with given fields: ctx, repoType, userID, search, sort, per, page, repoIDs +func (_m *MockRepoStore) ListRepoPublicToUserByRepoIDs(ctx context.Context, repoType types.RepositoryType, userID int64, search string, sort string, per int, page int, repoIDs []int64) ([]*database.Repository, int, error) { + ret := _m.Called(ctx, repoType, userID, search, sort, per, page, repoIDs) + + if len(ret) == 0 { + panic("no return value specified for ListRepoPublicToUserByRepoIDs") + } + + var r0 []*database.Repository + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, int64, string, string, int, int, []int64) ([]*database.Repository, int, error)); ok { + return rf(ctx, repoType, userID, search, sort, per, page, repoIDs) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, int64, string, string, int, int, []int64) []*database.Repository); ok { + r0 = rf(ctx, repoType, userID, search, sort, per, page, repoIDs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, int64, string, string, int, int, []int64) int); ok { + r1 = rf(ctx, repoType, userID, search, sort, per, page, repoIDs) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, types.RepositoryType, int64, string, string, int, int, []int64) error); ok { + r2 = rf(ctx, repoType, userID, search, sort, per, page, repoIDs) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockRepoStore_ListRepoPublicToUserByRepoIDs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListRepoPublicToUserByRepoIDs' +type MockRepoStore_ListRepoPublicToUserByRepoIDs_Call struct { + *mock.Call +} + +// ListRepoPublicToUserByRepoIDs is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - userID int64 +// - search string +// - sort string +// - per int +// - page int +// - repoIDs []int64 +func (_e *MockRepoStore_Expecter) ListRepoPublicToUserByRepoIDs(ctx interface{}, repoType interface{}, userID interface{}, search interface{}, sort interface{}, per interface{}, page interface{}, repoIDs interface{}) *MockRepoStore_ListRepoPublicToUserByRepoIDs_Call { + return &MockRepoStore_ListRepoPublicToUserByRepoIDs_Call{Call: _e.mock.On("ListRepoPublicToUserByRepoIDs", ctx, repoType, userID, search, sort, per, page, repoIDs)} +} + +func (_c *MockRepoStore_ListRepoPublicToUserByRepoIDs_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, userID int64, search string, sort string, per int, page int, repoIDs []int64)) *MockRepoStore_ListRepoPublicToUserByRepoIDs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(int64), args[3].(string), args[4].(string), args[5].(int), args[6].(int), args[7].([]int64)) + }) + return _c +} + +func (_c *MockRepoStore_ListRepoPublicToUserByRepoIDs_Call) Return(repos []*database.Repository, count int, err error) *MockRepoStore_ListRepoPublicToUserByRepoIDs_Call { + _c.Call.Return(repos, count, err) + return _c +} + +func (_c *MockRepoStore_ListRepoPublicToUserByRepoIDs_Call) RunAndReturn(run func(context.Context, types.RepositoryType, int64, string, string, int, int, []int64) ([]*database.Repository, int, error)) *MockRepoStore_ListRepoPublicToUserByRepoIDs_Call { + _c.Call.Return(run) + return _c +} + +// PublicToUser provides a mock function with given fields: ctx, repoType, userIDs, filter, per, page +func (_m *MockRepoStore) PublicToUser(ctx context.Context, repoType types.RepositoryType, userIDs []int64, filter *types.RepoFilter, per int, page int) ([]*database.Repository, int, error) { + ret := _m.Called(ctx, repoType, userIDs, filter, per, page) + + if len(ret) == 0 { + panic("no return value specified for PublicToUser") + } + + var r0 []*database.Repository + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, []int64, *types.RepoFilter, int, int) ([]*database.Repository, int, error)); ok { + return rf(ctx, repoType, userIDs, filter, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, []int64, *types.RepoFilter, int, int) []*database.Repository); ok { + r0 = rf(ctx, repoType, userIDs, filter, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, []int64, *types.RepoFilter, int, int) int); ok { + r1 = rf(ctx, repoType, userIDs, filter, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, types.RepositoryType, []int64, *types.RepoFilter, int, int) error); ok { + r2 = rf(ctx, repoType, userIDs, filter, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockRepoStore_PublicToUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublicToUser' +type MockRepoStore_PublicToUser_Call struct { + *mock.Call +} + +// PublicToUser is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - userIDs []int64 +// - filter *types.RepoFilter +// - per int +// - page int +func (_e *MockRepoStore_Expecter) PublicToUser(ctx interface{}, repoType interface{}, userIDs interface{}, filter interface{}, per interface{}, page interface{}) *MockRepoStore_PublicToUser_Call { + return &MockRepoStore_PublicToUser_Call{Call: _e.mock.On("PublicToUser", ctx, repoType, userIDs, filter, per, page)} +} + +func (_c *MockRepoStore_PublicToUser_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, userIDs []int64, filter *types.RepoFilter, per int, page int)) *MockRepoStore_PublicToUser_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].([]int64), args[3].(*types.RepoFilter), args[4].(int), args[5].(int)) + }) + return _c +} + +func (_c *MockRepoStore_PublicToUser_Call) Return(repos []*database.Repository, count int, err error) *MockRepoStore_PublicToUser_Call { + _c.Call.Return(repos, count, err) + return _c +} + +func (_c *MockRepoStore_PublicToUser_Call) RunAndReturn(run func(context.Context, types.RepositoryType, []int64, *types.RepoFilter, int, int) ([]*database.Repository, int, error)) *MockRepoStore_PublicToUser_Call { + _c.Call.Return(run) + return _c +} + +// SetUpdateTimeByPath provides a mock function with given fields: ctx, repoType, namespace, name, update +func (_m *MockRepoStore) SetUpdateTimeByPath(ctx context.Context, repoType types.RepositoryType, namespace string, name string, update time.Time) error { + ret := _m.Called(ctx, repoType, namespace, name, update) + + if len(ret) == 0 { + panic("no return value specified for SetUpdateTimeByPath") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, time.Time) error); ok { + r0 = rf(ctx, repoType, namespace, name, update) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoStore_SetUpdateTimeByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetUpdateTimeByPath' +type MockRepoStore_SetUpdateTimeByPath_Call struct { + *mock.Call +} + +// SetUpdateTimeByPath is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - update time.Time +func (_e *MockRepoStore_Expecter) SetUpdateTimeByPath(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, update interface{}) *MockRepoStore_SetUpdateTimeByPath_Call { + return &MockRepoStore_SetUpdateTimeByPath_Call{Call: _e.mock.On("SetUpdateTimeByPath", ctx, repoType, namespace, name, update)} +} + +func (_c *MockRepoStore_SetUpdateTimeByPath_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, update time.Time)) *MockRepoStore_SetUpdateTimeByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(time.Time)) + }) + return _c +} + +func (_c *MockRepoStore_SetUpdateTimeByPath_Call) Return(_a0 error) *MockRepoStore_SetUpdateTimeByPath_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoStore_SetUpdateTimeByPath_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, time.Time) error) *MockRepoStore_SetUpdateTimeByPath_Call { + _c.Call.Return(run) + return _c +} + +// TagIDs provides a mock function with given fields: ctx, repoID, category +func (_m *MockRepoStore) TagIDs(ctx context.Context, repoID int64, category string) ([]int64, error) { + ret := _m.Called(ctx, repoID, category) + + if len(ret) == 0 { + panic("no return value specified for TagIDs") + } + + var r0 []int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) ([]int64, error)); ok { + return rf(ctx, repoID, category) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, string) []int64); ok { + r0 = rf(ctx, repoID, category) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]int64) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, string) error); ok { + r1 = rf(ctx, repoID, category) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_TagIDs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TagIDs' +type MockRepoStore_TagIDs_Call struct { + *mock.Call +} + +// TagIDs is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - category string +func (_e *MockRepoStore_Expecter) TagIDs(ctx interface{}, repoID interface{}, category interface{}) *MockRepoStore_TagIDs_Call { + return &MockRepoStore_TagIDs_Call{Call: _e.mock.On("TagIDs", ctx, repoID, category)} +} + +func (_c *MockRepoStore_TagIDs_Call) Run(run func(ctx context.Context, repoID int64, category string)) *MockRepoStore_TagIDs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockRepoStore_TagIDs_Call) Return(tagIDs []int64, err error) *MockRepoStore_TagIDs_Call { + _c.Call.Return(tagIDs, err) + return _c +} + +func (_c *MockRepoStore_TagIDs_Call) RunAndReturn(run func(context.Context, int64, string) ([]int64, error)) *MockRepoStore_TagIDs_Call { + _c.Call.Return(run) + return _c +} + +// Tags provides a mock function with given fields: ctx, repoID +func (_m *MockRepoStore) Tags(ctx context.Context, repoID int64) ([]database.Tag, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for Tags") + } + + var r0 []database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.Tag, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.Tag); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_Tags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Tags' +type MockRepoStore_Tags_Call struct { + *mock.Call +} + +// Tags is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockRepoStore_Expecter) Tags(ctx interface{}, repoID interface{}) *MockRepoStore_Tags_Call { + return &MockRepoStore_Tags_Call{Call: _e.mock.On("Tags", ctx, repoID)} +} + +func (_c *MockRepoStore_Tags_Call) Run(run func(ctx context.Context, repoID int64)) *MockRepoStore_Tags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepoStore_Tags_Call) Return(tags []database.Tag, err error) *MockRepoStore_Tags_Call { + _c.Call.Return(tags, err) + return _c +} + +func (_c *MockRepoStore_Tags_Call) RunAndReturn(run func(context.Context, int64) ([]database.Tag, error)) *MockRepoStore_Tags_Call { + _c.Call.Return(run) + return _c +} + +// TagsWithCategory provides a mock function with given fields: ctx, repoID, category +func (_m *MockRepoStore) TagsWithCategory(ctx context.Context, repoID int64, category string) ([]database.Tag, error) { + ret := _m.Called(ctx, repoID, category) + + if len(ret) == 0 { + panic("no return value specified for TagsWithCategory") + } + + var r0 []database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) ([]database.Tag, error)); ok { + return rf(ctx, repoID, category) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, string) []database.Tag); ok { + r0 = rf(ctx, repoID, category) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, string) error); ok { + r1 = rf(ctx, repoID, category) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_TagsWithCategory_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TagsWithCategory' +type MockRepoStore_TagsWithCategory_Call struct { + *mock.Call +} + +// TagsWithCategory is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - category string +func (_e *MockRepoStore_Expecter) TagsWithCategory(ctx interface{}, repoID interface{}, category interface{}) *MockRepoStore_TagsWithCategory_Call { + return &MockRepoStore_TagsWithCategory_Call{Call: _e.mock.On("TagsWithCategory", ctx, repoID, category)} +} + +func (_c *MockRepoStore_TagsWithCategory_Call) Run(run func(ctx context.Context, repoID int64, category string)) *MockRepoStore_TagsWithCategory_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockRepoStore_TagsWithCategory_Call) Return(tags []database.Tag, err error) *MockRepoStore_TagsWithCategory_Call { + _c.Call.Return(tags, err) + return _c +} + +func (_c *MockRepoStore_TagsWithCategory_Call) RunAndReturn(run func(context.Context, int64, string) ([]database.Tag, error)) *MockRepoStore_TagsWithCategory_Call { + _c.Call.Return(run) + return _c +} + +// UpdateDownloads provides a mock function with given fields: ctx, repo +func (_m *MockRepoStore) UpdateDownloads(ctx context.Context, repo *database.Repository) error { + ret := _m.Called(ctx, repo) + + if len(ret) == 0 { + panic("no return value specified for UpdateDownloads") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Repository) error); ok { + r0 = rf(ctx, repo) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoStore_UpdateDownloads_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateDownloads' +type MockRepoStore_UpdateDownloads_Call struct { + *mock.Call +} + +// UpdateDownloads is a helper method to define mock.On call +// - ctx context.Context +// - repo *database.Repository +func (_e *MockRepoStore_Expecter) UpdateDownloads(ctx interface{}, repo interface{}) *MockRepoStore_UpdateDownloads_Call { + return &MockRepoStore_UpdateDownloads_Call{Call: _e.mock.On("UpdateDownloads", ctx, repo)} +} + +func (_c *MockRepoStore_UpdateDownloads_Call) Run(run func(ctx context.Context, repo *database.Repository)) *MockRepoStore_UpdateDownloads_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Repository)) + }) + return _c +} + +func (_c *MockRepoStore_UpdateDownloads_Call) Return(_a0 error) *MockRepoStore_UpdateDownloads_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoStore_UpdateDownloads_Call) RunAndReturn(run func(context.Context, *database.Repository) error) *MockRepoStore_UpdateDownloads_Call { + _c.Call.Return(run) + return _c +} + +// UpdateLicenseByTag provides a mock function with given fields: ctx, repoID +func (_m *MockRepoStore) UpdateLicenseByTag(ctx context.Context, repoID int64) error { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for UpdateLicenseByTag") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, repoID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoStore_UpdateLicenseByTag_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateLicenseByTag' +type MockRepoStore_UpdateLicenseByTag_Call struct { + *mock.Call +} + +// UpdateLicenseByTag is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockRepoStore_Expecter) UpdateLicenseByTag(ctx interface{}, repoID interface{}) *MockRepoStore_UpdateLicenseByTag_Call { + return &MockRepoStore_UpdateLicenseByTag_Call{Call: _e.mock.On("UpdateLicenseByTag", ctx, repoID)} +} + +func (_c *MockRepoStore_UpdateLicenseByTag_Call) Run(run func(ctx context.Context, repoID int64)) *MockRepoStore_UpdateLicenseByTag_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepoStore_UpdateLicenseByTag_Call) Return(_a0 error) *MockRepoStore_UpdateLicenseByTag_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoStore_UpdateLicenseByTag_Call) RunAndReturn(run func(context.Context, int64) error) *MockRepoStore_UpdateLicenseByTag_Call { + _c.Call.Return(run) + return _c +} + +// UpdateOrCreateRepo provides a mock function with given fields: ctx, input +func (_m *MockRepoStore) UpdateOrCreateRepo(ctx context.Context, input database.Repository) (*database.Repository, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for UpdateOrCreateRepo") + } + + var r0 *database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Repository) (*database.Repository, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Repository) *database.Repository); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Repository) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_UpdateOrCreateRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateOrCreateRepo' +type MockRepoStore_UpdateOrCreateRepo_Call struct { + *mock.Call +} + +// UpdateOrCreateRepo is a helper method to define mock.On call +// - ctx context.Context +// - input database.Repository +func (_e *MockRepoStore_Expecter) UpdateOrCreateRepo(ctx interface{}, input interface{}) *MockRepoStore_UpdateOrCreateRepo_Call { + return &MockRepoStore_UpdateOrCreateRepo_Call{Call: _e.mock.On("UpdateOrCreateRepo", ctx, input)} +} + +func (_c *MockRepoStore_UpdateOrCreateRepo_Call) Run(run func(ctx context.Context, input database.Repository)) *MockRepoStore_UpdateOrCreateRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Repository)) + }) + return _c +} + +func (_c *MockRepoStore_UpdateOrCreateRepo_Call) Return(_a0 *database.Repository, _a1 error) *MockRepoStore_UpdateOrCreateRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_UpdateOrCreateRepo_Call) RunAndReturn(run func(context.Context, database.Repository) (*database.Repository, error)) *MockRepoStore_UpdateOrCreateRepo_Call { + _c.Call.Return(run) + return _c +} + +// UpdateRepo provides a mock function with given fields: ctx, input +func (_m *MockRepoStore) UpdateRepo(ctx context.Context, input database.Repository) (*database.Repository, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for UpdateRepo") + } + + var r0 *database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Repository) (*database.Repository, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Repository) *database.Repository); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Repository) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoStore_UpdateRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateRepo' +type MockRepoStore_UpdateRepo_Call struct { + *mock.Call +} + +// UpdateRepo is a helper method to define mock.On call +// - ctx context.Context +// - input database.Repository +func (_e *MockRepoStore_Expecter) UpdateRepo(ctx interface{}, input interface{}) *MockRepoStore_UpdateRepo_Call { + return &MockRepoStore_UpdateRepo_Call{Call: _e.mock.On("UpdateRepo", ctx, input)} +} + +func (_c *MockRepoStore_UpdateRepo_Call) Run(run func(ctx context.Context, input database.Repository)) *MockRepoStore_UpdateRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Repository)) + }) + return _c +} + +func (_c *MockRepoStore_UpdateRepo_Call) Return(_a0 *database.Repository, _a1 error) *MockRepoStore_UpdateRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoStore_UpdateRepo_Call) RunAndReturn(run func(context.Context, database.Repository) (*database.Repository, error)) *MockRepoStore_UpdateRepo_Call { + _c.Call.Return(run) + return _c +} + +// UpdateRepoCloneDownloads provides a mock function with given fields: ctx, repo, date, cloneCount +func (_m *MockRepoStore) UpdateRepoCloneDownloads(ctx context.Context, repo *database.Repository, date time.Time, cloneCount int64) error { + ret := _m.Called(ctx, repo, date, cloneCount) + + if len(ret) == 0 { + panic("no return value specified for UpdateRepoCloneDownloads") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Repository, time.Time, int64) error); ok { + r0 = rf(ctx, repo, date, cloneCount) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoStore_UpdateRepoCloneDownloads_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateRepoCloneDownloads' +type MockRepoStore_UpdateRepoCloneDownloads_Call struct { + *mock.Call +} + +// UpdateRepoCloneDownloads is a helper method to define mock.On call +// - ctx context.Context +// - repo *database.Repository +// - date time.Time +// - cloneCount int64 +func (_e *MockRepoStore_Expecter) UpdateRepoCloneDownloads(ctx interface{}, repo interface{}, date interface{}, cloneCount interface{}) *MockRepoStore_UpdateRepoCloneDownloads_Call { + return &MockRepoStore_UpdateRepoCloneDownloads_Call{Call: _e.mock.On("UpdateRepoCloneDownloads", ctx, repo, date, cloneCount)} +} + +func (_c *MockRepoStore_UpdateRepoCloneDownloads_Call) Run(run func(ctx context.Context, repo *database.Repository, date time.Time, cloneCount int64)) *MockRepoStore_UpdateRepoCloneDownloads_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Repository), args[2].(time.Time), args[3].(int64)) + }) + return _c +} + +func (_c *MockRepoStore_UpdateRepoCloneDownloads_Call) Return(err error) *MockRepoStore_UpdateRepoCloneDownloads_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockRepoStore_UpdateRepoCloneDownloads_Call) RunAndReturn(run func(context.Context, *database.Repository, time.Time, int64) error) *MockRepoStore_UpdateRepoCloneDownloads_Call { + _c.Call.Return(run) + return _c +} + +// UpdateRepoFileDownloads provides a mock function with given fields: ctx, repo, date, clickDownloadCount +func (_m *MockRepoStore) UpdateRepoFileDownloads(ctx context.Context, repo *database.Repository, date time.Time, clickDownloadCount int64) error { + ret := _m.Called(ctx, repo, date, clickDownloadCount) + + if len(ret) == 0 { + panic("no return value specified for UpdateRepoFileDownloads") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Repository, time.Time, int64) error); ok { + r0 = rf(ctx, repo, date, clickDownloadCount) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoStore_UpdateRepoFileDownloads_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateRepoFileDownloads' +type MockRepoStore_UpdateRepoFileDownloads_Call struct { + *mock.Call +} + +// UpdateRepoFileDownloads is a helper method to define mock.On call +// - ctx context.Context +// - repo *database.Repository +// - date time.Time +// - clickDownloadCount int64 +func (_e *MockRepoStore_Expecter) UpdateRepoFileDownloads(ctx interface{}, repo interface{}, date interface{}, clickDownloadCount interface{}) *MockRepoStore_UpdateRepoFileDownloads_Call { + return &MockRepoStore_UpdateRepoFileDownloads_Call{Call: _e.mock.On("UpdateRepoFileDownloads", ctx, repo, date, clickDownloadCount)} +} + +func (_c *MockRepoStore_UpdateRepoFileDownloads_Call) Run(run func(ctx context.Context, repo *database.Repository, date time.Time, clickDownloadCount int64)) *MockRepoStore_UpdateRepoFileDownloads_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Repository), args[2].(time.Time), args[3].(int64)) + }) + return _c +} + +func (_c *MockRepoStore_UpdateRepoFileDownloads_Call) Return(err error) *MockRepoStore_UpdateRepoFileDownloads_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockRepoStore_UpdateRepoFileDownloads_Call) RunAndReturn(run func(context.Context, *database.Repository, time.Time, int64) error) *MockRepoStore_UpdateRepoFileDownloads_Call { + _c.Call.Return(run) + return _c +} + +// WithMirror provides a mock function with given fields: ctx, per, page +func (_m *MockRepoStore) WithMirror(ctx context.Context, per int, page int) ([]database.Repository, int, error) { + ret := _m.Called(ctx, per, page) + + if len(ret) == 0 { + panic("no return value specified for WithMirror") + } + + var r0 []database.Repository + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, int, int) ([]database.Repository, int, error)); ok { + return rf(ctx, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, int, int) []database.Repository); ok { + r0 = rf(ctx, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int, int) int); ok { + r1 = rf(ctx, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, int, int) error); ok { + r2 = rf(ctx, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockRepoStore_WithMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithMirror' +type MockRepoStore_WithMirror_Call struct { + *mock.Call +} + +// WithMirror is a helper method to define mock.On call +// - ctx context.Context +// - per int +// - page int +func (_e *MockRepoStore_Expecter) WithMirror(ctx interface{}, per interface{}, page interface{}) *MockRepoStore_WithMirror_Call { + return &MockRepoStore_WithMirror_Call{Call: _e.mock.On("WithMirror", ctx, per, page)} +} + +func (_c *MockRepoStore_WithMirror_Call) Run(run func(ctx context.Context, per int, page int)) *MockRepoStore_WithMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int), args[2].(int)) + }) + return _c +} + +func (_c *MockRepoStore_WithMirror_Call) Return(repos []database.Repository, count int, err error) *MockRepoStore_WithMirror_Call { + _c.Call.Return(repos, count, err) + return _c +} + +func (_c *MockRepoStore_WithMirror_Call) RunAndReturn(run func(context.Context, int, int) ([]database.Repository, int, error)) *MockRepoStore_WithMirror_Call { + _c.Call.Return(run) + return _c +} + +// NewMockRepoStore creates a new instance of MockRepoStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepoStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRepoStore { + mock := &MockRepoStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceResourceStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceResourceStore.go new file mode 100644 index 00000000..a1f8b278 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceResourceStore.go @@ -0,0 +1,437 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockSpaceResourceStore is an autogenerated mock type for the SpaceResourceStore type +type MockSpaceResourceStore struct { + mock.Mock +} + +type MockSpaceResourceStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSpaceResourceStore) EXPECT() *MockSpaceResourceStore_Expecter { + return &MockSpaceResourceStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, input +func (_m *MockSpaceResourceStore) Create(ctx context.Context, input database.SpaceResource) (*database.SpaceResource, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.SpaceResource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.SpaceResource) (*database.SpaceResource, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.SpaceResource) *database.SpaceResource); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SpaceResource) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.SpaceResource) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceResourceStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockSpaceResourceStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - input database.SpaceResource +func (_e *MockSpaceResourceStore_Expecter) Create(ctx interface{}, input interface{}) *MockSpaceResourceStore_Create_Call { + return &MockSpaceResourceStore_Create_Call{Call: _e.mock.On("Create", ctx, input)} +} + +func (_c *MockSpaceResourceStore_Create_Call) Run(run func(ctx context.Context, input database.SpaceResource)) *MockSpaceResourceStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.SpaceResource)) + }) + return _c +} + +func (_c *MockSpaceResourceStore_Create_Call) Return(_a0 *database.SpaceResource, _a1 error) *MockSpaceResourceStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceResourceStore_Create_Call) RunAndReturn(run func(context.Context, database.SpaceResource) (*database.SpaceResource, error)) *MockSpaceResourceStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, input +func (_m *MockSpaceResourceStore) Delete(ctx context.Context, input database.SpaceResource) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.SpaceResource) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockSpaceResourceStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockSpaceResourceStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - input database.SpaceResource +func (_e *MockSpaceResourceStore_Expecter) Delete(ctx interface{}, input interface{}) *MockSpaceResourceStore_Delete_Call { + return &MockSpaceResourceStore_Delete_Call{Call: _e.mock.On("Delete", ctx, input)} +} + +func (_c *MockSpaceResourceStore_Delete_Call) Run(run func(ctx context.Context, input database.SpaceResource)) *MockSpaceResourceStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.SpaceResource)) + }) + return _c +} + +func (_c *MockSpaceResourceStore_Delete_Call) Return(_a0 error) *MockSpaceResourceStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockSpaceResourceStore_Delete_Call) RunAndReturn(run func(context.Context, database.SpaceResource) error) *MockSpaceResourceStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindAll provides a mock function with given fields: ctx +func (_m *MockSpaceResourceStore) FindAll(ctx context.Context) ([]database.SpaceResource, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for FindAll") + } + + var r0 []database.SpaceResource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.SpaceResource, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.SpaceResource); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.SpaceResource) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceResourceStore_FindAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindAll' +type MockSpaceResourceStore_FindAll_Call struct { + *mock.Call +} + +// FindAll is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockSpaceResourceStore_Expecter) FindAll(ctx interface{}) *MockSpaceResourceStore_FindAll_Call { + return &MockSpaceResourceStore_FindAll_Call{Call: _e.mock.On("FindAll", ctx)} +} + +func (_c *MockSpaceResourceStore_FindAll_Call) Run(run func(ctx context.Context)) *MockSpaceResourceStore_FindAll_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockSpaceResourceStore_FindAll_Call) Return(_a0 []database.SpaceResource, _a1 error) *MockSpaceResourceStore_FindAll_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceResourceStore_FindAll_Call) RunAndReturn(run func(context.Context) ([]database.SpaceResource, error)) *MockSpaceResourceStore_FindAll_Call { + _c.Call.Return(run) + return _c +} + +// FindByID provides a mock function with given fields: ctx, id +func (_m *MockSpaceResourceStore) FindByID(ctx context.Context, id int64) (*database.SpaceResource, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for FindByID") + } + + var r0 *database.SpaceResource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.SpaceResource, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.SpaceResource); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SpaceResource) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceResourceStore_FindByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByID' +type MockSpaceResourceStore_FindByID_Call struct { + *mock.Call +} + +// FindByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockSpaceResourceStore_Expecter) FindByID(ctx interface{}, id interface{}) *MockSpaceResourceStore_FindByID_Call { + return &MockSpaceResourceStore_FindByID_Call{Call: _e.mock.On("FindByID", ctx, id)} +} + +func (_c *MockSpaceResourceStore_FindByID_Call) Run(run func(ctx context.Context, id int64)) *MockSpaceResourceStore_FindByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockSpaceResourceStore_FindByID_Call) Return(_a0 *database.SpaceResource, _a1 error) *MockSpaceResourceStore_FindByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceResourceStore_FindByID_Call) RunAndReturn(run func(context.Context, int64) (*database.SpaceResource, error)) *MockSpaceResourceStore_FindByID_Call { + _c.Call.Return(run) + return _c +} + +// FindByName provides a mock function with given fields: ctx, name +func (_m *MockSpaceResourceStore) FindByName(ctx context.Context, name string) (*database.SpaceResource, error) { + ret := _m.Called(ctx, name) + + if len(ret) == 0 { + panic("no return value specified for FindByName") + } + + var r0 *database.SpaceResource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.SpaceResource, error)); ok { + return rf(ctx, name) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.SpaceResource); ok { + r0 = rf(ctx, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SpaceResource) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceResourceStore_FindByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByName' +type MockSpaceResourceStore_FindByName_Call struct { + *mock.Call +} + +// FindByName is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *MockSpaceResourceStore_Expecter) FindByName(ctx interface{}, name interface{}) *MockSpaceResourceStore_FindByName_Call { + return &MockSpaceResourceStore_FindByName_Call{Call: _e.mock.On("FindByName", ctx, name)} +} + +func (_c *MockSpaceResourceStore_FindByName_Call) Run(run func(ctx context.Context, name string)) *MockSpaceResourceStore_FindByName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockSpaceResourceStore_FindByName_Call) Return(_a0 *database.SpaceResource, _a1 error) *MockSpaceResourceStore_FindByName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceResourceStore_FindByName_Call) RunAndReturn(run func(context.Context, string) (*database.SpaceResource, error)) *MockSpaceResourceStore_FindByName_Call { + _c.Call.Return(run) + return _c +} + +// Index provides a mock function with given fields: ctx, clusterId +func (_m *MockSpaceResourceStore) Index(ctx context.Context, clusterId string) ([]database.SpaceResource, error) { + ret := _m.Called(ctx, clusterId) + + if len(ret) == 0 { + panic("no return value specified for Index") + } + + var r0 []database.SpaceResource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]database.SpaceResource, error)); ok { + return rf(ctx, clusterId) + } + if rf, ok := ret.Get(0).(func(context.Context, string) []database.SpaceResource); ok { + r0 = rf(ctx, clusterId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.SpaceResource) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, clusterId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceResourceStore_Index_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Index' +type MockSpaceResourceStore_Index_Call struct { + *mock.Call +} + +// Index is a helper method to define mock.On call +// - ctx context.Context +// - clusterId string +func (_e *MockSpaceResourceStore_Expecter) Index(ctx interface{}, clusterId interface{}) *MockSpaceResourceStore_Index_Call { + return &MockSpaceResourceStore_Index_Call{Call: _e.mock.On("Index", ctx, clusterId)} +} + +func (_c *MockSpaceResourceStore_Index_Call) Run(run func(ctx context.Context, clusterId string)) *MockSpaceResourceStore_Index_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockSpaceResourceStore_Index_Call) Return(_a0 []database.SpaceResource, _a1 error) *MockSpaceResourceStore_Index_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceResourceStore_Index_Call) RunAndReturn(run func(context.Context, string) ([]database.SpaceResource, error)) *MockSpaceResourceStore_Index_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, input +func (_m *MockSpaceResourceStore) Update(ctx context.Context, input database.SpaceResource) (*database.SpaceResource, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 *database.SpaceResource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.SpaceResource) (*database.SpaceResource, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.SpaceResource) *database.SpaceResource); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SpaceResource) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.SpaceResource) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceResourceStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockSpaceResourceStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - input database.SpaceResource +func (_e *MockSpaceResourceStore_Expecter) Update(ctx interface{}, input interface{}) *MockSpaceResourceStore_Update_Call { + return &MockSpaceResourceStore_Update_Call{Call: _e.mock.On("Update", ctx, input)} +} + +func (_c *MockSpaceResourceStore_Update_Call) Run(run func(ctx context.Context, input database.SpaceResource)) *MockSpaceResourceStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.SpaceResource)) + }) + return _c +} + +func (_c *MockSpaceResourceStore_Update_Call) Return(_a0 *database.SpaceResource, _a1 error) *MockSpaceResourceStore_Update_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceResourceStore_Update_Call) RunAndReturn(run func(context.Context, database.SpaceResource) (*database.SpaceResource, error)) *MockSpaceResourceStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockSpaceResourceStore creates a new instance of MockSpaceResourceStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSpaceResourceStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSpaceResourceStore { + mock := &MockSpaceResourceStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_TagStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_TagStore.go new file mode 100644 index 00000000..d5a592d9 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_TagStore.go @@ -0,0 +1,1232 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" + + types "opencsg.com/csghub-server/common/types" +) + +// MockTagStore is an autogenerated mock type for the TagStore type +type MockTagStore struct { + mock.Mock +} + +type MockTagStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockTagStore) EXPECT() *MockTagStore_Expecter { + return &MockTagStore_Expecter{mock: &_m.Mock} +} + +// AllCodeCategories provides a mock function with given fields: ctx +func (_m *MockTagStore) AllCodeCategories(ctx context.Context) ([]database.TagCategory, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllCodeCategories") + } + + var r0 []database.TagCategory + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.TagCategory, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.TagCategory); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.TagCategory) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllCodeCategories_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllCodeCategories' +type MockTagStore_AllCodeCategories_Call struct { + *mock.Call +} + +// AllCodeCategories is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagStore_Expecter) AllCodeCategories(ctx interface{}) *MockTagStore_AllCodeCategories_Call { + return &MockTagStore_AllCodeCategories_Call{Call: _e.mock.On("AllCodeCategories", ctx)} +} + +func (_c *MockTagStore_AllCodeCategories_Call) Run(run func(ctx context.Context)) *MockTagStore_AllCodeCategories_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagStore_AllCodeCategories_Call) Return(_a0 []database.TagCategory, _a1 error) *MockTagStore_AllCodeCategories_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllCodeCategories_Call) RunAndReturn(run func(context.Context) ([]database.TagCategory, error)) *MockTagStore_AllCodeCategories_Call { + _c.Call.Return(run) + return _c +} + +// AllCodeTags provides a mock function with given fields: ctx +func (_m *MockTagStore) AllCodeTags(ctx context.Context) ([]*database.Tag, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllCodeTags") + } + + var r0 []*database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]*database.Tag, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []*database.Tag); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllCodeTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllCodeTags' +type MockTagStore_AllCodeTags_Call struct { + *mock.Call +} + +// AllCodeTags is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagStore_Expecter) AllCodeTags(ctx interface{}) *MockTagStore_AllCodeTags_Call { + return &MockTagStore_AllCodeTags_Call{Call: _e.mock.On("AllCodeTags", ctx)} +} + +func (_c *MockTagStore_AllCodeTags_Call) Run(run func(ctx context.Context)) *MockTagStore_AllCodeTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagStore_AllCodeTags_Call) Return(_a0 []*database.Tag, _a1 error) *MockTagStore_AllCodeTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllCodeTags_Call) RunAndReturn(run func(context.Context) ([]*database.Tag, error)) *MockTagStore_AllCodeTags_Call { + _c.Call.Return(run) + return _c +} + +// AllDatasetCategories provides a mock function with given fields: ctx +func (_m *MockTagStore) AllDatasetCategories(ctx context.Context) ([]database.TagCategory, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllDatasetCategories") + } + + var r0 []database.TagCategory + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.TagCategory, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.TagCategory); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.TagCategory) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllDatasetCategories_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllDatasetCategories' +type MockTagStore_AllDatasetCategories_Call struct { + *mock.Call +} + +// AllDatasetCategories is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagStore_Expecter) AllDatasetCategories(ctx interface{}) *MockTagStore_AllDatasetCategories_Call { + return &MockTagStore_AllDatasetCategories_Call{Call: _e.mock.On("AllDatasetCategories", ctx)} +} + +func (_c *MockTagStore_AllDatasetCategories_Call) Run(run func(ctx context.Context)) *MockTagStore_AllDatasetCategories_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagStore_AllDatasetCategories_Call) Return(_a0 []database.TagCategory, _a1 error) *MockTagStore_AllDatasetCategories_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllDatasetCategories_Call) RunAndReturn(run func(context.Context) ([]database.TagCategory, error)) *MockTagStore_AllDatasetCategories_Call { + _c.Call.Return(run) + return _c +} + +// AllDatasetTags provides a mock function with given fields: ctx +func (_m *MockTagStore) AllDatasetTags(ctx context.Context) ([]*database.Tag, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllDatasetTags") + } + + var r0 []*database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]*database.Tag, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []*database.Tag); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllDatasetTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllDatasetTags' +type MockTagStore_AllDatasetTags_Call struct { + *mock.Call +} + +// AllDatasetTags is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagStore_Expecter) AllDatasetTags(ctx interface{}) *MockTagStore_AllDatasetTags_Call { + return &MockTagStore_AllDatasetTags_Call{Call: _e.mock.On("AllDatasetTags", ctx)} +} + +func (_c *MockTagStore_AllDatasetTags_Call) Run(run func(ctx context.Context)) *MockTagStore_AllDatasetTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagStore_AllDatasetTags_Call) Return(_a0 []*database.Tag, _a1 error) *MockTagStore_AllDatasetTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllDatasetTags_Call) RunAndReturn(run func(context.Context) ([]*database.Tag, error)) *MockTagStore_AllDatasetTags_Call { + _c.Call.Return(run) + return _c +} + +// AllModelCategories provides a mock function with given fields: ctx +func (_m *MockTagStore) AllModelCategories(ctx context.Context) ([]database.TagCategory, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllModelCategories") + } + + var r0 []database.TagCategory + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.TagCategory, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.TagCategory); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.TagCategory) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllModelCategories_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllModelCategories' +type MockTagStore_AllModelCategories_Call struct { + *mock.Call +} + +// AllModelCategories is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagStore_Expecter) AllModelCategories(ctx interface{}) *MockTagStore_AllModelCategories_Call { + return &MockTagStore_AllModelCategories_Call{Call: _e.mock.On("AllModelCategories", ctx)} +} + +func (_c *MockTagStore_AllModelCategories_Call) Run(run func(ctx context.Context)) *MockTagStore_AllModelCategories_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagStore_AllModelCategories_Call) Return(_a0 []database.TagCategory, _a1 error) *MockTagStore_AllModelCategories_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllModelCategories_Call) RunAndReturn(run func(context.Context) ([]database.TagCategory, error)) *MockTagStore_AllModelCategories_Call { + _c.Call.Return(run) + return _c +} + +// AllModelTags provides a mock function with given fields: ctx +func (_m *MockTagStore) AllModelTags(ctx context.Context) ([]*database.Tag, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllModelTags") + } + + var r0 []*database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]*database.Tag, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []*database.Tag); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllModelTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllModelTags' +type MockTagStore_AllModelTags_Call struct { + *mock.Call +} + +// AllModelTags is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagStore_Expecter) AllModelTags(ctx interface{}) *MockTagStore_AllModelTags_Call { + return &MockTagStore_AllModelTags_Call{Call: _e.mock.On("AllModelTags", ctx)} +} + +func (_c *MockTagStore_AllModelTags_Call) Run(run func(ctx context.Context)) *MockTagStore_AllModelTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagStore_AllModelTags_Call) Return(_a0 []*database.Tag, _a1 error) *MockTagStore_AllModelTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllModelTags_Call) RunAndReturn(run func(context.Context) ([]*database.Tag, error)) *MockTagStore_AllModelTags_Call { + _c.Call.Return(run) + return _c +} + +// AllPromptCategories provides a mock function with given fields: ctx +func (_m *MockTagStore) AllPromptCategories(ctx context.Context) ([]database.TagCategory, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllPromptCategories") + } + + var r0 []database.TagCategory + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.TagCategory, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.TagCategory); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.TagCategory) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllPromptCategories_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllPromptCategories' +type MockTagStore_AllPromptCategories_Call struct { + *mock.Call +} + +// AllPromptCategories is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagStore_Expecter) AllPromptCategories(ctx interface{}) *MockTagStore_AllPromptCategories_Call { + return &MockTagStore_AllPromptCategories_Call{Call: _e.mock.On("AllPromptCategories", ctx)} +} + +func (_c *MockTagStore_AllPromptCategories_Call) Run(run func(ctx context.Context)) *MockTagStore_AllPromptCategories_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagStore_AllPromptCategories_Call) Return(_a0 []database.TagCategory, _a1 error) *MockTagStore_AllPromptCategories_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllPromptCategories_Call) RunAndReturn(run func(context.Context) ([]database.TagCategory, error)) *MockTagStore_AllPromptCategories_Call { + _c.Call.Return(run) + return _c +} + +// AllPromptTags provides a mock function with given fields: ctx +func (_m *MockTagStore) AllPromptTags(ctx context.Context) ([]*database.Tag, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllPromptTags") + } + + var r0 []*database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]*database.Tag, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []*database.Tag); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllPromptTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllPromptTags' +type MockTagStore_AllPromptTags_Call struct { + *mock.Call +} + +// AllPromptTags is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagStore_Expecter) AllPromptTags(ctx interface{}) *MockTagStore_AllPromptTags_Call { + return &MockTagStore_AllPromptTags_Call{Call: _e.mock.On("AllPromptTags", ctx)} +} + +func (_c *MockTagStore_AllPromptTags_Call) Run(run func(ctx context.Context)) *MockTagStore_AllPromptTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagStore_AllPromptTags_Call) Return(_a0 []*database.Tag, _a1 error) *MockTagStore_AllPromptTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllPromptTags_Call) RunAndReturn(run func(context.Context) ([]*database.Tag, error)) *MockTagStore_AllPromptTags_Call { + _c.Call.Return(run) + return _c +} + +// AllSpaceCategories provides a mock function with given fields: ctx +func (_m *MockTagStore) AllSpaceCategories(ctx context.Context) ([]database.TagCategory, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllSpaceCategories") + } + + var r0 []database.TagCategory + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.TagCategory, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.TagCategory); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.TagCategory) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllSpaceCategories_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllSpaceCategories' +type MockTagStore_AllSpaceCategories_Call struct { + *mock.Call +} + +// AllSpaceCategories is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagStore_Expecter) AllSpaceCategories(ctx interface{}) *MockTagStore_AllSpaceCategories_Call { + return &MockTagStore_AllSpaceCategories_Call{Call: _e.mock.On("AllSpaceCategories", ctx)} +} + +func (_c *MockTagStore_AllSpaceCategories_Call) Run(run func(ctx context.Context)) *MockTagStore_AllSpaceCategories_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagStore_AllSpaceCategories_Call) Return(_a0 []database.TagCategory, _a1 error) *MockTagStore_AllSpaceCategories_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllSpaceCategories_Call) RunAndReturn(run func(context.Context) ([]database.TagCategory, error)) *MockTagStore_AllSpaceCategories_Call { + _c.Call.Return(run) + return _c +} + +// AllSpaceTags provides a mock function with given fields: ctx +func (_m *MockTagStore) AllSpaceTags(ctx context.Context) ([]*database.Tag, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllSpaceTags") + } + + var r0 []*database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]*database.Tag, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []*database.Tag); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllSpaceTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllSpaceTags' +type MockTagStore_AllSpaceTags_Call struct { + *mock.Call +} + +// AllSpaceTags is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagStore_Expecter) AllSpaceTags(ctx interface{}) *MockTagStore_AllSpaceTags_Call { + return &MockTagStore_AllSpaceTags_Call{Call: _e.mock.On("AllSpaceTags", ctx)} +} + +func (_c *MockTagStore_AllSpaceTags_Call) Run(run func(ctx context.Context)) *MockTagStore_AllSpaceTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagStore_AllSpaceTags_Call) Return(_a0 []*database.Tag, _a1 error) *MockTagStore_AllSpaceTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllSpaceTags_Call) RunAndReturn(run func(context.Context) ([]*database.Tag, error)) *MockTagStore_AllSpaceTags_Call { + _c.Call.Return(run) + return _c +} + +// AllTags provides a mock function with given fields: ctx +func (_m *MockTagStore) AllTags(ctx context.Context) ([]database.Tag, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllTags") + } + + var r0 []database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.Tag, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.Tag); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllTags' +type MockTagStore_AllTags_Call struct { + *mock.Call +} + +// AllTags is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagStore_Expecter) AllTags(ctx interface{}) *MockTagStore_AllTags_Call { + return &MockTagStore_AllTags_Call{Call: _e.mock.On("AllTags", ctx)} +} + +func (_c *MockTagStore_AllTags_Call) Run(run func(ctx context.Context)) *MockTagStore_AllTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagStore_AllTags_Call) Return(_a0 []database.Tag, _a1 error) *MockTagStore_AllTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllTags_Call) RunAndReturn(run func(context.Context) ([]database.Tag, error)) *MockTagStore_AllTags_Call { + _c.Call.Return(run) + return _c +} + +// AllTagsByScope provides a mock function with given fields: ctx, scope +func (_m *MockTagStore) AllTagsByScope(ctx context.Context, scope database.TagScope) ([]*database.Tag, error) { + ret := _m.Called(ctx, scope) + + if len(ret) == 0 { + panic("no return value specified for AllTagsByScope") + } + + var r0 []*database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.TagScope) ([]*database.Tag, error)); ok { + return rf(ctx, scope) + } + if rf, ok := ret.Get(0).(func(context.Context, database.TagScope) []*database.Tag); ok { + r0 = rf(ctx, scope) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.TagScope) error); ok { + r1 = rf(ctx, scope) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllTagsByScope_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllTagsByScope' +type MockTagStore_AllTagsByScope_Call struct { + *mock.Call +} + +// AllTagsByScope is a helper method to define mock.On call +// - ctx context.Context +// - scope database.TagScope +func (_e *MockTagStore_Expecter) AllTagsByScope(ctx interface{}, scope interface{}) *MockTagStore_AllTagsByScope_Call { + return &MockTagStore_AllTagsByScope_Call{Call: _e.mock.On("AllTagsByScope", ctx, scope)} +} + +func (_c *MockTagStore_AllTagsByScope_Call) Run(run func(ctx context.Context, scope database.TagScope)) *MockTagStore_AllTagsByScope_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.TagScope)) + }) + return _c +} + +func (_c *MockTagStore_AllTagsByScope_Call) Return(_a0 []*database.Tag, _a1 error) *MockTagStore_AllTagsByScope_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllTagsByScope_Call) RunAndReturn(run func(context.Context, database.TagScope) ([]*database.Tag, error)) *MockTagStore_AllTagsByScope_Call { + _c.Call.Return(run) + return _c +} + +// AllTagsByScopeAndCategory provides a mock function with given fields: ctx, scope, category +func (_m *MockTagStore) AllTagsByScopeAndCategory(ctx context.Context, scope database.TagScope, category string) ([]*database.Tag, error) { + ret := _m.Called(ctx, scope, category) + + if len(ret) == 0 { + panic("no return value specified for AllTagsByScopeAndCategory") + } + + var r0 []*database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.TagScope, string) ([]*database.Tag, error)); ok { + return rf(ctx, scope, category) + } + if rf, ok := ret.Get(0).(func(context.Context, database.TagScope, string) []*database.Tag); ok { + r0 = rf(ctx, scope, category) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.TagScope, string) error); ok { + r1 = rf(ctx, scope, category) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_AllTagsByScopeAndCategory_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllTagsByScopeAndCategory' +type MockTagStore_AllTagsByScopeAndCategory_Call struct { + *mock.Call +} + +// AllTagsByScopeAndCategory is a helper method to define mock.On call +// - ctx context.Context +// - scope database.TagScope +// - category string +func (_e *MockTagStore_Expecter) AllTagsByScopeAndCategory(ctx interface{}, scope interface{}, category interface{}) *MockTagStore_AllTagsByScopeAndCategory_Call { + return &MockTagStore_AllTagsByScopeAndCategory_Call{Call: _e.mock.On("AllTagsByScopeAndCategory", ctx, scope, category)} +} + +func (_c *MockTagStore_AllTagsByScopeAndCategory_Call) Run(run func(ctx context.Context, scope database.TagScope, category string)) *MockTagStore_AllTagsByScopeAndCategory_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.TagScope), args[2].(string)) + }) + return _c +} + +func (_c *MockTagStore_AllTagsByScopeAndCategory_Call) Return(_a0 []*database.Tag, _a1 error) *MockTagStore_AllTagsByScopeAndCategory_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_AllTagsByScopeAndCategory_Call) RunAndReturn(run func(context.Context, database.TagScope, string) ([]*database.Tag, error)) *MockTagStore_AllTagsByScopeAndCategory_Call { + _c.Call.Return(run) + return _c +} + +// CreateTag provides a mock function with given fields: ctx, category, name, group, scope +func (_m *MockTagStore) CreateTag(ctx context.Context, category string, name string, group string, scope database.TagScope) (database.Tag, error) { + ret := _m.Called(ctx, category, name, group, scope) + + if len(ret) == 0 { + panic("no return value specified for CreateTag") + } + + var r0 database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, database.TagScope) (database.Tag, error)); ok { + return rf(ctx, category, name, group, scope) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, database.TagScope) database.Tag); ok { + r0 = rf(ctx, category, name, group, scope) + } else { + r0 = ret.Get(0).(database.Tag) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string, database.TagScope) error); ok { + r1 = rf(ctx, category, name, group, scope) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_CreateTag_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateTag' +type MockTagStore_CreateTag_Call struct { + *mock.Call +} + +// CreateTag is a helper method to define mock.On call +// - ctx context.Context +// - category string +// - name string +// - group string +// - scope database.TagScope +func (_e *MockTagStore_Expecter) CreateTag(ctx interface{}, category interface{}, name interface{}, group interface{}, scope interface{}) *MockTagStore_CreateTag_Call { + return &MockTagStore_CreateTag_Call{Call: _e.mock.On("CreateTag", ctx, category, name, group, scope)} +} + +func (_c *MockTagStore_CreateTag_Call) Run(run func(ctx context.Context, category string, name string, group string, scope database.TagScope)) *MockTagStore_CreateTag_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string), args[4].(database.TagScope)) + }) + return _c +} + +func (_c *MockTagStore_CreateTag_Call) Return(_a0 database.Tag, _a1 error) *MockTagStore_CreateTag_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_CreateTag_Call) RunAndReturn(run func(context.Context, string, string, string, database.TagScope) (database.Tag, error)) *MockTagStore_CreateTag_Call { + _c.Call.Return(run) + return _c +} + +// FindOrCreate provides a mock function with given fields: ctx, tag +func (_m *MockTagStore) FindOrCreate(ctx context.Context, tag database.Tag) (*database.Tag, error) { + ret := _m.Called(ctx, tag) + + if len(ret) == 0 { + panic("no return value specified for FindOrCreate") + } + + var r0 *database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Tag) (*database.Tag, error)); ok { + return rf(ctx, tag) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Tag) *database.Tag); ok { + r0 = rf(ctx, tag) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Tag) error); ok { + r1 = rf(ctx, tag) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_FindOrCreate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindOrCreate' +type MockTagStore_FindOrCreate_Call struct { + *mock.Call +} + +// FindOrCreate is a helper method to define mock.On call +// - ctx context.Context +// - tag database.Tag +func (_e *MockTagStore_Expecter) FindOrCreate(ctx interface{}, tag interface{}) *MockTagStore_FindOrCreate_Call { + return &MockTagStore_FindOrCreate_Call{Call: _e.mock.On("FindOrCreate", ctx, tag)} +} + +func (_c *MockTagStore_FindOrCreate_Call) Run(run func(ctx context.Context, tag database.Tag)) *MockTagStore_FindOrCreate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Tag)) + }) + return _c +} + +func (_c *MockTagStore_FindOrCreate_Call) Return(_a0 *database.Tag, _a1 error) *MockTagStore_FindOrCreate_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_FindOrCreate_Call) RunAndReturn(run func(context.Context, database.Tag) (*database.Tag, error)) *MockTagStore_FindOrCreate_Call { + _c.Call.Return(run) + return _c +} + +// GetTagsByScopeAndCategories provides a mock function with given fields: ctx, scope, categories +func (_m *MockTagStore) GetTagsByScopeAndCategories(ctx context.Context, scope database.TagScope, categories []string) ([]*database.Tag, error) { + ret := _m.Called(ctx, scope, categories) + + if len(ret) == 0 { + panic("no return value specified for GetTagsByScopeAndCategories") + } + + var r0 []*database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.TagScope, []string) ([]*database.Tag, error)); ok { + return rf(ctx, scope, categories) + } + if rf, ok := ret.Get(0).(func(context.Context, database.TagScope, []string) []*database.Tag); ok { + r0 = rf(ctx, scope, categories) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.TagScope, []string) error); ok { + r1 = rf(ctx, scope, categories) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_GetTagsByScopeAndCategories_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTagsByScopeAndCategories' +type MockTagStore_GetTagsByScopeAndCategories_Call struct { + *mock.Call +} + +// GetTagsByScopeAndCategories is a helper method to define mock.On call +// - ctx context.Context +// - scope database.TagScope +// - categories []string +func (_e *MockTagStore_Expecter) GetTagsByScopeAndCategories(ctx interface{}, scope interface{}, categories interface{}) *MockTagStore_GetTagsByScopeAndCategories_Call { + return &MockTagStore_GetTagsByScopeAndCategories_Call{Call: _e.mock.On("GetTagsByScopeAndCategories", ctx, scope, categories)} +} + +func (_c *MockTagStore_GetTagsByScopeAndCategories_Call) Run(run func(ctx context.Context, scope database.TagScope, categories []string)) *MockTagStore_GetTagsByScopeAndCategories_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.TagScope), args[2].([]string)) + }) + return _c +} + +func (_c *MockTagStore_GetTagsByScopeAndCategories_Call) Return(_a0 []*database.Tag, _a1 error) *MockTagStore_GetTagsByScopeAndCategories_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagStore_GetTagsByScopeAndCategories_Call) RunAndReturn(run func(context.Context, database.TagScope, []string) ([]*database.Tag, error)) *MockTagStore_GetTagsByScopeAndCategories_Call { + _c.Call.Return(run) + return _c +} + +// RemoveRepoTags provides a mock function with given fields: ctx, repoID, tagIDs +func (_m *MockTagStore) RemoveRepoTags(ctx context.Context, repoID int64, tagIDs []int64) error { + ret := _m.Called(ctx, repoID, tagIDs) + + if len(ret) == 0 { + panic("no return value specified for RemoveRepoTags") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, []int64) error); ok { + r0 = rf(ctx, repoID, tagIDs) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockTagStore_RemoveRepoTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveRepoTags' +type MockTagStore_RemoveRepoTags_Call struct { + *mock.Call +} + +// RemoveRepoTags is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - tagIDs []int64 +func (_e *MockTagStore_Expecter) RemoveRepoTags(ctx interface{}, repoID interface{}, tagIDs interface{}) *MockTagStore_RemoveRepoTags_Call { + return &MockTagStore_RemoveRepoTags_Call{Call: _e.mock.On("RemoveRepoTags", ctx, repoID, tagIDs)} +} + +func (_c *MockTagStore_RemoveRepoTags_Call) Run(run func(ctx context.Context, repoID int64, tagIDs []int64)) *MockTagStore_RemoveRepoTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].([]int64)) + }) + return _c +} + +func (_c *MockTagStore_RemoveRepoTags_Call) Return(err error) *MockTagStore_RemoveRepoTags_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTagStore_RemoveRepoTags_Call) RunAndReturn(run func(context.Context, int64, []int64) error) *MockTagStore_RemoveRepoTags_Call { + _c.Call.Return(run) + return _c +} + +// SaveTags provides a mock function with given fields: ctx, tags +func (_m *MockTagStore) SaveTags(ctx context.Context, tags []*database.Tag) error { + ret := _m.Called(ctx, tags) + + if len(ret) == 0 { + panic("no return value specified for SaveTags") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []*database.Tag) error); ok { + r0 = rf(ctx, tags) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockTagStore_SaveTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SaveTags' +type MockTagStore_SaveTags_Call struct { + *mock.Call +} + +// SaveTags is a helper method to define mock.On call +// - ctx context.Context +// - tags []*database.Tag +func (_e *MockTagStore_Expecter) SaveTags(ctx interface{}, tags interface{}) *MockTagStore_SaveTags_Call { + return &MockTagStore_SaveTags_Call{Call: _e.mock.On("SaveTags", ctx, tags)} +} + +func (_c *MockTagStore_SaveTags_Call) Run(run func(ctx context.Context, tags []*database.Tag)) *MockTagStore_SaveTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]*database.Tag)) + }) + return _c +} + +func (_c *MockTagStore_SaveTags_Call) Return(_a0 error) *MockTagStore_SaveTags_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockTagStore_SaveTags_Call) RunAndReturn(run func(context.Context, []*database.Tag) error) *MockTagStore_SaveTags_Call { + _c.Call.Return(run) + return _c +} + +// SetLibraryTag provides a mock function with given fields: ctx, repoType, namespace, name, newTag, oldTag +func (_m *MockTagStore) SetLibraryTag(ctx context.Context, repoType types.RepositoryType, namespace string, name string, newTag *database.Tag, oldTag *database.Tag) error { + ret := _m.Called(ctx, repoType, namespace, name, newTag, oldTag) + + if len(ret) == 0 { + panic("no return value specified for SetLibraryTag") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, *database.Tag, *database.Tag) error); ok { + r0 = rf(ctx, repoType, namespace, name, newTag, oldTag) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockTagStore_SetLibraryTag_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetLibraryTag' +type MockTagStore_SetLibraryTag_Call struct { + *mock.Call +} + +// SetLibraryTag is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - newTag *database.Tag +// - oldTag *database.Tag +func (_e *MockTagStore_Expecter) SetLibraryTag(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, newTag interface{}, oldTag interface{}) *MockTagStore_SetLibraryTag_Call { + return &MockTagStore_SetLibraryTag_Call{Call: _e.mock.On("SetLibraryTag", ctx, repoType, namespace, name, newTag, oldTag)} +} + +func (_c *MockTagStore_SetLibraryTag_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, newTag *database.Tag, oldTag *database.Tag)) *MockTagStore_SetLibraryTag_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(*database.Tag), args[5].(*database.Tag)) + }) + return _c +} + +func (_c *MockTagStore_SetLibraryTag_Call) Return(err error) *MockTagStore_SetLibraryTag_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTagStore_SetLibraryTag_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, *database.Tag, *database.Tag) error) *MockTagStore_SetLibraryTag_Call { + _c.Call.Return(run) + return _c +} + +// SetMetaTags provides a mock function with given fields: ctx, repoType, namespace, name, tags +func (_m *MockTagStore) SetMetaTags(ctx context.Context, repoType types.RepositoryType, namespace string, name string, tags []*database.Tag) ([]*database.RepositoryTag, error) { + ret := _m.Called(ctx, repoType, namespace, name, tags) + + if len(ret) == 0 { + panic("no return value specified for SetMetaTags") + } + + var r0 []*database.RepositoryTag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, []*database.Tag) ([]*database.RepositoryTag, error)); ok { + return rf(ctx, repoType, namespace, name, tags) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, []*database.Tag) []*database.RepositoryTag); ok { + r0 = rf(ctx, repoType, namespace, name, tags) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.RepositoryTag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string, []*database.Tag) error); ok { + r1 = rf(ctx, repoType, namespace, name, tags) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagStore_SetMetaTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetMetaTags' +type MockTagStore_SetMetaTags_Call struct { + *mock.Call +} + +// SetMetaTags is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - tags []*database.Tag +func (_e *MockTagStore_Expecter) SetMetaTags(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, tags interface{}) *MockTagStore_SetMetaTags_Call { + return &MockTagStore_SetMetaTags_Call{Call: _e.mock.On("SetMetaTags", ctx, repoType, namespace, name, tags)} +} + +func (_c *MockTagStore_SetMetaTags_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, tags []*database.Tag)) *MockTagStore_SetMetaTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].([]*database.Tag)) + }) + return _c +} + +func (_c *MockTagStore_SetMetaTags_Call) Return(repoTags []*database.RepositoryTag, err error) *MockTagStore_SetMetaTags_Call { + _c.Call.Return(repoTags, err) + return _c +} + +func (_c *MockTagStore_SetMetaTags_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, []*database.Tag) ([]*database.RepositoryTag, error)) *MockTagStore_SetMetaTags_Call { + _c.Call.Return(run) + return _c +} + +// UpsertRepoTags provides a mock function with given fields: ctx, repoID, oldTagIDs, newTagIDs +func (_m *MockTagStore) UpsertRepoTags(ctx context.Context, repoID int64, oldTagIDs []int64, newTagIDs []int64) error { + ret := _m.Called(ctx, repoID, oldTagIDs, newTagIDs) + + if len(ret) == 0 { + panic("no return value specified for UpsertRepoTags") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, []int64, []int64) error); ok { + r0 = rf(ctx, repoID, oldTagIDs, newTagIDs) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockTagStore_UpsertRepoTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpsertRepoTags' +type MockTagStore_UpsertRepoTags_Call struct { + *mock.Call +} + +// UpsertRepoTags is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - oldTagIDs []int64 +// - newTagIDs []int64 +func (_e *MockTagStore_Expecter) UpsertRepoTags(ctx interface{}, repoID interface{}, oldTagIDs interface{}, newTagIDs interface{}) *MockTagStore_UpsertRepoTags_Call { + return &MockTagStore_UpsertRepoTags_Call{Call: _e.mock.On("UpsertRepoTags", ctx, repoID, oldTagIDs, newTagIDs)} +} + +func (_c *MockTagStore_UpsertRepoTags_Call) Run(run func(ctx context.Context, repoID int64, oldTagIDs []int64, newTagIDs []int64)) *MockTagStore_UpsertRepoTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].([]int64), args[3].([]int64)) + }) + return _c +} + +func (_c *MockTagStore_UpsertRepoTags_Call) Return(err error) *MockTagStore_UpsertRepoTags_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockTagStore_UpsertRepoTags_Call) RunAndReturn(run func(context.Context, int64, []int64, []int64) error) *MockTagStore_UpsertRepoTags_Call { + _c.Call.Return(run) + return _c +} + +// NewMockTagStore creates a new instance of MockTagStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockTagStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockTagStore { + mock := &MockTagStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserLikesStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserLikesStore.go new file mode 100644 index 00000000..69d933d9 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserLikesStore.go @@ -0,0 +1,344 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// MockUserLikesStore is an autogenerated mock type for the UserLikesStore type +type MockUserLikesStore struct { + mock.Mock +} + +type MockUserLikesStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockUserLikesStore) EXPECT() *MockUserLikesStore_Expecter { + return &MockUserLikesStore_Expecter{mock: &_m.Mock} +} + +// Add provides a mock function with given fields: ctx, userId, repoId +func (_m *MockUserLikesStore) Add(ctx context.Context, userId int64, repoId int64) error { + ret := _m.Called(ctx, userId, repoId) + + if len(ret) == 0 { + panic("no return value specified for Add") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64) error); ok { + r0 = rf(ctx, userId, repoId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserLikesStore_Add_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Add' +type MockUserLikesStore_Add_Call struct { + *mock.Call +} + +// Add is a helper method to define mock.On call +// - ctx context.Context +// - userId int64 +// - repoId int64 +func (_e *MockUserLikesStore_Expecter) Add(ctx interface{}, userId interface{}, repoId interface{}) *MockUserLikesStore_Add_Call { + return &MockUserLikesStore_Add_Call{Call: _e.mock.On("Add", ctx, userId, repoId)} +} + +func (_c *MockUserLikesStore_Add_Call) Run(run func(ctx context.Context, userId int64, repoId int64)) *MockUserLikesStore_Add_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64)) + }) + return _c +} + +func (_c *MockUserLikesStore_Add_Call) Return(_a0 error) *MockUserLikesStore_Add_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockUserLikesStore_Add_Call) RunAndReturn(run func(context.Context, int64, int64) error) *MockUserLikesStore_Add_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, userId, repoId +func (_m *MockUserLikesStore) Delete(ctx context.Context, userId int64, repoId int64) error { + ret := _m.Called(ctx, userId, repoId) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64) error); ok { + r0 = rf(ctx, userId, repoId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserLikesStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockUserLikesStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - userId int64 +// - repoId int64 +func (_e *MockUserLikesStore_Expecter) Delete(ctx interface{}, userId interface{}, repoId interface{}) *MockUserLikesStore_Delete_Call { + return &MockUserLikesStore_Delete_Call{Call: _e.mock.On("Delete", ctx, userId, repoId)} +} + +func (_c *MockUserLikesStore_Delete_Call) Run(run func(ctx context.Context, userId int64, repoId int64)) *MockUserLikesStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64)) + }) + return _c +} + +func (_c *MockUserLikesStore_Delete_Call) Return(_a0 error) *MockUserLikesStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockUserLikesStore_Delete_Call) RunAndReturn(run func(context.Context, int64, int64) error) *MockUserLikesStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// IsExist provides a mock function with given fields: ctx, username, repoId +func (_m *MockUserLikesStore) IsExist(ctx context.Context, username string, repoId int64) (bool, error) { + ret := _m.Called(ctx, username, repoId) + + if len(ret) == 0 { + panic("no return value specified for IsExist") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, int64) (bool, error)); ok { + return rf(ctx, username, repoId) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int64) bool); ok { + r0 = rf(ctx, username, repoId) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int64) error); ok { + r1 = rf(ctx, username, repoId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserLikesStore_IsExist_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsExist' +type MockUserLikesStore_IsExist_Call struct { + *mock.Call +} + +// IsExist is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - repoId int64 +func (_e *MockUserLikesStore_Expecter) IsExist(ctx interface{}, username interface{}, repoId interface{}) *MockUserLikesStore_IsExist_Call { + return &MockUserLikesStore_IsExist_Call{Call: _e.mock.On("IsExist", ctx, username, repoId)} +} + +func (_c *MockUserLikesStore_IsExist_Call) Run(run func(ctx context.Context, username string, repoId int64)) *MockUserLikesStore_IsExist_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int64)) + }) + return _c +} + +func (_c *MockUserLikesStore_IsExist_Call) Return(exists bool, err error) *MockUserLikesStore_IsExist_Call { + _c.Call.Return(exists, err) + return _c +} + +func (_c *MockUserLikesStore_IsExist_Call) RunAndReturn(run func(context.Context, string, int64) (bool, error)) *MockUserLikesStore_IsExist_Call { + _c.Call.Return(run) + return _c +} + +// IsExistCollection provides a mock function with given fields: ctx, username, collectionId +func (_m *MockUserLikesStore) IsExistCollection(ctx context.Context, username string, collectionId int64) (bool, error) { + ret := _m.Called(ctx, username, collectionId) + + if len(ret) == 0 { + panic("no return value specified for IsExistCollection") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, int64) (bool, error)); ok { + return rf(ctx, username, collectionId) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int64) bool); ok { + r0 = rf(ctx, username, collectionId) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int64) error); ok { + r1 = rf(ctx, username, collectionId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserLikesStore_IsExistCollection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsExistCollection' +type MockUserLikesStore_IsExistCollection_Call struct { + *mock.Call +} + +// IsExistCollection is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - collectionId int64 +func (_e *MockUserLikesStore_Expecter) IsExistCollection(ctx interface{}, username interface{}, collectionId interface{}) *MockUserLikesStore_IsExistCollection_Call { + return &MockUserLikesStore_IsExistCollection_Call{Call: _e.mock.On("IsExistCollection", ctx, username, collectionId)} +} + +func (_c *MockUserLikesStore_IsExistCollection_Call) Run(run func(ctx context.Context, username string, collectionId int64)) *MockUserLikesStore_IsExistCollection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int64)) + }) + return _c +} + +func (_c *MockUserLikesStore_IsExistCollection_Call) Return(exists bool, err error) *MockUserLikesStore_IsExistCollection_Call { + _c.Call.Return(exists, err) + return _c +} + +func (_c *MockUserLikesStore_IsExistCollection_Call) RunAndReturn(run func(context.Context, string, int64) (bool, error)) *MockUserLikesStore_IsExistCollection_Call { + _c.Call.Return(run) + return _c +} + +// LikeCollection provides a mock function with given fields: ctx, userId, collectionId +func (_m *MockUserLikesStore) LikeCollection(ctx context.Context, userId int64, collectionId int64) error { + ret := _m.Called(ctx, userId, collectionId) + + if len(ret) == 0 { + panic("no return value specified for LikeCollection") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64) error); ok { + r0 = rf(ctx, userId, collectionId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserLikesStore_LikeCollection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LikeCollection' +type MockUserLikesStore_LikeCollection_Call struct { + *mock.Call +} + +// LikeCollection is a helper method to define mock.On call +// - ctx context.Context +// - userId int64 +// - collectionId int64 +func (_e *MockUserLikesStore_Expecter) LikeCollection(ctx interface{}, userId interface{}, collectionId interface{}) *MockUserLikesStore_LikeCollection_Call { + return &MockUserLikesStore_LikeCollection_Call{Call: _e.mock.On("LikeCollection", ctx, userId, collectionId)} +} + +func (_c *MockUserLikesStore_LikeCollection_Call) Run(run func(ctx context.Context, userId int64, collectionId int64)) *MockUserLikesStore_LikeCollection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64)) + }) + return _c +} + +func (_c *MockUserLikesStore_LikeCollection_Call) Return(_a0 error) *MockUserLikesStore_LikeCollection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockUserLikesStore_LikeCollection_Call) RunAndReturn(run func(context.Context, int64, int64) error) *MockUserLikesStore_LikeCollection_Call { + _c.Call.Return(run) + return _c +} + +// UnLikeCollection provides a mock function with given fields: ctx, userId, collectionId +func (_m *MockUserLikesStore) UnLikeCollection(ctx context.Context, userId int64, collectionId int64) error { + ret := _m.Called(ctx, userId, collectionId) + + if len(ret) == 0 { + panic("no return value specified for UnLikeCollection") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64) error); ok { + r0 = rf(ctx, userId, collectionId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserLikesStore_UnLikeCollection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UnLikeCollection' +type MockUserLikesStore_UnLikeCollection_Call struct { + *mock.Call +} + +// UnLikeCollection is a helper method to define mock.On call +// - ctx context.Context +// - userId int64 +// - collectionId int64 +func (_e *MockUserLikesStore_Expecter) UnLikeCollection(ctx interface{}, userId interface{}, collectionId interface{}) *MockUserLikesStore_UnLikeCollection_Call { + return &MockUserLikesStore_UnLikeCollection_Call{Call: _e.mock.On("UnLikeCollection", ctx, userId, collectionId)} +} + +func (_c *MockUserLikesStore_UnLikeCollection_Call) Run(run func(ctx context.Context, userId int64, collectionId int64)) *MockUserLikesStore_UnLikeCollection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64)) + }) + return _c +} + +func (_c *MockUserLikesStore_UnLikeCollection_Call) Return(_a0 error) *MockUserLikesStore_UnLikeCollection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockUserLikesStore_UnLikeCollection_Call) RunAndReturn(run func(context.Context, int64, int64) error) *MockUserLikesStore_UnLikeCollection_Call { + _c.Call.Return(run) + return _c +} + +// NewMockUserLikesStore creates a new instance of MockUserLikesStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockUserLikesStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockUserLikesStore { + mock := &MockUserLikesStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserStore.go new file mode 100644 index 00000000..3ef0f7e7 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserStore.go @@ -0,0 +1,814 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockUserStore is an autogenerated mock type for the UserStore type +type MockUserStore struct { + mock.Mock +} + +type MockUserStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockUserStore) EXPECT() *MockUserStore_Expecter { + return &MockUserStore_Expecter{mock: &_m.Mock} +} + +// ChangeUserName provides a mock function with given fields: ctx, username, newUsername +func (_m *MockUserStore) ChangeUserName(ctx context.Context, username string, newUsername string) error { + ret := _m.Called(ctx, username, newUsername) + + if len(ret) == 0 { + panic("no return value specified for ChangeUserName") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { + r0 = rf(ctx, username, newUsername) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserStore_ChangeUserName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ChangeUserName' +type MockUserStore_ChangeUserName_Call struct { + *mock.Call +} + +// ChangeUserName is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - newUsername string +func (_e *MockUserStore_Expecter) ChangeUserName(ctx interface{}, username interface{}, newUsername interface{}) *MockUserStore_ChangeUserName_Call { + return &MockUserStore_ChangeUserName_Call{Call: _e.mock.On("ChangeUserName", ctx, username, newUsername)} +} + +func (_c *MockUserStore_ChangeUserName_Call) Run(run func(ctx context.Context, username string, newUsername string)) *MockUserStore_ChangeUserName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockUserStore_ChangeUserName_Call) Return(err error) *MockUserStore_ChangeUserName_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockUserStore_ChangeUserName_Call) RunAndReturn(run func(context.Context, string, string) error) *MockUserStore_ChangeUserName_Call { + _c.Call.Return(run) + return _c +} + +// CountUsers provides a mock function with given fields: ctx +func (_m *MockUserStore) CountUsers(ctx context.Context) (int, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for CountUsers") + } + + var r0 int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (int, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) int); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserStore_CountUsers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CountUsers' +type MockUserStore_CountUsers_Call struct { + *mock.Call +} + +// CountUsers is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockUserStore_Expecter) CountUsers(ctx interface{}) *MockUserStore_CountUsers_Call { + return &MockUserStore_CountUsers_Call{Call: _e.mock.On("CountUsers", ctx)} +} + +func (_c *MockUserStore_CountUsers_Call) Run(run func(ctx context.Context)) *MockUserStore_CountUsers_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockUserStore_CountUsers_Call) Return(_a0 int, _a1 error) *MockUserStore_CountUsers_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockUserStore_CountUsers_Call) RunAndReturn(run func(context.Context) (int, error)) *MockUserStore_CountUsers_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, user, namespace +func (_m *MockUserStore) Create(ctx context.Context, user *database.User, namespace *database.Namespace) error { + ret := _m.Called(ctx, user, namespace) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.User, *database.Namespace) error); ok { + r0 = rf(ctx, user, namespace) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockUserStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - user *database.User +// - namespace *database.Namespace +func (_e *MockUserStore_Expecter) Create(ctx interface{}, user interface{}, namespace interface{}) *MockUserStore_Create_Call { + return &MockUserStore_Create_Call{Call: _e.mock.On("Create", ctx, user, namespace)} +} + +func (_c *MockUserStore_Create_Call) Run(run func(ctx context.Context, user *database.User, namespace *database.Namespace)) *MockUserStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.User), args[2].(*database.Namespace)) + }) + return _c +} + +func (_c *MockUserStore_Create_Call) Return(err error) *MockUserStore_Create_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockUserStore_Create_Call) RunAndReturn(run func(context.Context, *database.User, *database.Namespace) error) *MockUserStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// DeleteUserAndRelations provides a mock function with given fields: ctx, input +func (_m *MockUserStore) DeleteUserAndRelations(ctx context.Context, input database.User) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for DeleteUserAndRelations") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.User) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserStore_DeleteUserAndRelations_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteUserAndRelations' +type MockUserStore_DeleteUserAndRelations_Call struct { + *mock.Call +} + +// DeleteUserAndRelations is a helper method to define mock.On call +// - ctx context.Context +// - input database.User +func (_e *MockUserStore_Expecter) DeleteUserAndRelations(ctx interface{}, input interface{}) *MockUserStore_DeleteUserAndRelations_Call { + return &MockUserStore_DeleteUserAndRelations_Call{Call: _e.mock.On("DeleteUserAndRelations", ctx, input)} +} + +func (_c *MockUserStore_DeleteUserAndRelations_Call) Run(run func(ctx context.Context, input database.User)) *MockUserStore_DeleteUserAndRelations_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.User)) + }) + return _c +} + +func (_c *MockUserStore_DeleteUserAndRelations_Call) Return(err error) *MockUserStore_DeleteUserAndRelations_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockUserStore_DeleteUserAndRelations_Call) RunAndReturn(run func(context.Context, database.User) error) *MockUserStore_DeleteUserAndRelations_Call { + _c.Call.Return(run) + return _c +} + +// FindByAccessToken provides a mock function with given fields: ctx, token +func (_m *MockUserStore) FindByAccessToken(ctx context.Context, token string) (*database.User, error) { + ret := _m.Called(ctx, token) + + if len(ret) == 0 { + panic("no return value specified for FindByAccessToken") + } + + var r0 *database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.User, error)); ok { + return rf(ctx, token) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.User); ok { + r0 = rf(ctx, token) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.User) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, token) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserStore_FindByAccessToken_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByAccessToken' +type MockUserStore_FindByAccessToken_Call struct { + *mock.Call +} + +// FindByAccessToken is a helper method to define mock.On call +// - ctx context.Context +// - token string +func (_e *MockUserStore_Expecter) FindByAccessToken(ctx interface{}, token interface{}) *MockUserStore_FindByAccessToken_Call { + return &MockUserStore_FindByAccessToken_Call{Call: _e.mock.On("FindByAccessToken", ctx, token)} +} + +func (_c *MockUserStore_FindByAccessToken_Call) Run(run func(ctx context.Context, token string)) *MockUserStore_FindByAccessToken_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockUserStore_FindByAccessToken_Call) Return(_a0 *database.User, _a1 error) *MockUserStore_FindByAccessToken_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockUserStore_FindByAccessToken_Call) RunAndReturn(run func(context.Context, string) (*database.User, error)) *MockUserStore_FindByAccessToken_Call { + _c.Call.Return(run) + return _c +} + +// FindByGitAccessToken provides a mock function with given fields: ctx, token +func (_m *MockUserStore) FindByGitAccessToken(ctx context.Context, token string) (*database.User, error) { + ret := _m.Called(ctx, token) + + if len(ret) == 0 { + panic("no return value specified for FindByGitAccessToken") + } + + var r0 *database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.User, error)); ok { + return rf(ctx, token) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.User); ok { + r0 = rf(ctx, token) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.User) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, token) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserStore_FindByGitAccessToken_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByGitAccessToken' +type MockUserStore_FindByGitAccessToken_Call struct { + *mock.Call +} + +// FindByGitAccessToken is a helper method to define mock.On call +// - ctx context.Context +// - token string +func (_e *MockUserStore_Expecter) FindByGitAccessToken(ctx interface{}, token interface{}) *MockUserStore_FindByGitAccessToken_Call { + return &MockUserStore_FindByGitAccessToken_Call{Call: _e.mock.On("FindByGitAccessToken", ctx, token)} +} + +func (_c *MockUserStore_FindByGitAccessToken_Call) Run(run func(ctx context.Context, token string)) *MockUserStore_FindByGitAccessToken_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockUserStore_FindByGitAccessToken_Call) Return(_a0 *database.User, _a1 error) *MockUserStore_FindByGitAccessToken_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockUserStore_FindByGitAccessToken_Call) RunAndReturn(run func(context.Context, string) (*database.User, error)) *MockUserStore_FindByGitAccessToken_Call { + _c.Call.Return(run) + return _c +} + +// FindByID provides a mock function with given fields: ctx, id +func (_m *MockUserStore) FindByID(ctx context.Context, id int) (database.User, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for FindByID") + } + + var r0 database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int) (database.User, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int) database.User); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Get(0).(database.User) + } + + if rf, ok := ret.Get(1).(func(context.Context, int) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserStore_FindByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByID' +type MockUserStore_FindByID_Call struct { + *mock.Call +} + +// FindByID is a helper method to define mock.On call +// - ctx context.Context +// - id int +func (_e *MockUserStore_Expecter) FindByID(ctx interface{}, id interface{}) *MockUserStore_FindByID_Call { + return &MockUserStore_FindByID_Call{Call: _e.mock.On("FindByID", ctx, id)} +} + +func (_c *MockUserStore_FindByID_Call) Run(run func(ctx context.Context, id int)) *MockUserStore_FindByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int)) + }) + return _c +} + +func (_c *MockUserStore_FindByID_Call) Return(user database.User, err error) *MockUserStore_FindByID_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockUserStore_FindByID_Call) RunAndReturn(run func(context.Context, int) (database.User, error)) *MockUserStore_FindByID_Call { + _c.Call.Return(run) + return _c +} + +// FindByUUID provides a mock function with given fields: ctx, uuid +func (_m *MockUserStore) FindByUUID(ctx context.Context, uuid string) (*database.User, error) { + ret := _m.Called(ctx, uuid) + + if len(ret) == 0 { + panic("no return value specified for FindByUUID") + } + + var r0 *database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.User, error)); ok { + return rf(ctx, uuid) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.User); ok { + r0 = rf(ctx, uuid) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.User) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, uuid) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserStore_FindByUUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByUUID' +type MockUserStore_FindByUUID_Call struct { + *mock.Call +} + +// FindByUUID is a helper method to define mock.On call +// - ctx context.Context +// - uuid string +func (_e *MockUserStore_Expecter) FindByUUID(ctx interface{}, uuid interface{}) *MockUserStore_FindByUUID_Call { + return &MockUserStore_FindByUUID_Call{Call: _e.mock.On("FindByUUID", ctx, uuid)} +} + +func (_c *MockUserStore_FindByUUID_Call) Run(run func(ctx context.Context, uuid string)) *MockUserStore_FindByUUID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockUserStore_FindByUUID_Call) Return(_a0 *database.User, _a1 error) *MockUserStore_FindByUUID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockUserStore_FindByUUID_Call) RunAndReturn(run func(context.Context, string) (*database.User, error)) *MockUserStore_FindByUUID_Call { + _c.Call.Return(run) + return _c +} + +// FindByUsername provides a mock function with given fields: ctx, username +func (_m *MockUserStore) FindByUsername(ctx context.Context, username string) (database.User, error) { + ret := _m.Called(ctx, username) + + if len(ret) == 0 { + panic("no return value specified for FindByUsername") + } + + var r0 database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (database.User, error)); ok { + return rf(ctx, username) + } + if rf, ok := ret.Get(0).(func(context.Context, string) database.User); ok { + r0 = rf(ctx, username) + } else { + r0 = ret.Get(0).(database.User) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserStore_FindByUsername_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByUsername' +type MockUserStore_FindByUsername_Call struct { + *mock.Call +} + +// FindByUsername is a helper method to define mock.On call +// - ctx context.Context +// - username string +func (_e *MockUserStore_Expecter) FindByUsername(ctx interface{}, username interface{}) *MockUserStore_FindByUsername_Call { + return &MockUserStore_FindByUsername_Call{Call: _e.mock.On("FindByUsername", ctx, username)} +} + +func (_c *MockUserStore_FindByUsername_Call) Run(run func(ctx context.Context, username string)) *MockUserStore_FindByUsername_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockUserStore_FindByUsername_Call) Return(user database.User, err error) *MockUserStore_FindByUsername_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockUserStore_FindByUsername_Call) RunAndReturn(run func(context.Context, string) (database.User, error)) *MockUserStore_FindByUsername_Call { + _c.Call.Return(run) + return _c +} + +// Index provides a mock function with given fields: ctx +func (_m *MockUserStore) Index(ctx context.Context) ([]database.User, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Index") + } + + var r0 []database.User + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.User, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.User); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.User) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserStore_Index_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Index' +type MockUserStore_Index_Call struct { + *mock.Call +} + +// Index is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockUserStore_Expecter) Index(ctx interface{}) *MockUserStore_Index_Call { + return &MockUserStore_Index_Call{Call: _e.mock.On("Index", ctx)} +} + +func (_c *MockUserStore_Index_Call) Run(run func(ctx context.Context)) *MockUserStore_Index_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockUserStore_Index_Call) Return(users []database.User, err error) *MockUserStore_Index_Call { + _c.Call.Return(users, err) + return _c +} + +func (_c *MockUserStore_Index_Call) RunAndReturn(run func(context.Context) ([]database.User, error)) *MockUserStore_Index_Call { + _c.Call.Return(run) + return _c +} + +// IndexWithSearch provides a mock function with given fields: ctx, search, per, page +func (_m *MockUserStore) IndexWithSearch(ctx context.Context, search string, per int, page int) ([]database.User, int, error) { + ret := _m.Called(ctx, search, per, page) + + if len(ret) == 0 { + panic("no return value specified for IndexWithSearch") + } + + var r0 []database.User + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int) ([]database.User, int, error)); ok { + return rf(ctx, search, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int) []database.User); ok { + r0 = rf(ctx, search, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.User) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int) int); ok { + r1 = rf(ctx, search, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int) error); ok { + r2 = rf(ctx, search, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockUserStore_IndexWithSearch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IndexWithSearch' +type MockUserStore_IndexWithSearch_Call struct { + *mock.Call +} + +// IndexWithSearch is a helper method to define mock.On call +// - ctx context.Context +// - search string +// - per int +// - page int +func (_e *MockUserStore_Expecter) IndexWithSearch(ctx interface{}, search interface{}, per interface{}, page interface{}) *MockUserStore_IndexWithSearch_Call { + return &MockUserStore_IndexWithSearch_Call{Call: _e.mock.On("IndexWithSearch", ctx, search, per, page)} +} + +func (_c *MockUserStore_IndexWithSearch_Call) Run(run func(ctx context.Context, search string, per int, page int)) *MockUserStore_IndexWithSearch_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockUserStore_IndexWithSearch_Call) Return(users []database.User, count int, err error) *MockUserStore_IndexWithSearch_Call { + _c.Call.Return(users, count, err) + return _c +} + +func (_c *MockUserStore_IndexWithSearch_Call) RunAndReturn(run func(context.Context, string, int, int) ([]database.User, int, error)) *MockUserStore_IndexWithSearch_Call { + _c.Call.Return(run) + return _c +} + +// IsExist provides a mock function with given fields: ctx, username +func (_m *MockUserStore) IsExist(ctx context.Context, username string) (bool, error) { + ret := _m.Called(ctx, username) + + if len(ret) == 0 { + panic("no return value specified for IsExist") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (bool, error)); ok { + return rf(ctx, username) + } + if rf, ok := ret.Get(0).(func(context.Context, string) bool); ok { + r0 = rf(ctx, username) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserStore_IsExist_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsExist' +type MockUserStore_IsExist_Call struct { + *mock.Call +} + +// IsExist is a helper method to define mock.On call +// - ctx context.Context +// - username string +func (_e *MockUserStore_Expecter) IsExist(ctx interface{}, username interface{}) *MockUserStore_IsExist_Call { + return &MockUserStore_IsExist_Call{Call: _e.mock.On("IsExist", ctx, username)} +} + +func (_c *MockUserStore_IsExist_Call) Run(run func(ctx context.Context, username string)) *MockUserStore_IsExist_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockUserStore_IsExist_Call) Return(exists bool, err error) *MockUserStore_IsExist_Call { + _c.Call.Return(exists, err) + return _c +} + +func (_c *MockUserStore_IsExist_Call) RunAndReturn(run func(context.Context, string) (bool, error)) *MockUserStore_IsExist_Call { + _c.Call.Return(run) + return _c +} + +// IsExistByUUID provides a mock function with given fields: ctx, uuid +func (_m *MockUserStore) IsExistByUUID(ctx context.Context, uuid string) (bool, error) { + ret := _m.Called(ctx, uuid) + + if len(ret) == 0 { + panic("no return value specified for IsExistByUUID") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (bool, error)); ok { + return rf(ctx, uuid) + } + if rf, ok := ret.Get(0).(func(context.Context, string) bool); ok { + r0 = rf(ctx, uuid) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, uuid) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockUserStore_IsExistByUUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsExistByUUID' +type MockUserStore_IsExistByUUID_Call struct { + *mock.Call +} + +// IsExistByUUID is a helper method to define mock.On call +// - ctx context.Context +// - uuid string +func (_e *MockUserStore_Expecter) IsExistByUUID(ctx interface{}, uuid interface{}) *MockUserStore_IsExistByUUID_Call { + return &MockUserStore_IsExistByUUID_Call{Call: _e.mock.On("IsExistByUUID", ctx, uuid)} +} + +func (_c *MockUserStore_IsExistByUUID_Call) Run(run func(ctx context.Context, uuid string)) *MockUserStore_IsExistByUUID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockUserStore_IsExistByUUID_Call) Return(exists bool, err error) *MockUserStore_IsExistByUUID_Call { + _c.Call.Return(exists, err) + return _c +} + +func (_c *MockUserStore_IsExistByUUID_Call) RunAndReturn(run func(context.Context, string) (bool, error)) *MockUserStore_IsExistByUUID_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, user +func (_m *MockUserStore) Update(ctx context.Context, user *database.User) error { + ret := _m.Called(ctx, user) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.User) error); ok { + r0 = rf(ctx, user) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockUserStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockUserStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - user *database.User +func (_e *MockUserStore_Expecter) Update(ctx interface{}, user interface{}) *MockUserStore_Update_Call { + return &MockUserStore_Update_Call{Call: _e.mock.On("Update", ctx, user)} +} + +func (_c *MockUserStore_Update_Call) Run(run func(ctx context.Context, user *database.User)) *MockUserStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.User)) + }) + return _c +} + +func (_c *MockUserStore_Update_Call) Return(err error) *MockUserStore_Update_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockUserStore_Update_Call) RunAndReturn(run func(context.Context, *database.User) error) *MockUserStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockUserStore creates a new instance of MockUserStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockUserStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockUserStore { + mock := &MockUserStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/component/mock_RepoComponent.go b/_mocks/opencsg.com/csghub-server/component/mock_RepoComponent.go new file mode 100644 index 00000000..11296f06 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/component/mock_RepoComponent.go @@ -0,0 +1,3373 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package component + +import ( + context "context" + + deploy "opencsg.com/csghub-server/builder/deploy" + database "opencsg.com/csghub-server/builder/store/database" + + gitserver "opencsg.com/csghub-server/builder/git/gitserver" + + io "io" + + membership "opencsg.com/csghub-server/builder/git/membership" + + mock "github.com/stretchr/testify/mock" + + types "opencsg.com/csghub-server/common/types" +) + +// MockRepoComponent is an autogenerated mock type for the RepoComponent type +type MockRepoComponent struct { + mock.Mock +} + +type MockRepoComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRepoComponent) EXPECT() *MockRepoComponent_Expecter { + return &MockRepoComponent_Expecter{mock: &_m.Mock} +} + +// AllFiles provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) AllFiles(ctx context.Context, req types.GetAllFilesReq) ([]*types.File, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for AllFiles") + } + + var r0 []*types.File + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.GetAllFilesReq) ([]*types.File, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.GetAllFilesReq) []*types.File); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*types.File) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.GetAllFilesReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_AllFiles_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllFiles' +type MockRepoComponent_AllFiles_Call struct { + *mock.Call +} + +// AllFiles is a helper method to define mock.On call +// - ctx context.Context +// - req types.GetAllFilesReq +func (_e *MockRepoComponent_Expecter) AllFiles(ctx interface{}, req interface{}) *MockRepoComponent_AllFiles_Call { + return &MockRepoComponent_AllFiles_Call{Call: _e.mock.On("AllFiles", ctx, req)} +} + +func (_c *MockRepoComponent_AllFiles_Call) Run(run func(ctx context.Context, req types.GetAllFilesReq)) *MockRepoComponent_AllFiles_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.GetAllFilesReq)) + }) + return _c +} + +func (_c *MockRepoComponent_AllFiles_Call) Return(_a0 []*types.File, _a1 error) *MockRepoComponent_AllFiles_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_AllFiles_Call) RunAndReturn(run func(context.Context, types.GetAllFilesReq) ([]*types.File, error)) *MockRepoComponent_AllFiles_Call { + _c.Call.Return(run) + return _c +} + +// AllowAccessByRepoID provides a mock function with given fields: ctx, repoID, username +func (_m *MockRepoComponent) AllowAccessByRepoID(ctx context.Context, repoID int64, username string) (bool, error) { + ret := _m.Called(ctx, repoID, username) + + if len(ret) == 0 { + panic("no return value specified for AllowAccessByRepoID") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) (bool, error)); ok { + return rf(ctx, repoID, username) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, string) bool); ok { + r0 = rf(ctx, repoID, username) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, string) error); ok { + r1 = rf(ctx, repoID, username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_AllowAccessByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowAccessByRepoID' +type MockRepoComponent_AllowAccessByRepoID_Call struct { + *mock.Call +} + +// AllowAccessByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - username string +func (_e *MockRepoComponent_Expecter) AllowAccessByRepoID(ctx interface{}, repoID interface{}, username interface{}) *MockRepoComponent_AllowAccessByRepoID_Call { + return &MockRepoComponent_AllowAccessByRepoID_Call{Call: _e.mock.On("AllowAccessByRepoID", ctx, repoID, username)} +} + +func (_c *MockRepoComponent_AllowAccessByRepoID_Call) Run(run func(ctx context.Context, repoID int64, username string)) *MockRepoComponent_AllowAccessByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_AllowAccessByRepoID_Call) Return(_a0 bool, _a1 error) *MockRepoComponent_AllowAccessByRepoID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_AllowAccessByRepoID_Call) RunAndReturn(run func(context.Context, int64, string) (bool, error)) *MockRepoComponent_AllowAccessByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// AllowAccessDeploy provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) AllowAccessDeploy(ctx context.Context, req types.DeployActReq) (bool, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for AllowAccessDeploy") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq) (bool, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq) bool); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployActReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_AllowAccessDeploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowAccessDeploy' +type MockRepoComponent_AllowAccessDeploy_Call struct { + *mock.Call +} + +// AllowAccessDeploy is a helper method to define mock.On call +// - ctx context.Context +// - req types.DeployActReq +func (_e *MockRepoComponent_Expecter) AllowAccessDeploy(ctx interface{}, req interface{}) *MockRepoComponent_AllowAccessDeploy_Call { + return &MockRepoComponent_AllowAccessDeploy_Call{Call: _e.mock.On("AllowAccessDeploy", ctx, req)} +} + +func (_c *MockRepoComponent_AllowAccessDeploy_Call) Run(run func(ctx context.Context, req types.DeployActReq)) *MockRepoComponent_AllowAccessDeploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployActReq)) + }) + return _c +} + +func (_c *MockRepoComponent_AllowAccessDeploy_Call) Return(_a0 bool, _a1 error) *MockRepoComponent_AllowAccessDeploy_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_AllowAccessDeploy_Call) RunAndReturn(run func(context.Context, types.DeployActReq) (bool, error)) *MockRepoComponent_AllowAccessDeploy_Call { + _c.Call.Return(run) + return _c +} + +// AllowAccessEndpoint provides a mock function with given fields: ctx, currentUser, _a2 +func (_m *MockRepoComponent) AllowAccessEndpoint(ctx context.Context, currentUser string, _a2 *database.Deploy) (bool, error) { + ret := _m.Called(ctx, currentUser, _a2) + + if len(ret) == 0 { + panic("no return value specified for AllowAccessEndpoint") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, *database.Deploy) (bool, error)); ok { + return rf(ctx, currentUser, _a2) + } + if rf, ok := ret.Get(0).(func(context.Context, string, *database.Deploy) bool); ok { + r0 = rf(ctx, currentUser, _a2) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, *database.Deploy) error); ok { + r1 = rf(ctx, currentUser, _a2) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_AllowAccessEndpoint_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowAccessEndpoint' +type MockRepoComponent_AllowAccessEndpoint_Call struct { + *mock.Call +} + +// AllowAccessEndpoint is a helper method to define mock.On call +// - ctx context.Context +// - currentUser string +// - _a2 *database.Deploy +func (_e *MockRepoComponent_Expecter) AllowAccessEndpoint(ctx interface{}, currentUser interface{}, _a2 interface{}) *MockRepoComponent_AllowAccessEndpoint_Call { + return &MockRepoComponent_AllowAccessEndpoint_Call{Call: _e.mock.On("AllowAccessEndpoint", ctx, currentUser, _a2)} +} + +func (_c *MockRepoComponent_AllowAccessEndpoint_Call) Run(run func(ctx context.Context, currentUser string, _a2 *database.Deploy)) *MockRepoComponent_AllowAccessEndpoint_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(*database.Deploy)) + }) + return _c +} + +func (_c *MockRepoComponent_AllowAccessEndpoint_Call) Return(_a0 bool, _a1 error) *MockRepoComponent_AllowAccessEndpoint_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_AllowAccessEndpoint_Call) RunAndReturn(run func(context.Context, string, *database.Deploy) (bool, error)) *MockRepoComponent_AllowAccessEndpoint_Call { + _c.Call.Return(run) + return _c +} + +// AllowAdminAccess provides a mock function with given fields: ctx, repoType, namespace, name, username +func (_m *MockRepoComponent) AllowAdminAccess(ctx context.Context, repoType types.RepositoryType, namespace string, name string, username string) (bool, error) { + ret := _m.Called(ctx, repoType, namespace, name, username) + + if len(ret) == 0 { + panic("no return value specified for AllowAdminAccess") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string) (bool, error)); ok { + return rf(ctx, repoType, namespace, name, username) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string) bool); ok { + r0 = rf(ctx, repoType, namespace, name, username) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string, string) error); ok { + r1 = rf(ctx, repoType, namespace, name, username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_AllowAdminAccess_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowAdminAccess' +type MockRepoComponent_AllowAdminAccess_Call struct { + *mock.Call +} + +// AllowAdminAccess is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - username string +func (_e *MockRepoComponent_Expecter) AllowAdminAccess(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, username interface{}) *MockRepoComponent_AllowAdminAccess_Call { + return &MockRepoComponent_AllowAdminAccess_Call{Call: _e.mock.On("AllowAdminAccess", ctx, repoType, namespace, name, username)} +} + +func (_c *MockRepoComponent_AllowAdminAccess_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, username string)) *MockRepoComponent_AllowAdminAccess_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_AllowAdminAccess_Call) Return(_a0 bool, _a1 error) *MockRepoComponent_AllowAdminAccess_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_AllowAdminAccess_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, string) (bool, error)) *MockRepoComponent_AllowAdminAccess_Call { + _c.Call.Return(run) + return _c +} + +// AllowReadAccess provides a mock function with given fields: ctx, repoType, namespace, name, username +func (_m *MockRepoComponent) AllowReadAccess(ctx context.Context, repoType types.RepositoryType, namespace string, name string, username string) (bool, error) { + ret := _m.Called(ctx, repoType, namespace, name, username) + + if len(ret) == 0 { + panic("no return value specified for AllowReadAccess") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string) (bool, error)); ok { + return rf(ctx, repoType, namespace, name, username) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string) bool); ok { + r0 = rf(ctx, repoType, namespace, name, username) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string, string) error); ok { + r1 = rf(ctx, repoType, namespace, name, username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_AllowReadAccess_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowReadAccess' +type MockRepoComponent_AllowReadAccess_Call struct { + *mock.Call +} + +// AllowReadAccess is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - username string +func (_e *MockRepoComponent_Expecter) AllowReadAccess(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, username interface{}) *MockRepoComponent_AllowReadAccess_Call { + return &MockRepoComponent_AllowReadAccess_Call{Call: _e.mock.On("AllowReadAccess", ctx, repoType, namespace, name, username)} +} + +func (_c *MockRepoComponent_AllowReadAccess_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, username string)) *MockRepoComponent_AllowReadAccess_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_AllowReadAccess_Call) Return(_a0 bool, _a1 error) *MockRepoComponent_AllowReadAccess_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_AllowReadAccess_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, string) (bool, error)) *MockRepoComponent_AllowReadAccess_Call { + _c.Call.Return(run) + return _c +} + +// AllowReadAccessByDeployID provides a mock function with given fields: ctx, repoType, namespace, name, currentUser, deployID +func (_m *MockRepoComponent) AllowReadAccessByDeployID(ctx context.Context, repoType types.RepositoryType, namespace string, name string, currentUser string, deployID int64) (bool, error) { + ret := _m.Called(ctx, repoType, namespace, name, currentUser, deployID) + + if len(ret) == 0 { + panic("no return value specified for AllowReadAccessByDeployID") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string, int64) (bool, error)); ok { + return rf(ctx, repoType, namespace, name, currentUser, deployID) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string, int64) bool); ok { + r0 = rf(ctx, repoType, namespace, name, currentUser, deployID) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string, string, int64) error); ok { + r1 = rf(ctx, repoType, namespace, name, currentUser, deployID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_AllowReadAccessByDeployID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowReadAccessByDeployID' +type MockRepoComponent_AllowReadAccessByDeployID_Call struct { + *mock.Call +} + +// AllowReadAccessByDeployID is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - currentUser string +// - deployID int64 +func (_e *MockRepoComponent_Expecter) AllowReadAccessByDeployID(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, currentUser interface{}, deployID interface{}) *MockRepoComponent_AllowReadAccessByDeployID_Call { + return &MockRepoComponent_AllowReadAccessByDeployID_Call{Call: _e.mock.On("AllowReadAccessByDeployID", ctx, repoType, namespace, name, currentUser, deployID)} +} + +func (_c *MockRepoComponent_AllowReadAccessByDeployID_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, currentUser string, deployID int64)) *MockRepoComponent_AllowReadAccessByDeployID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(string), args[5].(int64)) + }) + return _c +} + +func (_c *MockRepoComponent_AllowReadAccessByDeployID_Call) Return(_a0 bool, _a1 error) *MockRepoComponent_AllowReadAccessByDeployID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_AllowReadAccessByDeployID_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, string, int64) (bool, error)) *MockRepoComponent_AllowReadAccessByDeployID_Call { + _c.Call.Return(run) + return _c +} + +// AllowReadAccessRepo provides a mock function with given fields: ctx, repo, username +func (_m *MockRepoComponent) AllowReadAccessRepo(ctx context.Context, repo *database.Repository, username string) (bool, error) { + ret := _m.Called(ctx, repo, username) + + if len(ret) == 0 { + panic("no return value specified for AllowReadAccessRepo") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Repository, string) (bool, error)); ok { + return rf(ctx, repo, username) + } + if rf, ok := ret.Get(0).(func(context.Context, *database.Repository, string) bool); ok { + r0 = rf(ctx, repo, username) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, *database.Repository, string) error); ok { + r1 = rf(ctx, repo, username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_AllowReadAccessRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowReadAccessRepo' +type MockRepoComponent_AllowReadAccessRepo_Call struct { + *mock.Call +} + +// AllowReadAccessRepo is a helper method to define mock.On call +// - ctx context.Context +// - repo *database.Repository +// - username string +func (_e *MockRepoComponent_Expecter) AllowReadAccessRepo(ctx interface{}, repo interface{}, username interface{}) *MockRepoComponent_AllowReadAccessRepo_Call { + return &MockRepoComponent_AllowReadAccessRepo_Call{Call: _e.mock.On("AllowReadAccessRepo", ctx, repo, username)} +} + +func (_c *MockRepoComponent_AllowReadAccessRepo_Call) Run(run func(ctx context.Context, repo *database.Repository, username string)) *MockRepoComponent_AllowReadAccessRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Repository), args[2].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_AllowReadAccessRepo_Call) Return(_a0 bool, _a1 error) *MockRepoComponent_AllowReadAccessRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_AllowReadAccessRepo_Call) RunAndReturn(run func(context.Context, *database.Repository, string) (bool, error)) *MockRepoComponent_AllowReadAccessRepo_Call { + _c.Call.Return(run) + return _c +} + +// AllowWriteAccess provides a mock function with given fields: ctx, repoType, namespace, name, username +func (_m *MockRepoComponent) AllowWriteAccess(ctx context.Context, repoType types.RepositoryType, namespace string, name string, username string) (bool, error) { + ret := _m.Called(ctx, repoType, namespace, name, username) + + if len(ret) == 0 { + panic("no return value specified for AllowWriteAccess") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string) (bool, error)); ok { + return rf(ctx, repoType, namespace, name, username) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string) bool); ok { + r0 = rf(ctx, repoType, namespace, name, username) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string, string) error); ok { + r1 = rf(ctx, repoType, namespace, name, username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_AllowWriteAccess_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowWriteAccess' +type MockRepoComponent_AllowWriteAccess_Call struct { + *mock.Call +} + +// AllowWriteAccess is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - username string +func (_e *MockRepoComponent_Expecter) AllowWriteAccess(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, username interface{}) *MockRepoComponent_AllowWriteAccess_Call { + return &MockRepoComponent_AllowWriteAccess_Call{Call: _e.mock.On("AllowWriteAccess", ctx, repoType, namespace, name, username)} +} + +func (_c *MockRepoComponent_AllowWriteAccess_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, username string)) *MockRepoComponent_AllowWriteAccess_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_AllowWriteAccess_Call) Return(_a0 bool, _a1 error) *MockRepoComponent_AllowWriteAccess_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_AllowWriteAccess_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, string) (bool, error)) *MockRepoComponent_AllowWriteAccess_Call { + _c.Call.Return(run) + return _c +} + +// Branches provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) Branches(ctx context.Context, req *types.GetBranchesReq) ([]types.Branch, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Branches") + } + + var r0 []types.Branch + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetBranchesReq) ([]types.Branch, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetBranchesReq) []types.Branch); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Branch) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetBranchesReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_Branches_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Branches' +type MockRepoComponent_Branches_Call struct { + *mock.Call +} + +// Branches is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetBranchesReq +func (_e *MockRepoComponent_Expecter) Branches(ctx interface{}, req interface{}) *MockRepoComponent_Branches_Call { + return &MockRepoComponent_Branches_Call{Call: _e.mock.On("Branches", ctx, req)} +} + +func (_c *MockRepoComponent_Branches_Call) Run(run func(ctx context.Context, req *types.GetBranchesReq)) *MockRepoComponent_Branches_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetBranchesReq)) + }) + return _c +} + +func (_c *MockRepoComponent_Branches_Call) Return(_a0 []types.Branch, _a1 error) *MockRepoComponent_Branches_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_Branches_Call) RunAndReturn(run func(context.Context, *types.GetBranchesReq) ([]types.Branch, error)) *MockRepoComponent_Branches_Call { + _c.Call.Return(run) + return _c +} + +// CheckCurrentUserPermission provides a mock function with given fields: ctx, userName, namespace, role +func (_m *MockRepoComponent) CheckCurrentUserPermission(ctx context.Context, userName string, namespace string, role membership.Role) (bool, error) { + ret := _m.Called(ctx, userName, namespace, role) + + if len(ret) == 0 { + panic("no return value specified for CheckCurrentUserPermission") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, membership.Role) (bool, error)); ok { + return rf(ctx, userName, namespace, role) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, membership.Role) bool); ok { + r0 = rf(ctx, userName, namespace, role) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, membership.Role) error); ok { + r1 = rf(ctx, userName, namespace, role) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_CheckCurrentUserPermission_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckCurrentUserPermission' +type MockRepoComponent_CheckCurrentUserPermission_Call struct { + *mock.Call +} + +// CheckCurrentUserPermission is a helper method to define mock.On call +// - ctx context.Context +// - userName string +// - namespace string +// - role membership.Role +func (_e *MockRepoComponent_Expecter) CheckCurrentUserPermission(ctx interface{}, userName interface{}, namespace interface{}, role interface{}) *MockRepoComponent_CheckCurrentUserPermission_Call { + return &MockRepoComponent_CheckCurrentUserPermission_Call{Call: _e.mock.On("CheckCurrentUserPermission", ctx, userName, namespace, role)} +} + +func (_c *MockRepoComponent_CheckCurrentUserPermission_Call) Run(run func(ctx context.Context, userName string, namespace string, role membership.Role)) *MockRepoComponent_CheckCurrentUserPermission_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(membership.Role)) + }) + return _c +} + +func (_c *MockRepoComponent_CheckCurrentUserPermission_Call) Return(_a0 bool, _a1 error) *MockRepoComponent_CheckCurrentUserPermission_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_CheckCurrentUserPermission_Call) RunAndReturn(run func(context.Context, string, string, membership.Role) (bool, error)) *MockRepoComponent_CheckCurrentUserPermission_Call { + _c.Call.Return(run) + return _c +} + +// Commits provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) Commits(ctx context.Context, req *types.GetCommitsReq) ([]types.Commit, *types.RepoPageOpts, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Commits") + } + + var r0 []types.Commit + var r1 *types.RepoPageOpts + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetCommitsReq) ([]types.Commit, *types.RepoPageOpts, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetCommitsReq) []types.Commit); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Commit) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetCommitsReq) *types.RepoPageOpts); ok { + r1 = rf(ctx, req) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*types.RepoPageOpts) + } + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.GetCommitsReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockRepoComponent_Commits_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Commits' +type MockRepoComponent_Commits_Call struct { + *mock.Call +} + +// Commits is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetCommitsReq +func (_e *MockRepoComponent_Expecter) Commits(ctx interface{}, req interface{}) *MockRepoComponent_Commits_Call { + return &MockRepoComponent_Commits_Call{Call: _e.mock.On("Commits", ctx, req)} +} + +func (_c *MockRepoComponent_Commits_Call) Run(run func(ctx context.Context, req *types.GetCommitsReq)) *MockRepoComponent_Commits_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetCommitsReq)) + }) + return _c +} + +func (_c *MockRepoComponent_Commits_Call) Return(_a0 []types.Commit, _a1 *types.RepoPageOpts, _a2 error) *MockRepoComponent_Commits_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockRepoComponent_Commits_Call) RunAndReturn(run func(context.Context, *types.GetCommitsReq) ([]types.Commit, *types.RepoPageOpts, error)) *MockRepoComponent_Commits_Call { + _c.Call.Return(run) + return _c +} + +// CreateFile provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) CreateFile(ctx context.Context, req *types.CreateFileReq) (*types.CreateFileResp, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for CreateFile") + } + + var r0 *types.CreateFileResp + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.CreateFileReq) (*types.CreateFileResp, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.CreateFileReq) *types.CreateFileResp); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.CreateFileResp) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.CreateFileReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_CreateFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateFile' +type MockRepoComponent_CreateFile_Call struct { + *mock.Call +} + +// CreateFile is a helper method to define mock.On call +// - ctx context.Context +// - req *types.CreateFileReq +func (_e *MockRepoComponent_Expecter) CreateFile(ctx interface{}, req interface{}) *MockRepoComponent_CreateFile_Call { + return &MockRepoComponent_CreateFile_Call{Call: _e.mock.On("CreateFile", ctx, req)} +} + +func (_c *MockRepoComponent_CreateFile_Call) Run(run func(ctx context.Context, req *types.CreateFileReq)) *MockRepoComponent_CreateFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.CreateFileReq)) + }) + return _c +} + +func (_c *MockRepoComponent_CreateFile_Call) Return(_a0 *types.CreateFileResp, _a1 error) *MockRepoComponent_CreateFile_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_CreateFile_Call) RunAndReturn(run func(context.Context, *types.CreateFileReq) (*types.CreateFileResp, error)) *MockRepoComponent_CreateFile_Call { + _c.Call.Return(run) + return _c +} + +// CreateMirror provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) CreateMirror(ctx context.Context, req types.CreateMirrorReq) (*database.Mirror, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for CreateMirror") + } + + var r0 *database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.CreateMirrorReq) (*database.Mirror, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.CreateMirrorReq) *database.Mirror); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.CreateMirrorReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_CreateMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateMirror' +type MockRepoComponent_CreateMirror_Call struct { + *mock.Call +} + +// CreateMirror is a helper method to define mock.On call +// - ctx context.Context +// - req types.CreateMirrorReq +func (_e *MockRepoComponent_Expecter) CreateMirror(ctx interface{}, req interface{}) *MockRepoComponent_CreateMirror_Call { + return &MockRepoComponent_CreateMirror_Call{Call: _e.mock.On("CreateMirror", ctx, req)} +} + +func (_c *MockRepoComponent_CreateMirror_Call) Run(run func(ctx context.Context, req types.CreateMirrorReq)) *MockRepoComponent_CreateMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.CreateMirrorReq)) + }) + return _c +} + +func (_c *MockRepoComponent_CreateMirror_Call) Return(_a0 *database.Mirror, _a1 error) *MockRepoComponent_CreateMirror_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_CreateMirror_Call) RunAndReturn(run func(context.Context, types.CreateMirrorReq) (*database.Mirror, error)) *MockRepoComponent_CreateMirror_Call { + _c.Call.Return(run) + return _c +} + +// CreateRepo provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) CreateRepo(ctx context.Context, req types.CreateRepoReq) (*gitserver.CreateRepoResp, *database.Repository, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for CreateRepo") + } + + var r0 *gitserver.CreateRepoResp + var r1 *database.Repository + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, types.CreateRepoReq) (*gitserver.CreateRepoResp, *database.Repository, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.CreateRepoReq) *gitserver.CreateRepoResp); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gitserver.CreateRepoResp) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.CreateRepoReq) *database.Repository); ok { + r1 = rf(ctx, req) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*database.Repository) + } + } + + if rf, ok := ret.Get(2).(func(context.Context, types.CreateRepoReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockRepoComponent_CreateRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRepo' +type MockRepoComponent_CreateRepo_Call struct { + *mock.Call +} + +// CreateRepo is a helper method to define mock.On call +// - ctx context.Context +// - req types.CreateRepoReq +func (_e *MockRepoComponent_Expecter) CreateRepo(ctx interface{}, req interface{}) *MockRepoComponent_CreateRepo_Call { + return &MockRepoComponent_CreateRepo_Call{Call: _e.mock.On("CreateRepo", ctx, req)} +} + +func (_c *MockRepoComponent_CreateRepo_Call) Run(run func(ctx context.Context, req types.CreateRepoReq)) *MockRepoComponent_CreateRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.CreateRepoReq)) + }) + return _c +} + +func (_c *MockRepoComponent_CreateRepo_Call) Return(_a0 *gitserver.CreateRepoResp, _a1 *database.Repository, _a2 error) *MockRepoComponent_CreateRepo_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockRepoComponent_CreateRepo_Call) RunAndReturn(run func(context.Context, types.CreateRepoReq) (*gitserver.CreateRepoResp, *database.Repository, error)) *MockRepoComponent_CreateRepo_Call { + _c.Call.Return(run) + return _c +} + +// CreateRuntimeFramework provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) CreateRuntimeFramework(ctx context.Context, req *types.RuntimeFrameworkReq) (*types.RuntimeFramework, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for CreateRuntimeFramework") + } + + var r0 *types.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.RuntimeFrameworkReq) (*types.RuntimeFramework, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.RuntimeFrameworkReq) *types.RuntimeFramework); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.RuntimeFrameworkReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_CreateRuntimeFramework_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRuntimeFramework' +type MockRepoComponent_CreateRuntimeFramework_Call struct { + *mock.Call +} + +// CreateRuntimeFramework is a helper method to define mock.On call +// - ctx context.Context +// - req *types.RuntimeFrameworkReq +func (_e *MockRepoComponent_Expecter) CreateRuntimeFramework(ctx interface{}, req interface{}) *MockRepoComponent_CreateRuntimeFramework_Call { + return &MockRepoComponent_CreateRuntimeFramework_Call{Call: _e.mock.On("CreateRuntimeFramework", ctx, req)} +} + +func (_c *MockRepoComponent_CreateRuntimeFramework_Call) Run(run func(ctx context.Context, req *types.RuntimeFrameworkReq)) *MockRepoComponent_CreateRuntimeFramework_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.RuntimeFrameworkReq)) + }) + return _c +} + +func (_c *MockRepoComponent_CreateRuntimeFramework_Call) Return(_a0 *types.RuntimeFramework, _a1 error) *MockRepoComponent_CreateRuntimeFramework_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_CreateRuntimeFramework_Call) RunAndReturn(run func(context.Context, *types.RuntimeFrameworkReq) (*types.RuntimeFramework, error)) *MockRepoComponent_CreateRuntimeFramework_Call { + _c.Call.Return(run) + return _c +} + +// DeleteDeploy provides a mock function with given fields: ctx, delReq +func (_m *MockRepoComponent) DeleteDeploy(ctx context.Context, delReq types.DeployActReq) error { + ret := _m.Called(ctx, delReq) + + if len(ret) == 0 { + panic("no return value specified for DeleteDeploy") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq) error); ok { + r0 = rf(ctx, delReq) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_DeleteDeploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteDeploy' +type MockRepoComponent_DeleteDeploy_Call struct { + *mock.Call +} + +// DeleteDeploy is a helper method to define mock.On call +// - ctx context.Context +// - delReq types.DeployActReq +func (_e *MockRepoComponent_Expecter) DeleteDeploy(ctx interface{}, delReq interface{}) *MockRepoComponent_DeleteDeploy_Call { + return &MockRepoComponent_DeleteDeploy_Call{Call: _e.mock.On("DeleteDeploy", ctx, delReq)} +} + +func (_c *MockRepoComponent_DeleteDeploy_Call) Run(run func(ctx context.Context, delReq types.DeployActReq)) *MockRepoComponent_DeleteDeploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployActReq)) + }) + return _c +} + +func (_c *MockRepoComponent_DeleteDeploy_Call) Return(_a0 error) *MockRepoComponent_DeleteDeploy_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_DeleteDeploy_Call) RunAndReturn(run func(context.Context, types.DeployActReq) error) *MockRepoComponent_DeleteDeploy_Call { + _c.Call.Return(run) + return _c +} + +// DeleteFile provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) DeleteFile(ctx context.Context, req *types.DeleteFileReq) (*types.DeleteFileResp, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for DeleteFile") + } + + var r0 *types.DeleteFileResp + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.DeleteFileReq) (*types.DeleteFileResp, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.DeleteFileReq) *types.DeleteFileResp); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.DeleteFileResp) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.DeleteFileReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_DeleteFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteFile' +type MockRepoComponent_DeleteFile_Call struct { + *mock.Call +} + +// DeleteFile is a helper method to define mock.On call +// - ctx context.Context +// - req *types.DeleteFileReq +func (_e *MockRepoComponent_Expecter) DeleteFile(ctx interface{}, req interface{}) *MockRepoComponent_DeleteFile_Call { + return &MockRepoComponent_DeleteFile_Call{Call: _e.mock.On("DeleteFile", ctx, req)} +} + +func (_c *MockRepoComponent_DeleteFile_Call) Run(run func(ctx context.Context, req *types.DeleteFileReq)) *MockRepoComponent_DeleteFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.DeleteFileReq)) + }) + return _c +} + +func (_c *MockRepoComponent_DeleteFile_Call) Return(_a0 *types.DeleteFileResp, _a1 error) *MockRepoComponent_DeleteFile_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_DeleteFile_Call) RunAndReturn(run func(context.Context, *types.DeleteFileReq) (*types.DeleteFileResp, error)) *MockRepoComponent_DeleteFile_Call { + _c.Call.Return(run) + return _c +} + +// DeleteMirror provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) DeleteMirror(ctx context.Context, req types.DeleteMirrorReq) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for DeleteMirror") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeleteMirrorReq) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_DeleteMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteMirror' +type MockRepoComponent_DeleteMirror_Call struct { + *mock.Call +} + +// DeleteMirror is a helper method to define mock.On call +// - ctx context.Context +// - req types.DeleteMirrorReq +func (_e *MockRepoComponent_Expecter) DeleteMirror(ctx interface{}, req interface{}) *MockRepoComponent_DeleteMirror_Call { + return &MockRepoComponent_DeleteMirror_Call{Call: _e.mock.On("DeleteMirror", ctx, req)} +} + +func (_c *MockRepoComponent_DeleteMirror_Call) Run(run func(ctx context.Context, req types.DeleteMirrorReq)) *MockRepoComponent_DeleteMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeleteMirrorReq)) + }) + return _c +} + +func (_c *MockRepoComponent_DeleteMirror_Call) Return(_a0 error) *MockRepoComponent_DeleteMirror_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_DeleteMirror_Call) RunAndReturn(run func(context.Context, types.DeleteMirrorReq) error) *MockRepoComponent_DeleteMirror_Call { + _c.Call.Return(run) + return _c +} + +// DeleteRepo provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) DeleteRepo(ctx context.Context, req types.DeleteRepoReq) (*database.Repository, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for DeleteRepo") + } + + var r0 *database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeleteRepoReq) (*database.Repository, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeleteRepoReq) *database.Repository); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeleteRepoReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_DeleteRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteRepo' +type MockRepoComponent_DeleteRepo_Call struct { + *mock.Call +} + +// DeleteRepo is a helper method to define mock.On call +// - ctx context.Context +// - req types.DeleteRepoReq +func (_e *MockRepoComponent_Expecter) DeleteRepo(ctx interface{}, req interface{}) *MockRepoComponent_DeleteRepo_Call { + return &MockRepoComponent_DeleteRepo_Call{Call: _e.mock.On("DeleteRepo", ctx, req)} +} + +func (_c *MockRepoComponent_DeleteRepo_Call) Run(run func(ctx context.Context, req types.DeleteRepoReq)) *MockRepoComponent_DeleteRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeleteRepoReq)) + }) + return _c +} + +func (_c *MockRepoComponent_DeleteRepo_Call) Return(_a0 *database.Repository, _a1 error) *MockRepoComponent_DeleteRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_DeleteRepo_Call) RunAndReturn(run func(context.Context, types.DeleteRepoReq) (*database.Repository, error)) *MockRepoComponent_DeleteRepo_Call { + _c.Call.Return(run) + return _c +} + +// DeleteRuntimeFramework provides a mock function with given fields: ctx, id +func (_m *MockRepoComponent) DeleteRuntimeFramework(ctx context.Context, id int64) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for DeleteRuntimeFramework") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_DeleteRuntimeFramework_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteRuntimeFramework' +type MockRepoComponent_DeleteRuntimeFramework_Call struct { + *mock.Call +} + +// DeleteRuntimeFramework is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockRepoComponent_Expecter) DeleteRuntimeFramework(ctx interface{}, id interface{}) *MockRepoComponent_DeleteRuntimeFramework_Call { + return &MockRepoComponent_DeleteRuntimeFramework_Call{Call: _e.mock.On("DeleteRuntimeFramework", ctx, id)} +} + +func (_c *MockRepoComponent_DeleteRuntimeFramework_Call) Run(run func(ctx context.Context, id int64)) *MockRepoComponent_DeleteRuntimeFramework_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepoComponent_DeleteRuntimeFramework_Call) Return(_a0 error) *MockRepoComponent_DeleteRuntimeFramework_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_DeleteRuntimeFramework_Call) RunAndReturn(run func(context.Context, int64) error) *MockRepoComponent_DeleteRuntimeFramework_Call { + _c.Call.Return(run) + return _c +} + +// DeployDetail provides a mock function with given fields: ctx, detailReq +func (_m *MockRepoComponent) DeployDetail(ctx context.Context, detailReq types.DeployActReq) (*types.DeployRepo, error) { + ret := _m.Called(ctx, detailReq) + + if len(ret) == 0 { + panic("no return value specified for DeployDetail") + } + + var r0 *types.DeployRepo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq) (*types.DeployRepo, error)); ok { + return rf(ctx, detailReq) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq) *types.DeployRepo); ok { + r0 = rf(ctx, detailReq) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.DeployRepo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployActReq) error); ok { + r1 = rf(ctx, detailReq) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_DeployDetail_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeployDetail' +type MockRepoComponent_DeployDetail_Call struct { + *mock.Call +} + +// DeployDetail is a helper method to define mock.On call +// - ctx context.Context +// - detailReq types.DeployActReq +func (_e *MockRepoComponent_Expecter) DeployDetail(ctx interface{}, detailReq interface{}) *MockRepoComponent_DeployDetail_Call { + return &MockRepoComponent_DeployDetail_Call{Call: _e.mock.On("DeployDetail", ctx, detailReq)} +} + +func (_c *MockRepoComponent_DeployDetail_Call) Run(run func(ctx context.Context, detailReq types.DeployActReq)) *MockRepoComponent_DeployDetail_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployActReq)) + }) + return _c +} + +func (_c *MockRepoComponent_DeployDetail_Call) Return(_a0 *types.DeployRepo, _a1 error) *MockRepoComponent_DeployDetail_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_DeployDetail_Call) RunAndReturn(run func(context.Context, types.DeployActReq) (*types.DeployRepo, error)) *MockRepoComponent_DeployDetail_Call { + _c.Call.Return(run) + return _c +} + +// DeployInstanceLogs provides a mock function with given fields: ctx, logReq +func (_m *MockRepoComponent) DeployInstanceLogs(ctx context.Context, logReq types.DeployActReq) (*deploy.MultiLogReader, error) { + ret := _m.Called(ctx, logReq) + + if len(ret) == 0 { + panic("no return value specified for DeployInstanceLogs") + } + + var r0 *deploy.MultiLogReader + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq) (*deploy.MultiLogReader, error)); ok { + return rf(ctx, logReq) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq) *deploy.MultiLogReader); ok { + r0 = rf(ctx, logReq) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*deploy.MultiLogReader) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployActReq) error); ok { + r1 = rf(ctx, logReq) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_DeployInstanceLogs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeployInstanceLogs' +type MockRepoComponent_DeployInstanceLogs_Call struct { + *mock.Call +} + +// DeployInstanceLogs is a helper method to define mock.On call +// - ctx context.Context +// - logReq types.DeployActReq +func (_e *MockRepoComponent_Expecter) DeployInstanceLogs(ctx interface{}, logReq interface{}) *MockRepoComponent_DeployInstanceLogs_Call { + return &MockRepoComponent_DeployInstanceLogs_Call{Call: _e.mock.On("DeployInstanceLogs", ctx, logReq)} +} + +func (_c *MockRepoComponent_DeployInstanceLogs_Call) Run(run func(ctx context.Context, logReq types.DeployActReq)) *MockRepoComponent_DeployInstanceLogs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployActReq)) + }) + return _c +} + +func (_c *MockRepoComponent_DeployInstanceLogs_Call) Return(_a0 *deploy.MultiLogReader, _a1 error) *MockRepoComponent_DeployInstanceLogs_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_DeployInstanceLogs_Call) RunAndReturn(run func(context.Context, types.DeployActReq) (*deploy.MultiLogReader, error)) *MockRepoComponent_DeployInstanceLogs_Call { + _c.Call.Return(run) + return _c +} + +// DeployStart provides a mock function with given fields: ctx, startReq +func (_m *MockRepoComponent) DeployStart(ctx context.Context, startReq types.DeployActReq) error { + ret := _m.Called(ctx, startReq) + + if len(ret) == 0 { + panic("no return value specified for DeployStart") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq) error); ok { + r0 = rf(ctx, startReq) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_DeployStart_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeployStart' +type MockRepoComponent_DeployStart_Call struct { + *mock.Call +} + +// DeployStart is a helper method to define mock.On call +// - ctx context.Context +// - startReq types.DeployActReq +func (_e *MockRepoComponent_Expecter) DeployStart(ctx interface{}, startReq interface{}) *MockRepoComponent_DeployStart_Call { + return &MockRepoComponent_DeployStart_Call{Call: _e.mock.On("DeployStart", ctx, startReq)} +} + +func (_c *MockRepoComponent_DeployStart_Call) Run(run func(ctx context.Context, startReq types.DeployActReq)) *MockRepoComponent_DeployStart_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployActReq)) + }) + return _c +} + +func (_c *MockRepoComponent_DeployStart_Call) Return(_a0 error) *MockRepoComponent_DeployStart_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_DeployStart_Call) RunAndReturn(run func(context.Context, types.DeployActReq) error) *MockRepoComponent_DeployStart_Call { + _c.Call.Return(run) + return _c +} + +// DeployStatus provides a mock function with given fields: ctx, repoType, namespace, name, deployID +func (_m *MockRepoComponent) DeployStatus(ctx context.Context, repoType types.RepositoryType, namespace string, name string, deployID int64) (string, string, []types.Instance, error) { + ret := _m.Called(ctx, repoType, namespace, name, deployID) + + if len(ret) == 0 { + panic("no return value specified for DeployStatus") + } + + var r0 string + var r1 string + var r2 []types.Instance + var r3 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, int64) (string, string, []types.Instance, error)); ok { + return rf(ctx, repoType, namespace, name, deployID) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, int64) string); ok { + r0 = rf(ctx, repoType, namespace, name, deployID) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string, int64) string); ok { + r1 = rf(ctx, repoType, namespace, name, deployID) + } else { + r1 = ret.Get(1).(string) + } + + if rf, ok := ret.Get(2).(func(context.Context, types.RepositoryType, string, string, int64) []types.Instance); ok { + r2 = rf(ctx, repoType, namespace, name, deployID) + } else { + if ret.Get(2) != nil { + r2 = ret.Get(2).([]types.Instance) + } + } + + if rf, ok := ret.Get(3).(func(context.Context, types.RepositoryType, string, string, int64) error); ok { + r3 = rf(ctx, repoType, namespace, name, deployID) + } else { + r3 = ret.Error(3) + } + + return r0, r1, r2, r3 +} + +// MockRepoComponent_DeployStatus_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeployStatus' +type MockRepoComponent_DeployStatus_Call struct { + *mock.Call +} + +// DeployStatus is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - deployID int64 +func (_e *MockRepoComponent_Expecter) DeployStatus(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, deployID interface{}) *MockRepoComponent_DeployStatus_Call { + return &MockRepoComponent_DeployStatus_Call{Call: _e.mock.On("DeployStatus", ctx, repoType, namespace, name, deployID)} +} + +func (_c *MockRepoComponent_DeployStatus_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, deployID int64)) *MockRepoComponent_DeployStatus_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(int64)) + }) + return _c +} + +func (_c *MockRepoComponent_DeployStatus_Call) Return(_a0 string, _a1 string, _a2 []types.Instance, _a3 error) *MockRepoComponent_DeployStatus_Call { + _c.Call.Return(_a0, _a1, _a2, _a3) + return _c +} + +func (_c *MockRepoComponent_DeployStatus_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, int64) (string, string, []types.Instance, error)) *MockRepoComponent_DeployStatus_Call { + _c.Call.Return(run) + return _c +} + +// DeployStop provides a mock function with given fields: ctx, stopReq +func (_m *MockRepoComponent) DeployStop(ctx context.Context, stopReq types.DeployActReq) error { + ret := _m.Called(ctx, stopReq) + + if len(ret) == 0 { + panic("no return value specified for DeployStop") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq) error); ok { + r0 = rf(ctx, stopReq) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_DeployStop_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeployStop' +type MockRepoComponent_DeployStop_Call struct { + *mock.Call +} + +// DeployStop is a helper method to define mock.On call +// - ctx context.Context +// - stopReq types.DeployActReq +func (_e *MockRepoComponent_Expecter) DeployStop(ctx interface{}, stopReq interface{}) *MockRepoComponent_DeployStop_Call { + return &MockRepoComponent_DeployStop_Call{Call: _e.mock.On("DeployStop", ctx, stopReq)} +} + +func (_c *MockRepoComponent_DeployStop_Call) Run(run func(ctx context.Context, stopReq types.DeployActReq)) *MockRepoComponent_DeployStop_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployActReq)) + }) + return _c +} + +func (_c *MockRepoComponent_DeployStop_Call) Return(_a0 error) *MockRepoComponent_DeployStop_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_DeployStop_Call) RunAndReturn(run func(context.Context, types.DeployActReq) error) *MockRepoComponent_DeployStop_Call { + _c.Call.Return(run) + return _c +} + +// DeployUpdate provides a mock function with given fields: ctx, updateReq, req +func (_m *MockRepoComponent) DeployUpdate(ctx context.Context, updateReq types.DeployActReq, req *types.DeployUpdateReq) error { + ret := _m.Called(ctx, updateReq, req) + + if len(ret) == 0 { + panic("no return value specified for DeployUpdate") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployActReq, *types.DeployUpdateReq) error); ok { + r0 = rf(ctx, updateReq, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_DeployUpdate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeployUpdate' +type MockRepoComponent_DeployUpdate_Call struct { + *mock.Call +} + +// DeployUpdate is a helper method to define mock.On call +// - ctx context.Context +// - updateReq types.DeployActReq +// - req *types.DeployUpdateReq +func (_e *MockRepoComponent_Expecter) DeployUpdate(ctx interface{}, updateReq interface{}, req interface{}) *MockRepoComponent_DeployUpdate_Call { + return &MockRepoComponent_DeployUpdate_Call{Call: _e.mock.On("DeployUpdate", ctx, updateReq, req)} +} + +func (_c *MockRepoComponent_DeployUpdate_Call) Run(run func(ctx context.Context, updateReq types.DeployActReq, req *types.DeployUpdateReq)) *MockRepoComponent_DeployUpdate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployActReq), args[2].(*types.DeployUpdateReq)) + }) + return _c +} + +func (_c *MockRepoComponent_DeployUpdate_Call) Return(_a0 error) *MockRepoComponent_DeployUpdate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_DeployUpdate_Call) RunAndReturn(run func(context.Context, types.DeployActReq, *types.DeployUpdateReq) error) *MockRepoComponent_DeployUpdate_Call { + _c.Call.Return(run) + return _c +} + +// DownloadFile provides a mock function with given fields: ctx, req, userName +func (_m *MockRepoComponent) DownloadFile(ctx context.Context, req *types.GetFileReq, userName string) (io.ReadCloser, int64, string, error) { + ret := _m.Called(ctx, req, userName) + + if len(ret) == 0 { + panic("no return value specified for DownloadFile") + } + + var r0 io.ReadCloser + var r1 int64 + var r2 string + var r3 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq, string) (io.ReadCloser, int64, string, error)); ok { + return rf(ctx, req, userName) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq, string) io.ReadCloser); ok { + r0 = rf(ctx, req, userName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(io.ReadCloser) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetFileReq, string) int64); ok { + r1 = rf(ctx, req, userName) + } else { + r1 = ret.Get(1).(int64) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.GetFileReq, string) string); ok { + r2 = rf(ctx, req, userName) + } else { + r2 = ret.Get(2).(string) + } + + if rf, ok := ret.Get(3).(func(context.Context, *types.GetFileReq, string) error); ok { + r3 = rf(ctx, req, userName) + } else { + r3 = ret.Error(3) + } + + return r0, r1, r2, r3 +} + +// MockRepoComponent_DownloadFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DownloadFile' +type MockRepoComponent_DownloadFile_Call struct { + *mock.Call +} + +// DownloadFile is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetFileReq +// - userName string +func (_e *MockRepoComponent_Expecter) DownloadFile(ctx interface{}, req interface{}, userName interface{}) *MockRepoComponent_DownloadFile_Call { + return &MockRepoComponent_DownloadFile_Call{Call: _e.mock.On("DownloadFile", ctx, req, userName)} +} + +func (_c *MockRepoComponent_DownloadFile_Call) Run(run func(ctx context.Context, req *types.GetFileReq, userName string)) *MockRepoComponent_DownloadFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetFileReq), args[2].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_DownloadFile_Call) Return(_a0 io.ReadCloser, _a1 int64, _a2 string, _a3 error) *MockRepoComponent_DownloadFile_Call { + _c.Call.Return(_a0, _a1, _a2, _a3) + return _c +} + +func (_c *MockRepoComponent_DownloadFile_Call) RunAndReturn(run func(context.Context, *types.GetFileReq, string) (io.ReadCloser, int64, string, error)) *MockRepoComponent_DownloadFile_Call { + _c.Call.Return(run) + return _c +} + +// FileInfo provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) FileInfo(ctx context.Context, req *types.GetFileReq) (*types.File, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for FileInfo") + } + + var r0 *types.File + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq) (*types.File, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq) *types.File); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.File) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetFileReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_FileInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FileInfo' +type MockRepoComponent_FileInfo_Call struct { + *mock.Call +} + +// FileInfo is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetFileReq +func (_e *MockRepoComponent_Expecter) FileInfo(ctx interface{}, req interface{}) *MockRepoComponent_FileInfo_Call { + return &MockRepoComponent_FileInfo_Call{Call: _e.mock.On("FileInfo", ctx, req)} +} + +func (_c *MockRepoComponent_FileInfo_Call) Run(run func(ctx context.Context, req *types.GetFileReq)) *MockRepoComponent_FileInfo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetFileReq)) + }) + return _c +} + +func (_c *MockRepoComponent_FileInfo_Call) Return(_a0 *types.File, _a1 error) *MockRepoComponent_FileInfo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_FileInfo_Call) RunAndReturn(run func(context.Context, *types.GetFileReq) (*types.File, error)) *MockRepoComponent_FileInfo_Call { + _c.Call.Return(run) + return _c +} + +// FileRaw provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) FileRaw(ctx context.Context, req *types.GetFileReq) (string, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for FileRaw") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq) (string, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq) string); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetFileReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_FileRaw_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FileRaw' +type MockRepoComponent_FileRaw_Call struct { + *mock.Call +} + +// FileRaw is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetFileReq +func (_e *MockRepoComponent_Expecter) FileRaw(ctx interface{}, req interface{}) *MockRepoComponent_FileRaw_Call { + return &MockRepoComponent_FileRaw_Call{Call: _e.mock.On("FileRaw", ctx, req)} +} + +func (_c *MockRepoComponent_FileRaw_Call) Run(run func(ctx context.Context, req *types.GetFileReq)) *MockRepoComponent_FileRaw_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetFileReq)) + }) + return _c +} + +func (_c *MockRepoComponent_FileRaw_Call) Return(_a0 string, _a1 error) *MockRepoComponent_FileRaw_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_FileRaw_Call) RunAndReturn(run func(context.Context, *types.GetFileReq) (string, error)) *MockRepoComponent_FileRaw_Call { + _c.Call.Return(run) + return _c +} + +// GetCommitWithDiff provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) GetCommitWithDiff(ctx context.Context, req *types.GetCommitsReq) (*types.CommitResponse, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetCommitWithDiff") + } + + var r0 *types.CommitResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetCommitsReq) (*types.CommitResponse, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetCommitsReq) *types.CommitResponse); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.CommitResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetCommitsReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_GetCommitWithDiff_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCommitWithDiff' +type MockRepoComponent_GetCommitWithDiff_Call struct { + *mock.Call +} + +// GetCommitWithDiff is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetCommitsReq +func (_e *MockRepoComponent_Expecter) GetCommitWithDiff(ctx interface{}, req interface{}) *MockRepoComponent_GetCommitWithDiff_Call { + return &MockRepoComponent_GetCommitWithDiff_Call{Call: _e.mock.On("GetCommitWithDiff", ctx, req)} +} + +func (_c *MockRepoComponent_GetCommitWithDiff_Call) Run(run func(ctx context.Context, req *types.GetCommitsReq)) *MockRepoComponent_GetCommitWithDiff_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetCommitsReq)) + }) + return _c +} + +func (_c *MockRepoComponent_GetCommitWithDiff_Call) Return(_a0 *types.CommitResponse, _a1 error) *MockRepoComponent_GetCommitWithDiff_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_GetCommitWithDiff_Call) RunAndReturn(run func(context.Context, *types.GetCommitsReq) (*types.CommitResponse, error)) *MockRepoComponent_GetCommitWithDiff_Call { + _c.Call.Return(run) + return _c +} + +// GetDeployBySvcName provides a mock function with given fields: ctx, svcName +func (_m *MockRepoComponent) GetDeployBySvcName(ctx context.Context, svcName string) (*database.Deploy, error) { + ret := _m.Called(ctx, svcName) + + if len(ret) == 0 { + panic("no return value specified for GetDeployBySvcName") + } + + var r0 *database.Deploy + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.Deploy, error)); ok { + return rf(ctx, svcName) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.Deploy); ok { + r0 = rf(ctx, svcName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Deploy) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, svcName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_GetDeployBySvcName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDeployBySvcName' +type MockRepoComponent_GetDeployBySvcName_Call struct { + *mock.Call +} + +// GetDeployBySvcName is a helper method to define mock.On call +// - ctx context.Context +// - svcName string +func (_e *MockRepoComponent_Expecter) GetDeployBySvcName(ctx interface{}, svcName interface{}) *MockRepoComponent_GetDeployBySvcName_Call { + return &MockRepoComponent_GetDeployBySvcName_Call{Call: _e.mock.On("GetDeployBySvcName", ctx, svcName)} +} + +func (_c *MockRepoComponent_GetDeployBySvcName_Call) Run(run func(ctx context.Context, svcName string)) *MockRepoComponent_GetDeployBySvcName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_GetDeployBySvcName_Call) Return(_a0 *database.Deploy, _a1 error) *MockRepoComponent_GetDeployBySvcName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_GetDeployBySvcName_Call) RunAndReturn(run func(context.Context, string) (*database.Deploy, error)) *MockRepoComponent_GetDeployBySvcName_Call { + _c.Call.Return(run) + return _c +} + +// GetMirror provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) GetMirror(ctx context.Context, req types.GetMirrorReq) (*database.Mirror, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for GetMirror") + } + + var r0 *database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.GetMirrorReq) (*database.Mirror, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.GetMirrorReq) *database.Mirror); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.GetMirrorReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_GetMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMirror' +type MockRepoComponent_GetMirror_Call struct { + *mock.Call +} + +// GetMirror is a helper method to define mock.On call +// - ctx context.Context +// - req types.GetMirrorReq +func (_e *MockRepoComponent_Expecter) GetMirror(ctx interface{}, req interface{}) *MockRepoComponent_GetMirror_Call { + return &MockRepoComponent_GetMirror_Call{Call: _e.mock.On("GetMirror", ctx, req)} +} + +func (_c *MockRepoComponent_GetMirror_Call) Run(run func(ctx context.Context, req types.GetMirrorReq)) *MockRepoComponent_GetMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.GetMirrorReq)) + }) + return _c +} + +func (_c *MockRepoComponent_GetMirror_Call) Return(_a0 *database.Mirror, _a1 error) *MockRepoComponent_GetMirror_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_GetMirror_Call) RunAndReturn(run func(context.Context, types.GetMirrorReq) (*database.Mirror, error)) *MockRepoComponent_GetMirror_Call { + _c.Call.Return(run) + return _c +} + +// GetNameSpaceInfo provides a mock function with given fields: ctx, path +func (_m *MockRepoComponent) GetNameSpaceInfo(ctx context.Context, path string) (*types.Namespace, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for GetNameSpaceInfo") + } + + var r0 *types.Namespace + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*types.Namespace, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *types.Namespace); ok { + r0 = rf(ctx, path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Namespace) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_GetNameSpaceInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNameSpaceInfo' +type MockRepoComponent_GetNameSpaceInfo_Call struct { + *mock.Call +} + +// GetNameSpaceInfo is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *MockRepoComponent_Expecter) GetNameSpaceInfo(ctx interface{}, path interface{}) *MockRepoComponent_GetNameSpaceInfo_Call { + return &MockRepoComponent_GetNameSpaceInfo_Call{Call: _e.mock.On("GetNameSpaceInfo", ctx, path)} +} + +func (_c *MockRepoComponent_GetNameSpaceInfo_Call) Run(run func(ctx context.Context, path string)) *MockRepoComponent_GetNameSpaceInfo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_GetNameSpaceInfo_Call) Return(_a0 *types.Namespace, _a1 error) *MockRepoComponent_GetNameSpaceInfo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_GetNameSpaceInfo_Call) RunAndReturn(run func(context.Context, string) (*types.Namespace, error)) *MockRepoComponent_GetNameSpaceInfo_Call { + _c.Call.Return(run) + return _c +} + +// GetUserRepoPermission provides a mock function with given fields: ctx, userName, repo +func (_m *MockRepoComponent) GetUserRepoPermission(ctx context.Context, userName string, repo *database.Repository) (*types.UserRepoPermission, error) { + ret := _m.Called(ctx, userName, repo) + + if len(ret) == 0 { + panic("no return value specified for GetUserRepoPermission") + } + + var r0 *types.UserRepoPermission + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, *database.Repository) (*types.UserRepoPermission, error)); ok { + return rf(ctx, userName, repo) + } + if rf, ok := ret.Get(0).(func(context.Context, string, *database.Repository) *types.UserRepoPermission); ok { + r0 = rf(ctx, userName, repo) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.UserRepoPermission) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, *database.Repository) error); ok { + r1 = rf(ctx, userName, repo) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_GetUserRepoPermission_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserRepoPermission' +type MockRepoComponent_GetUserRepoPermission_Call struct { + *mock.Call +} + +// GetUserRepoPermission is a helper method to define mock.On call +// - ctx context.Context +// - userName string +// - repo *database.Repository +func (_e *MockRepoComponent_Expecter) GetUserRepoPermission(ctx interface{}, userName interface{}, repo interface{}) *MockRepoComponent_GetUserRepoPermission_Call { + return &MockRepoComponent_GetUserRepoPermission_Call{Call: _e.mock.On("GetUserRepoPermission", ctx, userName, repo)} +} + +func (_c *MockRepoComponent_GetUserRepoPermission_Call) Run(run func(ctx context.Context, userName string, repo *database.Repository)) *MockRepoComponent_GetUserRepoPermission_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(*database.Repository)) + }) + return _c +} + +func (_c *MockRepoComponent_GetUserRepoPermission_Call) Return(_a0 *types.UserRepoPermission, _a1 error) *MockRepoComponent_GetUserRepoPermission_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_GetUserRepoPermission_Call) RunAndReturn(run func(context.Context, string, *database.Repository) (*types.UserRepoPermission, error)) *MockRepoComponent_GetUserRepoPermission_Call { + _c.Call.Return(run) + return _c +} + +// HeadDownloadFile provides a mock function with given fields: ctx, req, userName +func (_m *MockRepoComponent) HeadDownloadFile(ctx context.Context, req *types.GetFileReq, userName string) (*types.File, error) { + ret := _m.Called(ctx, req, userName) + + if len(ret) == 0 { + panic("no return value specified for HeadDownloadFile") + } + + var r0 *types.File + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq, string) (*types.File, error)); ok { + return rf(ctx, req, userName) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq, string) *types.File); ok { + r0 = rf(ctx, req, userName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.File) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetFileReq, string) error); ok { + r1 = rf(ctx, req, userName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_HeadDownloadFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HeadDownloadFile' +type MockRepoComponent_HeadDownloadFile_Call struct { + *mock.Call +} + +// HeadDownloadFile is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetFileReq +// - userName string +func (_e *MockRepoComponent_Expecter) HeadDownloadFile(ctx interface{}, req interface{}, userName interface{}) *MockRepoComponent_HeadDownloadFile_Call { + return &MockRepoComponent_HeadDownloadFile_Call{Call: _e.mock.On("HeadDownloadFile", ctx, req, userName)} +} + +func (_c *MockRepoComponent_HeadDownloadFile_Call) Run(run func(ctx context.Context, req *types.GetFileReq, userName string)) *MockRepoComponent_HeadDownloadFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetFileReq), args[2].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_HeadDownloadFile_Call) Return(_a0 *types.File, _a1 error) *MockRepoComponent_HeadDownloadFile_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_HeadDownloadFile_Call) RunAndReturn(run func(context.Context, *types.GetFileReq, string) (*types.File, error)) *MockRepoComponent_HeadDownloadFile_Call { + _c.Call.Return(run) + return _c +} + +// IncrDownloads provides a mock function with given fields: ctx, repoType, namespace, name +func (_m *MockRepoComponent) IncrDownloads(ctx context.Context, repoType types.RepositoryType, namespace string, name string) error { + ret := _m.Called(ctx, repoType, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for IncrDownloads") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) error); ok { + r0 = rf(ctx, repoType, namespace, name) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_IncrDownloads_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IncrDownloads' +type MockRepoComponent_IncrDownloads_Call struct { + *mock.Call +} + +// IncrDownloads is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +func (_e *MockRepoComponent_Expecter) IncrDownloads(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}) *MockRepoComponent_IncrDownloads_Call { + return &MockRepoComponent_IncrDownloads_Call{Call: _e.mock.On("IncrDownloads", ctx, repoType, namespace, name)} +} + +func (_c *MockRepoComponent_IncrDownloads_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string)) *MockRepoComponent_IncrDownloads_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_IncrDownloads_Call) Return(_a0 error) *MockRepoComponent_IncrDownloads_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_IncrDownloads_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string) error) *MockRepoComponent_IncrDownloads_Call { + _c.Call.Return(run) + return _c +} + +// IsLfs provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) IsLfs(ctx context.Context, req *types.GetFileReq) (bool, int64, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for IsLfs") + } + + var r0 bool + var r1 int64 + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq) (bool, int64, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq) bool); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetFileReq) int64); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int64) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.GetFileReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockRepoComponent_IsLfs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsLfs' +type MockRepoComponent_IsLfs_Call struct { + *mock.Call +} + +// IsLfs is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetFileReq +func (_e *MockRepoComponent_Expecter) IsLfs(ctx interface{}, req interface{}) *MockRepoComponent_IsLfs_Call { + return &MockRepoComponent_IsLfs_Call{Call: _e.mock.On("IsLfs", ctx, req)} +} + +func (_c *MockRepoComponent_IsLfs_Call) Run(run func(ctx context.Context, req *types.GetFileReq)) *MockRepoComponent_IsLfs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetFileReq)) + }) + return _c +} + +func (_c *MockRepoComponent_IsLfs_Call) Return(_a0 bool, _a1 int64, _a2 error) *MockRepoComponent_IsLfs_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockRepoComponent_IsLfs_Call) RunAndReturn(run func(context.Context, *types.GetFileReq) (bool, int64, error)) *MockRepoComponent_IsLfs_Call { + _c.Call.Return(run) + return _c +} + +// LastCommit provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) LastCommit(ctx context.Context, req *types.GetCommitsReq) (*types.Commit, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for LastCommit") + } + + var r0 *types.Commit + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetCommitsReq) (*types.Commit, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetCommitsReq) *types.Commit); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Commit) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetCommitsReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_LastCommit_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LastCommit' +type MockRepoComponent_LastCommit_Call struct { + *mock.Call +} + +// LastCommit is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetCommitsReq +func (_e *MockRepoComponent_Expecter) LastCommit(ctx interface{}, req interface{}) *MockRepoComponent_LastCommit_Call { + return &MockRepoComponent_LastCommit_Call{Call: _e.mock.On("LastCommit", ctx, req)} +} + +func (_c *MockRepoComponent_LastCommit_Call) Run(run func(ctx context.Context, req *types.GetCommitsReq)) *MockRepoComponent_LastCommit_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetCommitsReq)) + }) + return _c +} + +func (_c *MockRepoComponent_LastCommit_Call) Return(_a0 *types.Commit, _a1 error) *MockRepoComponent_LastCommit_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_LastCommit_Call) RunAndReturn(run func(context.Context, *types.GetCommitsReq) (*types.Commit, error)) *MockRepoComponent_LastCommit_Call { + _c.Call.Return(run) + return _c +} + +// ListDeploy provides a mock function with given fields: ctx, repoType, namespace, name, currentUser +func (_m *MockRepoComponent) ListDeploy(ctx context.Context, repoType types.RepositoryType, namespace string, name string, currentUser string) ([]types.DeployRepo, error) { + ret := _m.Called(ctx, repoType, namespace, name, currentUser) + + if len(ret) == 0 { + panic("no return value specified for ListDeploy") + } + + var r0 []types.DeployRepo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string) ([]types.DeployRepo, error)); ok { + return rf(ctx, repoType, namespace, name, currentUser) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string) []types.DeployRepo); ok { + r0 = rf(ctx, repoType, namespace, name, currentUser) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.DeployRepo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string, string) error); ok { + r1 = rf(ctx, repoType, namespace, name, currentUser) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_ListDeploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListDeploy' +type MockRepoComponent_ListDeploy_Call struct { + *mock.Call +} + +// ListDeploy is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - currentUser string +func (_e *MockRepoComponent_Expecter) ListDeploy(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, currentUser interface{}) *MockRepoComponent_ListDeploy_Call { + return &MockRepoComponent_ListDeploy_Call{Call: _e.mock.On("ListDeploy", ctx, repoType, namespace, name, currentUser)} +} + +func (_c *MockRepoComponent_ListDeploy_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, currentUser string)) *MockRepoComponent_ListDeploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_ListDeploy_Call) Return(_a0 []types.DeployRepo, _a1 error) *MockRepoComponent_ListDeploy_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_ListDeploy_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, string) ([]types.DeployRepo, error)) *MockRepoComponent_ListDeploy_Call { + _c.Call.Return(run) + return _c +} + +// ListRuntimeFramework provides a mock function with given fields: ctx, repoType, namespace, name, deployType +func (_m *MockRepoComponent) ListRuntimeFramework(ctx context.Context, repoType types.RepositoryType, namespace string, name string, deployType int) ([]types.RuntimeFramework, error) { + ret := _m.Called(ctx, repoType, namespace, name, deployType) + + if len(ret) == 0 { + panic("no return value specified for ListRuntimeFramework") + } + + var r0 []types.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, int) ([]types.RuntimeFramework, error)); ok { + return rf(ctx, repoType, namespace, name, deployType) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, int) []types.RuntimeFramework); ok { + r0 = rf(ctx, repoType, namespace, name, deployType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string, int) error); ok { + r1 = rf(ctx, repoType, namespace, name, deployType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_ListRuntimeFramework_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListRuntimeFramework' +type MockRepoComponent_ListRuntimeFramework_Call struct { + *mock.Call +} + +// ListRuntimeFramework is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - deployType int +func (_e *MockRepoComponent_Expecter) ListRuntimeFramework(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, deployType interface{}) *MockRepoComponent_ListRuntimeFramework_Call { + return &MockRepoComponent_ListRuntimeFramework_Call{Call: _e.mock.On("ListRuntimeFramework", ctx, repoType, namespace, name, deployType)} +} + +func (_c *MockRepoComponent_ListRuntimeFramework_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, deployType int)) *MockRepoComponent_ListRuntimeFramework_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(int)) + }) + return _c +} + +func (_c *MockRepoComponent_ListRuntimeFramework_Call) Return(_a0 []types.RuntimeFramework, _a1 error) *MockRepoComponent_ListRuntimeFramework_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_ListRuntimeFramework_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, int) ([]types.RuntimeFramework, error)) *MockRepoComponent_ListRuntimeFramework_Call { + _c.Call.Return(run) + return _c +} + +// ListRuntimeFrameworkWithType provides a mock function with given fields: ctx, deployType +func (_m *MockRepoComponent) ListRuntimeFrameworkWithType(ctx context.Context, deployType int) ([]types.RuntimeFramework, error) { + ret := _m.Called(ctx, deployType) + + if len(ret) == 0 { + panic("no return value specified for ListRuntimeFrameworkWithType") + } + + var r0 []types.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int) ([]types.RuntimeFramework, error)); ok { + return rf(ctx, deployType) + } + if rf, ok := ret.Get(0).(func(context.Context, int) []types.RuntimeFramework); ok { + r0 = rf(ctx, deployType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int) error); ok { + r1 = rf(ctx, deployType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_ListRuntimeFrameworkWithType_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListRuntimeFrameworkWithType' +type MockRepoComponent_ListRuntimeFrameworkWithType_Call struct { + *mock.Call +} + +// ListRuntimeFrameworkWithType is a helper method to define mock.On call +// - ctx context.Context +// - deployType int +func (_e *MockRepoComponent_Expecter) ListRuntimeFrameworkWithType(ctx interface{}, deployType interface{}) *MockRepoComponent_ListRuntimeFrameworkWithType_Call { + return &MockRepoComponent_ListRuntimeFrameworkWithType_Call{Call: _e.mock.On("ListRuntimeFrameworkWithType", ctx, deployType)} +} + +func (_c *MockRepoComponent_ListRuntimeFrameworkWithType_Call) Run(run func(ctx context.Context, deployType int)) *MockRepoComponent_ListRuntimeFrameworkWithType_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int)) + }) + return _c +} + +func (_c *MockRepoComponent_ListRuntimeFrameworkWithType_Call) Return(_a0 []types.RuntimeFramework, _a1 error) *MockRepoComponent_ListRuntimeFrameworkWithType_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_ListRuntimeFrameworkWithType_Call) RunAndReturn(run func(context.Context, int) ([]types.RuntimeFramework, error)) *MockRepoComponent_ListRuntimeFrameworkWithType_Call { + _c.Call.Return(run) + return _c +} + +// MirrorFromSaas provides a mock function with given fields: ctx, namespace, name, currentUser, repoType +func (_m *MockRepoComponent) MirrorFromSaas(ctx context.Context, namespace string, name string, currentUser string, repoType types.RepositoryType) error { + ret := _m.Called(ctx, namespace, name, currentUser, repoType) + + if len(ret) == 0 { + panic("no return value specified for MirrorFromSaas") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, types.RepositoryType) error); ok { + r0 = rf(ctx, namespace, name, currentUser, repoType) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_MirrorFromSaas_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MirrorFromSaas' +type MockRepoComponent_MirrorFromSaas_Call struct { + *mock.Call +} + +// MirrorFromSaas is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +// - currentUser string +// - repoType types.RepositoryType +func (_e *MockRepoComponent_Expecter) MirrorFromSaas(ctx interface{}, namespace interface{}, name interface{}, currentUser interface{}, repoType interface{}) *MockRepoComponent_MirrorFromSaas_Call { + return &MockRepoComponent_MirrorFromSaas_Call{Call: _e.mock.On("MirrorFromSaas", ctx, namespace, name, currentUser, repoType)} +} + +func (_c *MockRepoComponent_MirrorFromSaas_Call) Run(run func(ctx context.Context, namespace string, name string, currentUser string, repoType types.RepositoryType)) *MockRepoComponent_MirrorFromSaas_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string), args[4].(types.RepositoryType)) + }) + return _c +} + +func (_c *MockRepoComponent_MirrorFromSaas_Call) Return(_a0 error) *MockRepoComponent_MirrorFromSaas_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_MirrorFromSaas_Call) RunAndReturn(run func(context.Context, string, string, string, types.RepositoryType) error) *MockRepoComponent_MirrorFromSaas_Call { + _c.Call.Return(run) + return _c +} + +// PublicToUser provides a mock function with given fields: ctx, repoType, userName, filter, per, page +func (_m *MockRepoComponent) PublicToUser(ctx context.Context, repoType types.RepositoryType, userName string, filter *types.RepoFilter, per int, page int) ([]*database.Repository, int, error) { + ret := _m.Called(ctx, repoType, userName, filter, per, page) + + if len(ret) == 0 { + panic("no return value specified for PublicToUser") + } + + var r0 []*database.Repository + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, *types.RepoFilter, int, int) ([]*database.Repository, int, error)); ok { + return rf(ctx, repoType, userName, filter, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, *types.RepoFilter, int, int) []*database.Repository); ok { + r0 = rf(ctx, repoType, userName, filter, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, *types.RepoFilter, int, int) int); ok { + r1 = rf(ctx, repoType, userName, filter, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, types.RepositoryType, string, *types.RepoFilter, int, int) error); ok { + r2 = rf(ctx, repoType, userName, filter, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockRepoComponent_PublicToUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublicToUser' +type MockRepoComponent_PublicToUser_Call struct { + *mock.Call +} + +// PublicToUser is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - userName string +// - filter *types.RepoFilter +// - per int +// - page int +func (_e *MockRepoComponent_Expecter) PublicToUser(ctx interface{}, repoType interface{}, userName interface{}, filter interface{}, per interface{}, page interface{}) *MockRepoComponent_PublicToUser_Call { + return &MockRepoComponent_PublicToUser_Call{Call: _e.mock.On("PublicToUser", ctx, repoType, userName, filter, per, page)} +} + +func (_c *MockRepoComponent_PublicToUser_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, userName string, filter *types.RepoFilter, per int, page int)) *MockRepoComponent_PublicToUser_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(*types.RepoFilter), args[4].(int), args[5].(int)) + }) + return _c +} + +func (_c *MockRepoComponent_PublicToUser_Call) Return(repos []*database.Repository, count int, err error) *MockRepoComponent_PublicToUser_Call { + _c.Call.Return(repos, count, err) + return _c +} + +func (_c *MockRepoComponent_PublicToUser_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, *types.RepoFilter, int, int) ([]*database.Repository, int, error)) *MockRepoComponent_PublicToUser_Call { + _c.Call.Return(run) + return _c +} + +// RelatedRepos provides a mock function with given fields: ctx, repoID, currentUser +func (_m *MockRepoComponent) RelatedRepos(ctx context.Context, repoID int64, currentUser string) (map[types.RepositoryType][]*database.Repository, error) { + ret := _m.Called(ctx, repoID, currentUser) + + if len(ret) == 0 { + panic("no return value specified for RelatedRepos") + } + + var r0 map[types.RepositoryType][]*database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) (map[types.RepositoryType][]*database.Repository, error)); ok { + return rf(ctx, repoID, currentUser) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, string) map[types.RepositoryType][]*database.Repository); ok { + r0 = rf(ctx, repoID, currentUser) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[types.RepositoryType][]*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, string) error); ok { + r1 = rf(ctx, repoID, currentUser) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_RelatedRepos_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RelatedRepos' +type MockRepoComponent_RelatedRepos_Call struct { + *mock.Call +} + +// RelatedRepos is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - currentUser string +func (_e *MockRepoComponent_Expecter) RelatedRepos(ctx interface{}, repoID interface{}, currentUser interface{}) *MockRepoComponent_RelatedRepos_Call { + return &MockRepoComponent_RelatedRepos_Call{Call: _e.mock.On("RelatedRepos", ctx, repoID, currentUser)} +} + +func (_c *MockRepoComponent_RelatedRepos_Call) Run(run func(ctx context.Context, repoID int64, currentUser string)) *MockRepoComponent_RelatedRepos_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_RelatedRepos_Call) Return(_a0 map[types.RepositoryType][]*database.Repository, _a1 error) *MockRepoComponent_RelatedRepos_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_RelatedRepos_Call) RunAndReturn(run func(context.Context, int64, string) (map[types.RepositoryType][]*database.Repository, error)) *MockRepoComponent_RelatedRepos_Call { + _c.Call.Return(run) + return _c +} + +// SDKDownloadFile provides a mock function with given fields: ctx, req, userName +func (_m *MockRepoComponent) SDKDownloadFile(ctx context.Context, req *types.GetFileReq, userName string) (io.ReadCloser, int64, string, error) { + ret := _m.Called(ctx, req, userName) + + if len(ret) == 0 { + panic("no return value specified for SDKDownloadFile") + } + + var r0 io.ReadCloser + var r1 int64 + var r2 string + var r3 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq, string) (io.ReadCloser, int64, string, error)); ok { + return rf(ctx, req, userName) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq, string) io.ReadCloser); ok { + r0 = rf(ctx, req, userName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(io.ReadCloser) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetFileReq, string) int64); ok { + r1 = rf(ctx, req, userName) + } else { + r1 = ret.Get(1).(int64) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.GetFileReq, string) string); ok { + r2 = rf(ctx, req, userName) + } else { + r2 = ret.Get(2).(string) + } + + if rf, ok := ret.Get(3).(func(context.Context, *types.GetFileReq, string) error); ok { + r3 = rf(ctx, req, userName) + } else { + r3 = ret.Error(3) + } + + return r0, r1, r2, r3 +} + +// MockRepoComponent_SDKDownloadFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SDKDownloadFile' +type MockRepoComponent_SDKDownloadFile_Call struct { + *mock.Call +} + +// SDKDownloadFile is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetFileReq +// - userName string +func (_e *MockRepoComponent_Expecter) SDKDownloadFile(ctx interface{}, req interface{}, userName interface{}) *MockRepoComponent_SDKDownloadFile_Call { + return &MockRepoComponent_SDKDownloadFile_Call{Call: _e.mock.On("SDKDownloadFile", ctx, req, userName)} +} + +func (_c *MockRepoComponent_SDKDownloadFile_Call) Run(run func(ctx context.Context, req *types.GetFileReq, userName string)) *MockRepoComponent_SDKDownloadFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetFileReq), args[2].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_SDKDownloadFile_Call) Return(_a0 io.ReadCloser, _a1 int64, _a2 string, _a3 error) *MockRepoComponent_SDKDownloadFile_Call { + _c.Call.Return(_a0, _a1, _a2, _a3) + return _c +} + +func (_c *MockRepoComponent_SDKDownloadFile_Call) RunAndReturn(run func(context.Context, *types.GetFileReq, string) (io.ReadCloser, int64, string, error)) *MockRepoComponent_SDKDownloadFile_Call { + _c.Call.Return(run) + return _c +} + +// SDKListFiles provides a mock function with given fields: ctx, repoType, namespace, name, ref, userName +func (_m *MockRepoComponent) SDKListFiles(ctx context.Context, repoType types.RepositoryType, namespace string, name string, ref string, userName string) (*types.SDKFiles, error) { + ret := _m.Called(ctx, repoType, namespace, name, ref, userName) + + if len(ret) == 0 { + panic("no return value specified for SDKListFiles") + } + + var r0 *types.SDKFiles + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string, string) (*types.SDKFiles, error)); ok { + return rf(ctx, repoType, namespace, name, ref, userName) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string, string) *types.SDKFiles); ok { + r0 = rf(ctx, repoType, namespace, name, ref, userName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.SDKFiles) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, string, string, string, string) error); ok { + r1 = rf(ctx, repoType, namespace, name, ref, userName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_SDKListFiles_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SDKListFiles' +type MockRepoComponent_SDKListFiles_Call struct { + *mock.Call +} + +// SDKListFiles is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - ref string +// - userName string +func (_e *MockRepoComponent_Expecter) SDKListFiles(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, ref interface{}, userName interface{}) *MockRepoComponent_SDKListFiles_Call { + return &MockRepoComponent_SDKListFiles_Call{Call: _e.mock.On("SDKListFiles", ctx, repoType, namespace, name, ref, userName)} +} + +func (_c *MockRepoComponent_SDKListFiles_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, ref string, userName string)) *MockRepoComponent_SDKListFiles_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(string), args[5].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_SDKListFiles_Call) Return(_a0 *types.SDKFiles, _a1 error) *MockRepoComponent_SDKListFiles_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_SDKListFiles_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, string, string) (*types.SDKFiles, error)) *MockRepoComponent_SDKListFiles_Call { + _c.Call.Return(run) + return _c +} + +// SyncMirror provides a mock function with given fields: ctx, repoType, namespace, name, currentUser +func (_m *MockRepoComponent) SyncMirror(ctx context.Context, repoType types.RepositoryType, namespace string, name string, currentUser string) error { + ret := _m.Called(ctx, repoType, namespace, name, currentUser) + + if len(ret) == 0 { + panic("no return value specified for SyncMirror") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string, string) error); ok { + r0 = rf(ctx, repoType, namespace, name, currentUser) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_SyncMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SyncMirror' +type MockRepoComponent_SyncMirror_Call struct { + *mock.Call +} + +// SyncMirror is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +// - currentUser string +func (_e *MockRepoComponent_Expecter) SyncMirror(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}, currentUser interface{}) *MockRepoComponent_SyncMirror_Call { + return &MockRepoComponent_SyncMirror_Call{Call: _e.mock.On("SyncMirror", ctx, repoType, namespace, name, currentUser)} +} + +func (_c *MockRepoComponent_SyncMirror_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string, currentUser string)) *MockRepoComponent_SyncMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string), args[4].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_SyncMirror_Call) Return(_a0 error) *MockRepoComponent_SyncMirror_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_SyncMirror_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string, string) error) *MockRepoComponent_SyncMirror_Call { + _c.Call.Return(run) + return _c +} + +// Tags provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) Tags(ctx context.Context, req *types.GetTagsReq) ([]database.Tag, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Tags") + } + + var r0 []database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetTagsReq) ([]database.Tag, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetTagsReq) []database.Tag); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetTagsReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_Tags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Tags' +type MockRepoComponent_Tags_Call struct { + *mock.Call +} + +// Tags is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetTagsReq +func (_e *MockRepoComponent_Expecter) Tags(ctx interface{}, req interface{}) *MockRepoComponent_Tags_Call { + return &MockRepoComponent_Tags_Call{Call: _e.mock.On("Tags", ctx, req)} +} + +func (_c *MockRepoComponent_Tags_Call) Run(run func(ctx context.Context, req *types.GetTagsReq)) *MockRepoComponent_Tags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetTagsReq)) + }) + return _c +} + +func (_c *MockRepoComponent_Tags_Call) Return(_a0 []database.Tag, _a1 error) *MockRepoComponent_Tags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_Tags_Call) RunAndReturn(run func(context.Context, *types.GetTagsReq) ([]database.Tag, error)) *MockRepoComponent_Tags_Call { + _c.Call.Return(run) + return _c +} + +// Tree provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) Tree(ctx context.Context, req *types.GetFileReq) ([]*types.File, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Tree") + } + + var r0 []*types.File + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq) ([]*types.File, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.GetFileReq) []*types.File); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*types.File) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.GetFileReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_Tree_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Tree' +type MockRepoComponent_Tree_Call struct { + *mock.Call +} + +// Tree is a helper method to define mock.On call +// - ctx context.Context +// - req *types.GetFileReq +func (_e *MockRepoComponent_Expecter) Tree(ctx interface{}, req interface{}) *MockRepoComponent_Tree_Call { + return &MockRepoComponent_Tree_Call{Call: _e.mock.On("Tree", ctx, req)} +} + +func (_c *MockRepoComponent_Tree_Call) Run(run func(ctx context.Context, req *types.GetFileReq)) *MockRepoComponent_Tree_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.GetFileReq)) + }) + return _c +} + +func (_c *MockRepoComponent_Tree_Call) Return(_a0 []*types.File, _a1 error) *MockRepoComponent_Tree_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_Tree_Call) RunAndReturn(run func(context.Context, *types.GetFileReq) ([]*types.File, error)) *MockRepoComponent_Tree_Call { + _c.Call.Return(run) + return _c +} + +// UpdateDownloads provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) UpdateDownloads(ctx context.Context, req *types.UpdateDownloadsReq) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for UpdateDownloads") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UpdateDownloadsReq) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_UpdateDownloads_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateDownloads' +type MockRepoComponent_UpdateDownloads_Call struct { + *mock.Call +} + +// UpdateDownloads is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UpdateDownloadsReq +func (_e *MockRepoComponent_Expecter) UpdateDownloads(ctx interface{}, req interface{}) *MockRepoComponent_UpdateDownloads_Call { + return &MockRepoComponent_UpdateDownloads_Call{Call: _e.mock.On("UpdateDownloads", ctx, req)} +} + +func (_c *MockRepoComponent_UpdateDownloads_Call) Run(run func(ctx context.Context, req *types.UpdateDownloadsReq)) *MockRepoComponent_UpdateDownloads_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UpdateDownloadsReq)) + }) + return _c +} + +func (_c *MockRepoComponent_UpdateDownloads_Call) Return(_a0 error) *MockRepoComponent_UpdateDownloads_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_UpdateDownloads_Call) RunAndReturn(run func(context.Context, *types.UpdateDownloadsReq) error) *MockRepoComponent_UpdateDownloads_Call { + _c.Call.Return(run) + return _c +} + +// UpdateFile provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) UpdateFile(ctx context.Context, req *types.UpdateFileReq) (*types.UpdateFileResp, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for UpdateFile") + } + + var r0 *types.UpdateFileResp + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UpdateFileReq) (*types.UpdateFileResp, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UpdateFileReq) *types.UpdateFileResp); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.UpdateFileResp) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UpdateFileReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_UpdateFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateFile' +type MockRepoComponent_UpdateFile_Call struct { + *mock.Call +} + +// UpdateFile is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UpdateFileReq +func (_e *MockRepoComponent_Expecter) UpdateFile(ctx interface{}, req interface{}) *MockRepoComponent_UpdateFile_Call { + return &MockRepoComponent_UpdateFile_Call{Call: _e.mock.On("UpdateFile", ctx, req)} +} + +func (_c *MockRepoComponent_UpdateFile_Call) Run(run func(ctx context.Context, req *types.UpdateFileReq)) *MockRepoComponent_UpdateFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UpdateFileReq)) + }) + return _c +} + +func (_c *MockRepoComponent_UpdateFile_Call) Return(_a0 *types.UpdateFileResp, _a1 error) *MockRepoComponent_UpdateFile_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_UpdateFile_Call) RunAndReturn(run func(context.Context, *types.UpdateFileReq) (*types.UpdateFileResp, error)) *MockRepoComponent_UpdateFile_Call { + _c.Call.Return(run) + return _c +} + +// UpdateMirror provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) UpdateMirror(ctx context.Context, req types.UpdateMirrorReq) (*database.Mirror, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for UpdateMirror") + } + + var r0 *database.Mirror + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.UpdateMirrorReq) (*database.Mirror, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.UpdateMirrorReq) *database.Mirror); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Mirror) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.UpdateMirrorReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_UpdateMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateMirror' +type MockRepoComponent_UpdateMirror_Call struct { + *mock.Call +} + +// UpdateMirror is a helper method to define mock.On call +// - ctx context.Context +// - req types.UpdateMirrorReq +func (_e *MockRepoComponent_Expecter) UpdateMirror(ctx interface{}, req interface{}) *MockRepoComponent_UpdateMirror_Call { + return &MockRepoComponent_UpdateMirror_Call{Call: _e.mock.On("UpdateMirror", ctx, req)} +} + +func (_c *MockRepoComponent_UpdateMirror_Call) Run(run func(ctx context.Context, req types.UpdateMirrorReq)) *MockRepoComponent_UpdateMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.UpdateMirrorReq)) + }) + return _c +} + +func (_c *MockRepoComponent_UpdateMirror_Call) Return(_a0 *database.Mirror, _a1 error) *MockRepoComponent_UpdateMirror_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_UpdateMirror_Call) RunAndReturn(run func(context.Context, types.UpdateMirrorReq) (*database.Mirror, error)) *MockRepoComponent_UpdateMirror_Call { + _c.Call.Return(run) + return _c +} + +// UpdateRepo provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) UpdateRepo(ctx context.Context, req types.UpdateRepoReq) (*database.Repository, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for UpdateRepo") + } + + var r0 *database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.UpdateRepoReq) (*database.Repository, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.UpdateRepoReq) *database.Repository); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.UpdateRepoReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_UpdateRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateRepo' +type MockRepoComponent_UpdateRepo_Call struct { + *mock.Call +} + +// UpdateRepo is a helper method to define mock.On call +// - ctx context.Context +// - req types.UpdateRepoReq +func (_e *MockRepoComponent_Expecter) UpdateRepo(ctx interface{}, req interface{}) *MockRepoComponent_UpdateRepo_Call { + return &MockRepoComponent_UpdateRepo_Call{Call: _e.mock.On("UpdateRepo", ctx, req)} +} + +func (_c *MockRepoComponent_UpdateRepo_Call) Run(run func(ctx context.Context, req types.UpdateRepoReq)) *MockRepoComponent_UpdateRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.UpdateRepoReq)) + }) + return _c +} + +func (_c *MockRepoComponent_UpdateRepo_Call) Return(_a0 *database.Repository, _a1 error) *MockRepoComponent_UpdateRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_UpdateRepo_Call) RunAndReturn(run func(context.Context, types.UpdateRepoReq) (*database.Repository, error)) *MockRepoComponent_UpdateRepo_Call { + _c.Call.Return(run) + return _c +} + +// UpdateRuntimeFramework provides a mock function with given fields: ctx, id, req +func (_m *MockRepoComponent) UpdateRuntimeFramework(ctx context.Context, id int64, req *types.RuntimeFrameworkReq) (*types.RuntimeFramework, error) { + ret := _m.Called(ctx, id, req) + + if len(ret) == 0 { + panic("no return value specified for UpdateRuntimeFramework") + } + + var r0 *types.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, *types.RuntimeFrameworkReq) (*types.RuntimeFramework, error)); ok { + return rf(ctx, id, req) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, *types.RuntimeFrameworkReq) *types.RuntimeFramework); ok { + r0 = rf(ctx, id, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, *types.RuntimeFrameworkReq) error); ok { + r1 = rf(ctx, id, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_UpdateRuntimeFramework_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateRuntimeFramework' +type MockRepoComponent_UpdateRuntimeFramework_Call struct { + *mock.Call +} + +// UpdateRuntimeFramework is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +// - req *types.RuntimeFrameworkReq +func (_e *MockRepoComponent_Expecter) UpdateRuntimeFramework(ctx interface{}, id interface{}, req interface{}) *MockRepoComponent_UpdateRuntimeFramework_Call { + return &MockRepoComponent_UpdateRuntimeFramework_Call{Call: _e.mock.On("UpdateRuntimeFramework", ctx, id, req)} +} + +func (_c *MockRepoComponent_UpdateRuntimeFramework_Call) Run(run func(ctx context.Context, id int64, req *types.RuntimeFrameworkReq)) *MockRepoComponent_UpdateRuntimeFramework_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(*types.RuntimeFrameworkReq)) + }) + return _c +} + +func (_c *MockRepoComponent_UpdateRuntimeFramework_Call) Return(_a0 *types.RuntimeFramework, _a1 error) *MockRepoComponent_UpdateRuntimeFramework_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_UpdateRuntimeFramework_Call) RunAndReturn(run func(context.Context, int64, *types.RuntimeFrameworkReq) (*types.RuntimeFramework, error)) *MockRepoComponent_UpdateRuntimeFramework_Call { + _c.Call.Return(run) + return _c +} + +// UpdateTags provides a mock function with given fields: ctx, namespace, name, repoType, category, currentUser, tags +func (_m *MockRepoComponent) UpdateTags(ctx context.Context, namespace string, name string, repoType types.RepositoryType, category string, currentUser string, tags []string) error { + ret := _m.Called(ctx, namespace, name, repoType, category, currentUser, tags) + + if len(ret) == 0 { + panic("no return value specified for UpdateTags") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, types.RepositoryType, string, string, []string) error); ok { + r0 = rf(ctx, namespace, name, repoType, category, currentUser, tags) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_UpdateTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateTags' +type MockRepoComponent_UpdateTags_Call struct { + *mock.Call +} + +// UpdateTags is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +// - repoType types.RepositoryType +// - category string +// - currentUser string +// - tags []string +func (_e *MockRepoComponent_Expecter) UpdateTags(ctx interface{}, namespace interface{}, name interface{}, repoType interface{}, category interface{}, currentUser interface{}, tags interface{}) *MockRepoComponent_UpdateTags_Call { + return &MockRepoComponent_UpdateTags_Call{Call: _e.mock.On("UpdateTags", ctx, namespace, name, repoType, category, currentUser, tags)} +} + +func (_c *MockRepoComponent_UpdateTags_Call) Run(run func(ctx context.Context, namespace string, name string, repoType types.RepositoryType, category string, currentUser string, tags []string)) *MockRepoComponent_UpdateTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(types.RepositoryType), args[4].(string), args[5].(string), args[6].([]string)) + }) + return _c +} + +func (_c *MockRepoComponent_UpdateTags_Call) Return(_a0 error) *MockRepoComponent_UpdateTags_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_UpdateTags_Call) RunAndReturn(run func(context.Context, string, string, types.RepositoryType, string, string, []string) error) *MockRepoComponent_UpdateTags_Call { + _c.Call.Return(run) + return _c +} + +// UploadFile provides a mock function with given fields: ctx, req +func (_m *MockRepoComponent) UploadFile(ctx context.Context, req *types.CreateFileReq) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for UploadFile") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *types.CreateFileReq) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoComponent_UploadFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UploadFile' +type MockRepoComponent_UploadFile_Call struct { + *mock.Call +} + +// UploadFile is a helper method to define mock.On call +// - ctx context.Context +// - req *types.CreateFileReq +func (_e *MockRepoComponent_Expecter) UploadFile(ctx interface{}, req interface{}) *MockRepoComponent_UploadFile_Call { + return &MockRepoComponent_UploadFile_Call{Call: _e.mock.On("UploadFile", ctx, req)} +} + +func (_c *MockRepoComponent_UploadFile_Call) Run(run func(ctx context.Context, req *types.CreateFileReq)) *MockRepoComponent_UploadFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.CreateFileReq)) + }) + return _c +} + +func (_c *MockRepoComponent_UploadFile_Call) Return(_a0 error) *MockRepoComponent_UploadFile_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_UploadFile_Call) RunAndReturn(run func(context.Context, *types.CreateFileReq) error) *MockRepoComponent_UploadFile_Call { + _c.Call.Return(run) + return _c +} + +// NewMockRepoComponent creates a new instance of MockRepoComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepoComponent(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRepoComponent { + mock := &MockRepoComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/user/component/mock_MemberComponent.go b/_mocks/opencsg.com/csghub-server/user/component/mock_MemberComponent.go new file mode 100644 index 00000000..ba3423f0 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/user/component/mock_MemberComponent.go @@ -0,0 +1,522 @@ +// Code generated by mockery v2.48.0. DO NOT EDIT. + +package component + +import ( + context "context" + + membership "opencsg.com/csghub-server/builder/git/membership" + database "opencsg.com/csghub-server/builder/store/database" + + mock "github.com/stretchr/testify/mock" + + types "opencsg.com/csghub-server/common/types" +) + +// MockMemberComponent is an autogenerated mock type for the MemberComponent type +type MockMemberComponent struct { + mock.Mock +} + +type MockMemberComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *MockMemberComponent) EXPECT() *MockMemberComponent_Expecter { + return &MockMemberComponent_Expecter{mock: &_m.Mock} +} + +// AddMember provides a mock function with given fields: ctx, orgName, userName, operatorName, role +func (_m *MockMemberComponent) AddMember(ctx context.Context, orgName string, userName string, operatorName string, role string) error { + ret := _m.Called(ctx, orgName, userName, operatorName, role) + + if len(ret) == 0 { + panic("no return value specified for AddMember") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string) error); ok { + r0 = rf(ctx, orgName, userName, operatorName, role) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMemberComponent_AddMember_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddMember' +type MockMemberComponent_AddMember_Call struct { + *mock.Call +} + +// AddMember is a helper method to define mock.On call +// - ctx context.Context +// - orgName string +// - userName string +// - operatorName string +// - role string +func (_e *MockMemberComponent_Expecter) AddMember(ctx interface{}, orgName interface{}, userName interface{}, operatorName interface{}, role interface{}) *MockMemberComponent_AddMember_Call { + return &MockMemberComponent_AddMember_Call{Call: _e.mock.On("AddMember", ctx, orgName, userName, operatorName, role)} +} + +func (_c *MockMemberComponent_AddMember_Call) Run(run func(ctx context.Context, orgName string, userName string, operatorName string, role string)) *MockMemberComponent_AddMember_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string), args[4].(string)) + }) + return _c +} + +func (_c *MockMemberComponent_AddMember_Call) Return(_a0 error) *MockMemberComponent_AddMember_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMemberComponent_AddMember_Call) RunAndReturn(run func(context.Context, string, string, string, string) error) *MockMemberComponent_AddMember_Call { + _c.Call.Return(run) + return _c +} + +// AddMembers provides a mock function with given fields: ctx, orgName, users, operatorName, role +func (_m *MockMemberComponent) AddMembers(ctx context.Context, orgName string, users []string, operatorName string, role string) error { + ret := _m.Called(ctx, orgName, users, operatorName, role) + + if len(ret) == 0 { + panic("no return value specified for AddMembers") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, []string, string, string) error); ok { + r0 = rf(ctx, orgName, users, operatorName, role) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMemberComponent_AddMembers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddMembers' +type MockMemberComponent_AddMembers_Call struct { + *mock.Call +} + +// AddMembers is a helper method to define mock.On call +// - ctx context.Context +// - orgName string +// - users []string +// - operatorName string +// - role string +func (_e *MockMemberComponent_Expecter) AddMembers(ctx interface{}, orgName interface{}, users interface{}, operatorName interface{}, role interface{}) *MockMemberComponent_AddMembers_Call { + return &MockMemberComponent_AddMembers_Call{Call: _e.mock.On("AddMembers", ctx, orgName, users, operatorName, role)} +} + +func (_c *MockMemberComponent_AddMembers_Call) Run(run func(ctx context.Context, orgName string, users []string, operatorName string, role string)) *MockMemberComponent_AddMembers_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].([]string), args[3].(string), args[4].(string)) + }) + return _c +} + +func (_c *MockMemberComponent_AddMembers_Call) Return(_a0 error) *MockMemberComponent_AddMembers_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMemberComponent_AddMembers_Call) RunAndReturn(run func(context.Context, string, []string, string, string) error) *MockMemberComponent_AddMembers_Call { + _c.Call.Return(run) + return _c +} + +// ChangeMemberRole provides a mock function with given fields: ctx, orgName, userName, operatorName, oldRole, newRole +func (_m *MockMemberComponent) ChangeMemberRole(ctx context.Context, orgName string, userName string, operatorName string, oldRole string, newRole string) error { + ret := _m.Called(ctx, orgName, userName, operatorName, oldRole, newRole) + + if len(ret) == 0 { + panic("no return value specified for ChangeMemberRole") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, string) error); ok { + r0 = rf(ctx, orgName, userName, operatorName, oldRole, newRole) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMemberComponent_ChangeMemberRole_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ChangeMemberRole' +type MockMemberComponent_ChangeMemberRole_Call struct { + *mock.Call +} + +// ChangeMemberRole is a helper method to define mock.On call +// - ctx context.Context +// - orgName string +// - userName string +// - operatorName string +// - oldRole string +// - newRole string +func (_e *MockMemberComponent_Expecter) ChangeMemberRole(ctx interface{}, orgName interface{}, userName interface{}, operatorName interface{}, oldRole interface{}, newRole interface{}) *MockMemberComponent_ChangeMemberRole_Call { + return &MockMemberComponent_ChangeMemberRole_Call{Call: _e.mock.On("ChangeMemberRole", ctx, orgName, userName, operatorName, oldRole, newRole)} +} + +func (_c *MockMemberComponent_ChangeMemberRole_Call) Run(run func(ctx context.Context, orgName string, userName string, operatorName string, oldRole string, newRole string)) *MockMemberComponent_ChangeMemberRole_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string), args[4].(string), args[5].(string)) + }) + return _c +} + +func (_c *MockMemberComponent_ChangeMemberRole_Call) Return(_a0 error) *MockMemberComponent_ChangeMemberRole_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMemberComponent_ChangeMemberRole_Call) RunAndReturn(run func(context.Context, string, string, string, string, string) error) *MockMemberComponent_ChangeMemberRole_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, orgName, userName, operatorName, role +func (_m *MockMemberComponent) Delete(ctx context.Context, orgName string, userName string, operatorName string, role string) error { + ret := _m.Called(ctx, orgName, userName, operatorName, role) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string) error); ok { + r0 = rf(ctx, orgName, userName, operatorName, role) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMemberComponent_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockMemberComponent_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - orgName string +// - userName string +// - operatorName string +// - role string +func (_e *MockMemberComponent_Expecter) Delete(ctx interface{}, orgName interface{}, userName interface{}, operatorName interface{}, role interface{}) *MockMemberComponent_Delete_Call { + return &MockMemberComponent_Delete_Call{Call: _e.mock.On("Delete", ctx, orgName, userName, operatorName, role)} +} + +func (_c *MockMemberComponent_Delete_Call) Run(run func(ctx context.Context, orgName string, userName string, operatorName string, role string)) *MockMemberComponent_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string), args[4].(string)) + }) + return _c +} + +func (_c *MockMemberComponent_Delete_Call) Return(_a0 error) *MockMemberComponent_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMemberComponent_Delete_Call) RunAndReturn(run func(context.Context, string, string, string, string) error) *MockMemberComponent_Delete_Call { + _c.Call.Return(run) + return _c +} + +// GetMemberRole provides a mock function with given fields: ctx, orgName, userName +func (_m *MockMemberComponent) GetMemberRole(ctx context.Context, orgName string, userName string) (membership.Role, error) { + ret := _m.Called(ctx, orgName, userName) + + if len(ret) == 0 { + panic("no return value specified for GetMemberRole") + } + + var r0 membership.Role + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (membership.Role, error)); ok { + return rf(ctx, orgName, userName) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) membership.Role); ok { + r0 = rf(ctx, orgName, userName) + } else { + r0 = ret.Get(0).(membership.Role) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, orgName, userName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMemberComponent_GetMemberRole_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMemberRole' +type MockMemberComponent_GetMemberRole_Call struct { + *mock.Call +} + +// GetMemberRole is a helper method to define mock.On call +// - ctx context.Context +// - orgName string +// - userName string +func (_e *MockMemberComponent_Expecter) GetMemberRole(ctx interface{}, orgName interface{}, userName interface{}) *MockMemberComponent_GetMemberRole_Call { + return &MockMemberComponent_GetMemberRole_Call{Call: _e.mock.On("GetMemberRole", ctx, orgName, userName)} +} + +func (_c *MockMemberComponent_GetMemberRole_Call) Run(run func(ctx context.Context, orgName string, userName string)) *MockMemberComponent_GetMemberRole_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockMemberComponent_GetMemberRole_Call) Return(_a0 membership.Role, _a1 error) *MockMemberComponent_GetMemberRole_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMemberComponent_GetMemberRole_Call) RunAndReturn(run func(context.Context, string, string) (membership.Role, error)) *MockMemberComponent_GetMemberRole_Call { + _c.Call.Return(run) + return _c +} + +// InitRoles provides a mock function with given fields: ctx, org +func (_m *MockMemberComponent) InitRoles(ctx context.Context, org *database.Organization) error { + ret := _m.Called(ctx, org) + + if len(ret) == 0 { + panic("no return value specified for InitRoles") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Organization) error); ok { + r0 = rf(ctx, org) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMemberComponent_InitRoles_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'InitRoles' +type MockMemberComponent_InitRoles_Call struct { + *mock.Call +} + +// InitRoles is a helper method to define mock.On call +// - ctx context.Context +// - org *database.Organization +func (_e *MockMemberComponent_Expecter) InitRoles(ctx interface{}, org interface{}) *MockMemberComponent_InitRoles_Call { + return &MockMemberComponent_InitRoles_Call{Call: _e.mock.On("InitRoles", ctx, org)} +} + +func (_c *MockMemberComponent_InitRoles_Call) Run(run func(ctx context.Context, org *database.Organization)) *MockMemberComponent_InitRoles_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Organization)) + }) + return _c +} + +func (_c *MockMemberComponent_InitRoles_Call) Return(_a0 error) *MockMemberComponent_InitRoles_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMemberComponent_InitRoles_Call) RunAndReturn(run func(context.Context, *database.Organization) error) *MockMemberComponent_InitRoles_Call { + _c.Call.Return(run) + return _c +} + +// OrgMembers provides a mock function with given fields: ctx, orgName, currentUser, pageSize, page +func (_m *MockMemberComponent) OrgMembers(ctx context.Context, orgName string, currentUser string, pageSize int, page int) ([]types.Member, int, error) { + ret := _m.Called(ctx, orgName, currentUser, pageSize, page) + + if len(ret) == 0 { + panic("no return value specified for OrgMembers") + } + + var r0 []types.Member + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, int, int) ([]types.Member, int, error)); ok { + return rf(ctx, orgName, currentUser, pageSize, page) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, int, int) []types.Member); ok { + r0 = rf(ctx, orgName, currentUser, pageSize, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Member) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, int, int) int); ok { + r1 = rf(ctx, orgName, currentUser, pageSize, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, string, int, int) error); ok { + r2 = rf(ctx, orgName, currentUser, pageSize, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockMemberComponent_OrgMembers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OrgMembers' +type MockMemberComponent_OrgMembers_Call struct { + *mock.Call +} + +// OrgMembers is a helper method to define mock.On call +// - ctx context.Context +// - orgName string +// - currentUser string +// - pageSize int +// - page int +func (_e *MockMemberComponent_Expecter) OrgMembers(ctx interface{}, orgName interface{}, currentUser interface{}, pageSize interface{}, page interface{}) *MockMemberComponent_OrgMembers_Call { + return &MockMemberComponent_OrgMembers_Call{Call: _e.mock.On("OrgMembers", ctx, orgName, currentUser, pageSize, page)} +} + +func (_c *MockMemberComponent_OrgMembers_Call) Run(run func(ctx context.Context, orgName string, currentUser string, pageSize int, page int)) *MockMemberComponent_OrgMembers_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(int), args[4].(int)) + }) + return _c +} + +func (_c *MockMemberComponent_OrgMembers_Call) Return(_a0 []types.Member, _a1 int, _a2 error) *MockMemberComponent_OrgMembers_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockMemberComponent_OrgMembers_Call) RunAndReturn(run func(context.Context, string, string, int, int) ([]types.Member, int, error)) *MockMemberComponent_OrgMembers_Call { + _c.Call.Return(run) + return _c +} + +// SetAdmin provides a mock function with given fields: ctx, org, user +func (_m *MockMemberComponent) SetAdmin(ctx context.Context, org *database.Organization, user *database.User) error { + ret := _m.Called(ctx, org, user) + + if len(ret) == 0 { + panic("no return value specified for SetAdmin") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Organization, *database.User) error); ok { + r0 = rf(ctx, org, user) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMemberComponent_SetAdmin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetAdmin' +type MockMemberComponent_SetAdmin_Call struct { + *mock.Call +} + +// SetAdmin is a helper method to define mock.On call +// - ctx context.Context +// - org *database.Organization +// - user *database.User +func (_e *MockMemberComponent_Expecter) SetAdmin(ctx interface{}, org interface{}, user interface{}) *MockMemberComponent_SetAdmin_Call { + return &MockMemberComponent_SetAdmin_Call{Call: _e.mock.On("SetAdmin", ctx, org, user)} +} + +func (_c *MockMemberComponent_SetAdmin_Call) Run(run func(ctx context.Context, org *database.Organization, user *database.User)) *MockMemberComponent_SetAdmin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Organization), args[2].(*database.User)) + }) + return _c +} + +func (_c *MockMemberComponent_SetAdmin_Call) Return(_a0 error) *MockMemberComponent_SetAdmin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMemberComponent_SetAdmin_Call) RunAndReturn(run func(context.Context, *database.Organization, *database.User) error) *MockMemberComponent_SetAdmin_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx +func (_m *MockMemberComponent) Update(ctx context.Context) (*database.Member, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 *database.Member + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*database.Member, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *database.Member); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Member) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMemberComponent_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockMemberComponent_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockMemberComponent_Expecter) Update(ctx interface{}) *MockMemberComponent_Update_Call { + return &MockMemberComponent_Update_Call{Call: _e.mock.On("Update", ctx)} +} + +func (_c *MockMemberComponent_Update_Call) Run(run func(ctx context.Context)) *MockMemberComponent_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockMemberComponent_Update_Call) Return(org *database.Member, err error) *MockMemberComponent_Update_Call { + _c.Call.Return(org, err) + return _c +} + +func (_c *MockMemberComponent_Update_Call) RunAndReturn(run func(context.Context) (*database.Member, error)) *MockMemberComponent_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockMemberComponent creates a new instance of MockMemberComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockMemberComponent(t interface { + mock.TestingT + Cleanup(func()) +}) *MockMemberComponent { + mock := &MockMemberComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/builder/git/file_test.go b/builder/git/file_test.go index 106701d2..9d4f0860 100644 --- a/builder/git/file_test.go +++ b/builder/git/file_test.go @@ -1,38 +1,37 @@ package git import ( - "fmt" "testing" - - "opencsg.com/csghub-server/common/config" - "opencsg.com/csghub-server/common/types" ) +// FIXME: this test should be done in gitea/gitaly package separately as unit test +// or start a real gitea/gitaly server as a e2e test func TestDeleteRepoFile(t *testing.T) { - cfg, err := config.LoadConfig() - if err != nil { - t.Fatalf("failed to load config: %v", err) - } - cfg.GitServer.Type = types.GitServerTypeGitaly - git, err := NewGitServer(cfg) - if err != nil { - t.Fatalf("failed to create git server: %v", err) - } - req := types.DeleteFileReq{ - Namespace: "wanghh2003", - Name: "gp2", - Branch: types.MainBranch, - FilePath: "aaa.jsonl", - Content: "", - RepoType: types.PromptRepo, - CurrentUser: "wanghh2003", - Username: "wanghh2003", - Email: "wanghh2003@163.com", - Message: fmt.Sprintf("delete prompt %s", "aaa.jsonl"), - OriginPath: "", - } - err = git.DeleteRepoFile(&req) - if err != nil { - t.Fatalf("failed to delete repo file: %v", err) - } + + // cfg, err := config.LoadConfig() + // if err != nil { + // t.Fatalf("failed to load config: %v", err) + // } + // cfg.GitServer.Type = types.GitServerTypeGitaly + // git, err := NewGitServer(cfg) + // if err != nil { + // t.Fatalf("failed to create git server: %v", err) + // } + // req := types.DeleteFileReq{ + // Namespace: "wanghh2003", + // Name: "gp2", + // Branch: types.MainBranch, + // FilePath: "aaa.jsonl", + // Content: "", + // RepoType: types.PromptRepo, + // CurrentUser: "wanghh2003", + // Username: "wanghh2003", + // Email: "wanghh2003@163.com", + // Message: fmt.Sprintf("delete prompt %s", "aaa.jsonl"), + // OriginPath: "", + // } + // err = git.DeleteRepoFile(&req) + // if err != nil { + // t.Fatalf("failed to delete repo file: %v", err) + // } } diff --git a/builder/sensitive/aliyun_green.go b/builder/sensitive/aliyun_green.go index 109fc889..7c06a953 100644 --- a/builder/sensitive/aliyun_green.go +++ b/builder/sensitive/aliyun_green.go @@ -18,23 +18,75 @@ import ( "opencsg.com/csghub-server/common/utils/common" ) +type GreenClient interface { + TextScan(request *green.TextScanRequest) (response *TextScanResponse, err error) +} + +type greenClientImpl struct { + green *green.Client +} + +func (c *greenClientImpl) TextScan(request *green.TextScanRequest) (response *TextScanResponse, err error) { + textScanResponse, err := c.green.TextScan(request) + if err != nil { + slog.Error("Failed to call TextScan", slog.Any("error", err)) + return nil, err + } + data := textScanResponse.GetHttpContentBytes() + resp := new(TextScanResponse) + err = json.Unmarshal(data, resp) + if err != nil { + return nil, fmt.Errorf("error unmarshalling scan response: %w", err) + } + return resp, nil +} + +type Green2022Client interface { + GetRegionId() string + TextModeration(request *green20220302.TextModerationRequest) (_result *green20220302.TextModerationResponse, _err error) + ImageModeration(request *green20220302.ImageModerationRequest) (_result *green20220302.ImageModerationResponse, _err error) +} + +type green2022ClientImpl struct { + green *green20220302.Client +} + +func (c *green2022ClientImpl) GetRegionId() string { + return tea.StringValue(c.green.RegionId) +} + +func (c *green2022ClientImpl) TextModeration(request *green20220302.TextModerationRequest) (_result *green20220302.TextModerationResponse, _err error) { + return c.green.TextModeration(request) +} + +func (c *green2022ClientImpl) ImageModeration(request *green20220302.ImageModerationRequest) (_result *green20220302.ImageModerationResponse, _err error) { + return c.green.ImageModeration(request) +} + /* AliyunGreenChecker implements SensitiveChecker by calling Aliyun green sdk */ type AliyunGreenChecker struct { //improved client - cip *green20220302.Client + green2022 Green2022Client //normal client - c *green.Client + green GreenClient +} + +func NewAliyunChecker(green GreenClient, green2022 Green2022Client) *AliyunGreenChecker { + return &AliyunGreenChecker{ + green: green, + green2022: green2022, + } } var _ SensitiveChecker = (*AliyunGreenChecker)(nil) const smallTextSize = 500 -const largeTextSize = 9000 +const LargeTextSize = 9000 -// NewAliyunGreenChecker creates a new AliyunGreenChecker -func NewAliyunGreenChecker(config *config.Config) *AliyunGreenChecker { +// NewAliyunGreenCheckerFromConfig creates a new AliyunGreenChecker +func NewAliyunGreenCheckerFromConfig(config *config.Config) *AliyunGreenChecker { accessKeyID := config.SensitiveCheck.AccessKeyID accessKeySecret := config.SensitiveCheck.AccessKeySecret region := config.SensitiveCheck.Region @@ -60,17 +112,17 @@ func NewAliyunGreenChecker(config *config.Config) *AliyunGreenChecker { } return &AliyunGreenChecker{ - cip, - c, + &green2022ClientImpl{green: cip}, + &greenClientImpl{green: c}, } } // passLargeTextCheck splits large text into smaller `largeTextSize` bytes chunks and check them in batch -func (c *AliyunGreenChecker) passLargeTextCheck(ctx context.Context, text string) (*CheckResult, error) { - if len(text) > 100*largeTextSize { - return nil, fmt.Errorf("text length can't be greater than 100*%d", largeTextSize) +func (c *AliyunGreenChecker) PassLargeTextCheck(ctx context.Context, text string) (*CheckResult, error) { + if len(text) > 100*LargeTextSize { + return nil, fmt.Errorf("text length can't be greater than 100*%d", LargeTextSize) } - tasks := c.splitTasks(text) + tasks := c.SplitTasks(text) content, _ := json.Marshal( map[string]interface{}{ "scenes": [...]string{"antispam"}, @@ -80,17 +132,11 @@ func (c *AliyunGreenChecker) passLargeTextCheck(ctx context.Context, text string textScanRequest := green.CreateTextScanRequest() textScanRequest.SetContent(content) - textScanResponse, err := c.c.TextScan(textScanRequest) + resp, err := c.green.TextScan(textScanRequest) if err != nil { slog.Error("Failed to call TextScan", slog.Any("error", err)) return nil, err } - data := textScanResponse.GetHttpContentBytes() - resp := new(TextScanResponse) - err = json.Unmarshal(data, resp) - if err != nil { - return nil, fmt.Errorf("error unmarshalling scan response: %w", err) - } for _, data := range resp.Data { for _, result := range data.Results { if result.Label == "ad" || result.Label == "flood" { @@ -117,7 +163,7 @@ func (c *AliyunGreenChecker) passLargeTextCheck(ctx context.Context, text string func (c *AliyunGreenChecker) PassTextCheck(ctx context.Context, scenario Scenario, text string) (*CheckResult, error) { if len(text) > smallTextSize { slog.Info("switch to large text check", slog.String("scenario", string(scenario)), slog.Int("size", len(text))) - return c.passLargeTextCheck(ctx, text) + return c.PassLargeTextCheck(ctx, text) } task := map[string]string{"content": text} serviceParameters, _ := json.Marshal(task) @@ -125,7 +171,7 @@ func (c *AliyunGreenChecker) PassTextCheck(ctx context.Context, scenario Scenari Service: tea.String(string(scenario)), ServiceParameters: tea.String(string(serviceParameters)), } - resp, err := c.cip.TextModeration(textModerationRequest) + resp, err := c.green2022.TextModeration(textModerationRequest) if err != nil { slog.Error("fail to call aliyun TextModeration", slog.String("content", text), slog.Any("error", err)) return nil, err @@ -156,12 +202,12 @@ func (c *AliyunGreenChecker) PassTextCheck(ctx context.Context, scenario Scenari return &CheckResult{IsSensitive: false}, nil } -func (*AliyunGreenChecker) splitTasks(text string) []map[string]string { +func (*AliyunGreenChecker) SplitTasks(text string) []map[string]string { var tasks []map[string]string var i int - for i+largeTextSize < len(text) { - tasks = append(tasks, map[string]string{"content": text[i : i+largeTextSize]}) - i += largeTextSize + for i+LargeTextSize < len(text) { + tasks = append(tasks, map[string]string{"content": text[i : i+LargeTextSize]}) + i += LargeTextSize } if i <= len(text) { tasks = append(tasks, map[string]string{"content": text[i:]}) @@ -172,7 +218,7 @@ func (*AliyunGreenChecker) splitTasks(text string) []map[string]string { func (c *AliyunGreenChecker) PassImageCheck(ctx context.Context, scenario Scenario, ossBucketName, ossObjectName string) (*CheckResult, error) { serviceParameters, _ := json.Marshal( map[string]interface{}{ - "ossRegionId": tea.StringValue(c.cip.RegionId), + "ossRegionId": c.green2022.GetRegionId(), //for example: my-image-bucket "ossBucketName": ossBucketName, //for example: image/001.jpg @@ -183,7 +229,7 @@ func (c *AliyunGreenChecker) PassImageCheck(ctx context.Context, scenario Scenar Service: tea.String(string(scenario)), ServiceParameters: tea.String(string(serviceParameters)), } - resp, err := c.cip.ImageModeration(imageModerationRequest) + resp, err := c.green2022.ImageModeration(imageModerationRequest) if err != nil { slog.Error("fail to call aliyun ImageModeration", slog.String("ossBucketName", ossBucketName), slog.String("ossObjectName", ossObjectName), slog.Any("error", err)) diff --git a/builder/sensitive/aliyun_green_test.go b/builder/sensitive/aliyun_green_test.go index ae572205..b80d1cb8 100644 --- a/builder/sensitive/aliyun_green_test.go +++ b/builder/sensitive/aliyun_green_test.go @@ -1,27 +1,27 @@ -package sensitive +package sensitive_test import ( "context" "encoding/json" "fmt" "math" - "os" + "strings" "testing" - "opencsg.com/csghub-server/common/config" + "github.com/alibabacloud-go/green-20220302/client" + "github.com/alibabacloud-go/tea/tea" + "github.com/aliyun/alibaba-cloud-sdk-go/services/green" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + mockgreen "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/sensitive" + "opencsg.com/csghub-server/builder/sensitive" ) -func Test_splitTasks(t *testing.T) { - const txtFileName = "./large_text_to_check.txt" - c := new(AliyunGreenChecker) - buf, err := os.ReadFile(txtFileName) - if err != nil { - t.Log("Failed to read large text:", txtFileName) - t.FailNow() - } - largeText := string(buf) - tasks := c.splitTasks(largeText) - taskCount := math.Round(float64(len(largeText)) / float64(1000)) +func TestSensitiveChecker_SplitTasks(t *testing.T) { + c := new(sensitive.AliyunGreenChecker) + largeText := strings.Repeat("a", 50000) + tasks := c.SplitTasks(largeText) + taskCount := math.Round(float64(len(largeText)) / float64(sensitive.LargeTextSize)) fmt.Println(taskCount, len(tasks)) if len(tasks) != int(taskCount) { t.Logf("task count mismatch, expected: %d, got: %d", int(taskCount), len(tasks)) @@ -29,57 +29,113 @@ func Test_splitTasks(t *testing.T) { } } -func Test_passLargeTextCheck(t *testing.T) { - const txtFileName = "./large_text_to_check.txt" - cfg, err := config.LoadConfig() - if err != nil { - t.Log("Failed to load config:", err) - t.FailNow() - } - cfg.SensitiveCheck.Enable = true - c := NewAliyunGreenChecker(cfg) - buf, err := os.ReadFile(txtFileName) - if err != nil { - t.Log("Failed to read large text:", txtFileName) - t.FailNow() - } - largeText := string(buf) - tasks := c.splitTasks(largeText) - content, _ := json.Marshal( - map[string]interface{}{ - "scenes": [...]string{"antispam"}, - "tasks": tasks, - }, - ) - - result, err := c.passLargeTextCheck(context.Background(), string(content)) - - if err != nil { - t.Log(err.Error()) - t.FailNow() +func TestSensitiveChecker_PassLargeTextCheck(t *testing.T) { + gc := mockgreen.NewMockGreenClient(t) + checker := sensitive.NewAliyunChecker(gc, nil) + + t.Run("text too long", func(t *testing.T) { + _, err := checker.PassLargeTextCheck( + context.Background(), strings.Repeat("a", 150*sensitive.LargeTextSize), + ) + require.NotNil(t, err) + }) + + cases := []struct { + name string + label string + rate float32 + suggestion string + isSensitive bool + }{ + {"ad tag", "ad", 0.1, "", false}, + {"flood tag", "flood", 0.1, "block", false}, + {"low rate", "terrorism", 0.75, "block", false}, + {"block", "foo", 0.85, "block", true}, } - if result.IsSensitive { - t.Log("success", result) - t.FailNow() + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + text := strings.Repeat("a", sensitive.LargeTextSize+10) + tasks := checker.SplitTasks(text) + content, _ := json.Marshal( + map[string]interface{}{ + "scenes": [...]string{"antispam"}, + "tasks": tasks, + }, + ) + + textScanRequest := green.CreateTextScanRequest() + textScanRequest.SetContent(content) + + gc.EXPECT().TextScan(textScanRequest).Return(&sensitive.TextScanResponse{ + Data: []sensitive.TextScanResponseDataItem{ + {Results: []sensitive.TextScanResponseDataItemResult{ + {Label: c.label, Rate: c.rate, Suggestion: c.suggestion}, + }}, + }}, nil).Once() + result, err := checker.PassLargeTextCheck(context.Background(), strings.Repeat("a", sensitive.LargeTextSize+10)) + require.Nil(t, err) + require.Equal(t, c.isSensitive, result.IsSensitive) + }) } + } -func Test_PassTextCheck(t *testing.T) { - cfg, err := config.LoadConfig() - if err != nil { - t.Log("Failed to load config:", err) - t.FailNow() - } - cfg.SensitiveCheck.Enable = true - c := NewAliyunGreenChecker(cfg) - content := "http://github.com/repo" - result, err := c.PassTextCheck(context.Background(), ScenarioCommentDetection, content) - if err != nil { - t.Fail() +func TestSensitiveChecker_PassTextCheck(t *testing.T) { + gc := mockgreen.NewMockGreenClient(t) + g2c := mockgreen.NewMockGreen2022Client(t) + checker := sensitive.NewAliyunChecker(gc, g2c) + + t.Run("large text", func(t *testing.T) { + gc.EXPECT().TextScan(mock.Anything).Return(&sensitive.TextScanResponse{ + Data: []sensitive.TextScanResponseDataItem{ + {Results: []sensitive.TextScanResponseDataItemResult{ + {Label: "foo", Rate: 0.7, Suggestion: "pass"}, + }}, + }}, nil).Once() + _, err := checker.PassLargeTextCheck(context.Background(), strings.Repeat("a", sensitive.LargeTextSize+10)) + require.Nil(t, err) + }) + + cases := []struct { + labels string + isSensitive bool + }{ + {"", false}, + {"ad", false}, + {"flood", false}, + {"ad,flood", false}, + {"ad,flood,foo", true}, } - if result.IsSensitive { - t.Log("fail") - t.FailNow() + + for _, c := range cases { + t.Run(c.labels, func(t *testing.T) { + task := map[string]string{"content": "foo"} + params, err := json.Marshal(task) + require.Nil(t, err) + + req := &client.TextModerationRequest{ + Service: tea.String("foo"), + ServiceParameters: tea.String(string(params)), + } + + g2c.EXPECT().TextModeration(req).Return(&client.TextModerationResponse{ + StatusCode: tea.Int32(200), + Body: &client.TextModerationResponseBody{ + Code: tea.Int32(200), + RequestId: tea.String("z"), + Data: &client.TextModerationResponseBodyData{ + Labels: tea.String(c.labels), + Reason: tea.String("bar"), + }, + }, + }, nil).Once() + result, err := checker.PassTextCheck(context.Background(), "foo", "foo") + require.Nil(t, err) + require.Equal(t, c.isSensitive, result.IsSensitive) + if result.IsSensitive { + require.Equal(t, "bar", result.Reason) + } + }) } } diff --git a/common/tests/stores.go b/common/tests/stores.go new file mode 100644 index 00000000..c445d1a8 --- /dev/null +++ b/common/tests/stores.go @@ -0,0 +1,88 @@ +package tests + +import ( + "testing" + + mockdb "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/builder/store/database" +) + +type MockStores struct { + User database.UserStore + UserLikes database.UserLikesStore + Repo database.RepoStore + Model database.ModelStore + SpaceResource database.SpaceResourceStore + Tag database.TagStore + Dataset database.DatasetStore + PromptConversation database.PromptConversationStore + PromptPrefix database.PromptPrefixStore + LLMConfig database.LLMConfigStore + Prompt database.PromptStore + Namespace database.NamespaceStore +} + +func NewMockStores(t *testing.T) *MockStores { + return &MockStores{ + User: mockdb.NewMockUserStore(t), + UserLikes: mockdb.NewMockUserLikesStore(t), + Repo: mockdb.NewMockRepoStore(t), + Model: mockdb.NewMockModelStore(t), + SpaceResource: mockdb.NewMockSpaceResourceStore(t), + Tag: mockdb.NewMockTagStore(t), + Dataset: mockdb.NewMockDatasetStore(t), + PromptConversation: mockdb.NewMockPromptConversationStore(t), + PromptPrefix: mockdb.NewMockPromptPrefixStore(t), + LLMConfig: mockdb.NewMockLLMConfigStore(t), + Prompt: mockdb.NewMockPromptStore(t), + Namespace: mockdb.NewMockNamespaceStore(t), + } +} + +func (s *MockStores) UserMock() *mockdb.MockUserStore { + return s.User.(*mockdb.MockUserStore) +} + +func (s *MockStores) UserLikesMock() *mockdb.MockUserLikesStore { + return s.UserLikes.(*mockdb.MockUserLikesStore) +} + +func (s *MockStores) RepoMock() *mockdb.MockRepoStore { + return s.Repo.(*mockdb.MockRepoStore) +} + +func (s *MockStores) ModelMock() *mockdb.MockModelStore { + return s.Model.(*mockdb.MockModelStore) +} + +func (s *MockStores) SpaceResourceMock() *mockdb.MockSpaceResourceStore { + return s.SpaceResource.(*mockdb.MockSpaceResourceStore) +} + +func (s *MockStores) TagMock() *mockdb.MockTagStore { + return s.Tag.(*mockdb.MockTagStore) +} + +func (s *MockStores) DatasetMock() *mockdb.MockDatasetStore { + return s.Dataset.(*mockdb.MockDatasetStore) +} + +func (s *MockStores) PromptConversationMock() *mockdb.MockPromptConversationStore { + return s.PromptConversation.(*mockdb.MockPromptConversationStore) +} + +func (s *MockStores) PromptPrefixMock() *mockdb.MockPromptPrefixStore { + return s.PromptPrefix.(*mockdb.MockPromptPrefixStore) +} + +func (s *MockStores) LLMConfigMock() *mockdb.MockLLMConfigStore { + return s.LLMConfig.(*mockdb.MockLLMConfigStore) +} + +func (s *MockStores) PromptMock() *mockdb.MockPromptStore { + return s.Prompt.(*mockdb.MockPromptStore) +} + +func (s *MockStores) NamespaceMock() *mockdb.MockNamespaceStore { + return s.Namespace.(*mockdb.MockNamespaceStore) +} diff --git a/common/utils/common/sync_version_test.go b/common/utils/common/sync_version_test.go index 5c4590f3..82bdf377 100644 --- a/common/utils/common/sync_version_test.go +++ b/common/utils/common/sync_version_test.go @@ -18,8 +18,8 @@ func TestAddPrefixBySourceID(t *testing.T) { ChangeLog: "test log", } str := AddPrefixBySourceID(s.SourceID, "test") - if str != "OpenCSG_test" { - t.Errorf("Expected str should be 'OpenCSG_test' but got %s", str) + if str != "CSG_test" { + t.Errorf("Expected str should be 'CSG_test' but got %s", str) } s1 := &database.SyncVersion{ @@ -31,8 +31,8 @@ func TestAddPrefixBySourceID(t *testing.T) { ChangeLog: "test log", } str1 := AddPrefixBySourceID(s1.SourceID, "test") - if str1 != "Huggingface_test" { - t.Errorf("Expected str should be 'Huggingface_test' but got %s", str) + if str1 != "HF_test" { + t.Errorf("Expected str should be 'HF_test' but got %s", str1) } } @@ -48,7 +48,7 @@ func TestTrimPrefixCloneURLBySourceID(t *testing.T) { cloneURL := TrimPrefixCloneURLBySourceID( "https://opencsg.com", "model", - "OpenCSG_namespace", + "CSG_namespace", "name", s.SourceID, ) @@ -67,7 +67,7 @@ func TestTrimPrefixCloneURLBySourceID(t *testing.T) { cloneURL1 := TrimPrefixCloneURLBySourceID( "https://opencsg.com", "model", - "Huggingface_namespace", + "HF_namespace", "name", s1.SourceID, ) diff --git a/component/code.go b/component/code.go index 57415f69..653d4faf 100644 --- a/component/code.go +++ b/component/code.go @@ -274,7 +274,7 @@ func (c *codeComponentImpl) Show(ctx context.Context, namespace, name, currentUs return nil, fmt.Errorf("failed to find code, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, currentUser, code.Repository) + permission, err := c.GetUserRepoPermission(ctx, currentUser, code.Repository) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -282,7 +282,7 @@ func (c *codeComponentImpl) Show(ctx context.Context, namespace, name, currentUs return nil, ErrUnauthorized } - ns, err := c.getNameSpaceInfo(ctx, namespace) + ns, err := c.GetNameSpaceInfo(ctx, namespace) if err != nil { return nil, fmt.Errorf("failed to get namespace info for code, error: %w", err) } @@ -352,7 +352,7 @@ func (c *codeComponentImpl) Relations(ctx context.Context, namespace, name, curr } func (c *codeComponentImpl) getRelations(ctx context.Context, repoID int64, currentUser string) (*types.Relations, error) { - res, err := c.relatedRepos(ctx, repoID, currentUser) + res, err := c.RelatedRepos(ctx, repoID, currentUser) if err != nil { return nil, err } diff --git a/component/dataset.go b/component/dataset.go index 9f42a11b..a8e7753d 100644 --- a/component/dataset.go +++ b/component/dataset.go @@ -131,7 +131,7 @@ func (c *datasetComponentImpl) Create(ctx context.Context, req *types.CreateData } if !user.CanAdmin() { if namespace.NamespaceType == database.OrgNamespace { - canWrite, err := c.checkCurrentUserPermission(ctx, req.Username, req.Namespace, membership.RoleWrite) + canWrite, err := c.CheckCurrentUserPermission(ctx, req.Username, req.Namespace, membership.RoleWrite) if err != nil { return nil, err } @@ -392,7 +392,7 @@ func (c *datasetComponentImpl) Show(ctx context.Context, namespace, name, curren return nil, fmt.Errorf("failed to find dataset, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, currentUser, dataset.Repository) + permission, err := c.GetUserRepoPermission(ctx, currentUser, dataset.Repository) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -400,7 +400,7 @@ func (c *datasetComponentImpl) Show(ctx context.Context, namespace, name, curren return nil, ErrUnauthorized } - ns, err := c.getNameSpaceInfo(ctx, namespace) + ns, err := c.GetNameSpaceInfo(ctx, namespace) if err != nil { return nil, fmt.Errorf("failed to get namespace info for dataset, error: %w", err) } @@ -472,7 +472,7 @@ func (c *datasetComponentImpl) Relations(ctx context.Context, namespace, name, c } func (c *datasetComponentImpl) getRelations(ctx context.Context, repoID int64, currentUser string) (*types.Relations, error) { - res, err := c.relatedRepos(ctx, repoID, currentUser) + res, err := c.RelatedRepos(ctx, repoID, currentUser) if err != nil { return nil, err } diff --git a/component/model.go b/component/model.go index 536e0306..1d8a738a 100644 --- a/component/model.go +++ b/component/model.go @@ -383,7 +383,7 @@ func (c *modelComponentImpl) Show(ctx context.Context, namespace, name, currentU return nil, fmt.Errorf("failed to find model, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, currentUser, model.Repository) + permission, err := c.GetUserRepoPermission(ctx, currentUser, model.Repository) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -391,7 +391,7 @@ func (c *modelComponentImpl) Show(ctx context.Context, namespace, name, currentU return nil, ErrUnauthorized } - ns, err := c.getNameSpaceInfo(ctx, namespace) + ns, err := c.GetNameSpaceInfo(ctx, namespace) if err != nil { return nil, fmt.Errorf("failed to get namespace info for model, error: %w", err) } @@ -545,7 +545,7 @@ func (c *modelComponentImpl) SDKModelInfo(ctx context.Context, namespace, name, return nil, fmt.Errorf("failed to get last commit, error: %w", err) } - relatedRepos, _ := c.relatedRepos(ctx, model.RepositoryID, currentUser) + relatedRepos, _ := c.RelatedRepos(ctx, model.RepositoryID, currentUser) relatedSpaces := relatedRepos[types.SpaceRepo] spaceNames := make([]string, len(relatedSpaces)) for idx, s := range relatedSpaces { @@ -770,7 +770,7 @@ func (c *modelComponentImpl) DelRelationDataset(ctx context.Context, req types.R } func (c *modelComponentImpl) getRelations(ctx context.Context, fromRepoID int64, currentUser string) (*types.Relations, error) { - res, err := c.relatedRepos(ctx, fromRepoID, currentUser) + res, err := c.RelatedRepos(ctx, fromRepoID, currentUser) if err != nil { return nil, err } diff --git a/component/model_test.go b/component/model_test.go index d9190831..dcf01bf2 100644 --- a/component/model_test.go +++ b/component/model_test.go @@ -3,32 +3,97 @@ package component import ( "context" "testing" - "time" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + gsmock "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/git/gitserver" + "opencsg.com/csghub-server/builder/git/gitserver" + "opencsg.com/csghub-server/builder/store/database" "opencsg.com/csghub-server/common/tests" "opencsg.com/csghub-server/common/types" ) -func TestSetRelationDatasetsAndPrompts(t *testing.T) { - cfg := InitTestDB(t) - - mc, err := NewModelComponent(cfg) - if err != nil { - t.Fatalf("failed to create model component: %v", err) +func NewTestModelComponent(stores *tests.MockStores, git gitserver.GitServer) (ModelComponent, error) { + c := &modelComponentImpl{} + c.ms = stores.Model + c.rs = stores.Repo + c.SS = stores.SpaceResource + c.us = stores.User + c.ts = stores.Tag + c.ds = stores.Dataset + c.repoComponentImpl = &repoComponentImpl{ + git: git, + user: stores.User, + repo: stores.Repo, } + return c, nil +} - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() +func TestModelComponent_SetRelationDatasetsAndPrompts(t *testing.T) { + ctx := context.TODO() - req := types.RelationDatasets{ - CurrentUser: tests.CurrentUser, - Namespace: tests.TestModelNamespace, - Name: tests.TestModelName, - Datasets: []string{"wanghh2003/ds7"}, - } + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + model, err := NewTestModelComponent(stores, gitServer) + require.Nil(t, err) + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + Email: "foo@bar.com", + RoleMask: "foo", + }, nil).Once() + err = model.SetRelationDatasets(ctx, types.RelationDatasets{ + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + }) + require.NotNil(t, err) + require.Contains(t, err.Error(), "only admin") + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + Email: "foo@bar.com", + RoleMask: "foo-admin", + }, nil).Once() + + stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(&database.Repository{}, nil).Once() + // --- + // foo: "foo" + // bar: "bar" + gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: types.MainBranch, + Path: REPOCARD_FILENAME, + RepoType: types.ModelRepo, + }).Return(&types.File{ + Content: "LS0tCiBmb286ICJmb28iCiBiYXI6ICJiYXIi", + }, nil).Once() + + // --- + // bar: bar + // datasets: + // - a + // - b + // foo: foo + + // --- + gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ + Branch: types.MainBranch, + Message: "update dataset tags", + FilePath: REPOCARD_FILENAME, + RepoType: types.ModelRepo, + Namespace: "ns", + Name: "n", + Username: "foo", + Email: "foo@bar.com", + Content: "LS0tCmJhcjogYmFyCmRhdGFzZXRzOgogICAgLSBhCiAgICAtIGIKZm9vOiBmb28KCi0tLQ==", + }).Return(nil).Once() + + err = model.SetRelationDatasets(ctx, types.RelationDatasets{ + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + Datasets: []string{"a", "b"}, + }) + require.Nil(t, err) - err = mc.SetRelationDatasets(ctx, req) - if err != nil { - t.Errorf("failed to set relation datasets: %v", err) - } } diff --git a/component/prompt.go b/component/prompt.go index 7c77be5b..b8381637 100644 --- a/component/prompt.go +++ b/component/prompt.go @@ -16,6 +16,7 @@ import ( "opencsg.com/csghub-server/builder/git/gitserver" "opencsg.com/csghub-server/builder/git/membership" "opencsg.com/csghub-server/builder/llm" + "opencsg.com/csghub-server/builder/rpc" "opencsg.com/csghub-server/builder/sensitive" "opencsg.com/csghub-server/builder/store/database" "opencsg.com/csghub-server/common/config" @@ -30,15 +31,20 @@ var ( ) type promptComponentImpl struct { - gs gitserver.GitServer - user database.UserStore - pc database.PromptConversationStore - pp database.PromptPrefixStore - lc database.LLMConfigStore - pt database.PromptStore - llm *llm.Client - *repoComponentImpl - maxPromptFS int64 + config *config.Config + userStore database.UserStore + userLikeStore database.UserLikesStore + userSvcClient rpc.UserSvcClient + promptConvStore database.PromptConversationStore + promptPrefixStore database.PromptPrefixStore + llmConfigStore database.LLMConfigStore + promptStore database.PromptStore + repoStore database.RepoStore + repoComponent RepoComponent + gitServer gitserver.GitServer + namespaceStore database.NamespaceStore + llmClient *llm.Client + maxPromptFS int64 } type PromptComponent interface { @@ -78,35 +84,42 @@ func NewPromptComponent(cfg *config.Config) (PromptComponent, error) { if err != nil { return nil, fmt.Errorf("failed to create git server,cause:%w", err) } + usc := rpc.NewUserSvcHttpClient(fmt.Sprintf("%s:%d", cfg.User.Host, cfg.User.Port), + rpc.AuthWithApiKey(cfg.APIToken)) return &promptComponentImpl{ - gs: gs, - user: database.NewUserStore(), - pc: database.NewPromptConversationStore(), - pp: database.NewPromptPrefixStore(), - lc: database.NewLLMConfigStore(), - pt: database.NewPromptStore(), - llm: llm.NewClient(), - repoComponentImpl: r, + userStore: database.NewUserStore(), + userLikeStore: database.NewUserLikesStore(), + userSvcClient: usc, + promptConvStore: database.NewPromptConversationStore(), + promptPrefixStore: database.NewPromptPrefixStore(), + llmConfigStore: database.NewLLMConfigStore(), + promptStore: database.NewPromptStore(), + llmClient: llm.NewClient(), + repoStore: database.NewRepoStore(), + repoComponent: r, + gitServer: gs, maxPromptFS: cfg.Dataset.PromptMaxJsonlFileSize, }, nil } func (c *promptComponentImpl) ListPrompt(ctx context.Context, req types.PromptReq) ([]PromptOutput, error) { - r, err := c.repo.FindByPath(ctx, types.PromptRepo, req.Namespace, req.Name) + r, err := c.repoStore.FindByPath(ctx, types.PromptRepo, req.Namespace, req.Name) if err != nil { - return nil, fmt.Errorf("failed to find dataset, error: %w", err) + return nil, fmt.Errorf("failed to find prompt set, error: %w", err) } - allow, err := c.AllowReadAccessRepo(ctx, r, req.CurrentUser) + slog.Debug("ListPrompt check user permission begin") + allow, err := c.repoComponent.AllowReadAccessRepo(ctx, r, req.CurrentUser) + slog.Debug("ListPrompt check user permission end") if err != nil { - return nil, fmt.Errorf("failed to check dataset permission, error: %w", err) + return nil, fmt.Errorf("failed to check prompt set permission, error: %w", err) } if !allow { return nil, ErrUnauthorized } slog.Debug("ListPrompt get repo file tree begin") - tree, err := GetFilePathObjects(req.Namespace, req.Name, "", types.PromptRepo, "", c.git.GetRepoFileTree) + tree, err := GetFilePathObjects(req.Namespace, req.Name, "", types.PromptRepo, "", c.gitServer.GetRepoFileTree) slog.Debug("ListPrompt get repo file tree end") if err != nil { return nil, fmt.Errorf("failed to get repo file tree, error: %w", err) @@ -160,16 +173,15 @@ func (c *promptComponentImpl) ListPrompt(ctx context.Context, req types.PromptRe <-done return prompts, nil - } func (c *promptComponentImpl) GetPrompt(ctx context.Context, req types.PromptReq) (*PromptOutput, error) { - r, err := c.repo.FindByPath(ctx, types.PromptRepo, req.Namespace, req.Name) + r, err := c.repoStore.FindByPath(ctx, types.PromptRepo, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find prompt repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, r) + permission, err := c.repoComponent.GetUserRepoPermission(ctx, req.CurrentUser, r) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -194,7 +206,7 @@ func (c *promptComponentImpl) GetPrompt(ctx context.Context, req types.PromptReq } func (c *promptComponentImpl) ParseJsonFile(ctx context.Context, req gitserver.GetRepoInfoByPathReq) (*PromptOutput, error) { - f, err := c.gs.GetRepoFileContents(ctx, req) + f, err := c.gitServer.GetRepoFileContents(ctx, req) if err != nil { return nil, fmt.Errorf("failed to get %s contents, cause:%w", req.Path, err) } @@ -246,7 +258,7 @@ func (c *promptComponentImpl) CreatePrompt(ctx context.Context, req types.Prompt Email: u.Email, Message: fmt.Sprintf("create prompt %s", req.Path), } - _, err = c.CreateFile(ctx, &fileReq) + _, err = c.repoComponent.CreateFile(ctx, &fileReq) if err != nil { return nil, fmt.Errorf("failed to create prompt file %s, cause: %w", req.Path, err) } @@ -283,7 +295,7 @@ func (c *promptComponentImpl) UpdatePrompt(ctx context.Context, req types.Prompt Email: u.Email, Message: fmt.Sprintf("update prompt %s", req.Path), } - _, err = c.UpdateFile(ctx, &fileReq) + _, err = c.repoComponent.UpdateFile(ctx, &fileReq) if err != nil { return nil, fmt.Errorf("failed to update prompt file %s, cause: %w", req.Path, err) } @@ -313,7 +325,7 @@ func (c *promptComponentImpl) DeletePrompt(ctx context.Context, req types.Prompt OriginPath: "", } - _, err = c.DeleteFile(ctx, &fileReq) + _, err = c.repoComponent.DeleteFile(ctx, &fileReq) if err != nil { return fmt.Errorf("failed to delete prompt %s, cause: %w", req.Path, err) } @@ -328,7 +340,7 @@ func (c *promptComponentImpl) checkFileExist(ctx context.Context, req types.Prom Path: req.Path, RepoType: types.PromptRepo, } - _, err := c.git.GetRepoFileRaw(ctx, getFileRawReq) + _, err := c.gitServer.GetRepoFileRaw(ctx, getFileRawReq) if err != nil { return false, fmt.Errorf("failed to get prompt repository %s/%s file %s raw, error: %w", req.Namespace, req.Name, req.Path, err) } @@ -336,19 +348,19 @@ func (c *promptComponentImpl) checkFileExist(ctx context.Context, req types.Prom } func (c *promptComponentImpl) checkPromptRepoPermission(ctx context.Context, req types.PromptReq) (*database.User, error) { - namespace, err := c.namespace.FindByPath(ctx, req.Namespace) + namespace, err := c.namespaceStore.FindByPath(ctx, req.Namespace) if err != nil { return nil, errors.New("namespace does not exist") } - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return nil, errors.New("user does not exist") } if !user.CanAdmin() { if namespace.NamespaceType == database.OrgNamespace { - canWrite, err := c.checkCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleWrite) + canWrite, err := c.repoComponent.CheckCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleWrite) if err != nil { return nil, err } @@ -365,7 +377,7 @@ func (c *promptComponentImpl) checkPromptRepoPermission(ctx context.Context, req } func (c *promptComponentImpl) NewConversation(ctx context.Context, req types.ConversationTitleReq) (*database.PromptConversation, error) { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return nil, errors.New("user does not exist") } @@ -375,7 +387,7 @@ func (c *promptComponentImpl) NewConversation(ctx context.Context, req types.Con Title: req.Title, } - err = c.pc.CreateConversation(ctx, conversation) + err = c.promptConvStore.CreateConversation(ctx, conversation) if err != nil { return nil, fmt.Errorf("new conversation error: %w", err) } @@ -384,11 +396,11 @@ func (c *promptComponentImpl) NewConversation(ctx context.Context, req types.Con } func (c *promptComponentImpl) ListConversationsByUserID(ctx context.Context, currentUser string) ([]database.PromptConversation, error) { - user, err := c.user.FindByUsername(ctx, currentUser) + user, err := c.userStore.FindByUsername(ctx, currentUser) if err != nil { return nil, errors.New("user does not exist") } - conversations, err := c.pc.FindConversationsByUserID(ctx, user.ID) + conversations, err := c.promptConvStore.FindConversationsByUserID(ctx, user.ID) if err != nil { return nil, fmt.Errorf("find conversations by user %s error: %w", currentUser, err) } @@ -396,11 +408,11 @@ func (c *promptComponentImpl) ListConversationsByUserID(ctx context.Context, cur } func (c *promptComponentImpl) GetConversation(ctx context.Context, req types.ConversationReq) (*database.PromptConversation, error) { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return nil, errors.New("user does not exist") } - conversation, err := c.pc.GetConversationByID(ctx, user.ID, req.Uuid, true) + conversation, err := c.promptConvStore.GetConversationByID(ctx, user.ID, req.Uuid, true) if err != nil { return nil, fmt.Errorf("get conversation by id %s error: %w", req.Uuid, err) } @@ -408,12 +420,12 @@ func (c *promptComponentImpl) GetConversation(ctx context.Context, req types.Con } func (c *promptComponentImpl) SubmitMessage(ctx context.Context, req types.ConversationReq) (<-chan string, error) { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return nil, errors.New("user does not exist") } - _, err = c.pc.GetConversationByID(ctx, user.ID, req.Uuid, false) + _, err = c.promptConvStore.GetConversationByID(ctx, user.ID, req.Uuid, false) if err != nil { return nil, fmt.Errorf("invalid conversation by uuid %s error: %w", req.Uuid, err) } @@ -423,12 +435,12 @@ func (c *promptComponentImpl) SubmitMessage(ctx context.Context, req types.Conve Role: UserRole, Content: req.Message, } - _, err = c.pc.SaveConversationMessage(ctx, reqMsg) + _, err = c.promptConvStore.SaveConversationMessage(ctx, reqMsg) if err != nil { return nil, fmt.Errorf("save user prompt input error: %w", err) } - llmConfig, err := c.lc.GetOptimization(ctx) + llmConfig, err := c.llmConfigStore.GetOptimization(ctx) if err != nil { return nil, fmt.Errorf("get llm config error: %w", err) } @@ -440,7 +452,7 @@ func (c *promptComponentImpl) SubmitMessage(ctx context.Context, req types.Conve } promptPrefix := "" - prefix, err := c.pp.Get(ctx) + prefix, err := c.promptPrefixStore.Get(ctx) if err != nil { slog.Warn("fail to find prompt prefix", slog.Any("err", err)) } else { @@ -466,7 +478,7 @@ func (c *promptComponentImpl) SubmitMessage(ctx context.Context, req types.Conve } slog.Debug("llm request", slog.Any("reqData", reqData)) - ch, err := c.llm.Chat(ctx, llmConfig.ApiEndpoint, headers, reqData) + ch, err := c.llmClient.Chat(ctx, llmConfig.ApiEndpoint, headers, reqData) if err != nil { return nil, fmt.Errorf("call llm error: %w", err) } @@ -479,7 +491,7 @@ func (c *promptComponentImpl) SaveGeneratedText(ctx context.Context, req types.C Role: AssistantRole, Content: req.Message, } - msg, err := c.pc.SaveConversationMessage(ctx, respMsg) + msg, err := c.promptConvStore.SaveConversationMessage(ctx, respMsg) if err != nil { return nil, fmt.Errorf("save system generated response error: %w", err) } @@ -487,12 +499,12 @@ func (c *promptComponentImpl) SaveGeneratedText(ctx context.Context, req types.C } func (c *promptComponentImpl) RemoveConversation(ctx context.Context, req types.ConversationReq) error { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return errors.New("user does not exist") } - err = c.pc.DeleteConversationsByID(ctx, user.ID, req.Uuid) + err = c.promptConvStore.DeleteConversationsByID(ctx, user.ID, req.Uuid) if err != nil { return fmt.Errorf("remove conversation error: %w", err) } @@ -500,12 +512,12 @@ func (c *promptComponentImpl) RemoveConversation(ctx context.Context, req types. } func (c *promptComponentImpl) UpdateConversation(ctx context.Context, req types.ConversationTitleReq) (*database.PromptConversation, error) { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return nil, errors.New("user does not exist") } - err = c.pc.UpdateConversation(ctx, database.PromptConversation{ + err = c.promptConvStore.UpdateConversation(ctx, database.PromptConversation{ UserID: user.ID, ConversationID: req.Uuid, Title: req.Title, @@ -514,7 +526,7 @@ func (c *promptComponentImpl) UpdateConversation(ctx context.Context, req types. return nil, fmt.Errorf("update conversation title error: %w", err) } - resp, err := c.pc.GetConversationByID(ctx, user.ID, req.Uuid, false) + resp, err := c.promptConvStore.GetConversationByID(ctx, user.ID, req.Uuid, false) if err != nil { return nil, fmt.Errorf("invalid conversation by uuid %s error: %w", req.Uuid, err) } @@ -522,15 +534,15 @@ func (c *promptComponentImpl) UpdateConversation(ctx context.Context, req types. } func (c *promptComponentImpl) LikeConversationMessage(ctx context.Context, req types.ConversationMessageReq) error { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return errors.New("user does not exist") } - _, err = c.pc.GetConversationByID(ctx, user.ID, req.Uuid, false) + _, err = c.promptConvStore.GetConversationByID(ctx, user.ID, req.Uuid, false) if err != nil { return fmt.Errorf("invalid conversation by uuid %s error: %w", req.Uuid, err) } - err = c.pc.LikeMessageByID(ctx, req.Id) + err = c.promptConvStore.LikeMessageByID(ctx, req.Id) if err != nil { return fmt.Errorf("update like message by id %d error: %w", req.Id, err) } @@ -538,15 +550,15 @@ func (c *promptComponentImpl) LikeConversationMessage(ctx context.Context, req t } func (c *promptComponentImpl) HateConversationMessage(ctx context.Context, req types.ConversationMessageReq) error { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return errors.New("user does not exist") } - _, err = c.pc.GetConversationByID(ctx, user.ID, req.Uuid, false) + _, err = c.promptConvStore.GetConversationByID(ctx, user.ID, req.Uuid, false) if err != nil { return fmt.Errorf("invalid conversation by uuid %s error: %w", req.Uuid, err) } - err = c.pc.HateMessageByID(ctx, req.Id) + err = c.promptConvStore.HateMessageByID(ctx, req.Id) if err != nil { return fmt.Errorf("update hate message by id %d error: %w", req.Id, err) } @@ -559,18 +571,23 @@ func isChinese(s string) bool { } func (c *promptComponentImpl) SetRelationModels(ctx context.Context, req types.RelationModels) error { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return fmt.Errorf("user does not exist, %w", err) } - if !user.CanAdmin() { - return fmt.Errorf("only admin was allowed to set models for prompt") + repo, err := c.repoStore.FindByPath(ctx, types.PromptRepo, req.Namespace, req.Name) + if err != nil { + return fmt.Errorf("failed to find prompt, error: %w", err) } - _, err = c.repo.FindByPath(ctx, types.PromptRepo, req.Namespace, req.Name) + permission, err := c.repoComponent.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { - return fmt.Errorf("failed to find prompt dataset, error: %w", err) + return fmt.Errorf("failed to get user repo permission, error: %w", err) + } + + if !permission.CanWrite { + return fmt.Errorf("user %s do not allow to set relation models", req.CurrentUser) } getFileContentReq := gitserver.GetRepoInfoByPathReq{ @@ -580,7 +597,7 @@ func (c *promptComponentImpl) SetRelationModels(ctx context.Context, req types.R Path: REPOCARD_FILENAME, RepoType: types.PromptRepo, } - metaMap, splits, err := GetMetaMapFromReadMe(c.gs, getFileContentReq) + metaMap, splits, err := GetMetaMapFromReadMe(c.gitServer, getFileContentReq) if err != nil { return fmt.Errorf("failed parse meta from readme, cause: %w", err) } @@ -601,7 +618,7 @@ func (c *promptComponentImpl) SetRelationModels(ctx context.Context, req types.R readmeReq.Email = user.Email readmeReq.Content = base64.StdEncoding.EncodeToString([]byte(output)) - err = c.git.UpdateRepoFile(&readmeReq) + err = c.gitServer.UpdateRepoFile(&readmeReq) if err != nil { return fmt.Errorf("failed to set models tag to %s file, cause: %w", readmeReq.FilePath, err) } @@ -657,7 +674,7 @@ func GetOutputForReadme(metaMap map[string]any, splits []string) (string, error) } func (c *promptComponentImpl) AddRelationModel(ctx context.Context, req types.RelationModel) error { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return fmt.Errorf("user does not exist, %w", err) } @@ -666,7 +683,7 @@ func (c *promptComponentImpl) AddRelationModel(ctx context.Context, req types.Re return fmt.Errorf("only admin was allowed to set models for prompt") } - _, err = c.repo.FindByPath(ctx, types.PromptRepo, req.Namespace, req.Name) + _, err = c.repoStore.FindByPath(ctx, types.PromptRepo, req.Namespace, req.Name) if err != nil { return fmt.Errorf("failed to find prompt dataset, error: %w", err) } @@ -678,7 +695,7 @@ func (c *promptComponentImpl) AddRelationModel(ctx context.Context, req types.Re Path: REPOCARD_FILENAME, RepoType: types.PromptRepo, } - metaMap, splits, err := GetMetaMapFromReadMe(c.gs, getFileContentReq) + metaMap, splits, err := GetMetaMapFromReadMe(c.gitServer, getFileContentReq) if err != nil { return fmt.Errorf("failed parse meta from readme, cause: %w", err) } @@ -705,7 +722,7 @@ func (c *promptComponentImpl) AddRelationModel(ctx context.Context, req types.Re readmeReq.Email = user.Email readmeReq.Content = base64.StdEncoding.EncodeToString([]byte(output)) - err = c.git.UpdateRepoFile(&readmeReq) + err = c.gitServer.UpdateRepoFile(&readmeReq) if err != nil { return fmt.Errorf("failed to add model tag to %s file, cause: %w", readmeReq.FilePath, err) } @@ -714,7 +731,7 @@ func (c *promptComponentImpl) AddRelationModel(ctx context.Context, req types.Re } func (c *promptComponentImpl) DelRelationModel(ctx context.Context, req types.RelationModel) error { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return fmt.Errorf("user does not exist, %w", err) } @@ -723,7 +740,7 @@ func (c *promptComponentImpl) DelRelationModel(ctx context.Context, req types.Re return fmt.Errorf("only admin was allowed to delete model for prompt") } - _, err = c.repo.FindByPath(ctx, types.PromptRepo, req.Namespace, req.Name) + _, err = c.repoStore.FindByPath(ctx, types.PromptRepo, req.Namespace, req.Name) if err != nil { return fmt.Errorf("failed to find prompt, error: %w", err) } @@ -735,7 +752,7 @@ func (c *promptComponentImpl) DelRelationModel(ctx context.Context, req types.Re Path: REPOCARD_FILENAME, RepoType: types.PromptRepo, } - metaMap, splits, err := GetMetaMapFromReadMe(c.git, getFileContentReq) + metaMap, splits, err := GetMetaMapFromReadMe(c.gitServer, getFileContentReq) if err != nil { return fmt.Errorf("failed parse meta from readme, cause: %w", err) } @@ -767,7 +784,7 @@ func (c *promptComponentImpl) DelRelationModel(ctx context.Context, req types.Re readmeReq.Email = user.Email readmeReq.Content = base64.StdEncoding.EncodeToString([]byte(output)) - err = c.git.UpdateRepoFile(&readmeReq) + err = c.gitServer.UpdateRepoFile(&readmeReq) if err != nil { return fmt.Errorf("failed to delete model tag to %s file, cause: %w", readmeReq.FilePath, err) } @@ -781,18 +798,18 @@ func (c *promptComponentImpl) CreatePromptRepo(ctx context.Context, req *types.C tags []types.RepoTag ) - namespace, err := c.namespace.FindByPath(ctx, req.Namespace) + namespace, err := c.namespaceStore.FindByPath(ctx, req.Namespace) if err != nil { return nil, errors.New("namespace does not exist") } - user, err := c.user.FindByUsername(ctx, req.Username) + user, err := c.userStore.FindByUsername(ctx, req.Username) if err != nil { return nil, errors.New("user does not exist") } if !user.CanAdmin() { if namespace.NamespaceType == database.OrgNamespace { - canWrite, err := c.checkCurrentUserPermission(ctx, req.Username, req.Namespace, membership.RoleWrite) + canWrite, err := c.repoComponent.CheckCurrentUserPermission(ctx, req.Username, req.Namespace, membership.RoleWrite) if err != nil { return nil, err } @@ -819,7 +836,7 @@ func (c *promptComponentImpl) CreatePromptRepo(ctx context.Context, req *types.C req.RepoType = types.PromptRepo req.Readme = generateReadmeData(req.License) req.Nickname = nickname - _, dbRepo, err := c.CreateRepo(ctx, req.CreateRepoReq) + _, dbRepo, err := c.repoComponent.CreateRepo(ctx, req.CreateRepoReq) if err != nil { return nil, err } @@ -829,13 +846,13 @@ func (c *promptComponentImpl) CreatePromptRepo(ctx context.Context, req *types.C RepositoryID: dbRepo.ID, } - prompt, err := c.pt.Create(ctx, dbPrompt) + prompt, err := c.promptStore.Create(ctx, dbPrompt) if err != nil { return nil, fmt.Errorf("failed to create database prompt, cause: %w", err) } // Create README.md file - err = c.git.CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ + err = c.gitServer.CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ Username: user.Username, Email: user.Email, Message: initCommitMessage, @@ -851,7 +868,7 @@ func (c *promptComponentImpl) CreatePromptRepo(ctx context.Context, req *types.C } // Create .gitattributes file - err = c.git.CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ + err = c.gitServer.CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ Username: user.Username, Email: user.Email, Message: initCommitMessage, @@ -907,7 +924,7 @@ func (c *promptComponentImpl) IndexPromptRepo(ctx context.Context, filter *types err error resPrompts []types.PromptRes ) - repos, total, err := c.PublicToUser(ctx, types.PromptRepo, filter.Username, filter, per, page) + repos, total, err := c.repoComponent.PublicToUser(ctx, types.PromptRepo, filter.Username, filter, per, page) if err != nil { newError := fmt.Errorf("failed to get public prompt repos,error:%w", err) return nil, 0, newError @@ -916,7 +933,7 @@ func (c *promptComponentImpl) IndexPromptRepo(ctx context.Context, filter *types for _, repo := range repos { repoIDs = append(repoIDs, repo.ID) } - prompts, err := c.pt.ByRepoIDs(ctx, repoIDs) + prompts, err := c.promptStore.ByRepoIDs(ctx, repoIDs) if err != nil { newError := fmt.Errorf("failed to get prompts by repo ids,error:%w", err) return nil, 0, newError @@ -978,18 +995,18 @@ func (c *promptComponentImpl) IndexPromptRepo(ctx context.Context, filter *types func (c *promptComponentImpl) UpdatePromptRepo(ctx context.Context, req *types.UpdatePromptRepoReq) (*types.PromptRes, error) { req.RepoType = types.PromptRepo - dbRepo, err := c.UpdateRepo(ctx, req.UpdateRepoReq) + dbRepo, err := c.repoComponent.UpdateRepo(ctx, req.UpdateRepoReq) if err != nil { return nil, err } - prompt, err := c.pt.ByRepoID(ctx, dbRepo.ID) + prompt, err := c.promptStore.ByRepoID(ctx, dbRepo.ID) if err != nil { return nil, fmt.Errorf("failed to find prompt, error: %w", err) } // update times of prompt repo - err = c.pt.Update(ctx, *prompt) + err = c.promptStore.Update(ctx, *prompt) if err != nil { return nil, fmt.Errorf("failed to update prompt, error: %w", err) } @@ -1012,7 +1029,7 @@ func (c *promptComponentImpl) UpdatePromptRepo(ctx context.Context, req *types.U } func (c *promptComponentImpl) RemoveRepo(ctx context.Context, namespace, name, currentUser string) error { - prompt, err := c.pt.FindByPath(ctx, namespace, name) + prompt, err := c.promptStore.FindByPath(ctx, namespace, name) if err != nil { return fmt.Errorf("failed to find prompt, error: %w", err) } @@ -1023,12 +1040,12 @@ func (c *promptComponentImpl) RemoveRepo(ctx context.Context, namespace, name, c Name: name, RepoType: types.PromptRepo, } - _, err = c.DeleteRepo(ctx, deleteDatabaseRepoReq) + _, err = c.repoComponent.DeleteRepo(ctx, deleteDatabaseRepoReq) if err != nil { return fmt.Errorf("failed to delete repo of prompt, error: %w", err) } - err = c.pt.Delete(ctx, *prompt) + err = c.promptStore.Delete(ctx, *prompt) if err != nil { return fmt.Errorf("failed to delete database prompt, error: %w", err) } @@ -1037,12 +1054,12 @@ func (c *promptComponentImpl) RemoveRepo(ctx context.Context, namespace, name, c func (c *promptComponentImpl) Show(ctx context.Context, namespace, name, currentUser string) (*types.PromptRes, error) { var tags []types.RepoTag - prompt, err := c.pt.FindByPath(ctx, namespace, name) + prompt, err := c.promptStore.FindByPath(ctx, namespace, name) if err != nil { return nil, fmt.Errorf("failed to find prompt, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, currentUser, prompt.Repository) + permission, err := c.repoComponent.GetUserRepoPermission(ctx, currentUser, prompt.Repository) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -1050,7 +1067,7 @@ func (c *promptComponentImpl) Show(ctx context.Context, namespace, name, current return nil, ErrUnauthorized } - ns, err := c.getNameSpaceInfo(ctx, namespace) + ns, err := c.repoComponent.GetNameSpaceInfo(ctx, namespace) if err != nil { return nil, fmt.Errorf("failed to get namespace info for prompt, error: %w", err) } @@ -1067,7 +1084,7 @@ func (c *promptComponentImpl) Show(ctx context.Context, namespace, name, current }) } - likeExists, err := c.uls.IsExist(ctx, currentUser, prompt.Repository.ID) + likeExists, err := c.userLikeStore.IsExist(ctx, currentUser, prompt.Repository.ID) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user likes,error:%w", err) return nil, newError @@ -1107,12 +1124,12 @@ func (c *promptComponentImpl) Show(ctx context.Context, namespace, name, current } func (c *promptComponentImpl) Relations(ctx context.Context, namespace, name, currentUser string) (*types.Relations, error) { - prompt, err := c.pt.FindByPath(ctx, namespace, name) + prompt, err := c.promptStore.FindByPath(ctx, namespace, name) if err != nil { return nil, fmt.Errorf("failed to find prompt repo, error: %w", err) } - allow, _ := c.AllowReadAccessRepo(ctx, prompt.Repository, currentUser) + allow, _ := c.repoComponent.AllowReadAccessRepo(ctx, prompt.Repository, currentUser) if !allow { return nil, ErrUnauthorized } @@ -1121,7 +1138,7 @@ func (c *promptComponentImpl) Relations(ctx context.Context, namespace, name, cu } func (c *promptComponentImpl) getRelations(ctx context.Context, repoID int64, currentUser string) (*types.Relations, error) { - res, err := c.relatedRepos(ctx, repoID, currentUser) + res, err := c.repoComponent.RelatedRepos(ctx, repoID, currentUser) if err != nil { return nil, err } @@ -1214,7 +1231,7 @@ func (c *promptComponentImpl) OrgPrompts(ctx context.Context, req *types.OrgProm } } onlyPublic := !r.CanRead() - prompts, total, err := c.pt.ByOrgPath(ctx, req.Namespace, req.PageSize, req.Page, onlyPublic) + prompts, total, err := c.promptStore.ByOrgPath(ctx, req.Namespace, req.PageSize, req.Page, onlyPublic) if err != nil { newError := fmt.Errorf("failed to get user prompts,error:%w", err) slog.Error(newError.Error()) diff --git a/component/prompt_test.go b/component/prompt_test.go index adf77fbf..e043d725 100644 --- a/component/prompt_test.go +++ b/component/prompt_test.go @@ -2,231 +2,1099 @@ package component import ( "context" + "encoding/base64" + "encoding/json" + "errors" + "fmt" + "net/http" "testing" - "time" + "github.com/alibabacloud-go/tea/tea" + "github.com/jarcoal/httpmock" + "github.com/spf13/cast" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + gsmock "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/git/gitserver" + urpc_mock "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/rpc" + component_mock "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/component" + "opencsg.com/csghub-server/builder/git/gitserver" + "opencsg.com/csghub-server/builder/git/membership" + "opencsg.com/csghub-server/builder/llm" + "opencsg.com/csghub-server/builder/rpc" "opencsg.com/csghub-server/builder/store/database" "opencsg.com/csghub-server/common/config" "opencsg.com/csghub-server/common/tests" "opencsg.com/csghub-server/common/types" ) -func InitTestDB(t *testing.T) *config.Config { - cfg, err := config.LoadConfig() - cfg.GitServer.Type = types.GitServerTypeGitaly - if err != nil { - t.Fatalf("failed to load config: %v", err) +func NewTestPromptComponent(stores *tests.MockStores, rpcUser rpc.UserSvcClient, gitServer gitserver.GitServer) *promptComponentImpl { + cfg := &config.Config{} + cfg.APIServer.PublicDomain = "https://foo.com" + cfg.APIServer.SSHDomain = "ssh://test@127.0.0.1" + return &promptComponentImpl{ + userStore: stores.User, + userLikeStore: stores.UserLikes, + promptConvStore: stores.PromptConversation, + promptPrefixStore: stores.PromptPrefix, + llmConfigStore: stores.LLMConfig, + promptStore: stores.Prompt, + namespaceStore: stores.Namespace, + userSvcClient: rpcUser, + gitServer: gitServer, + repoStore: stores.Repo, + llmClient: llm.NewClient(), + config: cfg, } - if len(tests.TestDSN) > 0 { - cfg.Database.DSN = tests.TestDSN - } - dbConfig := database.DBConfig{ - Dialect: database.DatabaseDialect(cfg.Database.Driver), - DSN: cfg.Database.DSN, - } - database.InitDB(dbConfig) - return cfg } -func TestCreatePrompt(t *testing.T) { - cfg := InitTestDB(t) - pc, err := NewPromptComponent(cfg) - if err != nil { - t.Fatalf("failed to create prompt component: %v", err) - } - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() +func TestPromptComponent_CheckPermission(t *testing.T) { + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + rpcUser := urpc_mock.NewMockUserSvcClient(t) + pc := NewTestPromptComponent(stores, rpcUser, gitServer) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() req := types.PromptReq{ - Namespace: tests.TestPromptNamespace, - Name: tests.TestPromptName, - CurrentUser: tests.CurrentUser, - } - - testTitle := "test1" - testContent := "test prompt1" - testLanguage := "zh" - testSource := "https://github.com/prompt" - - body := CreatePromptReq{ - Prompt: Prompt{ - Title: testTitle, - Content: testContent, - Language: testLanguage, - Source: testSource, - }, + Path: "p", + Namespace: "ns", + Name: "n", + CurrentUser: "foo", } - testRes, err := pc.CreatePrompt(ctx, req, &body) - if err != nil { - t.Errorf("failed to create prompt: %v", err) - } - if testRes.Title != testTitle || testRes.Content != testContent || testRes.Language != testLanguage || testRes.Source != testSource { - t.Errorf("failed to create prompt with %v", body) - } + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, errors.New("")).Once() + _, err := pc.checkPromptRepoPermission(ctx, req) + require.Contains(t, err.Error(), "namespace does not exist") + + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil).Once() + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{}, errors.New("")).Once() + _, err = pc.checkPromptRepoPermission(ctx, req) + require.Contains(t, err.Error(), "user does not exist") + + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + NamespaceType: database.UserNamespace, + Path: "zzz", + }, nil).Once() + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + RoleMask: "foo", + Username: "zzz", + }, nil).Once() + _, err = pc.checkPromptRepoPermission(ctx, req) + require.Nil(t, err) + + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + NamespaceType: database.UserNamespace, + Path: "uuu", + }, nil).Once() + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + RoleMask: "foo", + Username: "vvv", + }, nil).Once() + _, err = pc.checkPromptRepoPermission(ctx, req) + require.Contains(t, err.Error(), "user do not have permission") + + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + NamespaceType: database.UserNamespace, + Path: "uuu", + }, nil).Once() + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + RoleMask: "foo", + Username: "uuu", + }, nil).Once() + _, err = pc.checkPromptRepoPermission(ctx, req) + require.Nil(t, err) + + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + NamespaceType: database.OrgNamespace, + }, nil).Once() + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + RoleMask: "super-admin", + }, nil).Once() + _, err = pc.checkPromptRepoPermission(ctx, req) + require.Nil(t, err) + + // no write role + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + NamespaceType: database.OrgNamespace, + }, nil).Once() + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + RoleMask: "person", + }, nil).Once() + mockedRepoComponent.EXPECT().CheckCurrentUserPermission(ctx, "foo", "ns", membership.RoleWrite).Return(false, nil).Once() + _, err = pc.checkPromptRepoPermission(ctx, req) + require.Contains(t, err.Error(), "user do not have permission") + + // has write role + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + NamespaceType: database.OrgNamespace, + }, nil).Once() + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + RoleMask: "person", + }, nil).Once() + mockedRepoComponent.EXPECT().CheckCurrentUserPermission(ctx, "foo", "ns", membership.RoleWrite).Return(true, nil).Once() + _, err = pc.checkPromptRepoPermission(ctx, req) + require.Nil(t, err) } -func TestUpdatePrompt(t *testing.T) { - cfg := InitTestDB(t) - pc, err := NewPromptComponent(cfg) - if err != nil { - t.Fatalf("failed to create prompt component: %v", err) +func TestPromptComponent_CreatePrompt(t *testing.T) { + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + rpcUser := urpc_mock.NewMockUserSvcClient(t) + pc := NewTestPromptComponent(stores, rpcUser, gitServer) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + for _, exist := range []bool{true, false} { + t.Run(fmt.Sprintf("file exist: %v", exist), func(t *testing.T) { + + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + NamespaceType: database.OrgNamespace, + }, nil).Once() + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + RoleMask: "foo-admin", + Email: "foo@bar.com", + }, nil).Once() + if exist { + gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: types.MainBranch, + Path: "TEST.jsonl", + RepoType: types.PromptRepo, + }).Return("", nil).Once() + + _, err := pc.CreatePrompt(ctx, types.PromptReq{ + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + Path: "p", + }, &CreatePromptReq{ + Prompt: Prompt{Title: "TEST", Content: "test"}, + }) + require.NotNil(t, err) + return + } else { + gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: types.MainBranch, + Path: "TEST.jsonl", + RepoType: types.PromptRepo, + }).Return("", errors.New("")).Once() + } + + mockedRepoComponent.EXPECT().CreateFile(ctx, &types.CreateFileReq{ + Namespace: "ns", + Name: "n", + Branch: types.MainBranch, + FilePath: "TEST.jsonl", + Content: "eyJ0aXRsZSI6IlRFU1QiLCJjb250ZW50IjoidGVzdCIsImxhbmd1YWdlIjoiIiwidGFncyI6bnVsbCwidHlwZSI6IiIsInNvdXJjZSI6IiIsImF1dGhvciI6IiIsInRpbWUiOiIiLCJjb3B5cmlnaHQiOiIiLCJmZWVkYmFjayI6bnVsbH0=", + RepoType: types.PromptRepo, + CurrentUser: "foo", + Username: "foo", + Email: "foo@bar.com", + Message: fmt.Sprintf("create prompt %s", "TEST.jsonl"), + }).Return(&types.CreateFileResp{}, nil).Once() + + _, err := pc.CreatePrompt(ctx, types.PromptReq{ + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + Path: "p", + }, &CreatePromptReq{ + Prompt: Prompt{Title: "TEST", Content: "test"}, + }) + require.Nil(t, err) + + }) } - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() - req := types.PromptReq{ - Namespace: tests.TestPromptNamespace, - Name: tests.TestPromptName, - CurrentUser: tests.CurrentUser, - Path: "test1.jsonl", - } - - updateTitle := "test2" - updateContent := "test prompt2" - updateLanguage := "en" - updateSource := "https://github.com/prompt2" - - body := UpdatePromptReq{ - Prompt: Prompt{ - Title: updateTitle, - Content: updateContent, - Language: updateLanguage, - Source: updateSource, - }, +} + +func TestPromptComponent_UpdatePrompt(t *testing.T) { + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + rpcUser := urpc_mock.NewMockUserSvcClient(t) + pc := NewTestPromptComponent(stores, rpcUser, gitServer) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + for _, exist := range []bool{true, false} { + t.Run(fmt.Sprintf("file exist: %v", exist), func(t *testing.T) { + + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + NamespaceType: database.OrgNamespace, + }, nil).Once() + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + RoleMask: "foo-admin", + Email: "foo@bar.com", + }, nil).Once() + if !exist { + gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: types.MainBranch, + Path: "TEST.jsonl", + RepoType: types.PromptRepo, + }).Return("", errors.New("")).Once() + + _, err := pc.UpdatePrompt(ctx, types.PromptReq{ + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + Path: "TEST.jsonl", + }, &UpdatePromptReq{ + Prompt: Prompt{Title: "TEST.jsonl", Content: "test"}, + }) + require.NotNil(t, err) + return + } else { + gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: types.MainBranch, + Path: "TEST.jsonl", + RepoType: types.PromptRepo, + }).Return("", nil).Once() + } + + mockedRepoComponent.EXPECT().UpdateFile(ctx, &types.UpdateFileReq{ + Namespace: "ns", + Name: "n", + Branch: types.MainBranch, + FilePath: "TEST.jsonl", + Content: "eyJ0aXRsZSI6IlRFU1QiLCJjb250ZW50IjoidGVzdCIsImxhbmd1YWdlIjoiIiwidGFncyI6bnVsbCwidHlwZSI6IiIsInNvdXJjZSI6IiIsImF1dGhvciI6IiIsInRpbWUiOiIiLCJjb3B5cmlnaHQiOiIiLCJmZWVkYmFjayI6bnVsbH0=", + RepoType: types.PromptRepo, + CurrentUser: "foo", + Username: "foo", + Email: "foo@bar.com", + Message: fmt.Sprintf("update prompt %s", "TEST.jsonl"), + }).Return(&types.UpdateFileResp{}, nil).Once() + + _, err := pc.UpdatePrompt(ctx, types.PromptReq{ + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + Path: "TEST.jsonl", + }, &UpdatePromptReq{ + Prompt: Prompt{Title: "TEST", Content: "test"}, + }) + require.Nil(t, err) + + }) } - testRes, err := pc.UpdatePrompt(ctx, req, &body) - if err != nil { - t.Errorf("failed to update prompt: %v", err) + +} + +func TestPromptComponent_DeletePrompt(t *testing.T) { + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + rpcUser := urpc_mock.NewMockUserSvcClient(t) + pc := NewTestPromptComponent(stores, rpcUser, gitServer) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + NamespaceType: database.OrgNamespace, + }, nil).Once() + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + RoleMask: "foo-admin", + Email: "foo@bar.com", + }, nil).Once() + + mockedRepoComponent.EXPECT().DeleteFile(ctx, &types.DeleteFileReq{ + Namespace: "ns", + Name: "n", + Branch: types.MainBranch, + FilePath: "TEST.jsonl", + Content: "", + RepoType: types.PromptRepo, + CurrentUser: "foo", + Username: "foo", + Email: "foo@bar.com", + Message: fmt.Sprintf("delete prompt %s", "TEST.jsonl"), + }).Return(&types.DeleteFileResp{}, nil).Once() + + err := pc.DeletePrompt(ctx, types.PromptReq{ + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + Path: "TEST.jsonl", + }) + require.Nil(t, err) + +} + +func TestPromptComponent_ListPrompt(t *testing.T) { + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + rpcUser := urpc_mock.NewMockUserSvcClient(t) + pc := NewTestPromptComponent(stores, rpcUser, gitServer) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + repo := &database.Repository{} + stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() + mockedRepoComponent.EXPECT().AllowReadAccessRepo(ctx, repo, "foo").Return(true, nil).Once() + + gitServer.EXPECT().GetRepoFileTree(context.Background(), gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + RepoType: types.PromptRepo, + }).Return([]*types.File{ + {Name: "foo.jsonl", Path: "foo.jsonl"}, + {Name: "bar.jsonl", Path: "bar.jsonl"}, + {Name: "main.go", Path: "main.go"}, + {Name: "large.jsonl", Path: "large.jsonl", Size: 12345678987654}, + }, nil) + + for _, name := range []string{"foo.jsonl", "bar.jsonl"} { + gitServer.EXPECT().GetRepoFileContents(ctx, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: "main", + Path: name, + RepoType: types.PromptRepo, + }).Return(&types.File{ + Content: "LS0tCiB0aXRsZTogImFpIg==", + }, nil).Once() } - if testRes.Title != updateTitle || testRes.Content != updateContent || testRes.Language != updateLanguage || testRes.Source != updateSource { - t.Errorf("failed to update prompt with %v", body) + outputs, err := pc.ListPrompt(ctx, types.PromptReq{ + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + Path: "p", + }) + require.Nil(t, err) + require.Equal(t, 2, len(outputs)) + paths := []string{} + for _, o := range outputs { + require.Equal(t, "ai", o.Title) + paths = append(paths, o.FilePath) } + require.ElementsMatch(t, []string{"foo.jsonl", "bar.jsonl"}, paths) + } -func TestDeletePrompt(t *testing.T) { - cfg := InitTestDB(t) - pc, err := NewPromptComponent(cfg) - if err != nil { - t.Fatalf("failed to create prompt component: %v", err) - } - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() +func TestPromptComponent_GetPrompt(t *testing.T) { + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + rpcUser := urpc_mock.NewMockUserSvcClient(t) + pc := NewTestPromptComponent(stores, rpcUser, gitServer) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() - req := types.PromptReq{ - Namespace: tests.TestPromptNamespace, - Name: tests.TestPromptName, - CurrentUser: tests.CurrentUser, - Path: "test1.jsonl", + repo := &database.Repository{} + stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() + mockedRepoComponent.EXPECT().GetUserRepoPermission(ctx, "foo", repo).Return(&types.UserRepoPermission{ + CanRead: true, + }, nil).Once() + + gitServer.EXPECT().GetRepoFileContents(ctx, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: "main", + Path: "foo.jsonl", + RepoType: types.PromptRepo, + }).Return(&types.File{ + Content: "LS0tCiB0aXRsZTogImFpIg==", + }, nil).Once() + + output, err := pc.GetPrompt(ctx, types.PromptReq{ + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + Path: "foo.jsonl", + }) + require.Nil(t, err) + require.Equal(t, "ai", output.Title) + require.Equal(t, "foo.jsonl", output.FilePath) +} + +func TestPromptComponent_NewConversation(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + ctx := context.TODO() + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + stores.PromptConversationMock().EXPECT().CreateConversation(ctx, database.PromptConversation{ + UserID: 123, + ConversationID: "zzz", + Title: "test", + }).Return(nil).Once() + + cv, err := pc.NewConversation(ctx, types.ConversationTitleReq{ + CurrentUser: "foo", + ConversationTitle: types.ConversationTitle{ + Uuid: "zzz", + Title: "test", + }, + }) + require.Nil(t, err) + require.Equal(t, 123, int(cv.UserID)) + +} + +func TestPromptComponent_ListConversationByUserID(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + ctx := context.TODO() + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + mockedResults := []database.PromptConversation{ + {Title: "foo"}, + {Title: "bar"}, } + stores.PromptConversationMock().EXPECT().FindConversationsByUserID(ctx, int64(123)).Return(mockedResults, nil).Once() + + results, err := pc.ListConversationsByUserID(ctx, "foo") + require.Nil(t, err) + require.Equal(t, mockedResults, results) + +} + +func TestPromptComponent_GetConversation(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + ctx := context.TODO() + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + mocked := &database.PromptConversation{} + stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", true).Return(mocked, nil).Once() + + cv, err := pc.GetConversation(ctx, types.ConversationReq{ + CurrentUser: "foo", + Conversation: types.Conversation{ + Uuid: "uuid", + }, + }) + require.Nil(t, err) + require.Equal(t, mocked, cv) - err = pc.DeletePrompt(ctx, req) - if err != nil { - t.Errorf("failed to delete prompt: %v", err) +} + +func TestPromptComponent_SubmitMessage(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + ctx := context.TODO() + + for _, lang := range []string{"en", "zh"} { + t.Run(lang, func(t *testing.T) { + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(&database.PromptConversation{}, nil).Once() + + content := "go" + if lang == "zh" { + content = "围棋" + } + stores.PromptConversationMock().EXPECT().SaveConversationMessage( + ctx, database.PromptConversationMessage{ + ConversationID: "uuid", + Role: UserRole, + Content: content, + }, + ).Return(&database.PromptConversationMessage{}, nil) + stores.LLMConfigMock().EXPECT().GetOptimization(ctx).Return(&database.LLMConfig{ + ApiEndpoint: "https://llm.com", + AuthHeader: `{"token": "foobar"}`, + }, nil).Once() + stores.PromptPrefixMock().EXPECT().Get(ctx).Return(&database.PromptPrefix{ + ZH: "use Chinese", + EN: "use English", + }, nil).Once() + httpmock.Activate() + t.Cleanup(httpmock.DeactivateAndReset) + + httpmock.RegisterResponder("POST", "https://llm.com", + func(req *http.Request) (*http.Response, error) { + article := make(map[string]interface{}) + if err := json.NewDecoder(req.Body).Decode(&article); err != nil { + return httpmock.NewStringResponse(400, ""), nil + } + prefix := cast.ToStringMap(cast.ToSlice(article["messages"])[0])["content"] + d := "" + switch prefix { + case "use English": + d = `[{"id": 1, "name": "My Great Article"}]` + case "use Chinese": + d = `[{"id": 1, "name": "好好好"}]` + default: + d = "wrong" + } + return httpmock.NewStringResponse( + 200, d, + ), nil + }) + + ch, err := pc.SubmitMessage(ctx, types.ConversationReq{ + CurrentUser: "foo", + Conversation: types.Conversation{ + Uuid: "uuid", + Message: content, + }, + }) + require.Nil(t, err) + all := "" + for i := range ch { + all += i + } + if lang == "en" { + require.Equal(t, "[{\"id\": 1, \"name\": \"My Great Article\"}]", all) + } else { + require.Equal(t, "[{\"id\": 1, \"name\": \"好好好\"}]", all) + } + }) } } -func TestCreatePromptRepo(t *testing.T) { - cfg := InitTestDB(t) - pc, err := NewPromptComponent(cfg) - if err != nil { - t.Fatalf("failed to create prompt component: %v", err) +func TestPromptComponent_SaveGeneratedText(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + ctx := context.TODO() + + mocked := &database.PromptConversationMessage{} + stores.PromptConversationMock().EXPECT().SaveConversationMessage(ctx, database.PromptConversationMessage{ + ConversationID: "uuid", + Role: AssistantRole, + Content: "m", + }).Return(mocked, nil).Once() + + m, err := pc.SaveGeneratedText(ctx, types.Conversation{ + Uuid: "uuid", + Message: "m", + Temperature: tea.Float64(0.8), + }) + require.Nil(t, err) + require.Equal(t, mocked, m) +} + +func TestPromptComponent_RemoveConversation(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + ctx := context.TODO() + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + stores.PromptConversationMock().EXPECT().DeleteConversationsByID(ctx, int64(123), "uuid").Return(nil).Once() + + err := pc.RemoveConversation(ctx, types.ConversationReq{ + CurrentUser: "foo", + Conversation: types.Conversation{ + Uuid: "uuid", + }, + }) + require.Nil(t, err) +} + +func TestPromptComponent_UpdateConversation(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + ctx := context.TODO() + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + stores.PromptConversationMock().EXPECT().UpdateConversation(ctx, database.PromptConversation{ + UserID: 123, + ConversationID: "uuid", + Title: "title", + }).Return(nil).Once() + mocked := &database.PromptConversation{} + stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(mocked, nil) + + cv, err := pc.UpdateConversation(ctx, types.ConversationTitleReq{ + CurrentUser: "foo", + ConversationTitle: types.ConversationTitle{ + Uuid: "uuid", + Title: "title", + }, + }) + require.Nil(t, err) + require.Equal(t, mocked, cv) +} + +func TestPromptComponent_LikeConversationMessage(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + ctx := context.TODO() + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(&database.PromptConversation{}, nil).Once() + stores.PromptConversationMock().EXPECT().LikeMessageByID(ctx, int64(123)).Return(nil).Once() + + err := pc.LikeConversationMessage(ctx, types.ConversationMessageReq{ + Uuid: "uuid", + Id: 123, + CurrentUser: "foo", + }) + require.Nil(t, err) +} + +func TestPromptComponent_HateConversationMessage(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + ctx := context.TODO() + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(&database.PromptConversation{}, nil).Once() + stores.PromptConversationMock().EXPECT().HateMessageByID(ctx, int64(123)).Return(nil).Once() + + err := pc.HateConversationMessage(ctx, types.ConversationMessageReq{ + Uuid: "uuid", + Id: 123, + CurrentUser: "foo", + }) + require.Nil(t, err) +} + +func TestPromptComponent_SetRelationModels(t *testing.T) { + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + pc := NewTestPromptComponent(stores, nil, gitServer) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + ID: 123, + Email: "foo@bar.com", + }, nil).Once() + repo := &database.Repository{} + stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() + mockedRepoComponent.EXPECT().GetUserRepoPermission(ctx, "foo", repo).Return(&types.UserRepoPermission{ + CanWrite: true, + }, nil).Once() + gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: "main", + Path: "README.md", + RepoType: types.PromptRepo, + }).Return(&types.File{ + Content: "LS0tCiB0aXRsZTogImFpIg==", + }, nil).Once() + gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ + Branch: types.MainBranch, + Message: "update model relation tags", + FilePath: REPOCARD_FILENAME, + RepoType: types.PromptRepo, + Namespace: "ns", + Name: "n", + Username: "foo", + Email: "foo@bar.com", + Content: "LS0tCm1vZGVsczoKICAgIC0gbWEKICAgIC0gbWIKICAgIC0gbWMKdGl0bGU6IGFpCgotLS0=", + }).Return(nil).Once() + + err := pc.SetRelationModels(ctx, types.RelationModels{ + Models: []string{"ma", "mb", "mc"}, + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + }) + require.Nil(t, err) + +} + +func TestPromptComponent_AddRelationModel(t *testing.T) { + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + pc := NewTestPromptComponent(stores, nil, gitServer) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + ID: 123, + Email: "foo@bar.com", + RoleMask: "foo-admin", + }, nil).Once() + repo := &database.Repository{} + stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() + gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: "main", + Path: "README.md", + RepoType: types.PromptRepo, + }).Return(&types.File{ + Content: "LS0tCiB0aXRsZTogImFpIg==", + }, nil).Once() + gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ + Branch: types.MainBranch, + Message: "add relation model", + FilePath: REPOCARD_FILENAME, + RepoType: types.PromptRepo, + Namespace: "ns", + Name: "n", + Username: "foo", + Email: "foo@bar.com", + Content: "LS0tCm1vZGVsczoKICAgIC0gbWEKdGl0bGU6IGFpCgotLS0=", + }).Return(nil).Once() + + err := pc.AddRelationModel(ctx, types.RelationModel{ + Model: "ma", + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + }) + require.Nil(t, err) + +} + +func TestPromptComponent_DelRelationModel(t *testing.T) { + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + pc := NewTestPromptComponent(stores, nil, gitServer) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + ID: 123, + Email: "foo@bar.com", + RoleMask: "foo-admin", + }, nil).Once() + repo := &database.Repository{} + stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() + gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: "main", + Path: "README.md", + RepoType: types.PromptRepo, + }).Return(&types.File{ + Content: "LS0tCm1vZGVsczoKICAgIC0gbWEKdGl0bGU6IGFpCgotLS0=", + }, nil).Once() + gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ + Branch: types.MainBranch, + Message: "delete relation model", + FilePath: REPOCARD_FILENAME, + RepoType: types.PromptRepo, + Namespace: "ns", + Name: "n", + Username: "foo", + Email: "foo@bar.com", + Content: "LS0tCm1vZGVsczogW10KdGl0bGU6IGFpCgotLS0=", + }).Return(nil).Once() + + err := pc.DelRelationModel(ctx, types.RelationModel{ + Model: "ma", + Namespace: "ns", + Name: "n", + CurrentUser: "foo", + }) + require.Nil(t, err) + +} + +func TestPromptComponent_CreatePromptRepo(t *testing.T) { + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + pc := NewTestPromptComponent(stores, nil, gitServer) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + ID: 123, + Email: "foo@bar.com", + RoleMask: "foo-admin", + }, nil).Once() + + req := types.CreateRepoReq{ + Username: "foo", + Namespace: "ns", + Name: "n", + Nickname: "nc", + Description: "good", + License: "MIT", + Readme: "\n---\nlicense: MIT\n---\n\t", + DefaultBranch: "main", + RepoType: types.PromptRepo, } - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil).Once() + dbRepo := &database.Repository{} + mockedRepoComponent.EXPECT().CreateRepo(ctx, req).Return(&gitserver.CreateRepoResp{}, dbRepo, nil) + dbPrompt := database.Prompt{ + Repository: dbRepo, + RepositoryID: dbRepo.ID, + } + stores.PromptMock().EXPECT().Create(ctx, dbPrompt).Return(&database.Prompt{ + Repository: &database.Repository{ + Name: "r1", + Tags: []database.Tag{ + {Name: "t1"}, + {Name: "t2"}, + }, + }, + }, nil) + // create readme + gitServer.EXPECT().CreateRepoFile(&types.CreateFileReq{ + Email: "foo@bar.com", + Message: "initial commit", + Branch: "main", + Content: "Ci0tLQpsaWNlbnNlOiBNSVQKLS0tCgk=", + NewBranch: "main", + FilePath: "README.md", + Namespace: "ns", + Name: "n", + RepoType: types.PromptRepo, + }).Return(nil).Once() + // create .gitattributes + gitServer.EXPECT().CreateRepoFile(&types.CreateFileReq{ + Email: "foo@bar.com", + Message: "initial commit", + Branch: "main", + Content: base64.StdEncoding.EncodeToString([]byte(datasetGitattributesContent)), + NewBranch: "main", + FilePath: ".gitattributes", + Namespace: "ns", + Name: "n", + RepoType: types.PromptRepo, + }).Return(nil).Once() - req := types.CreatePromptRepoReq{ + res, err := pc.CreatePromptRepo(ctx, &types.CreatePromptRepoReq{ CreateRepoReq: types.CreateRepoReq{ - Username: tests.CurrentUser, - Namespace: tests.TestNewPromptNamespace, - Name: tests.TestNewPromptName, - Nickname: "mynickname", - Description: "this is test prompt repo", - Private: true, + Username: "foo", + Namespace: "ns", + Name: "n", + Nickname: "nc", + Description: "good", License: "MIT", - Labels: "text", - Readme: "test prompt", + }, + }) + require.Nil(t, err) + expected := types.PromptRes{ + Name: "r1", + Repository: types.Repository{ + HTTPCloneURL: "https://foo.com/s/.git", + SSHCloneURL: "test@127.0.0.1:s/.git", + }, + User: types.User{Email: "foo@bar.com"}, + Tags: []types.RepoTag{ + {Name: "t1"}, + {Name: "t2"}, }, } + require.Equal(t, expected, *res) - testRes, err := pc.CreatePromptRepo(ctx, &req) - if err != nil { - t.Errorf("failed to create repo: %v", err) - } - if testRes.Name != tests.TestNewPromptName || testRes.Nickname != "mynickname" { - t.Errorf("failed to create repo with %v", req) - } } -func TestUpdatePromptRepo(t *testing.T) { - cfg := InitTestDB(t) - pc, err := NewPromptComponent(cfg) - if err != nil { - t.Fatalf("failed to create prompt component: %v", err) +func TestPromptComponent_IndexPromptRepo(t *testing.T) { + stores := tests.NewMockStores(t) + gitServer := gsmock.NewMockGitServer(t) + pc := NewTestPromptComponent(stores, nil, gitServer) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + filter := &types.RepoFilter{Username: "foo"} + mockedRepoComponent.EXPECT().PublicToUser(ctx, types.PromptRepo, "foo", filter, 1, 1).Return([]*database.Repository{ + {ID: 1, Name: "rp1"}, {ID: 2, Name: "rp2"}, + {ID: 3, Name: "rp3", Tags: []database.Tag{{Name: "t1"}, {Name: "t2"}}}, + }, 30, nil).Once() + stores.PromptMock().EXPECT().ByRepoIDs(ctx, []int64{1, 2, 3}).Return([]database.Prompt{ + {ID: 6, RepositoryID: 2, Repository: &database.Repository{}}, + {ID: 5, RepositoryID: 1, Repository: &database.Repository{}}, + {ID: 4, RepositoryID: 3, Repository: &database.Repository{}}, + {ID: 3, RepositoryID: 2, Repository: &database.Repository{}}, + }, nil).Once() + + results, total, err := pc.IndexPromptRepo(ctx, filter, 1, 1) + require.Nil(t, err) + require.Equal(t, 30, total) + require.Equal(t, []types.PromptRes{ + { + RepositoryID: 1, + ID: 5, Name: "rp1", Repository: types.Repository{ + HTTPCloneURL: "https://foo.com/s/.git", + SSHCloneURL: "test@127.0.0.1:s/.git", + }}, + { + RepositoryID: 2, + ID: 6, Name: "rp2", Repository: types.Repository{ + HTTPCloneURL: "https://foo.com/s/.git", + SSHCloneURL: "test@127.0.0.1:s/.git", + }}, + { + RepositoryID: 3, + ID: 4, Name: "rp3", Repository: types.Repository{ + HTTPCloneURL: "https://foo.com/s/.git", + SSHCloneURL: "test@127.0.0.1:s/.git", + }, Tags: []types.RepoTag{{Name: "t1"}, {Name: "t2"}}}, + }, results) + +} + +func TestPromptComponent_UpdatePromptRepo(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + req := &types.UpdatePromptRepoReq{ + UpdateRepoReq: types.UpdateRepoReq{RepoType: types.PromptRepo}, } - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() + mockedRepo := &database.Repository{Name: "rp1", ID: 123} + mockedRepoComponent.EXPECT().UpdateRepo(ctx, req.UpdateRepoReq).Return(mockedRepo, nil).Once() + mockedPrompt := &database.Prompt{ID: 3} + stores.PromptMock().EXPECT().ByRepoID(ctx, int64(123)).Return(mockedPrompt, nil).Once() + stores.PromptMock().EXPECT().Update(ctx, *mockedPrompt).Return(nil).Once() + + res, err := pc.UpdatePromptRepo(ctx, req) + require.Nil(t, err) + require.Equal(t, types.PromptRes{ + RepositoryID: 123, + ID: 3, + Name: "rp1", + }, *res) + +} + +func TestPromptComponent_RemovetRepo(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + mockedPrompt := &database.Prompt{} + stores.PromptMock().EXPECT().FindByPath(ctx, "ns", "n").Return(mockedPrompt, nil).Once() + mockedRepoComponent.EXPECT().DeleteRepo(ctx, types.DeleteRepoReq{ + Username: "foo", + Namespace: "ns", + Name: "n", + RepoType: types.PromptRepo, + }).Return(nil, nil).Once() + stores.PromptMock().EXPECT().Delete(ctx, *mockedPrompt).Return(nil).Once() - NewNickName := "mynewnickname" - NewDesc := "this is test prompt repo" - NewPrivate := true + err := pc.RemoveRepo(ctx, "ns", "n", "foo") + require.Nil(t, err) + +} - req := types.UpdatePromptRepoReq{ - UpdateRepoReq: types.UpdateRepoReq{ - Username: tests.CurrentUser, - Namespace: tests.TestNewPromptNamespace, - Name: tests.TestNewPromptName, - Nickname: &NewNickName, - Description: &NewDesc, - Private: &NewPrivate, +func TestPromptComponent_Show(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() + + mockedPrompt := &database.Prompt{ + Repository: &database.Repository{ + ID: 123, + Tags: []database.Tag{{Name: "t1"}}, }, } + stores.PromptMock().EXPECT().FindByPath(ctx, "ns", "n").Return(mockedPrompt, nil).Once() + mockedRepoComponent.EXPECT().GetUserRepoPermission(ctx, "foo", mockedPrompt.Repository).Return(&types.UserRepoPermission{ + CanRead: true, + }, nil).Once() + mockedRepoComponent.EXPECT().GetNameSpaceInfo(ctx, "ns").Return(&types.Namespace{}, nil).Once() + stores.UserLikesMock().EXPECT().IsExist(ctx, "foo", int64(123)).Return(true, nil).Once() - testRes, err := pc.UpdatePromptRepo(ctx, &req) - if err != nil { - t.Errorf("failed to update repo: %v", err) - } + res, err := pc.Show(ctx, "ns", "n", "foo") + require.Nil(t, err) + require.Equal(t, types.PromptRes{ + RepositoryID: 123, + Repository: types.Repository{ + HTTPCloneURL: "https://foo.com/s/.git", + SSHCloneURL: "test@127.0.0.1:s/.git", + }, + Tags: []types.RepoTag{{Name: "t1"}}, + UserLikes: true, + Namespace: &types.Namespace{}, + }, *res) - if testRes.Nickname != NewNickName || testRes.Description != NewDesc || !testRes.Private { - t.Errorf("failed to update repo with %v", req) - } } -func TestRemoveRepo(t *testing.T) { - cfg := InitTestDB(t) - pc, err := NewPromptComponent(cfg) - if err != nil { - t.Fatalf("failed to create prompt component: %v", err) - } - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() +func TestPromptComponent_Relations(t *testing.T) { + stores := tests.NewMockStores(t) + pc := NewTestPromptComponent(stores, nil, nil) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() - err = pc.RemoveRepo(ctx, tests.TestNewPromptNamespace, tests.TestNewPromptName, tests.CurrentUser) - if err != nil { - t.Errorf("failed to remove repo: %v", err) + mockedPrompt := &database.Prompt{ + RepositoryID: 123, + Repository: &database.Repository{ + ID: 123, + Tags: []database.Tag{{Name: "t1"}}, + }, } + stores.PromptMock().EXPECT().FindByPath(ctx, "ns", "n").Return(mockedPrompt, nil).Once() + mockedRepoComponent.EXPECT().AllowReadAccessRepo(ctx, mockedPrompt.Repository, "foo").Return(true, nil).Once() + mockedRepoComponent.EXPECT().RelatedRepos(ctx, int64(123), "foo").Return( + map[types.RepositoryType][]*database.Repository{ + types.ModelRepo: { + {ID: 1, Name: "r1"}, + {ID: 2, Name: "r2"}, + }, + types.PromptRepo: { + {ID: 3, Name: "r3"}, + {ID: 4, Name: "r4"}, + }, + }, + nil).Once() + + r, err := pc.Relations(ctx, "ns", "n", "foo") + require.Nil(t, err) + require.Equal(t, types.Relations{ + Models: []*types.Model{ + {Name: "r1"}, + {Name: "r2"}, + }, + }, *r) + } -func TestSetRelationModels(t *testing.T) { - cfg := InitTestDB(t) - pc, err := NewPromptComponent(cfg) - if err != nil { - t.Fatalf("failed to create prompt component: %v", err) - } - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() +func TestPromptComponent_OrgPrompts(t *testing.T) { + stores := tests.NewMockStores(t) + rpcUser := urpc_mock.NewMockUserSvcClient(t) + pc := NewTestPromptComponent(stores, rpcUser, nil) + mockedRepoComponent := component_mock.NewMockRepoComponent(t) + pc.repoComponent = mockedRepoComponent + ctx := context.TODO() - req := types.RelationModels{ - CurrentUser: tests.CurrentUser, - Namespace: tests.TestPromptNamespace, - Name: tests.TestPromptName, - Models: []string{"wanghh2003/csg-wukong-1B", "wanghh2003/abc", "wanghh2003/gitalym1"}, + cases := []struct { + role membership.Role + publicOnly bool + }{ + {membership.RoleUnknown, true}, + {membership.RoleAdmin, false}, } - err = pc.SetRelationModels(ctx, req) + for _, c := range cases { + t.Run(string(c.role), func(t *testing.T) { + rpcUser.EXPECT().GetMemberRole(ctx, "ns", "foo").Return(c.role, nil).Once() + stores.PromptMock().EXPECT().ByOrgPath(ctx, "ns", 1, 1, c.publicOnly).Return([]database.Prompt{ + {ID: 1, Repository: &database.Repository{Name: "r1"}}, + {ID: 2, Repository: &database.Repository{Name: "r2"}}, + {ID: 3, Repository: &database.Repository{Name: "r3"}}, + }, 100, nil) + res, count, err := pc.OrgPrompts(ctx, &types.OrgDatasetsReq{ + Namespace: "ns", + CurrentUser: "foo", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 1, + }, + }) + require.Nil(t, err) + require.Equal(t, 100, count) + require.Equal(t, []types.PromptRes{ + {ID: 1, Name: "r1"}, + {ID: 2, Name: "r2"}, + {ID: 3, Name: "r3"}, + }, res) + }) - if err != nil { - t.Errorf("failed to set relation models: %v", err) } + } diff --git a/component/recom_test.go b/component/recom_test.go index c238f0b2..139e9eac 100644 --- a/component/recom_test.go +++ b/component/recom_test.go @@ -5,20 +5,32 @@ import ( "testing" "time" + "github.com/stretchr/testify/mock" + gsmock "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/git/gitserver" + "opencsg.com/csghub-server/builder/git/gitserver" "opencsg.com/csghub-server/builder/store/database" - "opencsg.com/csghub-server/common/config" + "opencsg.com/csghub-server/common/tests" ) -func TestCalculateRecomScore(t *testing.T) { - cfg := &config.Config{} - rc, err := NewRecomComponent(cfg) - if err != nil { - t.Fatal(err) +func NewTestRecomComponent(stores *tests.MockStores, gitServer gitserver.GitServer) *recomComponentImpl { + return &recomComponentImpl{ + repos: stores.Repo, + gs: gitServer, } - ctx := context.Background() +} + +func TestRecomComponent_CalculateTotalScore(t *testing.T) { + gitServer := gsmock.NewMockGitServer(t) + rc := &recomComponentImpl{gs: gitServer} + ctx := context.TODO() + + gitServer.EXPECT().GetRepoFileTree(mock.Anything, gitserver.GetRepoInfoByPathReq{ + Namespace: "foo", + Name: "bar", + }).Return(nil, nil) // Test case 1: repository created 24 hours ago - repo1 := &database.Repository{} + repo1 := &database.Repository{Path: "foo/bar"} repo1.CreatedAt = time.Now().Add(-24 * time.Hour) weights1 := map[string]string{ "freshness": expFreshness, @@ -29,7 +41,7 @@ func TestCalculateRecomScore(t *testing.T) { } // Test case 2: repository created 48 hours ago - repo2 := &database.Repository{} + repo2 := &database.Repository{Path: "foo/bar"} repo2.CreatedAt = time.Now().Add(-50 * time.Hour) weights2 := map[string]string{ "freshness": expFreshness, @@ -40,7 +52,7 @@ func TestCalculateRecomScore(t *testing.T) { } // Test case 3: repository created 168 hours ago - repo3 := &database.Repository{} + repo3 := &database.Repository{Path: "foo/bar"} repo3.CreatedAt = time.Now().Add(-168 * time.Hour) weights3 := map[string]string{ "freshness": expFreshness, diff --git a/component/repo.go b/component/repo.go index 553e2ed1..d1378f42 100644 --- a/component/repo.go +++ b/component/repo.go @@ -139,6 +139,10 @@ type RepoComponent interface { DeployUpdate(ctx context.Context, updateReq types.DeployActReq, req *types.DeployUpdateReq) error DeployStart(ctx context.Context, startReq types.DeployActReq) error AllFiles(ctx context.Context, req types.GetAllFilesReq) ([]*types.File, error) + GetUserRepoPermission(ctx context.Context, userName string, repo *database.Repository) (*types.UserRepoPermission, error) + CheckCurrentUserPermission(ctx context.Context, userName string, namespace string, role membership.Role) (bool, error) + GetNameSpaceInfo(ctx context.Context, path string) (*types.Namespace, error) + RelatedRepos(ctx context.Context, repoID int64, currentUser string) (map[types.RepositoryType][]*database.Repository, error) } func NewRepoComponentImpl(config *config.Config) (*repoComponentImpl, error) { @@ -233,7 +237,7 @@ func (c *repoComponentImpl) CreateRepo(ctx context.Context, req types.CreateRepo if !user.CanAdmin() { if namespace.NamespaceType == database.OrgNamespace { - canWrite, err := c.checkCurrentUserPermission(ctx, req.Username, req.Namespace, membership.RoleWrite) + canWrite, err := c.CheckCurrentUserPermission(ctx, req.Username, req.Namespace, membership.RoleWrite) if err != nil { return nil, nil, err } @@ -309,7 +313,7 @@ func (c *repoComponentImpl) UpdateRepo(ctx context.Context, req types.UpdateRepo if !user.CanAdmin() { if namespace.NamespaceType == database.OrgNamespace { - canWrite, err := c.checkCurrentUserPermission(ctx, req.Username, req.Namespace, membership.RoleWrite) + canWrite, err := c.CheckCurrentUserPermission(ctx, req.Username, req.Namespace, membership.RoleWrite) if err != nil { return nil, err } @@ -374,7 +378,7 @@ func (c *repoComponentImpl) DeleteRepo(ctx context.Context, req types.DeleteRepo } if namespace.NamespaceType == database.OrgNamespace { - canWrite, err := c.checkCurrentUserPermission(ctx, req.Username, req.Namespace, membership.RoleAdmin) + canWrite, err := c.CheckCurrentUserPermission(ctx, req.Username, req.Namespace, membership.RoleAdmin) if err != nil { return nil, err } @@ -436,8 +440,8 @@ func (c *repoComponentImpl) PublicToUser(ctx context.Context, repoType types.Rep return repos, count, nil } -// relatedRepos gets all repos related to the given repo, and return them by repo type -func (c *repoComponentImpl) relatedRepos(ctx context.Context, repoID int64, currentUser string) (map[types.RepositoryType][]*database.Repository, error) { +// RelatedRepos gets all repos related to the given repo, and return them by repo type +func (c *repoComponentImpl) RelatedRepos(ctx context.Context, repoID int64, currentUser string) (map[types.RepositoryType][]*database.Repository, error) { fromRelations, err := c.rel.From(ctx, repoID) if err != nil { return nil, fmt.Errorf("failed to get repo relation from, error: %w", err) @@ -467,17 +471,17 @@ func (c *repoComponentImpl) relatedRepos(ctx context.Context, repoID int64, curr opts = append(opts, database.Columns("id", "repository_type", "path", "user_id", "private", "name", "nickname", "description", "download_count", "updated_at")) - relatedRepos, err := c.repo.FindByIds(ctx, relatedRepoIDs, opts...) + RelatedRepos, err := c.repo.FindByIds(ctx, relatedRepoIDs, opts...) if err != nil { return nil, fmt.Errorf("failed to get relation to repositories by ids, error: %w", err) } - relatedRepos, err = c.visiableToUser(ctx, relatedRepos, currentUser) + RelatedRepos, err = c.visiableToUser(ctx, RelatedRepos, currentUser) if err != nil { return nil, fmt.Errorf("failed to check related repositories visiable to user:%s, %w", currentUser, err) } res := make(map[types.RepositoryType][]*database.Repository) - for _, repo := range relatedRepos { + for _, repo := range RelatedRepos { res[repo.RepositoryType] = append(res[repo.RepositoryType], repo) } return res, nil @@ -491,7 +495,7 @@ func (c *repoComponentImpl) visiableToUser(ctx context.Context, repos []*databas continue } namespace, _ := repo.NamespaceAndName() - canRead, err := c.checkCurrentUserPermission(ctx, currentUser, namespace, membership.RoleRead) + canRead, err := c.CheckCurrentUserPermission(ctx, currentUser, namespace, membership.RoleRead) if err != nil { return nil, err } @@ -517,7 +521,7 @@ func (c *repoComponentImpl) CreateFile(ctx context.Context, req *types.CreateFil return nil, fmt.Errorf("failed to find repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -630,7 +634,7 @@ func (c *repoComponentImpl) UpdateFile(ctx context.Context, req *types.UpdateFil return nil, fmt.Errorf("failed to find repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -716,7 +720,7 @@ func (c *repoComponentImpl) DeleteFile(ctx context.Context, req *types.DeleteFil return nil, fmt.Errorf("failed to find repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -824,7 +828,7 @@ func (c *repoComponentImpl) Commits(ctx context.Context, req *types.GetCommitsRe return nil, nil, fmt.Errorf("failed to find repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return nil, nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -856,7 +860,7 @@ func (c *repoComponentImpl) LastCommit(ctx context.Context, req *types.GetCommit return nil, fmt.Errorf("failed to find repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -886,7 +890,7 @@ func (c *repoComponentImpl) FileRaw(ctx context.Context, req *types.GetFileReq) return "", fmt.Errorf("failed to find repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return "", fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -930,7 +934,7 @@ func (c *repoComponentImpl) DownloadFile(ctx context.Context, req *types.GetFile return nil, 0, "", fmt.Errorf("failed to find repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return nil, 0, "", fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -980,7 +984,7 @@ func (c *repoComponentImpl) Branches(ctx context.Context, req *types.GetBranches return nil, fmt.Errorf("failed to find repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -1011,7 +1015,7 @@ func (c *repoComponentImpl) Tags(ctx context.Context, req *types.GetTagsReq) ([] return nil, fmt.Errorf("failed to find %s, error: %w", req.RepoType, err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -1032,7 +1036,7 @@ func (c *repoComponentImpl) UpdateTags(ctx context.Context, namespace, name stri return fmt.Errorf("failed to find repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, currentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, currentUser, repo) if err != nil { return fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -1056,7 +1060,7 @@ func (c *repoComponentImpl) Tree(ctx context.Context, req *types.GetFileReq) ([] return nil, fmt.Errorf("repo does not exist, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -1335,7 +1339,7 @@ func (c *repoComponentImpl) FileInfo(ctx context.Context, req *types.GetFileReq) return nil, fmt.Errorf("failed to find repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -1402,7 +1406,7 @@ func (c *repoComponentImpl) AllowReadAccessRepo(ctx context.Context, repo *datab } namespace, _ := repo.NamespaceAndName() - return c.checkCurrentUserPermission(ctx, username, namespace, membership.RoleRead) + return c.CheckCurrentUserPermission(ctx, username, namespace, membership.RoleRead) } func (c *repoComponentImpl) AllowReadAccess(ctx context.Context, repoType types.RepositoryType, namespace, name, username string) (bool, error) { @@ -1426,7 +1430,7 @@ func (c *repoComponentImpl) AllowWriteAccess(ctx context.Context, repoType types return false, ErrUserNotFound } - return c.checkCurrentUserPermission(ctx, username, namespace, membership.RoleWrite) + return c.CheckCurrentUserPermission(ctx, username, namespace, membership.RoleWrite) } func (c *repoComponentImpl) AllowAdminAccess(ctx context.Context, repoType types.RepositoryType, namespace, name, username string) (bool, error) { @@ -1442,10 +1446,10 @@ func (c *repoComponentImpl) AllowAdminAccess(ctx context.Context, repoType types return false, ErrUserNotFound } - return c.checkCurrentUserPermission(ctx, username, namespace, membership.RoleAdmin) + return c.CheckCurrentUserPermission(ctx, username, namespace, membership.RoleAdmin) } -func (c *repoComponentImpl) getUserRepoPermission(ctx context.Context, userName string, repo *database.Repository) (*types.UserRepoPermission, error) { +func (c *repoComponentImpl) GetUserRepoPermission(ctx context.Context, userName string, repo *database.Repository) (*types.UserRepoPermission, error) { if userName == "" { //anonymous user only has read permission to public repo return &types.UserRepoPermission{CanRead: !repo.Private, CanWrite: false, CanAdmin: false}, nil @@ -1485,7 +1489,7 @@ func (c *repoComponentImpl) getUserRepoPermission(ctx context.Context, userName } } -func (c *repoComponentImpl) checkCurrentUserPermission(ctx context.Context, userName string, namespace string, role membership.Role) (bool, error) { +func (c *repoComponentImpl) CheckCurrentUserPermission(ctx context.Context, userName string, namespace string, role membership.Role) (bool, error) { ns, err := c.namespace.FindByPath(ctx, namespace) if err != nil { return false, err @@ -1521,7 +1525,7 @@ func (c *repoComponentImpl) GetCommitWithDiff(ctx context.Context, req *types.Ge return nil, fmt.Errorf("failed to find repo, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, req.CurrentUser, repo) + permission, err := c.GetUserRepoPermission(ctx, req.CurrentUser, repo) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -1547,7 +1551,7 @@ func (c *repoComponentImpl) CreateMirror(ctx context.Context, req types.CreateMi mirror database.Mirror taskId int64 ) - admin, err := c.checkCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleAdmin) + admin, err := c.CheckCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleAdmin) if err != nil { return nil, fmt.Errorf("failed to check permission to create mirror, error: %w", err) } @@ -1762,7 +1766,7 @@ func (c *repoComponentImpl) mirrorFromSaasSync(ctx context.Context, mirror *data } func (c *repoComponentImpl) GetMirror(ctx context.Context, req types.GetMirrorReq) (*database.Mirror, error) { - admin, err := c.checkCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleAdmin) + admin, err := c.CheckCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleAdmin) if err != nil { return nil, fmt.Errorf("failed to check permission to create mirror, error: %w", err) } @@ -1782,7 +1786,7 @@ func (c *repoComponentImpl) GetMirror(ctx context.Context, req types.GetMirrorRe } func (c *repoComponentImpl) UpdateMirror(ctx context.Context, req types.UpdateMirrorReq) (*database.Mirror, error) { - admin, err := c.checkCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleAdmin) + admin, err := c.CheckCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleAdmin) if err != nil { return nil, fmt.Errorf("failed to check permission to create mirror, error: %w", err) } @@ -1826,7 +1830,7 @@ func (c *repoComponentImpl) UpdateMirror(ctx context.Context, req types.UpdateMi } func (c *repoComponentImpl) DeleteMirror(ctx context.Context, req types.DeleteMirrorReq) error { - admin, err := c.checkCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleAdmin) + admin, err := c.CheckCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleAdmin) if err != nil { return fmt.Errorf("failed to check permission to create mirror, error: %w", err) } @@ -2402,7 +2406,7 @@ func (c *repoComponentImpl) GetDeployBySvcName(ctx context.Context, svcName stri } func (c *repoComponentImpl) SyncMirror(ctx context.Context, repoType types.RepositoryType, namespace, name, currentUser string) error { - admin, err := c.checkCurrentUserPermission(ctx, currentUser, namespace, membership.RoleAdmin) + admin, err := c.CheckCurrentUserPermission(ctx, currentUser, namespace, membership.RoleAdmin) if err != nil { return fmt.Errorf("failed to check permission to create mirror, error: %w", err) } @@ -2587,7 +2591,7 @@ func (c *repoComponentImpl) AllFiles(ctx context.Context, req types.GetAllFilesR return nil, fmt.Errorf("failed to find repo") } if repo.Private { - read, err := c.checkCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleRead) + read, err := c.CheckCurrentUserPermission(ctx, req.CurrentUser, req.Namespace, membership.RoleRead) if err != nil { return nil, fmt.Errorf("failed to check permission to get all files, error: %w", err) } @@ -2609,7 +2613,7 @@ func (c *repoComponentImpl) isAdminRole(user database.User) bool { return user.CanAdmin() } -func (c *repoComponentImpl) getNameSpaceInfo(ctx context.Context, path string) (*types.Namespace, error) { +func (c *repoComponentImpl) GetNameSpaceInfo(ctx context.Context, path string) (*types.Namespace, error) { nsResp, err := c.userSvcClient.GetNameSpaceInfo(ctx, path) if err != nil { return nil, fmt.Errorf("failed to get namespace infor from user service, path: %s, error: %w", path, err) diff --git a/component/space.go b/component/space.go index dc9a6baa..51107b71 100644 --- a/component/space.go +++ b/component/space.go @@ -212,7 +212,7 @@ func (c *spaceComponentImpl) Show(ctx context.Context, namespace, name, currentU return nil, fmt.Errorf("failed to find space, error: %w", err) } - permission, err := c.getUserRepoPermission(ctx, currentUser, space.Repository) + permission, err := c.GetUserRepoPermission(ctx, currentUser, space.Repository) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -220,7 +220,7 @@ func (c *spaceComponentImpl) Show(ctx context.Context, namespace, name, currentU return nil, ErrUnauthorized } - ns, err := c.getNameSpaceInfo(ctx, namespace) + ns, err := c.GetNameSpaceInfo(ctx, namespace) if err != nil { return nil, fmt.Errorf("failed to get namespace info for model, error: %w", err) } diff --git a/component/tagparser/contentparser_test.go b/component/tagparser/contentparser_test.go index 3c4f96d4..9c3a4019 100644 --- a/component/tagparser/contentparser_test.go +++ b/component/tagparser/contentparser_test.go @@ -1,8 +1,9 @@ package tagparser import ( - "slices" "testing" + + "github.com/stretchr/testify/require" ) const readme = ` @@ -20,7 +21,7 @@ pretty_name: SkyPile-150B size_categories: - 100B Date: Wed, 27 Nov 2024 14:56:16 +0800 Subject: [PATCH 3/3] Add missing database tests --- builder/store/database/event.go | 6 + builder/store/database/event_test.go | 39 +++ builder/store/database/lfs_lock.go | 8 +- builder/store/database/lfs_lock_test.go | 47 ++++ builder/store/database/lfs_meta_object.go | 10 +- .../store/database/lfs_meta_object_test.go | 82 ++++++ builder/store/database/llm_config.go | 4 + builder/store/database/llm_config_test.go | 40 +++ builder/store/database/member.go | 6 + builder/store/database/member_test.go | 46 ++++ builder/store/database/mirror.go | 8 +- builder/store/database/mirror_source.go | 6 + builder/store/database/mirror_source_test.go | 54 ++++ builder/store/database/mirror_test.go | 253 ++++++++++++++++++ builder/store/database/model.go | 6 + builder/store/database/model_test.go | 227 ++++++++++++++++ builder/store/database/multi_sync.go | 8 +- builder/store/database/multi_sync_test.go | 61 +++++ builder/store/database/namespace.go | 21 +- builder/store/database/namespace_test.go | 37 +++ builder/store/database/organization.go | 6 + builder/store/database/organization_test.go | 80 ++++++ builder/store/database/prompt.go | 9 +- builder/store/database/prompt_conversation.go | 4 + .../database/prompt_conversation_test.go | 95 +++++++ builder/store/database/prompt_prefix.go | 4 + builder/store/database/prompt_prefix_test.go | 32 +++ builder/store/database/recom.go | 6 + builder/store/database/recom_test.go | 57 ++++ builder/store/database/repo_relation.go | 6 + builder/store/database/repo_relation_test.go | 111 ++++++++ builder/store/database/repository_file.go | 6 + .../store/database/repository_file_check.go | 6 + .../database/repository_file_check_test.go | 39 +++ .../store/database/repository_file_test.go | 138 ++++++++++ .../database/repository_runtime_framework.go | 39 ++- .../repository_runtime_framework_test.go | 65 +++++ builder/store/database/resources_models.go | 4 + .../store/database/resources_models_test.go | 45 ++++ builder/store/database/space.go | 32 ++- builder/store/database/space_resource.go | 4 + builder/store/database/space_resource_test.go | 59 ++++ builder/store/database/space_sdk.go | 4 + builder/store/database/space_sdk_test.go | 50 ++++ builder/store/database/space_test.go | 220 +++++++++++++++ builder/store/database/ssh_key.go | 6 + builder/store/database/ssh_key_test.go | 65 +++++ builder/store/database/sync_client_setting.go | 6 + .../database/sync_client_setting_test.go | 46 ++++ builder/store/database/sync_version.go | 6 + builder/store/database/sync_version_test.go | 49 ++++ builder/store/database/telemetry.go | 6 + builder/store/database/telemetry_test.go | 23 ++ component/callback/git_callback.go | 2 +- component/repo.go | 2 +- 55 files changed, 2258 insertions(+), 43 deletions(-) create mode 100644 builder/store/database/event_test.go create mode 100644 builder/store/database/lfs_lock_test.go create mode 100644 builder/store/database/lfs_meta_object_test.go create mode 100644 builder/store/database/llm_config_test.go create mode 100644 builder/store/database/member_test.go create mode 100644 builder/store/database/mirror_source_test.go create mode 100644 builder/store/database/mirror_test.go create mode 100644 builder/store/database/model_test.go create mode 100644 builder/store/database/multi_sync_test.go create mode 100644 builder/store/database/namespace_test.go create mode 100644 builder/store/database/organization_test.go create mode 100644 builder/store/database/prompt_conversation_test.go create mode 100644 builder/store/database/prompt_prefix_test.go create mode 100644 builder/store/database/recom_test.go create mode 100644 builder/store/database/repo_relation_test.go create mode 100644 builder/store/database/repository_file_check_test.go create mode 100644 builder/store/database/repository_file_test.go create mode 100644 builder/store/database/repository_runtime_framework_test.go create mode 100644 builder/store/database/resources_models_test.go create mode 100644 builder/store/database/space_resource_test.go create mode 100644 builder/store/database/space_sdk_test.go create mode 100644 builder/store/database/space_test.go create mode 100644 builder/store/database/ssh_key_test.go create mode 100644 builder/store/database/sync_client_setting_test.go create mode 100644 builder/store/database/sync_version_test.go create mode 100644 builder/store/database/telemetry_test.go diff --git a/builder/store/database/event.go b/builder/store/database/event.go index 1add4e6e..dfe1f04a 100644 --- a/builder/store/database/event.go +++ b/builder/store/database/event.go @@ -18,6 +18,12 @@ func NewEventStore() EventStore { } } +func NewEventStoreWithDB(db *DB) EventStore { + return &eventStoreImpl{ + db: db, + } +} + func (s *eventStoreImpl) Save(ctx context.Context, event Event) error { return assertAffectedOneRow(s.db.Core.NewInsert().Model(&event).Exec(ctx)) } diff --git a/builder/store/database/event_test.go b/builder/store/database/event_test.go new file mode 100644 index 00000000..6a15577e --- /dev/null +++ b/builder/store/database/event_test.go @@ -0,0 +1,39 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestEventStore_Save(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewEventStoreWithDB(db) + err := store.Save(ctx, database.Event{ + Module: "m1", + }) + require.Nil(t, err) + event := &database.Event{} + err = db.Core.NewSelect().Model(event).Where("module=?", "m1").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "m1", event.Module) + + err = store.BatchSave(ctx, []database.Event{ + {Module: "m2"}, + {Module: "m3"}, + }) + require.Nil(t, err) + err = db.Core.NewSelect().Model(event).Where("module=?", "m2").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "m2", event.Module) + err = db.Core.NewSelect().Model(event).Where("module=?", "m3").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "m3", event.Module) + +} diff --git a/builder/store/database/lfs_lock.go b/builder/store/database/lfs_lock.go index bd762eba..6b55c366 100644 --- a/builder/store/database/lfs_lock.go +++ b/builder/store/database/lfs_lock.go @@ -22,6 +22,12 @@ func NewLfsLockStore() LfsLockStore { } } +func NewLfsLockStoreWithDB(db *DB) LfsLockStore { + return &lfsLockStoreImpl{ + db: db, + } +} + type LfsLock struct { ID int64 `bun:",pk,autoincrement" json:"id"` RepositoryID int64 `bun:",notnull" json:"repository_id"` @@ -37,7 +43,7 @@ func (s *lfsLockStoreImpl) FindByID(ctx context.Context, ID int64) (*LfsLock, er err := s.db.Operator.Core.NewSelect(). Model(&lfsLock). Relation("User"). - Where("id = ?", ID). + Where("lfs_lock.id = ?", ID). Scan(ctx) if err != nil { return nil, err diff --git a/builder/store/database/lfs_lock_test.go b/builder/store/database/lfs_lock_test.go new file mode 100644 index 00000000..4cc50b8c --- /dev/null +++ b/builder/store/database/lfs_lock_test.go @@ -0,0 +1,47 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestLfsLockStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewLfsLockStoreWithDB(db) + _, err := store.Create(ctx, database.LfsLock{ + RepositoryID: 123, + Path: "foo/bar", + }) + require.Nil(t, err) + + lock := &database.LfsLock{} + err = db.Core.NewSelect().Model(lock).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "foo/bar", lock.Path) + + lock, err = store.FindByID(ctx, lock.ID) + require.Nil(t, err) + require.Equal(t, "foo/bar", lock.Path) + + lock, err = store.FindByPath(ctx, 123, "foo/bar") + require.Nil(t, err) + require.Equal(t, "foo/bar", lock.Path) + + ls, err := store.FindByRepoID(ctx, 123, 1, 10) + require.Nil(t, err) + require.Equal(t, 1, len(ls)) + require.Equal(t, "foo/bar", ls[0].Path) + + err = store.RemoveByID(ctx, lock.ID) + require.Nil(t, err) + _, err = store.FindByID(ctx, lock.ID) + require.NotNil(t, err) + +} diff --git a/builder/store/database/lfs_meta_object.go b/builder/store/database/lfs_meta_object.go index 22b3db70..db43437f 100644 --- a/builder/store/database/lfs_meta_object.go +++ b/builder/store/database/lfs_meta_object.go @@ -25,6 +25,12 @@ func NewLfsMetaObjectStore() LfsMetaObjectStore { } } +func NewLfsMetaObjectStoreWithDB(db *DB) LfsMetaObjectStore { + return &lfsMetaObjectStoreImpl{ + db: db, + } +} + type LfsMetaObject struct { ID int64 `bun:",pk,autoincrement" json:"user_id"` Oid string `bun:",notnull" json:"oid"` @@ -70,10 +76,10 @@ func (s *lfsMetaObjectStoreImpl) Create(ctx context.Context, lfsObj LfsMetaObjec } func (s *lfsMetaObjectStoreImpl) RemoveByOid(ctx context.Context, oid string, repoID int64) error { - err := s.db.Operator.Core.NewDelete(). + _, err := s.db.Operator.Core.NewDelete(). Model(&LfsMetaObject{}). Where("oid = ? and repository_id= ?", oid, repoID). - Scan(ctx) + Exec(ctx) return err } diff --git a/builder/store/database/lfs_meta_object_test.go b/builder/store/database/lfs_meta_object_test.go new file mode 100644 index 00000000..e4d04b77 --- /dev/null +++ b/builder/store/database/lfs_meta_object_test.go @@ -0,0 +1,82 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestLfsMetaStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewLfsMetaObjectStoreWithDB(db) + _, err := store.Create(ctx, database.LfsMetaObject{ + RepositoryID: 123, + Oid: "foobar", + }) + require.Nil(t, err) + + obj := &database.LfsMetaObject{} + err = db.Core.NewSelect().Model(obj).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "foobar", obj.Oid) + + obj, err = store.FindByOID(ctx, 123, "foobar") + require.Nil(t, err) + require.Equal(t, "foobar", obj.Oid) + + objs, err := store.FindByRepoID(ctx, 123) + require.Nil(t, err) + require.Equal(t, 1, len(objs)) + require.Equal(t, "foobar", objs[0].Oid) + + // update + _, err = store.UpdateOrCreate(ctx, database.LfsMetaObject{ + RepositoryID: 123, + Oid: "foobar", + Size: 999, + }) + require.Nil(t, err) + obj, err = store.FindByOID(ctx, 123, "foobar") + require.Nil(t, err) + require.Equal(t, 999, int(obj.Size)) + + // create + _, err = store.UpdateOrCreate(ctx, database.LfsMetaObject{ + RepositoryID: 456, + Oid: "bar", + Size: 998, + }) + require.Nil(t, err) + obj, err = store.FindByOID(ctx, 456, "bar") + require.Nil(t, err) + require.Equal(t, 998, int(obj.Size)) + + err = store.BulkUpdateOrCreate(ctx, []database.LfsMetaObject{ + {RepositoryID: 123, Oid: "foobar", Size: 1}, + {RepositoryID: 456, Oid: "bar", Size: 2}, + {RepositoryID: 789, Oid: "barfoo", Size: 3}, + }) + require.Nil(t, err) + + obj, err = store.FindByOID(ctx, 123, "foobar") + require.Nil(t, err) + require.Equal(t, 1, int(obj.Size)) + obj, err = store.FindByOID(ctx, 456, "bar") + require.Nil(t, err) + require.Equal(t, 2, int(obj.Size)) + obj, err = store.FindByOID(ctx, 789, "barfoo") + require.Nil(t, err) + require.Equal(t, 3, int(obj.Size)) + + err = store.RemoveByOid(ctx, "foobar", 123) + require.Nil(t, err) + _, err = store.FindByOID(ctx, 123, "foobar") + require.NotNil(t, err) + +} diff --git a/builder/store/database/llm_config.go b/builder/store/database/llm_config.go index 6c1758f8..eac56136 100644 --- a/builder/store/database/llm_config.go +++ b/builder/store/database/llm_config.go @@ -27,6 +27,10 @@ func NewLLMConfigStore() LLMConfigStore { return &lLMConfigStoreImpl{db: defaultDB} } +func NewLLMConfigStoreWithDB(db *DB) LLMConfigStore { + return &lLMConfigStoreImpl{db: db} +} + func (s *lLMConfigStoreImpl) GetOptimization(ctx context.Context) (*LLMConfig, error) { var config LLMConfig err := s.db.Operator.Core.NewSelect().Model(&config).Where("type = 1 and enabled = true").Limit(1).Scan(ctx) diff --git a/builder/store/database/llm_config_test.go b/builder/store/database/llm_config_test.go new file mode 100644 index 00000000..5e157025 --- /dev/null +++ b/builder/store/database/llm_config_test.go @@ -0,0 +1,40 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestLLMConfigStore_GetOptimization(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewLLMConfigStoreWithDB(db) + _, err := db.Core.NewInsert().Model(&database.LLMConfig{ + Type: 1, + Enabled: true, + ModelName: "c1", + }).Exec(ctx) + require.Nil(t, err) + _, err = db.Core.NewInsert().Model(&database.LLMConfig{ + Type: 2, + Enabled: true, + ModelName: "c2", + }).Exec(ctx) + require.Nil(t, err) + _, err = db.Core.NewInsert().Model(&database.LLMConfig{ + Type: 1, + Enabled: false, + ModelName: "c3", + }).Exec(ctx) + require.Nil(t, err) + + cfg, err := store.GetOptimization(ctx) + require.Nil(t, err) + require.Equal(t, "c1", cfg.ModelName) +} diff --git a/builder/store/database/member.go b/builder/store/database/member.go index 12f4316f..db2ca309 100644 --- a/builder/store/database/member.go +++ b/builder/store/database/member.go @@ -23,6 +23,12 @@ func NewMemberStore() MemberStore { } } +func NewMemberStoreWithDB(db *DB) MemberStore { + return &memberStoreImpl{ + db: db, + } +} + // Member is the relationship between a user and an organization. type Member struct { ID int64 `bun:",pk,autoincrement" json:"id"` diff --git a/builder/store/database/member_test.go b/builder/store/database/member_test.go new file mode 100644 index 00000000..6af010c1 --- /dev/null +++ b/builder/store/database/member_test.go @@ -0,0 +1,46 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestMemberStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewMemberStoreWithDB(db) + + err := store.Add(ctx, 123, 456, "foo") + require.Nil(t, err) + mem := &database.Member{} + err = db.Core.NewSelect().Model(mem).Where("user_id=?", 456).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "foo", mem.Role) + + mem, err = store.Find(ctx, 123, 456) + require.Nil(t, err) + require.Equal(t, "foo", mem.Role) + + ms, err := store.UserMembers(ctx, 456) + require.Nil(t, err) + require.Equal(t, 1, len(ms)) + require.Equal(t, "foo", ms[0].Role) + + ms, count, err := store.OrganizationMembers(ctx, 123, 10, 1) + require.Nil(t, err) + require.Equal(t, 1, len(ms)) + require.Equal(t, 1, count) + require.Equal(t, "foo", ms[0].Role) + + err = store.Delete(ctx, 123, 456, "foo") + require.Nil(t, err) + _, err = store.Find(ctx, 123, 456) + require.NotNil(t, err) + +} diff --git a/builder/store/database/mirror.go b/builder/store/database/mirror.go index 9f733d56..d9ccd448 100644 --- a/builder/store/database/mirror.go +++ b/builder/store/database/mirror.go @@ -41,6 +41,12 @@ func NewMirrorStore() MirrorStore { } } +func NewMirrorStoreWithDB(db *DB) MirrorStore { + return &mirrorStoreImpl{ + db: db, + } +} + type Mirror struct { ID int64 `bun:",pk,autoincrement" json:"id"` Interval string `bun:",notnull" json:"interval"` @@ -185,7 +191,7 @@ func (s *mirrorStoreImpl) WithPaginationWithRepository(ctx context.Context) ([]M var mirrors []Mirror err := s.db.Operator.Core.NewSelect(). Model(&mirrors). - Relation("Repositoy"). + Relation("Repository"). Scan(ctx) if err != nil { return nil, err diff --git a/builder/store/database/mirror_source.go b/builder/store/database/mirror_source.go index 314f171c..33b9017e 100644 --- a/builder/store/database/mirror_source.go +++ b/builder/store/database/mirror_source.go @@ -25,6 +25,12 @@ func NewMirrorSourceStore() MirrorSourceStore { } } +func NewMirrorSourceStoreWithDB(db *DB) MirrorSourceStore { + return &mirrorSourceStoreImpl{ + db: db, + } +} + type MirrorSource struct { ID int64 `bun:",pk,autoincrement" json:"id"` SourceName string `bun:",notnull,unique" json:"source_name"` diff --git a/builder/store/database/mirror_source_test.go b/builder/store/database/mirror_source_test.go new file mode 100644 index 00000000..b742c3ca --- /dev/null +++ b/builder/store/database/mirror_source_test.go @@ -0,0 +1,54 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestMirrorSourceStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewMirrorSourceStoreWithDB(db) + _, err := store.Create(ctx, &database.MirrorSource{ + SourceName: "foo", + }) + require.Nil(t, err) + + mi := &database.MirrorSource{} + err = db.Core.NewSelect().Model(mi).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "foo", mi.SourceName) + + mi, err = store.Get(ctx, mi.ID) + require.Nil(t, err) + require.Equal(t, "foo", mi.SourceName) + + mi, err = store.FindByName(ctx, "foo") + require.Nil(t, err) + require.Equal(t, "foo", mi.SourceName) + + mi.SourceName = "bar" + err = store.Update(ctx, mi) + require.Nil(t, err) + mi = &database.MirrorSource{} + err = db.Core.NewSelect().Model(mi).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "bar", mi.SourceName) + + mis, err := store.Index(ctx) + require.Nil(t, err) + require.Equal(t, 1, len(mis)) + require.Equal(t, "bar", mis[0].SourceName) + + err = store.Delete(ctx, mi) + require.Nil(t, err) + _, err = store.Get(ctx, mi.ID) + require.NotNil(t, err) + +} diff --git a/builder/store/database/mirror_test.go b/builder/store/database/mirror_test.go new file mode 100644 index 00000000..ab056121 --- /dev/null +++ b/builder/store/database/mirror_test.go @@ -0,0 +1,253 @@ +package database_test + +import ( + "context" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestMirrorStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewMirrorStoreWithDB(db) + _, err := store.Create(ctx, &database.Mirror{ + Interval: "foo", + RepositoryID: 123, + PushMirrorCreated: true, + Status: types.MirrorFinished, + Priority: types.HighMirrorPriority, + }) + require.Nil(t, err) + + mi := &database.Mirror{} + err = db.Core.NewSelect().Model(mi).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "foo", mi.Interval) + + mi, err = store.FindByID(ctx, mi.ID) + require.Nil(t, err) + require.Equal(t, "foo", mi.Interval) + + mi, err = store.FindByRepoID(ctx, 123) + require.Nil(t, err) + require.Equal(t, "foo", mi.Interval) + + exist, err := store.IsExist(ctx, 123) + require.Nil(t, err) + require.True(t, exist) + exist, err = store.IsExist(ctx, 456) + require.Nil(t, err) + require.False(t, exist) + + repo := &database.Repository{ + RepositoryType: types.ModelRepo, + GitPath: "models_ns/n", + Name: "repo", + } + err = db.Core.NewInsert().Model(repo).Scan(ctx, repo) + require.Nil(t, err) + + exist, err = store.IsRepoExist(ctx, types.ModelRepo, "ns", "n") + require.Nil(t, err) + require.True(t, exist) + + exist, err = store.IsRepoExist(ctx, types.ModelRepo, "ns", "n2") + require.Nil(t, err) + require.False(t, exist) + + mi.RepositoryID = repo.ID + err = store.Update(ctx, mi) + require.Nil(t, err) + + err = db.Core.NewSelect().Model(mi).Scan(ctx) + require.Nil(t, err) + require.Equal(t, repo.ID, mi.RepositoryID) + + mi, err = store.FindByRepoPath(ctx, types.ModelRepo, "ns", "n") + require.Nil(t, err) + require.Equal(t, repo.ID, mi.RepositoryID) + + ms, err := store.WithPagination(ctx) + require.Nil(t, err) + require.Equal(t, 1, len(ms)) + + ms, err = store.WithPaginationWithRepository(ctx) + require.Nil(t, err) + require.Equal(t, 1, len(ms)) + require.Equal(t, "repo", ms[0].Repository.Name) + + ms, err = store.PushedMirror(ctx) + require.Nil(t, err) + require.Equal(t, 1, len(ms)) + + ms, err = store.NoPushMirror(ctx) + require.Nil(t, err) + require.Equal(t, 0, len(ms)) + + ms, err = store.Finished(ctx) + require.Nil(t, err) + require.Equal(t, 1, len(ms)) + + ms, err = store.Unfinished(ctx) + require.Nil(t, err) + require.Equal(t, 0, len(ms)) + + mi.AccessToken = "abc" + repo.Nickname = "fooo" + err = store.UpdateMirrorAndRepository(ctx, mi, repo) + require.Nil(t, err) + mi = &database.Mirror{} + err = db.Core.NewSelect().Model(mi).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "abc", mi.AccessToken) + repo = &database.Repository{} + err = db.Core.NewSelect().Model(repo).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "fooo", repo.Nickname) + + err = store.Delete(ctx, mi) + require.Nil(t, err) + _, err = store.FindByID(ctx, mi.ID) + require.NotNil(t, err) + +} + +func TestMirrorStore_FindWithMapping(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewMirrorStoreWithDB(db) + + repos := []*database.Repository{ + {Name: "repo1", RepositoryType: types.ModelRepo, Path: "models_ns/repo1"}, + {Name: "repo2", RepositoryType: types.DatasetRepo, Path: "datasets_ns/repo2"}, + {Name: "repo3", RepositoryType: types.PromptRepo, Path: "prompts_ns/repo3"}, + } + + for _, repo := range repos { + repo.GitPath = repo.Path + err := db.Core.NewInsert().Model(repo).Scan(ctx, repo) + require.Nil(t, err) + sp := strings.Split(repo.Path, "_") + _, err = store.Create(ctx, &database.Mirror{ + RepositoryID: repo.ID, + SourceRepoPath: strings.ReplaceAll(sp[1], "ns/", "nsn/"), + Interval: repo.Name, + }) + require.Nil(t, err) + } + + mi, err := store.FindWithMapping(ctx, types.ModelRepo, "ns", "repo1", types.CSGHubMapping) + require.Nil(t, err) + require.Equal(t, "repo1", mi.Interval) + + _, err = store.FindWithMapping(ctx, types.ModelRepo, "ns", "repo1", types.HFMapping) + require.NotNil(t, err) + + mi, err = store.FindWithMapping(ctx, types.ModelRepo, "nsn", "repo1", types.HFMapping) + require.Nil(t, err) + require.Equal(t, "repo1", mi.Interval) + + mi, err = store.FindWithMapping(ctx, types.DatasetRepo, "nsn", "repo2", types.HFMapping) + require.Nil(t, err) + require.Equal(t, "repo2", mi.Interval) + + mi, err = store.FindWithMapping(ctx, types.PromptRepo, "nsn", "repo3", types.AutoMapping) + require.Nil(t, err) + require.Equal(t, "repo3", mi.Interval) +} + +func TestMirrorStore_ToSync(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewMirrorStoreWithDB(db) + + dt := time.Now().Add(1 * time.Hour) + mirrors := []*database.Mirror{ + {NextExecutionTimestamp: dt, Status: types.MirrorFailed, Interval: "m1"}, + {NextExecutionTimestamp: dt, Status: types.MirrorFinished, Interval: "m2"}, + {NextExecutionTimestamp: dt, Status: types.MirrorIncomplete, Interval: "m3"}, + {NextExecutionTimestamp: dt, Status: types.MirrorRepoSynced, Interval: "m4"}, + {NextExecutionTimestamp: dt, Status: types.MirrorRunning, Interval: "m5"}, + {NextExecutionTimestamp: dt, Status: types.MirrorWaiting, Interval: "m6"}, + {NextExecutionTimestamp: dt.Add(-5 * time.Hour), Status: types.MirrorFinished, Interval: "m7"}, + } + for _, m := range mirrors { + _, err := store.Create(ctx, m) + require.Nil(t, err) + } + + ms, err := store.ToSyncRepo(ctx) + require.Nil(t, err) + names := []string{} + for _, m := range ms { + names = append(names, m.Interval) + } + require.ElementsMatch(t, []string{"m1", "m3", "m6", "m7"}, names) + + ms, err = store.ToSyncLfs(ctx) + require.Nil(t, err) + names = []string{} + for _, m := range ms { + names = append(names, m.Interval) + } + require.ElementsMatch(t, []string{"m4", "m7"}, names) + +} + +func TestMirrorStore_IndexWithPagination(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewMirrorStoreWithDB(db) + + mirrors := []*database.Mirror{ + {Interval: "m1", LocalRepoPath: "foo", SourceUrl: "bar"}, + {Interval: "m2", LocalRepoPath: "bar", SourceUrl: "foo"}, + } + for _, m := range mirrors { + _, err := store.Create(ctx, m) + require.Nil(t, err) + } + + ms, count, err := store.IndexWithPagination(ctx, 10, 1) + require.Nil(t, err) + names := []string{} + for _, m := range ms { + names = append(names, m.Interval) + } + require.Equal(t, 2, count) + require.ElementsMatch(t, []string{"m1", "m2"}, names) + +} + +func TestMirrorStore_StatusCount(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewMirrorStoreWithDB(db) + + mirrors := []*database.Mirror{ + {Interval: "m1", Status: types.MirrorFailed}, + {Interval: "m2", Status: types.MirrorFailed}, + {Interval: "m3", Status: types.MirrorFinished}, + } + for _, m := range mirrors { + _, err := store.Create(ctx, m) + require.Nil(t, err) + } + +} diff --git a/builder/store/database/model.go b/builder/store/database/model.go index 34452bc7..067c0008 100644 --- a/builder/store/database/model.go +++ b/builder/store/database/model.go @@ -37,6 +37,12 @@ func NewModelStore() ModelStore { } } +func NewModelStoreWithDB(db *DB) ModelStore { + return &modelStoreImpl{ + db: db, + } +} + type Model struct { ID int64 `bun:",pk,autoincrement" json:"id"` RepositoryID int64 `bun:",notnull" json:"repository_id"` diff --git a/builder/store/database/model_test.go b/builder/store/database/model_test.go new file mode 100644 index 00000000..f5d70afc --- /dev/null +++ b/builder/store/database/model_test.go @@ -0,0 +1,227 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestModelStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewModelStoreWithDB(db) + _, err := store.Create(ctx, database.Model{ + RepositoryID: 123, + }) + require.Nil(t, err) + + m := &database.Model{} + err = db.Core.NewSelect().Model(m).Where("repository_id=?", 123).Scan(ctx) + require.Nil(t, err) + + m, err = store.ByID(ctx, m.ID) + require.Nil(t, err) + require.Equal(t, int64(123), m.RepositoryID) + + m.RepositoryID = 456 + _, err = store.Update(ctx, *m) + require.Nil(t, err) + m = &database.Model{} + err = db.Core.NewSelect().Model(m).Where("repository_id=?", 456).Scan(ctx) + require.Nil(t, err) + + m, err = store.ByRepoID(ctx, 456) + require.Nil(t, err) + require.Equal(t, int64(456), m.RepositoryID) + + ms, err := store.ByRepoIDs(ctx, []int64{456}) + require.Nil(t, err) + require.Equal(t, int64(456), ms[0].RepositoryID) + + _, err = store.CreateIfNotExist(ctx, database.Model{ + RepositoryID: 789, + }) + require.Nil(t, err) + m, err = store.ByRepoID(ctx, 789) + require.Nil(t, err) + require.Equal(t, int64(789), m.RepositoryID) + + repo := &database.Repository{ + Path: "foo/bar", + GitPath: "foo/bar2", + Private: true, + } + err = db.Core.NewInsert().Model(repo).Scan(ctx, repo) + require.Nil(t, err) + m.RepositoryID = repo.ID + _, err = store.Update(ctx, *m) + require.Nil(t, err) + + ms, total, err := store.ByUsername(ctx, "foo", 10, 1, false) + require.Nil(t, err) + require.Equal(t, 1, total) + require.Equal(t, len(ms), 1) + + ms, total, err = store.ByUsername(ctx, "foo", 10, 1, true) + require.Nil(t, err) + require.Equal(t, 0, total) + require.Equal(t, len(ms), 0) + + ms, total, err = store.ByOrgPath(ctx, "foo", 10, 1, false) + require.Nil(t, err) + require.Equal(t, 1, total) + require.Equal(t, len(ms), 1) + + ms, total, err = store.ByOrgPath(ctx, "foo", 10, 1, true) + require.Nil(t, err) + require.Equal(t, 0, total) + require.Equal(t, len(ms), 0) + + m, err = store.FindByPath(ctx, "foo", "bar") + require.Nil(t, err) + require.Equal(t, repo.ID, m.RepositoryID) + + err = store.Delete(ctx, *m) + require.Nil(t, err) + _, err = store.FindByPath(ctx, "foo", "bar") + require.NotNil(t, err) +} + +func TestModelStore_ListByPath(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewModelStoreWithDB(db) + + dt := &database.Tag{} + err := db.Core.NewInsert().Model(&database.Tag{ + Name: "tag1", + Category: "evaluation", + }).Scan(ctx, dt) + require.Nil(t, err) + tag1pk := dt.ID + + err = db.Core.NewInsert().Model(&database.Tag{ + Name: "tag2", + Category: "foo", + }).Scan(ctx, dt) + require.Nil(t, err) + tag2pk := dt.ID + + dr := &database.Repository{} + err = db.Core.NewInsert().Model(&database.Repository{ + Name: "repo", + Path: "foo/bar", + GitPath: "a", + }).Scan(ctx, dr) + require.Nil(t, err) + repopk := dr.ID + + for _, tpk := range []int64{tag1pk, tag2pk} { + _, err = db.Core.NewInsert().Model(&database.RepositoryTag{ + RepositoryID: repopk, + TagID: tpk, + }).Exec(ctx) + require.Nil(t, err) + } + + _, err = store.Create(ctx, database.Model{ + RepositoryID: repopk, + }) + require.Nil(t, err) + + dr2 := &database.Repository{} + err = db.Core.NewInsert().Model(&database.Repository{ + Name: "repo2", + Path: "bar/foo", + GitPath: "b", + }).Scan(ctx, dr2) + require.Nil(t, err) + _, err = store.Create(ctx, database.Model{ + RepositoryID: dr2.ID, + }) + require.Nil(t, err) + + dr3 := &database.Repository{} + err = db.Core.NewInsert().Model(&database.Repository{ + Name: "repo3", + Path: "foo/bar", + GitPath: "c", + RepositoryType: types.ModelRepo, + }).Scan(ctx, dr3) + require.Nil(t, err) + _, err = store.Create(ctx, database.Model{ + RepositoryID: dr3.ID, + }) + require.Nil(t, err) + + dss, err := store.ListByPath(ctx, []string{"bar/foo", "foo/bar"}) + require.Nil(t, err) + require.Equal(t, 3, len(dss)) + + tags := []string{} + for _, t := range dss[1].Repository.Tags { + tags = append(tags, t.Name) + } + require.Equal(t, []string{}, tags) + + names := []string{} + for _, ds := range dss { + names = append(names, ds.Repository.Name) + } + require.Equal(t, []string{"repo2", "repo", "repo3"}, names) + +} + +func TestModelStore_UserLikes(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewModelStoreWithDB(db) + + repos := []*database.Repository{ + {Name: "repo1", Path: "p1", GitPath: "p1"}, + {Name: "repo2", Path: "p2", GitPath: "p2"}, + {Name: "repo3", Path: "p3", GitPath: "p3"}, + } + + for _, repo := range repos { + err := db.Core.NewInsert().Model(repo).Scan(ctx, repo) + require.Nil(t, err) + _, err = store.Create(ctx, database.Model{ + RepositoryID: repo.ID, + }) + require.Nil(t, err) + + } + + _, err := db.Core.NewInsert().Model(&database.UserLike{ + UserID: 123, + RepoID: repos[0].ID, + }).Exec(ctx) + require.Nil(t, err) + _, err = db.Core.NewInsert().Model(&database.UserLike{ + UserID: 123, + RepoID: repos[2].ID, + }).Exec(ctx) + require.Nil(t, err) + + dss, total, err := store.UserLikesModels(ctx, 123, 10, 1) + require.Nil(t, err) + require.Equal(t, 2, total) + + names := []string{} + for _, ds := range dss { + names = append(names, ds.Repository.Name) + } + require.Equal(t, []string{"repo1", "repo3"}, names) + +} diff --git a/builder/store/database/multi_sync.go b/builder/store/database/multi_sync.go index 521efba5..9d810604 100644 --- a/builder/store/database/multi_sync.go +++ b/builder/store/database/multi_sync.go @@ -24,8 +24,14 @@ func NewMultiSyncStore() MultiSyncStore { } } +func NewMultiSyncStoreWithDB(db *DB) MultiSyncStore { + return &multiSyncStoreImpl{ + db: db, + } +} + func (s *multiSyncStoreImpl) Create(ctx context.Context, v SyncVersion) (*SyncVersion, error) { - res, err := s.db.Core.NewInsert().Model(&v).Exec(ctx, &v) + res, err := s.db.Core.NewInsert().Model(&v).Exec(ctx) if err := assertAffectedOneRow(res, err); err != nil { return nil, fmt.Errorf("create sync version in db failed,error:%w", err) } diff --git a/builder/store/database/multi_sync_test.go b/builder/store/database/multi_sync_test.go new file mode 100644 index 00000000..63ac36c9 --- /dev/null +++ b/builder/store/database/multi_sync_test.go @@ -0,0 +1,61 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestMultiSyncStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewMultiSyncStoreWithDB(db) + + _, err := store.Create(ctx, database.SyncVersion{ + Version: 123, + SourceID: 1, + RepoPath: "a", + RepoType: types.ModelRepo, + }) + require.Nil(t, err) + + sv := &database.SyncVersion{} + err = db.Core.NewSelect().Model(sv).Where("version=?", 123).Scan(ctx) + require.Nil(t, err) + require.Equal(t, 123, int(sv.Version)) + + _, err = store.Create(ctx, database.SyncVersion{ + Version: 103, + SourceID: 1, + RepoPath: "a", + RepoType: types.ModelRepo, + }) + require.Nil(t, err) + _, err = store.Create(ctx, database.SyncVersion{ + Version: 143, + SourceID: 1, + RepoPath: "a", + RepoType: types.ModelRepo, + }) + require.Nil(t, err) + svs, err := store.GetAfter(ctx, 123, 1) + require.Nil(t, err) + require.Equal(t, len(svs), 1) + require.Equal(t, 143, int(svs[0].Version)) + + svv, err := store.GetLatest(ctx) + require.Nil(t, err) + require.Equal(t, 143, int(svv.Version)) + + svs, err = store.GetAfterDistinct(ctx, 100) + require.Nil(t, err) + require.Equal(t, len(svs), 1) + require.True(t, int(svs[0].Version) > 100) + +} diff --git a/builder/store/database/namespace.go b/builder/store/database/namespace.go index 063fa6f6..28eb1a1d 100644 --- a/builder/store/database/namespace.go +++ b/builder/store/database/namespace.go @@ -4,17 +4,22 @@ import ( "context" ) -type namespaceStoreImpl struct { - db *DB +// Define the NamespaceStore interface +type NamespaceStore interface { + FindByPath(ctx context.Context, path string) (Namespace, error) + Exists(ctx context.Context, path string) (bool, error) } -type NamespaceStore interface { - FindByPath(ctx context.Context, path string) (namespace Namespace, err error) - Exists(ctx context.Context, path string) (exists bool, err error) +type NamespaceStoreImpl struct { + db *DB } func NewNamespaceStore() NamespaceStore { - return &namespaceStoreImpl{db: defaultDB} + return &NamespaceStoreImpl{db: defaultDB} +} + +func NewNamespaceStoreWithDB(db *DB) NamespaceStore { + return &NamespaceStoreImpl{db: db} } type NamespaceType string @@ -34,13 +39,13 @@ type Namespace struct { times } -func (s *namespaceStoreImpl) FindByPath(ctx context.Context, path string) (namespace Namespace, err error) { +func (s *NamespaceStoreImpl) FindByPath(ctx context.Context, path string) (namespace Namespace, err error) { namespace.Path = path err = s.db.Operator.Core.NewSelect().Model(&namespace).Relation("User").Where("path = ?", path).Scan(ctx) return } -func (s *namespaceStoreImpl) Exists(ctx context.Context, path string) (exists bool, err error) { +func (s *NamespaceStoreImpl) Exists(ctx context.Context, path string) (exists bool, err error) { var namespace Namespace return s.db.Operator.Core. NewSelect(). diff --git a/builder/store/database/namespace_test.go b/builder/store/database/namespace_test.go new file mode 100644 index 00000000..8f4970e4 --- /dev/null +++ b/builder/store/database/namespace_test.go @@ -0,0 +1,37 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestNamespaceStore_All(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewNamespaceStoreWithDB(db) + + _, err := db.Core.NewInsert().Model(&database.Namespace{ + Path: "foo/bar", + }).Exec(ctx) + require.Nil(t, err) + + exist, err := store.Exists(ctx, "foo/bar") + require.Nil(t, err) + require.True(t, exist) + exist, err = store.Exists(ctx, "foo/bar2") + require.Nil(t, err) + require.False(t, exist) + + ns, err := store.FindByPath(ctx, "foo/bar") + require.Nil(t, err) + require.Equal(t, "foo/bar", ns.Path) + _, err = store.FindByPath(ctx, "foo/bar2") + require.NotNil(t, err) + +} diff --git a/builder/store/database/organization.go b/builder/store/database/organization.go index ede0fda2..68eec4b8 100644 --- a/builder/store/database/organization.go +++ b/builder/store/database/organization.go @@ -26,6 +26,12 @@ func NewOrgStore() OrgStore { } } +func NewOrgStoreWithDB(db *DB) OrgStore { + return &orgStoreImpl{ + db: db, + } +} + type Organization struct { ID int64 `bun:",pk,autoincrement" json:"id"` Nickname string `bun:"name,notnull" json:"name"` diff --git a/builder/store/database/organization_test.go b/builder/store/database/organization_test.go new file mode 100644 index 00000000..91a8ebf2 --- /dev/null +++ b/builder/store/database/organization_test.go @@ -0,0 +1,80 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestOrganizationStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewOrgStoreWithDB(db) + err := store.Create(ctx, &database.Organization{ + Name: "o1", + }, &database.Namespace{Path: "o1"}) + require.Nil(t, err) + + org := &database.Organization{} + err = db.Core.NewSelect().Model(org).Where("path=?", "o1").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "o1", org.Name) + ns := &database.Namespace{} + err = db.Core.NewSelect().Model(ns).Where("path=?", "o1").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "o1", ns.Path) + require.Equal(t, database.OrgNamespace, ns.NamespaceType) + + orgv, err := store.FindByPath(ctx, "o1") + require.Nil(t, err) + require.Equal(t, "o1", orgv.Name) + + exist, err := store.Exists(ctx, "o1") + require.Nil(t, err) + require.True(t, exist) + exist, err = store.Exists(ctx, "bar") + require.Nil(t, err) + require.False(t, exist) + + org.Homepage = "abc" + err = store.Update(ctx, org) + require.Nil(t, err) + org = &database.Organization{} + err = db.Core.NewSelect().Model(org).Where("path=?", "o1").Scan(ctx) + require.Nil(t, err) + require.Equal(t, "abc", org.Homepage) + + owner := &database.User{Username: "u1"} + err = db.Core.NewInsert().Model(owner).Scan(ctx, owner) + require.Nil(t, err) + + member := &database.Member{ + OrganizationID: org.ID, + UserID: 321, + } + err = db.Core.NewInsert().Model(member).Scan(ctx, member) + require.Nil(t, err) + org.UserID = owner.ID + err = store.Update(ctx, org) + require.Nil(t, err) + + orgs, err := store.GetUserOwnOrgs(ctx, "u1") + require.Nil(t, err) + require.Equal(t, 1, len(orgs)) + + orgs, err = store.GetUserBelongOrgs(ctx, 321) + require.Nil(t, err) + require.Equal(t, 1, len(orgs)) + + err = store.Delete(ctx, "o1") + require.Nil(t, err) + exist, err = store.Exists(ctx, "foo") + require.Nil(t, err) + require.False(t, exist) + +} diff --git a/builder/store/database/prompt.go b/builder/store/database/prompt.go index a8a0d4fb..383a229c 100644 --- a/builder/store/database/prompt.go +++ b/builder/store/database/prompt.go @@ -29,14 +29,14 @@ type PromptStore interface { ByOrgPath(ctx context.Context, namespace string, per, page int, onlyPublic bool) (prompts []Prompt, total int, err error) } -func NewPromptStore() PromptStore { - return &promptStoreImpl{db: defaultDB} -} - func NewPromptStoreWithDB(db *DB) PromptStore { return &promptStoreImpl{db: db} } +func NewPromptStore() PromptStore { + return &promptStoreImpl{db: defaultDB} +} + func (s *promptStoreImpl) Create(ctx context.Context, input Prompt) (*Prompt, error) { res, err := s.db.Core.NewInsert().Model(&input).Exec(ctx, &input) if err := assertAffectedOneRow(res, err); err != nil { @@ -121,6 +121,7 @@ func (s *promptStoreImpl) ByUsername(ctx context.Context, username string, per, if err != nil { return } + total, err = query.Count(ctx) if err != nil { return diff --git a/builder/store/database/prompt_conversation.go b/builder/store/database/prompt_conversation.go index f2bfa535..d1217b40 100644 --- a/builder/store/database/prompt_conversation.go +++ b/builder/store/database/prompt_conversation.go @@ -45,6 +45,10 @@ func NewPromptConversationStore() PromptConversationStore { return &promptConversationStoreImpl{db: defaultDB} } +func NewPromptConversationStoreWithDB(db *DB) PromptConversationStore { + return &promptConversationStoreImpl{db: db} +} + func (p *promptConversationStoreImpl) CreateConversation(ctx context.Context, conversation PromptConversation) error { err := p.db.Operator.Core.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error { if err := assertAffectedOneRow(tx.NewInsert().Model(&conversation).Exec(ctx)); err != nil { diff --git a/builder/store/database/prompt_conversation_test.go b/builder/store/database/prompt_conversation_test.go new file mode 100644 index 00000000..7426b411 --- /dev/null +++ b/builder/store/database/prompt_conversation_test.go @@ -0,0 +1,95 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestPromptConversationStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewPromptConversationStoreWithDB(db) + msg := &database.PromptConversationMessage{ + ConversationID: "cv", + Content: "msg", + } + err := db.Core.NewInsert().Model(msg).Scan(ctx, msg) + require.Nil(t, err) + err = store.CreateConversation(ctx, database.PromptConversation{ + UserID: 123, + ConversationID: "cv", + Title: "foo", + }) + require.Nil(t, err) + + pc := &database.PromptConversation{} + err = db.Core.NewSelect().Model(pc).Where("user_id=?", 123).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "foo", pc.Title) + + pc, err = store.GetConversationByID(ctx, 123, "cv", false) + require.Nil(t, err) + require.Equal(t, "foo", pc.Title) + require.Nil(t, pc.Messages) + pc, err = store.GetConversationByID(ctx, 123, "cv", true) + require.Nil(t, err) + require.Equal(t, "foo", pc.Title) + require.Equal(t, 1, len(pc.Messages)) + require.Equal(t, "msg", pc.Messages[0].Content) + + pc.Title = "bar" + err = store.UpdateConversation(ctx, *pc) + require.Nil(t, err) + pc = &database.PromptConversation{} + err = db.Core.NewSelect().Model(pc).Where("user_id=?", 123).Scan(ctx) + require.Nil(t, err) + require.Equal(t, "bar", pc.Title) + + pcs, err := store.FindConversationsByUserID(ctx, 123) + require.Nil(t, err) + require.Equal(t, 1, len(pcs)) + require.Equal(t, "bar", pcs[0].Title) + + _, err = store.SaveConversationMessage(ctx, database.PromptConversationMessage{ + ConversationID: pc.ConversationID, + Content: "foobar", + }) + require.Nil(t, err) + + pc, err = store.GetConversationByID(ctx, 123, "cv", true) + require.Nil(t, err) + require.Equal(t, 2, len(pc.Messages)) + + err = store.LikeMessageByID(ctx, msg.ID) + require.Nil(t, err) + err = db.Core.NewSelect().Model(msg).WherePK().Scan(ctx) + require.Nil(t, err) + require.Equal(t, true, msg.UserLike) + err = store.LikeMessageByID(ctx, msg.ID) + require.Nil(t, err) + err = db.Core.NewSelect().Model(msg).WherePK().Scan(ctx) + require.Nil(t, err) + require.Equal(t, false, msg.UserLike) + + err = store.HateMessageByID(ctx, msg.ID) + require.Nil(t, err) + err = db.Core.NewSelect().Model(msg).WherePK().Scan(ctx) + require.Nil(t, err) + require.Equal(t, true, msg.UserHate) + err = store.HateMessageByID(ctx, msg.ID) + require.Nil(t, err) + err = db.Core.NewSelect().Model(msg).WherePK().Scan(ctx) + require.Nil(t, err) + require.Equal(t, false, msg.UserHate) + + err = store.DeleteConversationsByID(ctx, 123, pc.ConversationID) + require.Nil(t, err) + _, err = store.GetConversationByID(ctx, 123, "cv", false) + require.NotNil(t, err) +} diff --git a/builder/store/database/prompt_prefix.go b/builder/store/database/prompt_prefix.go index 03f14e3f..e31fda82 100644 --- a/builder/store/database/prompt_prefix.go +++ b/builder/store/database/prompt_prefix.go @@ -23,6 +23,10 @@ func NewPromptPrefixStore() PromptPrefixStore { return &promptPrefixStoreImpl{db: defaultDB} } +func NewPromptPrefixStoreWithDB(db *DB) PromptPrefixStore { + return &promptPrefixStoreImpl{db: db} +} + func (p *promptPrefixStoreImpl) Get(ctx context.Context) (*PromptPrefix, error) { var prefix PromptPrefix err := p.db.Operator.Core.NewSelect().Model(&prefix).Order("id desc").Limit(1).Scan(ctx) diff --git a/builder/store/database/prompt_prefix_test.go b/builder/store/database/prompt_prefix_test.go new file mode 100644 index 00000000..24b6bcd0 --- /dev/null +++ b/builder/store/database/prompt_prefix_test.go @@ -0,0 +1,32 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestPromptPrefixStore_Get(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewPromptPrefixStoreWithDB(db) + + _, err := db.Core.NewInsert().Model(&database.PromptPrefix{ + EN: "foo", + }).Exec(ctx) + require.Nil(t, err) + _, err = db.Core.NewInsert().Model(&database.PromptPrefix{ + EN: "bar", + }).Exec(ctx) + require.Nil(t, err) + + prefix, err := store.Get(ctx) + require.Nil(t, err) + require.Equal(t, "bar", prefix.EN) + +} diff --git a/builder/store/database/recom.go b/builder/store/database/recom.go index 5535f19e..7387325e 100644 --- a/builder/store/database/recom.go +++ b/builder/store/database/recom.go @@ -22,6 +22,12 @@ func NewRecomStore() RecomStore { } } +func NewRecomStoreWithDB(db *DB) RecomStore { + return &recomStoreImpl{ + db: db, + } +} + // Index returns repos in descend order of score. func (s *recomStoreImpl) Index(ctx context.Context, page, pageSize int) ([]*RecomRepoScore, error) { items := make([]*RecomRepoScore, 0) diff --git a/builder/store/database/recom_test.go b/builder/store/database/recom_test.go new file mode 100644 index 00000000..52866395 --- /dev/null +++ b/builder/store/database/recom_test.go @@ -0,0 +1,57 @@ +package database_test + +import ( + "context" + "fmt" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestRecomStore_All(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRecomStoreWithDB(db) + + err := store.UpsertScore(ctx, 123, 1) + require.Nil(t, err) + err = store.UpsertScore(ctx, 123, 2) + require.Nil(t, err) + err = store.UpsertScore(ctx, 456, 1) + require.Nil(t, err) + + scores, err := store.Index(ctx, 0, 10) + require.Nil(t, err) + require.Equal(t, 2, len(scores)) + ids := []string{} + for _, s := range scores { + ids = append(ids, fmt.Sprintf("%d/%.0f", s.RepositoryID, s.Score)) + } + require.Equal(t, []string{"123/2", "456/1"}, ids) + + _, err = db.Core.NewInsert().Model(&database.RecomWeight{Name: "w1"}).Exec(ctx) + require.Nil(t, err) + ws, err := store.LoadWeights(ctx) + require.Nil(t, err) + require.Equal(t, 3, len(ws)) + names := []string{} + for _, w := range ws { + names = append(names, w.Name) + } + require.ElementsMatch(t, []string{"freshness", "downloads", "w1"}, names) + + _, err = db.Core.NewInsert().Model(&database.RecomOpWeight{ + Weight: 3, + RepositoryID: 123, + }).Exec(ctx) + require.Nil(t, err) + wos, err := store.LoadOpWeights(ctx) + require.Nil(t, err) + require.Equal(t, 1, len(wos)) + require.Equal(t, 3, wos[0].Weight) + +} diff --git a/builder/store/database/repo_relation.go b/builder/store/database/repo_relation.go index ad2e7398..6ac2c17d 100644 --- a/builder/store/database/repo_relation.go +++ b/builder/store/database/repo_relation.go @@ -29,6 +29,12 @@ func NewRepoRelationsStore() RepoRelationsStore { } } +func NewRepoRelationsStoreWithDB(db *DB) RepoRelationsStore { + return &repoRelationsStoreImpl{ + db: db, + } +} + type RepoRelation struct { ID int64 `bun:",pk,autoincrement" json:"id"` FromRepoID int64 `bun:",notnull" json:"from_repo_id"` diff --git a/builder/store/database/repo_relation_test.go b/builder/store/database/repo_relation_test.go new file mode 100644 index 00000000..6441e7fd --- /dev/null +++ b/builder/store/database/repo_relation_test.go @@ -0,0 +1,111 @@ +package database_test + +import ( + "context" + "fmt" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestRepoRelationStore_FromTo(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoRelationsStoreWithDB(db) + relations := []*database.RepoRelation{ + {FromRepoID: 1, ToRepoID: 2}, + {FromRepoID: 1, ToRepoID: 3}, + {FromRepoID: 1, ToRepoID: 4}, + {FromRepoID: 3, ToRepoID: 5}, + } + + for _, rel := range relations { + err := db.Core.NewInsert().Model(rel).Scan(ctx, rel) + require.Nil(t, err) + } + + rs, err := store.From(ctx, 1) + require.Nil(t, err) + ids := []int64{} + for _, r := range rs { + ids = append(ids, r.ToRepoID) + } + require.ElementsMatch(t, []int64{2, 3, 4}, ids) + + rs, err = store.To(ctx, 5) + require.Nil(t, err) + ids = []int64{} + for _, r := range rs { + ids = append(ids, r.FromRepoID) + } + require.ElementsMatch(t, []int64{3}, ids) + + err = store.Delete(ctx, 1, 3) + require.Nil(t, err) + rs, err = store.From(ctx, 1) + require.Nil(t, err) + ids = []int64{} + for _, r := range rs { + ids = append(ids, r.ToRepoID) + } + require.ElementsMatch(t, []int64{2, 4}, ids) + +} + +func TestRepoRelationStore_Override(t *testing.T) { + cases := []struct { + from int64 + to []int64 + expected1To []int64 + expected3To []int64 + }{ + {1, nil, []int64{}, []int64{5}}, + {1, []int64{2}, []int64{2}, []int64{5}}, + {1, []int64{5}, []int64{5}, []int64{5}}, + {1, []int64{2, 3}, []int64{2, 3}, []int64{5}}, + } + + for _, c := range cases { + t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoRelationsStoreWithDB(db) + relations := []*database.RepoRelation{ + {FromRepoID: 1, ToRepoID: 2}, + {FromRepoID: 1, ToRepoID: 3}, + {FromRepoID: 1, ToRepoID: 4}, + {FromRepoID: 3, ToRepoID: 5}, + } + + for _, rel := range relations { + err := db.Core.NewInsert().Model(rel).Scan(ctx, rel) + require.Nil(t, err) + } + + err := store.Override(ctx, c.from, c.to...) + require.Nil(t, err) + + rs, err := store.From(ctx, 1) + require.Nil(t, err) + ids := []int64{} + for _, r := range rs { + ids = append(ids, r.ToRepoID) + } + require.ElementsMatch(t, c.expected1To, ids) + + rs, err = store.From(ctx, 3) + require.Nil(t, err) + ids = []int64{} + for _, r := range rs { + ids = append(ids, r.ToRepoID) + } + require.ElementsMatch(t, c.expected3To, ids) + }) + } +} diff --git a/builder/store/database/repository_file.go b/builder/store/database/repository_file.go index 4c268310..e1bc3b09 100644 --- a/builder/store/database/repository_file.go +++ b/builder/store/database/repository_file.go @@ -39,6 +39,12 @@ func NewRepoFileStore() RepoFileStore { } } +func NewRepoFileStoreWithDB(db *DB) RepoFileStore { + return &repoFileStoreImpl{ + db: db, + } +} + func (s *repoFileStoreImpl) Create(ctx context.Context, file *RepositoryFile) error { _, err := s.db.Operator.Core.NewInsert().Model(file).Exec(ctx) return err diff --git a/builder/store/database/repository_file_check.go b/builder/store/database/repository_file_check.go index 09d82b31..d320bae9 100644 --- a/builder/store/database/repository_file_check.go +++ b/builder/store/database/repository_file_check.go @@ -33,6 +33,12 @@ func NewRepoFileCheckStore() RepoFileCheckStore { } } +func NewRepoFileCheckStoreWithDB(db *DB) RepoFileCheckStore { + return &repoFileCheckStoreImpl{ + db: db, + } +} + func (s *repoFileCheckStoreImpl) Create(ctx context.Context, history RepositoryFileCheck) error { _, err := s.db.Operator.Core.NewInsert().Model(&history).Exec(ctx) return err diff --git a/builder/store/database/repository_file_check_test.go b/builder/store/database/repository_file_check_test.go new file mode 100644 index 00000000..e01c728d --- /dev/null +++ b/builder/store/database/repository_file_check_test.go @@ -0,0 +1,39 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestRepositoryFileCheckStore_CreateUpsert(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoFileCheckStoreWithDB(db) + + err := store.Create(ctx, database.RepositoryFileCheck{ + RepoFileID: 123, + Message: "foo", + Status: types.SensitiveCheckPass, + }) + require.Nil(t, err) + rf := &database.RepositoryFileCheck{} + err = db.Core.NewSelect().Model(rf).Where("repo_file_id=?", 123).Scan(ctx, rf) + require.Nil(t, err) + require.Equal(t, "foo", rf.Message) + + rf.Message = "bar" + err = store.Upsert(ctx, *rf) + require.Nil(t, err) + rf = &database.RepositoryFileCheck{} + err = db.Core.NewSelect().Model(rf).Where("repo_file_id=?", 123).Scan(ctx, rf) + require.Nil(t, err) + require.Equal(t, "bar", rf.Message) + +} diff --git a/builder/store/database/repository_file_test.go b/builder/store/database/repository_file_test.go new file mode 100644 index 00000000..fb22b225 --- /dev/null +++ b/builder/store/database/repository_file_test.go @@ -0,0 +1,138 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestRepoFileStore_Create(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoFileStoreWithDB(db) + + err := store.Create(ctx, &database.RepositoryFile{ + Path: "foo", + RepositoryID: 123, + }) + require.Nil(t, err) + + rf := &database.RepositoryFile{} + err = db.Core.NewSelect().Model(rf).Where("path=?", "foo").Scan(ctx, rf) + require.Nil(t, err) + require.Equal(t, "foo", rf.Path) + +} + +func TestRepoFileStore_BatchGet(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoFileStoreWithDB(db) + + repo := &database.Repository{} + err := db.Core.NewInsert().Model(repo).Scan(ctx, repo) + require.Nil(t, err) + + // check failed file + err = store.Create(ctx, &database.RepositoryFile{ + RepositoryID: repo.ID, + Path: "foo", + Branch: "main", + }) + require.Nil(t, err) + rf := &database.RepositoryFile{} + err = db.Core.NewSelect().Model(rf).Where("path=?", "foo").Scan(ctx, rf) + require.Nil(t, err) + + _, err = db.Core.NewInsert().Model(&database.RepositoryFileCheck{ + RepoFileID: rf.ID, + Status: types.SensitiveCheckFail, + }).Exec(ctx) + require.Nil(t, err) + + // check pass file + err = store.Create(ctx, &database.RepositoryFile{ + RepositoryID: repo.ID, + Path: "bar", + Branch: "main", + }) + require.Nil(t, err) + rf = &database.RepositoryFile{} + err = db.Core.NewSelect().Model(rf).Where("path=?", "bar").Scan(ctx, rf) + require.Nil(t, err) + + _, err = db.Core.NewInsert().Model(&database.RepositoryFileCheck{ + RepoFileID: rf.ID, + Status: types.SensitiveCheckPass, + }).Exec(ctx) + require.Nil(t, err) + + rfs, err := store.BatchGet(ctx, repo.ID, 0, 10) + require.Nil(t, err) + ps := []string{} + for _, rf := range rfs { + ps = append(ps, rf.Path) + } + require.Equal(t, []string{"foo", "bar"}, ps) + + rfs, err = store.BatchGetUnchcked(ctx, repo.ID, 0, 10) + require.Nil(t, err) + ps = []string{} + for _, rf := range rfs { + ps = append(ps, rf.Path) + } + require.Equal(t, []string{}, ps) + + exist, err := store.ExistsSensitiveCheckRecord(ctx, repo.ID, "main", types.SensitiveCheckPass) + require.Nil(t, err) + require.True(t, exist) + exist, err = store.ExistsSensitiveCheckRecord(ctx, repo.ID, "main", types.SensitiveCheckFail) + require.Nil(t, err) + require.True(t, exist) + exist, err = store.ExistsSensitiveCheckRecord(ctx, repo.ID, "main", types.SensitiveCheckSkip) + require.Nil(t, err) + require.False(t, exist) +} + +func TestRepoFileStore_Exists(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepoFileStoreWithDB(db) + + err := store.Create(ctx, &database.RepositoryFile{ + Path: "foo", + RepositoryID: 123, + Branch: "main", + CommitSha: "12321", + }) + require.Nil(t, err) + + exist, err := store.Exists(ctx, database.RepositoryFile{ + Path: "foo", + RepositoryID: 123, + Branch: "main", + CommitSha: "12321", + }) + require.Nil(t, err) + require.True(t, exist) + + exist, err = store.Exists(ctx, database.RepositoryFile{ + Path: "foo", + RepositoryID: 123, + Branch: "main", + CommitSha: "12322", + }) + require.Nil(t, err) + require.False(t, exist) + +} diff --git a/builder/store/database/repository_runtime_framework.go b/builder/store/database/repository_runtime_framework.go index 841a29f3..b060f6da 100644 --- a/builder/store/database/repository_runtime_framework.go +++ b/builder/store/database/repository_runtime_framework.go @@ -5,16 +5,33 @@ import ( "fmt" ) -type RepositoriesRuntimeFrameworkStore struct { +type RepositoriesRuntimeFrameworkStore interface { + ListByRuntimeFrameworkID(ctx context.Context, runtimeFrameworkID int64, deployType int) ([]RepositoriesRuntimeFramework, error) + Add(ctx context.Context, runtimeFrameworkID, repoID int64, deployType int) error + Delete(ctx context.Context, runtimeFrameworkID, repoID int64, deployType int) error + DeleteByRepoID(ctx context.Context, repoID int64) error + GetByIDsAndType(ctx context.Context, runtimeFrameworkID, repoID int64, deployType int) ([]RepositoriesRuntimeFramework, error) + ListRepoIDsByType(ctx context.Context, deployType int) ([]RepositoriesRuntimeFramework, error) + GetByRepoIDsAndType(ctx context.Context, repoID int64, deployType int) ([]RepositoriesRuntimeFramework, error) + GetByRepoIDs(ctx context.Context, repoID int64) ([]RepositoriesRuntimeFramework, error) +} + +type repositoriesRuntimeFrameworkStoreImpl struct { db *DB } -func NewRepositoriesRuntimeFramework() *RepositoriesRuntimeFrameworkStore { - return &RepositoriesRuntimeFrameworkStore{ +func NewRepositoriesRuntimeFramework() RepositoriesRuntimeFrameworkStore { + return &repositoriesRuntimeFrameworkStoreImpl{ db: defaultDB, } } +func NewRepositoriesRuntimeFrameworkWithDB(db *DB) RepositoriesRuntimeFrameworkStore { + return &repositoriesRuntimeFrameworkStoreImpl{ + db: db, + } +} + type RepositoriesRuntimeFramework struct { ID int64 `bun:",pk,autoincrement" json:"id"` RuntimeFrameworkID int64 `bun:",notnull" json:"runtime_framework_id"` @@ -23,7 +40,7 @@ type RepositoriesRuntimeFramework struct { Type int `bun:",notnull" json:"type"` // 0-space, 1-inference, 2-finetune } -func (m *RepositoriesRuntimeFrameworkStore) ListByRuntimeFrameworkID(ctx context.Context, runtimeFrameworkID int64, deployType int) ([]RepositoriesRuntimeFramework, error) { +func (m *repositoriesRuntimeFrameworkStoreImpl) ListByRuntimeFrameworkID(ctx context.Context, runtimeFrameworkID int64, deployType int) ([]RepositoriesRuntimeFramework, error) { var result []RepositoriesRuntimeFramework _, err := m.db.Operator.Core. NewSelect(). @@ -35,7 +52,7 @@ func (m *RepositoriesRuntimeFrameworkStore) ListByRuntimeFrameworkID(ctx context return result, nil } -func (m *RepositoriesRuntimeFrameworkStore) Add(ctx context.Context, runtimeFrameworkID, repoID int64, deployType int) error { +func (m *repositoriesRuntimeFrameworkStoreImpl) Add(ctx context.Context, runtimeFrameworkID, repoID int64, deployType int) error { relation := RepositoriesRuntimeFramework{ RuntimeFrameworkID: runtimeFrameworkID, RepoID: repoID, @@ -45,7 +62,7 @@ func (m *RepositoriesRuntimeFrameworkStore) Add(ctx context.Context, runtimeFram return err } -func (m *RepositoriesRuntimeFrameworkStore) Delete(ctx context.Context, runtimeFrameworkID, repoID int64, deployType int) error { +func (m *repositoriesRuntimeFrameworkStoreImpl) Delete(ctx context.Context, runtimeFrameworkID, repoID int64, deployType int) error { res, err := m.db.BunDB.Exec("delete from repositories_runtime_frameworks where type = ? and repo_id = ? and runtime_framework_id = ?", deployType, repoID, runtimeFrameworkID) if err != nil { return err @@ -54,7 +71,7 @@ func (m *RepositoriesRuntimeFrameworkStore) Delete(ctx context.Context, runtimeF return err } -func (m *RepositoriesRuntimeFrameworkStore) DeleteByRepoID(ctx context.Context, repoID int64) error { +func (m *repositoriesRuntimeFrameworkStoreImpl) DeleteByRepoID(ctx context.Context, repoID int64) error { _, err := m.db.Operator.Core.NewDelete().Model((*RepositoriesRuntimeFramework)(nil)).Where("repo_id = ?", repoID).Exec(ctx) if err != nil { return fmt.Errorf("delete repo runtime failed, %w", err) @@ -62,25 +79,25 @@ func (m *RepositoriesRuntimeFrameworkStore) DeleteByRepoID(ctx context.Context, return nil } -func (m *RepositoriesRuntimeFrameworkStore) GetByIDsAndType(ctx context.Context, runtimeFrameworkID, repoID int64, deployType int) ([]RepositoriesRuntimeFramework, error) { +func (m *repositoriesRuntimeFrameworkStoreImpl) GetByIDsAndType(ctx context.Context, runtimeFrameworkID, repoID int64, deployType int) ([]RepositoriesRuntimeFramework, error) { var result []RepositoriesRuntimeFramework _, err := m.db.Operator.Core.NewSelect().Model(&result).Where("type = ? and repo_id=? and runtime_framework_id = ?", deployType, repoID, runtimeFrameworkID).Exec(ctx, &result) return result, err } -func (m *RepositoriesRuntimeFrameworkStore) ListRepoIDsByType(ctx context.Context, deployType int) ([]RepositoriesRuntimeFramework, error) { +func (m *repositoriesRuntimeFrameworkStoreImpl) ListRepoIDsByType(ctx context.Context, deployType int) ([]RepositoriesRuntimeFramework, error) { var result []RepositoriesRuntimeFramework _, err := m.db.Operator.Core.NewSelect().Model(&result).Where("type = ?", deployType).Exec(ctx, &result) return result, err } -func (m *RepositoriesRuntimeFrameworkStore) GetByRepoIDsAndType(ctx context.Context, repoID int64, deployType int) ([]RepositoriesRuntimeFramework, error) { +func (m *repositoriesRuntimeFrameworkStoreImpl) GetByRepoIDsAndType(ctx context.Context, repoID int64, deployType int) ([]RepositoriesRuntimeFramework, error) { var result []RepositoriesRuntimeFramework _, err := m.db.Operator.Core.NewSelect().Model(&result).Where("type = ? and repo_id=?", deployType, repoID).Exec(ctx, &result) return result, err } -func (m *RepositoriesRuntimeFrameworkStore) GetByRepoIDs(ctx context.Context, repoID int64) ([]RepositoriesRuntimeFramework, error) { +func (m *repositoriesRuntimeFrameworkStoreImpl) GetByRepoIDs(ctx context.Context, repoID int64) ([]RepositoriesRuntimeFramework, error) { var result []RepositoriesRuntimeFramework _, err := m.db.Operator.Core.NewSelect().Model(&result).Where("repo_id=?", repoID).Exec(ctx, &result) if err != nil { diff --git a/builder/store/database/repository_runtime_framework_test.go b/builder/store/database/repository_runtime_framework_test.go new file mode 100644 index 00000000..e2f43f09 --- /dev/null +++ b/builder/store/database/repository_runtime_framework_test.go @@ -0,0 +1,65 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestRepoRuntimeFrameworkStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewRepositoriesRuntimeFrameworkWithDB(db) + err := store.Add(ctx, 123, 456, 1) + require.Nil(t, err) + + rf := &database.RepositoriesRuntimeFramework{} + err = db.Core.NewSelect().Model(rf).Where("repo_id=?", 456).Scan(ctx) + require.Nil(t, err) + require.Equal(t, 456, int(rf.RepoID)) + + rfs, err := store.GetByIDsAndType(ctx, 123, 456, 1) + require.Nil(t, err) + require.Equal(t, 1, len(rfs)) + require.Equal(t, 456, int(rfs[0].RepoID)) + + rfs, err = store.ListRepoIDsByType(ctx, 1) + require.Nil(t, err) + require.Equal(t, 1, len(rfs)) + require.Equal(t, 456, int(rfs[0].RepoID)) + rfs, err = store.ListRepoIDsByType(ctx, 2) + require.Nil(t, err) + require.Equal(t, 0, len(rfs)) + + rfs, err = store.GetByRepoIDsAndType(ctx, 456, 1) + require.Nil(t, err) + require.Equal(t, 1, len(rfs)) + require.Equal(t, 456, int(rfs[0].RepoID)) + rfs, err = store.GetByRepoIDsAndType(ctx, 456, 2) + require.Nil(t, err) + require.Equal(t, 0, len(rfs)) + + rfs, err = store.GetByRepoIDs(ctx, 456) + require.Nil(t, err) + require.Equal(t, 1, len(rfs)) + require.Equal(t, 456, int(rfs[0].RepoID)) + + err = store.Delete(ctx, 123, 456, 1) + require.Nil(t, err) + rfs, err = store.GetByIDsAndType(ctx, 123, 456, 1) + require.Nil(t, err) + require.Equal(t, 0, len(rfs)) + + err = store.Add(ctx, 123, 456, 1) + require.Nil(t, err) + err = store.DeleteByRepoID(ctx, 456) + require.Nil(t, err) + rfs, err = store.GetByIDsAndType(ctx, 123, 456, 1) + require.Nil(t, err) + require.Equal(t, 0, len(rfs)) +} diff --git a/builder/store/database/resources_models.go b/builder/store/database/resources_models.go index 02348331..5dbc1da9 100644 --- a/builder/store/database/resources_models.go +++ b/builder/store/database/resources_models.go @@ -19,6 +19,10 @@ func NewResourceModelStore() ResourceModelStore { return &resourceModelStoreImpl{db: defaultDB} } +func NewResourceModelStoreWithDB(db *DB) ResourceModelStore { + return &resourceModelStoreImpl{db: db} +} + type ResourceModel struct { ID int64 `bun:",pk,autoincrement" json:"id"` ResourceName string `bun:",notnull" json:"resource_name"` diff --git a/builder/store/database/resources_models_test.go b/builder/store/database/resources_models_test.go new file mode 100644 index 00000000..a0c80a21 --- /dev/null +++ b/builder/store/database/resources_models_test.go @@ -0,0 +1,45 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestResourceModelStore_All(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewResourceModelStoreWithDB(db) + _, err := db.Core.NewInsert().Model(&database.ResourceModel{ + ModelName: "foo", + }).Exec(ctx) + require.Nil(t, err) + _, err = db.Core.NewInsert().Model(&database.ResourceModel{ + ModelName: "bar", + }).Exec(ctx) + require.Nil(t, err) + + ms, err := store.FindByModelName(ctx, "foo") + require.Nil(t, err) + require.Equal(t, 1, len(ms)) + require.Equal(t, "foo", ms[0].ModelName) + + _, err = db.Core.NewInsert().Model(&database.RepositoriesRuntimeFramework{ + RepoID: 123, + }).Exec(ctx) + require.Nil(t, err) + + m, err := store.CheckModelNameNotInRFRepo(ctx, "foo", 456) + require.Nil(t, err) + require.Equal(t, "foo", m.ModelName) + + m, err = store.CheckModelNameNotInRFRepo(ctx, "foo", 123) + require.Nil(t, err) + require.Nil(t, m) + +} diff --git a/builder/store/database/space.go b/builder/store/database/space.go index c9ecb6d4..9c0bb665 100644 --- a/builder/store/database/space.go +++ b/builder/store/database/space.go @@ -14,8 +14,8 @@ type spaceStoreImpl struct { } type SpaceStore interface { - BeginTx(ctx context.Context) (bun.Tx, error) - CreateTx(ctx context.Context, tx bun.Tx, input Space) (*Space, error) + // BeginTx(ctx context.Context) (bun.Tx, error) + // CreateTx(ctx context.Context, tx bun.Tx, input Space) (*Space, error) Create(ctx context.Context, input Space) (*Space, error) Update(ctx context.Context, input Space) (err error) FindByPath(ctx context.Context, namespace, name string) (*Space, error) @@ -36,20 +36,26 @@ func NewSpaceStore() SpaceStore { } } -func (s *spaceStoreImpl) BeginTx(ctx context.Context) (bun.Tx, error) { - return s.db.Core.BeginTx(ctx, nil) +func NewSpaceStoreWithDB(db *DB) SpaceStore { + return &spaceStoreImpl{ + db: db, + } } -func (s *spaceStoreImpl) CreateTx(ctx context.Context, tx bun.Tx, input Space) (*Space, error) { - res, err := tx.NewInsert().Model(&input).Exec(ctx) - if err := assertAffectedOneRow(res, err); err != nil { - slog.Error("create space in tx failed", slog.String("error", err.Error())) - return nil, fmt.Errorf("create space in tx failed,error:%w", err) - } +// func (s *spaceStoreImpl) BeginTx(ctx context.Context) (bun.Tx, error) { +// return s.db.Core.BeginTx(ctx, nil) +// } - input.ID, _ = res.LastInsertId() - return &input, nil -} +// func (s *spaceStoreImpl) CreateTx(ctx context.Context, tx bun.Tx, input Space) (*Space, error) { +// res, err := tx.NewInsert().Model(&input).Exec(ctx) +// if err := assertAffectedOneRow(res, err); err != nil { +// slog.Error("create space in tx failed", slog.String("error", err.Error())) +// return nil, fmt.Errorf("create space in tx failed,error:%w", err) +// } + +// input.ID, _ = res.LastInsertId() +// return &input, nil +// } func (s *spaceStoreImpl) Create(ctx context.Context, input Space) (*Space, error) { res, err := s.db.Core.NewInsert().Model(&input).Exec(ctx) diff --git a/builder/store/database/space_resource.go b/builder/store/database/space_resource.go index deaeada8..e1d2dc08 100644 --- a/builder/store/database/space_resource.go +++ b/builder/store/database/space_resource.go @@ -23,6 +23,10 @@ func NewSpaceResourceStore() SpaceResourceStore { return &spaceResourceStoreImpl{db: defaultDB} } +func NewSpaceResourceStoreWithDB(db *DB) SpaceResourceStore { + return &spaceResourceStoreImpl{db: db} +} + type SpaceResource struct { ID int64 `bun:",pk,autoincrement" json:"id"` Name string `bun:",notnull" json:"name"` diff --git a/builder/store/database/space_resource_test.go b/builder/store/database/space_resource_test.go new file mode 100644 index 00000000..28885c44 --- /dev/null +++ b/builder/store/database/space_resource_test.go @@ -0,0 +1,59 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestSpaceResourceStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewSpaceResourceStoreWithDB(db) + + _, err := store.Create(ctx, database.SpaceResource{ + Name: "r1", + ClusterID: "c1", + }) + require.Nil(t, err) + sr := &database.SpaceResource{} + err = db.Core.NewSelect().Model(sr).Where("name=?", "r1").Scan(ctx, sr) + require.Nil(t, err) + require.Equal(t, "c1", sr.ClusterID) + + sr, err = store.FindByID(ctx, sr.ID) + require.Nil(t, err) + require.Equal(t, "c1", sr.ClusterID) + + sr, err = store.FindByName(ctx, "r1") + require.Nil(t, err) + require.Equal(t, "c1", sr.ClusterID) + + srs, err := store.FindAll(ctx) + require.Nil(t, err) + require.Equal(t, 1, len(srs)) + require.Equal(t, "c1", srs[0].ClusterID) + + srs, err = store.Index(ctx, "c1") + require.Nil(t, err) + require.Equal(t, 1, len(srs)) + require.Equal(t, "c1", srs[0].ClusterID) + + sr.Name = "r2" + _, err = store.Update(ctx, *sr) + require.Nil(t, err) + sr, err = store.FindByID(ctx, sr.ID) + require.Nil(t, err) + require.Equal(t, "r2", sr.Name) + + err = store.Delete(ctx, *sr) + require.Nil(t, err) + _, err = store.FindByID(ctx, sr.ID) + require.NotNil(t, err) + +} diff --git a/builder/store/database/space_sdk.go b/builder/store/database/space_sdk.go index a5f243aa..e4246a6d 100644 --- a/builder/store/database/space_sdk.go +++ b/builder/store/database/space_sdk.go @@ -21,6 +21,10 @@ func NewSpaceSdkStore() SpaceSdkStore { return &spaceSdkStoreImpl{db: defaultDB} } +func NewSpaceSdkStoreWithDB(db *DB) SpaceSdkStore { + return &spaceSdkStoreImpl{db: db} +} + type SpaceSdk struct { ID int64 `bun:",pk,autoincrement" json:"id"` Name string `bun:",notnull" json:"name"` diff --git a/builder/store/database/space_sdk_test.go b/builder/store/database/space_sdk_test.go new file mode 100644 index 00000000..410ab5a4 --- /dev/null +++ b/builder/store/database/space_sdk_test.go @@ -0,0 +1,50 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestSpaceSDKStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewSpaceSdkStoreWithDB(db) + + _, err := store.Create(ctx, database.SpaceSdk{ + Name: "r1", + Version: "v1", + }) + require.Nil(t, err) + ss := &database.SpaceSdk{} + err = db.Core.NewSelect().Model(ss).Where("name=?", "r1").Scan(ctx, ss) + require.Nil(t, err) + require.Equal(t, "v1", ss.Version) + + ss, err = store.FindByID(ctx, ss.ID) + require.Nil(t, err) + require.Equal(t, "v1", ss.Version) + + sss, err := store.Index(ctx) + require.Nil(t, err) + require.Equal(t, 1, len(sss)) + require.Equal(t, "v1", sss[0].Version) + + ss.Name = "r2" + _, err = store.Update(ctx, *ss) + require.Nil(t, err) + ss, err = store.FindByID(ctx, ss.ID) + require.Nil(t, err) + require.Equal(t, "r2", ss.Name) + + err = store.Delete(ctx, *ss) + require.Nil(t, err) + _, err = store.FindByID(ctx, ss.ID) + require.NotNil(t, err) + +} diff --git a/builder/store/database/space_test.go b/builder/store/database/space_test.go new file mode 100644 index 00000000..f585694b --- /dev/null +++ b/builder/store/database/space_test.go @@ -0,0 +1,220 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestSpaceStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewSpaceStoreWithDB(db) + _, err := store.Create(ctx, database.Space{ + RepositoryID: 123, + }) + require.Nil(t, err) + + sp := &database.Space{} + err = db.Core.NewSelect().Model(sp).Where("repository_id=?", 123).Scan(ctx) + require.Nil(t, err) + + sp, err = store.ByID(ctx, sp.ID) + require.Nil(t, err) + require.Equal(t, int64(123), sp.RepositoryID) + + sp.RepositoryID = 456 + err = store.Update(ctx, *sp) + require.Nil(t, err) + sp = &database.Space{} + err = db.Core.NewSelect().Model(sp).Where("repository_id=?", 456).Scan(ctx) + require.Nil(t, err) + + sp, err = store.ByRepoID(ctx, 456) + require.Nil(t, err) + require.Equal(t, int64(456), sp.RepositoryID) + + sps, err := store.ByRepoIDs(ctx, []int64{456}) + require.Nil(t, err) + require.Equal(t, int64(456), sps[0].RepositoryID) + + repo := &database.Repository{ + Path: "foo/bar", + GitPath: "foo/bar2", + Private: true, + RepositoryType: types.SpaceRepo, + } + err = db.Core.NewInsert().Model(repo).Scan(ctx, repo) + require.Nil(t, err) + sp.RepositoryID = repo.ID + err = store.Update(ctx, *sp) + require.Nil(t, err) + + sps, total, err := store.ByUsername(ctx, "foo", 10, 1, false) + require.Nil(t, err) + require.Equal(t, 1, total) + require.Equal(t, len(sps), 1) + + sps, total, err = store.ByUsername(ctx, "foo", 10, 1, true) + require.Nil(t, err) + require.Equal(t, 0, total) + require.Equal(t, len(sps), 0) + + sps, total, err = store.ByOrgPath(ctx, "foo", 10, 1, false) + require.Nil(t, err) + require.Equal(t, 1, total) + require.Equal(t, len(sps), 1) + + sps, total, err = store.ByOrgPath(ctx, "foo", 10, 1, true) + require.Nil(t, err) + require.Equal(t, 0, total) + require.Equal(t, len(sps), 0) + + sp, err = store.FindByPath(ctx, "foo", "bar") + require.Nil(t, err) + require.Equal(t, repo.ID, sp.RepositoryID) + + err = store.Delete(ctx, *sp) + require.Nil(t, err) + _, err = store.FindByPath(ctx, "foo", "bar") + require.NotNil(t, err) +} + +func TestSpaceStore_ListByPath(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewSpaceStoreWithDB(db) + + dt := &database.Tag{} + err := db.Core.NewInsert().Model(&database.Tag{ + Name: "tag1", + Category: "evaluation", + }).Scan(ctx, dt) + require.Nil(t, err) + tag1pk := dt.ID + + err = db.Core.NewInsert().Model(&database.Tag{ + Name: "tag2", + Category: "foo", + }).Scan(ctx, dt) + require.Nil(t, err) + tag2pk := dt.ID + + dr := &database.Repository{} + err = db.Core.NewInsert().Model(&database.Repository{ + Name: "repo", + Path: "foo/bar", + GitPath: "a", + }).Scan(ctx, dr) + require.Nil(t, err) + repopk := dr.ID + + for _, tpk := range []int64{tag1pk, tag2pk} { + _, err = db.Core.NewInsert().Model(&database.RepositoryTag{ + RepositoryID: repopk, + TagID: tpk, + }).Exec(ctx) + require.Nil(t, err) + } + + _, err = store.Create(ctx, database.Space{ + RepositoryID: repopk, + }) + require.Nil(t, err) + + dr2 := &database.Repository{} + err = db.Core.NewInsert().Model(&database.Repository{ + Name: "repo2", + Path: "bar/foo", + GitPath: "b", + }).Scan(ctx, dr2) + require.Nil(t, err) + _, err = store.Create(ctx, database.Space{ + RepositoryID: dr2.ID, + }) + require.Nil(t, err) + + dr3 := &database.Repository{} + err = db.Core.NewInsert().Model(&database.Repository{ + Name: "repo3", + Path: "foo/bar", + GitPath: "c", + RepositoryType: types.ModelRepo, + }).Scan(ctx, dr3) + require.Nil(t, err) + _, err = store.Create(ctx, database.Space{ + RepositoryID: dr3.ID, + }) + require.Nil(t, err) + + sps, err := store.ListByPath(ctx, []string{"bar/foo", "foo/bar"}) + require.Nil(t, err) + require.Equal(t, 3, len(sps)) + + tags := []string{} + for _, t := range sps[1].Repository.Tags { + tags = append(tags, t.Name) + } + require.Equal(t, []string{}, tags) + + names := []string{} + for _, sp := range sps { + names = append(names, sp.Repository.Name) + } + require.Equal(t, []string{"repo2", "repo", "repo3"}, names) + +} + +func TestSpaceStore_UserLikes(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewSpaceStoreWithDB(db) + + repos := []*database.Repository{ + {Name: "repo1", Path: "p1", GitPath: "p1"}, + {Name: "repo2", Path: "p2", GitPath: "p2"}, + {Name: "repo3", Path: "p3", GitPath: "p3"}, + } + + for _, repo := range repos { + err := db.Core.NewInsert().Model(repo).Scan(ctx, repo) + require.Nil(t, err) + _, err = store.Create(ctx, database.Space{ + RepositoryID: repo.ID, + }) + require.Nil(t, err) + + } + + _, err := db.Core.NewInsert().Model(&database.UserLike{ + UserID: 123, + RepoID: repos[0].ID, + }).Exec(ctx) + require.Nil(t, err) + _, err = db.Core.NewInsert().Model(&database.UserLike{ + UserID: 123, + RepoID: repos[2].ID, + }).Exec(ctx) + require.Nil(t, err) + + sps, total, err := store.ByUserLikes(ctx, 123, 10, 1) + require.Nil(t, err) + require.Equal(t, 2, total) + + names := []string{} + for _, sp := range sps { + names = append(names, sp.Repository.Name) + } + require.Equal(t, []string{"repo1", "repo3"}, names) + +} diff --git a/builder/store/database/ssh_key.go b/builder/store/database/ssh_key.go index dd49d114..6bd7f269 100644 --- a/builder/store/database/ssh_key.go +++ b/builder/store/database/ssh_key.go @@ -26,6 +26,12 @@ func NewSSHKeyStore() SSHKeyStore { } } +func NewSSHKeyStoreWithDB(db *DB) SSHKeyStore { + return &sSHKeyStoreImpl{ + db: db, + } +} + type SSHKey struct { ID int64 `bun:",pk,autoincrement" json:"id"` GitID int64 `bun:",notnull" json:"git_id"` diff --git a/builder/store/database/ssh_key_test.go b/builder/store/database/ssh_key_test.go new file mode 100644 index 00000000..ba5ecaf8 --- /dev/null +++ b/builder/store/database/ssh_key_test.go @@ -0,0 +1,65 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestSSHKeyStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewSSHKeyStoreWithDB(db) + user := &database.User{ + Username: "user", + } + err := db.Core.NewInsert().Model(user).Scan(ctx, user) + require.Nil(t, err) + _, err = store.Create(ctx, &database.SSHKey{ + GitID: 123, + FingerprintSHA256: "foo", + UserID: user.ID, + Name: "key", + Content: "content", + }) + require.Nil(t, err) + + sh := &database.SSHKey{} + err = db.Core.NewSelect().Model(sh).Where("git_id=?", 123).Scan(ctx) + require.Nil(t, err) + + sh, err = store.FindByID(ctx, sh.ID) + require.Nil(t, err) + require.Equal(t, int64(123), sh.GitID) + + sh, err = store.FindByFingerpringSHA256(ctx, "foo") + require.Nil(t, err) + require.Equal(t, int64(123), sh.GitID) + + exist, err := store.IsExist(ctx, "user", "key") + require.Nil(t, err) + require.True(t, exist) + + shv, err := store.FindByUsernameAndName(ctx, "user", "key") + require.Nil(t, err) + require.Equal(t, int64(123), shv.GitID) + + sh, err = store.FindByKeyContent(ctx, "content") + require.Nil(t, err) + require.Equal(t, int64(123), sh.GitID) + + sh, err = store.FindByNameAndUserID(ctx, "key", user.ID) + require.Nil(t, err) + require.Equal(t, int64(123), sh.GitID) + + err = store.Delete(ctx, 123) + require.Nil(t, err) + _, err = store.FindByID(ctx, sh.ID) + require.NotNil(t, err) + +} diff --git a/builder/store/database/sync_client_setting.go b/builder/store/database/sync_client_setting.go index f80c7c0d..8f3f8654 100644 --- a/builder/store/database/sync_client_setting.go +++ b/builder/store/database/sync_client_setting.go @@ -19,6 +19,12 @@ func NewSyncClientSettingStore() SyncClientSettingStore { } } +func NewSyncClientSettingStoreWithDB(db *DB) SyncClientSettingStore { + return &syncClientSettingStoreImpl{ + db: db, + } +} + type SyncClientSetting struct { ID int64 `bun:",pk,autoincrement" json:"id"` Token string `bun:",notnull" json:"token"` diff --git a/builder/store/database/sync_client_setting_test.go b/builder/store/database/sync_client_setting_test.go new file mode 100644 index 00000000..d3124fe8 --- /dev/null +++ b/builder/store/database/sync_client_setting_test.go @@ -0,0 +1,46 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestSyncClientSettingStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewSyncClientSettingStoreWithDB(db) + err := store.DeleteAll(ctx) + require.Nil(t, err) + + _, err = store.Create(ctx, &database.SyncClientSetting{ + Token: "tk", + ConcurrentCount: 5, + }) + require.Nil(t, err) + + sc := &database.SyncClientSetting{} + err = db.Core.NewSelect().Model(sc).Where("token=?", "tk").Scan(ctx, sc) + require.Nil(t, err) + require.Equal(t, 5, sc.ConcurrentCount) + + sc, err = store.First(ctx) + require.Nil(t, err) + require.Equal(t, 5, sc.ConcurrentCount) + + exist, err := store.SyncClientSettingExists(ctx) + require.Nil(t, err) + require.True(t, exist) + + err = store.DeleteAll(ctx) + require.Nil(t, err) + exist, err = store.SyncClientSettingExists(ctx) + require.Nil(t, err) + require.False(t, exist) + +} diff --git a/builder/store/database/sync_version.go b/builder/store/database/sync_version.go index 15762858..f194a061 100644 --- a/builder/store/database/sync_version.go +++ b/builder/store/database/sync_version.go @@ -25,6 +25,12 @@ func NewSyncVersionStore() SyncVersionStore { } } +func NewSyncVersionStoreWithDB(db *DB) SyncVersionStore { + return &syncVersionStoreImpl{ + db: db, + } +} + func (s *syncVersionStoreImpl) Create(ctx context.Context, version *SyncVersion) (err error) { _, err = s.db.Operator.Core.NewInsert().Model(version).Exec(ctx) return diff --git a/builder/store/database/sync_version_test.go b/builder/store/database/sync_version_test.go new file mode 100644 index 00000000..34d0b94e --- /dev/null +++ b/builder/store/database/sync_version_test.go @@ -0,0 +1,49 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestSyncVersionStore_CRUD(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewSyncVersionStoreWithDB(db) + + err := store.Create(ctx, &database.SyncVersion{ + Version: 1, + SourceID: 123, + RepoPath: "foo", + RepoType: types.ModelRepo, + }) + require.Nil(t, err) + + sv := &database.SyncVersion{} + err = db.Core.NewSelect().Model(sv).Where("version=?", 1).Scan(ctx, sv) + require.Nil(t, err) + require.Equal(t, int64(123), sv.SourceID) + + sv, err = store.FindByPath(ctx, "foo") + require.Nil(t, err) + require.Equal(t, int64(1), sv.Version) + + sv, err = store.FindByRepoTypeAndPath(ctx, "foo", types.ModelRepo) + require.Nil(t, err) + require.Equal(t, int64(1), sv.Version) + + err = store.BatchCreate(ctx, []database.SyncVersion{ + {Version: 2, RepoPath: "bar"}, + }) + require.Nil(t, err) + sv, err = store.FindByPath(ctx, "bar") + require.Nil(t, err) + require.Equal(t, int64(2), sv.Version) + +} diff --git a/builder/store/database/telemetry.go b/builder/store/database/telemetry.go index b56b42a7..29393f21 100644 --- a/builder/store/database/telemetry.go +++ b/builder/store/database/telemetry.go @@ -41,6 +41,12 @@ func NewTelemetryStore() TelemetryStore { } } +func NewTelemetryStoreWithDB(db *DB) TelemetryStore { + return &telemetryStoreImpl{ + db: db, + } +} + func (s *telemetryStoreImpl) Save(ctx context.Context, telemetry *Telemetry) error { return assertAffectedOneRow(s.db.Core.NewInsert().Model(telemetry).Exec(ctx)) } diff --git a/builder/store/database/telemetry_test.go b/builder/store/database/telemetry_test.go new file mode 100644 index 00000000..55db2c48 --- /dev/null +++ b/builder/store/database/telemetry_test.go @@ -0,0 +1,23 @@ +package database_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" +) + +func TestTelemetryStore_Save(t *testing.T) { + db := tests.InitTestDB() + defer db.Close() + ctx := context.TODO() + + store := database.NewTelemetryStoreWithDB(db) + err := store.Save(ctx, &database.Telemetry{ + UUID: "foo", + }) + require.Nil(t, err) + +} diff --git a/component/callback/git_callback.go b/component/callback/git_callback.go index 7b51eba4..4c41798f 100644 --- a/component/callback/git_callback.go +++ b/component/callback/git_callback.go @@ -32,7 +32,7 @@ type GitCallbackComponent struct { rs database.RepoStore rrs database.RepoRelationsStore mirrorStore database.MirrorStore - rrf *database.RepositoriesRuntimeFrameworkStore + rrf database.RepositoriesRuntimeFrameworkStore rac component.RuntimeArchitectureComponent ras database.RuntimeArchitecturesStore rfs database.RuntimeFrameworksStore diff --git a/component/repo.go b/component/repo.go index d1378f42..84ec0202 100644 --- a/component/repo.go +++ b/component/repo.go @@ -65,7 +65,7 @@ type repoComponentImpl struct { mirrorSource database.MirrorSourceStore tokenStore database.AccessTokenStore rtfm database.RuntimeFrameworksStore - rrtfms *database.RepositoriesRuntimeFrameworkStore + rrtfms database.RepositoriesRuntimeFrameworkStore syncVersion database.SyncVersionStore syncClientSetting database.SyncClientSettingStore file database.FileStore