From 21c49c855ea9fc0deb9bc32e09d6a0e14649d500 Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Wed, 12 Oct 2022 19:02:09 -0500 Subject: [PATCH] codeintel: Reorganize types (#42847) --- internal/codeintel/autoindexing/iface.go | 42 +- internal/codeintel/autoindexing/init.go | 9 +- .../internal/background/background_jobs.go | 13 +- .../autoindexing/internal/background/iface.go | 42 +- .../job_dependency_indexing_scheduler.go | 4 +- .../job_dependency_sync_scheduler.go | 4 +- .../internal/background/job_scheduler.go | 4 +- .../internal/background/mocks_test.go | 2959 ++++++++++------- .../autoindexing/internal/store/store.go | 4 +- .../internal/store/store_indexes.go | 4 +- .../internal/store/store_indexes_test.go | 6 +- internal/codeintel/autoindexing/mocks_test.go | 68 +- internal/codeintel/autoindexing/service.go | 20 +- .../codeintel/autoindexing/shared/iface.go | 48 - .../codeintel/autoindexing/shared/types.go | 60 +- .../graphql/codeintel_tree_info_resolver.go | 4 +- .../autoindexing/transport/graphql/iface.go | 6 +- .../transport/graphql/mocks_temp.go | 66 +- .../graphql/precise_based_support_resolver.go | 9 +- .../autoindexing/transport/graphql/utils.go | 16 +- .../transport/graphql/utils_test.go | 6 +- internal/codeintel/codenav/commit_cache.go | 5 +- .../codeintel/codenav/gittree_translator.go | 5 +- internal/codeintel/codenav/request_state.go | 7 +- internal/codeintel/codenav/shared/iface.go | 16 - internal/codeintel/codenav/shared/types.go | 4 - .../codenav/transport/graphql/iface.go | 6 +- .../codenav/transport/graphql/mocks_test.go | 100 +- .../policies/internal/store/store.go | 3 +- .../internal/store/store_configuration.go | 3 +- .../store/store_configuration_test.go | 3 +- internal/codeintel/policies/mocks_test.go | 23 +- internal/codeintel/policies/service.go | 5 +- internal/codeintel/policies/shared/types.go | 24 +- .../policies/transport/graphql/iface.go | 3 +- .../transport/graphql/root_resolver.go | 3 +- internal/codeintel/shared/resolvers/iface.go | 5 +- .../shared/resolvers/index_resolvers.go | 2 +- .../indexes_repository_namespace_resolver.go | 2 +- .../shared/resolvers/indexes_resolver.go | 5 +- .../codeintel/shared/resolvers/mocks_temp.go | 46 +- .../shared/resolvers/upload_resolver.go | 4 +- .../uploads_repository_namespace_resolver.go | 4 +- .../shared/resolvers/uploads_resolver.go | 5 +- internal/codeintel/shared/types/codenav.go | 21 + internal/codeintel/shared/types/dump.go | 25 + internal/codeintel/shared/types/index.go | 8 - .../shared/types/indexer_resolver.go | 30 + internal/codeintel/shared/types/indexers.go | 239 +- internal/codeintel/shared/types/policy.go | 33 + internal/codeintel/shared/types/types.go | 188 -- internal/codeintel/shared/types/upload.go | 49 + internal/codeintel/uploads/cleanup.go | 2 +- internal/codeintel/uploads/expirer.go | 6 +- internal/codeintel/uploads/expirer_test.go | 7 +- internal/codeintel/uploads/iface.go | 6 +- .../codeintel/uploads/internal/store/store.go | 4 +- .../uploads/internal/store/store_uploads.go | 12 +- .../internal/store/store_uploads_test.go | 10 +- internal/codeintel/uploads/mocks_test.go | 89 +- internal/codeintel/uploads/service.go | 4 +- internal/codeintel/uploads/shared/types.go | 72 +- .../uploads/transport/graphql/iface.go | 8 +- .../uploads/transport/graphql/mocks_temp.go | 68 +- .../uploads/transport/graphql/utils.go | 20 +- .../uploads/transport/graphql/utils_test.go | 6 +- mockgen.test.yaml | 15 +- 67 files changed, 2480 insertions(+), 2119 deletions(-) delete mode 100644 internal/codeintel/autoindexing/shared/iface.go delete mode 100644 internal/codeintel/codenav/shared/iface.go create mode 100644 internal/codeintel/shared/types/codenav.go create mode 100644 internal/codeintel/shared/types/dump.go create mode 100644 internal/codeintel/shared/types/indexer_resolver.go create mode 100644 internal/codeintel/shared/types/policy.go delete mode 100644 internal/codeintel/shared/types/types.go create mode 100644 internal/codeintel/shared/types/upload.go diff --git a/internal/codeintel/autoindexing/iface.go b/internal/codeintel/autoindexing/iface.go index 28972817a40..a51176e8036 100644 --- a/internal/codeintel/autoindexing/iface.go +++ b/internal/codeintel/autoindexing/iface.go @@ -4,12 +4,19 @@ import ( "context" "time" + "github.com/grafana/regexp" + "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/codeintel/dependencies" policies "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" codeinteltypes "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" + "github.com/sourcegraph/sourcegraph/internal/repoupdater/protocol" "github.com/sourcegraph/sourcegraph/internal/types" + "github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config" "github.com/sourcegraph/sourcegraph/lib/codeintel/precise" ) @@ -18,7 +25,7 @@ type DependenciesService interface { } type PoliciesService interface { - GetConfigurationPolicies(ctx context.Context, opts codeinteltypes.GetConfigurationPoliciesOptions) ([]codeinteltypes.ConfigurationPolicy, int, error) + GetConfigurationPolicies(ctx context.Context, opts policiesshared.GetConfigurationPoliciesOptions) ([]codeinteltypes.ConfigurationPolicy, int, error) } type ReposStore interface { @@ -42,3 +49,36 @@ type AutoIndexingServiceForDepScheduling interface { type PolicyMatcher interface { CommitsDescribedByPolicyInternal(ctx context.Context, repositoryID int, policies []codeinteltypes.ConfigurationPolicy, now time.Time, filterCommits ...string) (map[string][]policies.PolicyMatch, error) } + +type RepoUpdaterClient interface { + RepoLookup(ctx context.Context, args protocol.RepoLookupArgs) (*protocol.RepoLookupResult, error) + EnqueueRepoUpdate(ctx context.Context, repo api.RepoName) (*protocol.RepoUpdateResponse, error) +} + +type GitserverClient interface { + Head(ctx context.Context, repositoryID int) (string, bool, error) + CommitExists(ctx context.Context, repositoryID int, commit string) (bool, error) + ListFiles(ctx context.Context, repositoryID int, commit string, pattern *regexp.Regexp) ([]string, error) + FileExists(ctx context.Context, repositoryID int, commit, file string) (bool, error) + RawContents(ctx context.Context, repositoryID int, commit, file string) ([]byte, error) + ResolveRevision(ctx context.Context, repositoryID int, versionString string) (api.CommitID, error) + ListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error) + + CommitDate(ctx context.Context, repositoryID int, commit string) (string, time.Time, bool, error) + RefDescriptions(ctx context.Context, repositoryID int, gitOjbs ...string) (map[string][]gitdomain.RefDescription, error) + CommitsUniqueToBranch(ctx context.Context, repositoryID int, branchName string, isDefaultBranch bool, maxAge *time.Time) (map[string]time.Time, error) +} + +type InferenceService interface { + InferIndexJobs(ctx context.Context, repo api.RepoName, commit, overrideScript string) ([]config.IndexJob, error) + InferIndexJobHints(ctx context.Context, repo api.RepoName, commit, overrideScript string) ([]config.IndexJobHint, error) +} + +type UploadService interface { + GetRepoName(ctx context.Context, repositoryID int) (_ string, err error) // upload service + GetDirtyRepositories(ctx context.Context) (_ map[int]int, err error) // upload service + GetUploadsByIDs(ctx context.Context, ids ...int) (_ []codeinteltypes.Upload, err error) // upload service + GetUploadByID(ctx context.Context, id int) (codeinteltypes.Upload, bool, error) + ReferencesForUpload(ctx context.Context, uploadID int) (shared.PackageReferenceScanner, error) + GetRepositoriesForIndexScan(ctx context.Context, table, column string, processDelay time.Duration, allowGlobalPolicies bool, repositoryMatchLimit *int, limit int, now time.Time) (_ []int, err error) +} diff --git a/internal/codeintel/autoindexing/init.go b/internal/codeintel/autoindexing/init.go index d339bc88760..8ec72d05bb5 100644 --- a/internal/codeintel/autoindexing/init.go +++ b/internal/codeintel/autoindexing/init.go @@ -4,7 +4,6 @@ import ( backgroundjobs "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background" "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/inference" "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/store" - "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/memo" "github.com/sourcegraph/sourcegraph/internal/observation" @@ -18,10 +17,10 @@ import ( // If the service is not yet initialized, it will use the provided dependencies. func GetService( db database.DB, - uploadSvc shared.UploadService, + uploadSvc UploadService, depsSvc DependenciesService, policiesSvc PoliciesService, - gitserver shared.GitserverClient, + gitserver GitserverClient, ) *Service { svc, _ := initServiceMemo.Init(serviceDependencies{ db, @@ -36,10 +35,10 @@ func GetService( type serviceDependencies struct { db database.DB - uploadSvc shared.UploadService + uploadSvc UploadService depsSvc DependenciesService policiesSvc PoliciesService - gitserver shared.GitserverClient + gitserver GitserverClient } var initServiceMemo = memo.NewMemoizedConstructorWithArg(func(deps serviceDependencies) (*Service, error) { diff --git a/internal/codeintel/autoindexing/internal/background/background_jobs.go b/internal/codeintel/autoindexing/internal/background/background_jobs.go index dac5e85f64b..572ae72fbfe 100644 --- a/internal/codeintel/autoindexing/internal/background/background_jobs.go +++ b/internal/codeintel/autoindexing/internal/background/background_jobs.go @@ -8,7 +8,6 @@ import ( "github.com/sourcegraph/log" "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/store" - "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/goroutine" "github.com/sourcegraph/sourcegraph/internal/observation" @@ -38,14 +37,14 @@ type BackgroundJob interface { } type backgroundJob struct { - uploadSvc shared.UploadService + uploadSvc UploadService depsSvc DependenciesService policiesSvc PoliciesService autoindexingSvc AutoIndexingService policyMatcher PolicyMatcher - repoUpdater shared.RepoUpdaterClient - gitserverClient shared.GitserverClient + repoUpdater RepoUpdaterClient + gitserverClient GitserverClient store store.Store repoStore ReposStore @@ -68,12 +67,12 @@ type backgroundJob struct { func New( db database.DB, store store.Store, - uploadSvc shared.UploadService, + uploadSvc UploadService, depsSvc DependenciesService, policiesSvc PoliciesService, policyMatcher PolicyMatcher, - gitserverClient shared.GitserverClient, - repoUpdater shared.RepoUpdaterClient, + gitserverClient GitserverClient, + repoUpdater RepoUpdaterClient, observationContext *observation.Context, ) BackgroundJob { repoStore := db.Repos() diff --git a/internal/codeintel/autoindexing/internal/background/iface.go b/internal/codeintel/autoindexing/internal/background/iface.go index cb4ef1e4541..e00ed862281 100644 --- a/internal/codeintel/autoindexing/internal/background/iface.go +++ b/internal/codeintel/autoindexing/internal/background/iface.go @@ -4,12 +4,19 @@ import ( "context" "time" + "github.com/grafana/regexp" + "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/codeintel/dependencies" policies "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" codeinteltypes "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" "github.com/sourcegraph/sourcegraph/internal/database" + "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" + "github.com/sourcegraph/sourcegraph/internal/repoupdater/protocol" "github.com/sourcegraph/sourcegraph/internal/types" + "github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config" "github.com/sourcegraph/sourcegraph/lib/codeintel/precise" ) @@ -35,7 +42,7 @@ type PolicyMatcher interface { } type PoliciesService interface { - GetConfigurationPolicies(ctx context.Context, opts codeinteltypes.GetConfigurationPoliciesOptions) ([]codeinteltypes.ConfigurationPolicy, int, error) + GetConfigurationPolicies(ctx context.Context, opts policiesshared.GetConfigurationPoliciesOptions) ([]codeinteltypes.ConfigurationPolicy, int, error) } type AutoIndexingService interface { @@ -43,3 +50,36 @@ type AutoIndexingService interface { QueueIndexesForPackage(ctx context.Context, pkg precise.Package) (err error) InsertDependencyIndexingJob(ctx context.Context, uploadID int, externalServiceKind string, syncTime time.Time) (id int, err error) } + +type RepoUpdaterClient interface { + RepoLookup(ctx context.Context, args protocol.RepoLookupArgs) (*protocol.RepoLookupResult, error) + EnqueueRepoUpdate(ctx context.Context, repo api.RepoName) (*protocol.RepoUpdateResponse, error) +} + +type GitserverClient interface { + Head(ctx context.Context, repositoryID int) (string, bool, error) + CommitExists(ctx context.Context, repositoryID int, commit string) (bool, error) + ListFiles(ctx context.Context, repositoryID int, commit string, pattern *regexp.Regexp) ([]string, error) + FileExists(ctx context.Context, repositoryID int, commit, file string) (bool, error) + RawContents(ctx context.Context, repositoryID int, commit, file string) ([]byte, error) + ResolveRevision(ctx context.Context, repositoryID int, versionString string) (api.CommitID, error) + ListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error) + + CommitDate(ctx context.Context, repositoryID int, commit string) (string, time.Time, bool, error) + RefDescriptions(ctx context.Context, repositoryID int, gitOjbs ...string) (map[string][]gitdomain.RefDescription, error) + CommitsUniqueToBranch(ctx context.Context, repositoryID int, branchName string, isDefaultBranch bool, maxAge *time.Time) (map[string]time.Time, error) +} + +type InferenceService interface { + InferIndexJobs(ctx context.Context, repo api.RepoName, commit, overrideScript string) ([]config.IndexJob, error) + InferIndexJobHints(ctx context.Context, repo api.RepoName, commit, overrideScript string) ([]config.IndexJobHint, error) +} + +type UploadService interface { + GetRepoName(ctx context.Context, repositoryID int) (_ string, err error) // upload service + GetDirtyRepositories(ctx context.Context) (_ map[int]int, err error) // upload service + GetUploadsByIDs(ctx context.Context, ids ...int) (_ []codeinteltypes.Upload, err error) // upload service + GetUploadByID(ctx context.Context, id int) (codeinteltypes.Upload, bool, error) + ReferencesForUpload(ctx context.Context, uploadID int) (shared.PackageReferenceScanner, error) + GetRepositoriesForIndexScan(ctx context.Context, table, column string, processDelay time.Duration, allowGlobalPolicies bool, repositoryMatchLimit *int, limit int, now time.Time) (_ []int, err error) +} diff --git a/internal/codeintel/autoindexing/internal/background/job_dependency_indexing_scheduler.go b/internal/codeintel/autoindexing/internal/background/job_dependency_indexing_scheduler.go index 07847d853be..1fa996709d0 100644 --- a/internal/codeintel/autoindexing/internal/background/job_dependency_indexing_scheduler.go +++ b/internal/codeintel/autoindexing/internal/background/job_dependency_indexing_scheduler.go @@ -52,13 +52,13 @@ func (b *backgroundJob) NewDependencyIndexingScheduler(pollInterval time.Duratio } type dependencyIndexingSchedulerHandler struct { - uploadsSvc shared.UploadService + uploadsSvc UploadService repoStore ReposStore indexEnqueuer AutoIndexingService extsvcStore ExternalServiceStore gitserverRepoStore GitserverRepoStore workerStore dbworkerstore.Store - repoUpdater shared.RepoUpdaterClient + repoUpdater RepoUpdaterClient } const requeueBackoff = time.Second * 30 diff --git a/internal/codeintel/autoindexing/internal/background/job_dependency_sync_scheduler.go b/internal/codeintel/autoindexing/internal/background/job_dependency_sync_scheduler.go index 8ed89265277..3316e6c1c4f 100644 --- a/internal/codeintel/autoindexing/internal/background/job_dependency_sync_scheduler.go +++ b/internal/codeintel/autoindexing/internal/background/job_dependency_sync_scheduler.go @@ -46,7 +46,7 @@ func (b *backgroundJob) NewDependencySyncScheduler(pollInterval time.Duration) * } type dependencySyncSchedulerHandler struct { - uploadsSvc shared.UploadService + uploadsSvc UploadService depsSvc DependenciesService autoindexingSvc AutoIndexingService workerStore dbworkerstore.Store @@ -231,7 +231,7 @@ func (h *dependencySyncSchedulerHandler) insertDependencyRepo(ctx context.Contex // shouldIndexDependencies returns true if the given upload should undergo dependency // indexing. Currently, we're only enabling dependency indexing for a repositories that // were indexed via lsif-go, scip-java, lsif-tsc and scip-typescript. -func (h *dependencySyncSchedulerHandler) shouldIndexDependencies(ctx context.Context, store shared.UploadService, uploadID int) (bool, error) { +func (h *dependencySyncSchedulerHandler) shouldIndexDependencies(ctx context.Context, store UploadService, uploadID int) (bool, error) { upload, _, err := store.GetUploadByID(ctx, uploadID) if err != nil { return false, errors.Wrap(err, "dbstore.GetUploadByID") diff --git a/internal/codeintel/autoindexing/internal/background/job_scheduler.go b/internal/codeintel/autoindexing/internal/background/job_scheduler.go index a6a1be6e942..a90a31c48e1 100644 --- a/internal/codeintel/autoindexing/internal/background/job_scheduler.go +++ b/internal/codeintel/autoindexing/internal/background/job_scheduler.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" "github.com/sourcegraph/sourcegraph/internal/conf" "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" "github.com/sourcegraph/sourcegraph/internal/goroutine" @@ -80,7 +80,7 @@ func (b backgroundJob) handleRepository(ctx context.Context, repositoryID, polic for { // Retrieve the set of configuration policies that affect indexing for this repository. - policies, totalCount, err := b.policiesSvc.GetConfigurationPolicies(ctx, types.GetConfigurationPoliciesOptions{ + policies, totalCount, err := b.policiesSvc.GetConfigurationPolicies(ctx, policiesshared.GetConfigurationPoliciesOptions{ RepositoryID: repositoryID, ForIndexing: true, Limit: policyBatchSize, diff --git a/internal/codeintel/autoindexing/internal/background/mocks_test.go b/internal/codeintel/autoindexing/internal/background/mocks_test.go index 891afbe9c2d..7302721597f 100644 --- a/internal/codeintel/autoindexing/internal/background/mocks_test.go +++ b/internal/codeintel/autoindexing/internal/background/mocks_test.go @@ -15,13 +15,15 @@ import ( api "github.com/sourcegraph/sourcegraph/internal/api" store "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/store" shared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" - shared2 "github.com/sourcegraph/sourcegraph/internal/codeintel/dependencies/shared" + shared1 "github.com/sourcegraph/sourcegraph/internal/codeintel/dependencies/shared" + enterprise "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise" types "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" - shared1 "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" + shared2 "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" database "github.com/sourcegraph/sourcegraph/internal/database" gitdomain "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" protocol "github.com/sourcegraph/sourcegraph/internal/repoupdater/protocol" types1 "github.com/sourcegraph/sourcegraph/internal/types" + config "github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config" precise "github.com/sourcegraph/sourcegraph/lib/codeintel/precise" ) @@ -126,7 +128,7 @@ func NewMockStore() *MockStore { }, }, DeleteIndexesFunc: &StoreDeleteIndexesFunc{ - defaultHook: func(context.Context, types.DeleteIndexesOptions) (r0 error) { + defaultHook: func(context.Context, shared.DeleteIndexesOptions) (r0 error) { return }, }, @@ -156,7 +158,7 @@ func NewMockStore() *MockStore { }, }, GetIndexesFunc: &StoreGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { return }, }, @@ -263,7 +265,7 @@ func NewStrictMockStore() *MockStore { }, }, DeleteIndexesFunc: &StoreDeleteIndexesFunc{ - defaultHook: func(context.Context, types.DeleteIndexesOptions) error { + defaultHook: func(context.Context, shared.DeleteIndexesOptions) error { panic("unexpected invocation of MockStore.DeleteIndexes") }, }, @@ -293,7 +295,7 @@ func NewStrictMockStore() *MockStore { }, }, GetIndexesFunc: &StoreGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { panic("unexpected invocation of MockStore.GetIndexes") }, }, @@ -586,15 +588,15 @@ func (c StoreDeleteIndexByIDFuncCall) Results() []interface{} { // StoreDeleteIndexesFunc describes the behavior when the DeleteIndexes // method of the parent MockStore instance is invoked. type StoreDeleteIndexesFunc struct { - defaultHook func(context.Context, types.DeleteIndexesOptions) error - hooks []func(context.Context, types.DeleteIndexesOptions) error + defaultHook func(context.Context, shared.DeleteIndexesOptions) error + hooks []func(context.Context, shared.DeleteIndexesOptions) error history []StoreDeleteIndexesFuncCall mutex sync.Mutex } // DeleteIndexes delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockStore) DeleteIndexes(v0 context.Context, v1 types.DeleteIndexesOptions) error { +func (m *MockStore) DeleteIndexes(v0 context.Context, v1 shared.DeleteIndexesOptions) error { r0 := m.DeleteIndexesFunc.nextHook()(v0, v1) m.DeleteIndexesFunc.appendCall(StoreDeleteIndexesFuncCall{v0, v1, r0}) return r0 @@ -602,7 +604,7 @@ func (m *MockStore) DeleteIndexes(v0 context.Context, v1 types.DeleteIndexesOpti // SetDefaultHook sets function that is called when the DeleteIndexes method // of the parent MockStore instance is invoked and the hook queue is empty. -func (f *StoreDeleteIndexesFunc) SetDefaultHook(hook func(context.Context, types.DeleteIndexesOptions) error) { +func (f *StoreDeleteIndexesFunc) SetDefaultHook(hook func(context.Context, shared.DeleteIndexesOptions) error) { f.defaultHook = hook } @@ -610,7 +612,7 @@ func (f *StoreDeleteIndexesFunc) SetDefaultHook(hook func(context.Context, types // DeleteIndexes method of the parent MockStore instance invokes the hook at // the front of the queue and discards it. After the queue is empty, the // default hook function is invoked for any future action. -func (f *StoreDeleteIndexesFunc) PushHook(hook func(context.Context, types.DeleteIndexesOptions) error) { +func (f *StoreDeleteIndexesFunc) PushHook(hook func(context.Context, shared.DeleteIndexesOptions) error) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -619,19 +621,19 @@ func (f *StoreDeleteIndexesFunc) PushHook(hook func(context.Context, types.Delet // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *StoreDeleteIndexesFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(context.Context, types.DeleteIndexesOptions) error { + f.SetDefaultHook(func(context.Context, shared.DeleteIndexesOptions) error { return r0 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *StoreDeleteIndexesFunc) PushReturn(r0 error) { - f.PushHook(func(context.Context, types.DeleteIndexesOptions) error { + f.PushHook(func(context.Context, shared.DeleteIndexesOptions) error { return r0 }) } -func (f *StoreDeleteIndexesFunc) nextHook() func(context.Context, types.DeleteIndexesOptions) error { +func (f *StoreDeleteIndexesFunc) nextHook() func(context.Context, shared.DeleteIndexesOptions) error { f.mutex.Lock() defer f.mutex.Unlock() @@ -669,7 +671,7 @@ type StoreDeleteIndexesFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.DeleteIndexesOptions + Arg1 shared.DeleteIndexesOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 error @@ -1242,15 +1244,15 @@ func (c StoreGetIndexConfigurationByRepositoryIDFuncCall) Results() []interface{ // StoreGetIndexesFunc describes the behavior when the GetIndexes method of // the parent MockStore instance is invoked. type StoreGetIndexesFunc struct { - defaultHook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) - hooks []func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) + defaultHook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) + hooks []func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) history []StoreGetIndexesFuncCall mutex sync.Mutex } // GetIndexes delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockStore) GetIndexes(v0 context.Context, v1 types.GetIndexesOptions) ([]types.Index, int, error) { +func (m *MockStore) GetIndexes(v0 context.Context, v1 shared.GetIndexesOptions) ([]types.Index, int, error) { r0, r1, r2 := m.GetIndexesFunc.nextHook()(v0, v1) m.GetIndexesFunc.appendCall(StoreGetIndexesFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -1258,7 +1260,7 @@ func (m *MockStore) GetIndexes(v0 context.Context, v1 types.GetIndexesOptions) ( // SetDefaultHook sets function that is called when the GetIndexes method of // the parent MockStore instance is invoked and the hook queue is empty. -func (f *StoreGetIndexesFunc) SetDefaultHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *StoreGetIndexesFunc) SetDefaultHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.defaultHook = hook } @@ -1266,7 +1268,7 @@ func (f *StoreGetIndexesFunc) SetDefaultHook(hook func(context.Context, types.Ge // GetIndexes method of the parent MockStore instance invokes the hook at // the front of the queue and discards it. After the queue is empty, the // default hook function is invoked for any future action. -func (f *StoreGetIndexesFunc) PushHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *StoreGetIndexesFunc) PushHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -1275,19 +1277,19 @@ func (f *StoreGetIndexesFunc) PushHook(hook func(context.Context, types.GetIndex // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *StoreGetIndexesFunc) SetDefaultReturn(r0 []types.Index, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.SetDefaultHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *StoreGetIndexesFunc) PushReturn(r0 []types.Index, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.PushHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } -func (f *StoreGetIndexesFunc) nextHook() func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { +func (f *StoreGetIndexesFunc) nextHook() func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -1325,7 +1327,7 @@ type StoreGetIndexesFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetIndexesOptions + Arg1 shared.GetIndexesOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Index @@ -3312,9 +3314,881 @@ func (c StoreUpdateSourcedCommitsFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } +// MockAutoIndexingService is a mock implementation of the +// AutoIndexingService interface (from the package +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) +// used for unit testing. +type MockAutoIndexingService struct { + // InsertDependencyIndexingJobFunc is an instance of a mock function + // object controlling the behavior of the method + // InsertDependencyIndexingJob. + InsertDependencyIndexingJobFunc *AutoIndexingServiceInsertDependencyIndexingJobFunc + // QueueIndexesFunc is an instance of a mock function object controlling + // the behavior of the method QueueIndexes. + QueueIndexesFunc *AutoIndexingServiceQueueIndexesFunc + // QueueIndexesForPackageFunc is an instance of a mock function object + // controlling the behavior of the method QueueIndexesForPackage. + QueueIndexesForPackageFunc *AutoIndexingServiceQueueIndexesForPackageFunc +} + +// NewMockAutoIndexingService creates a new mock of the AutoIndexingService +// interface. All methods return zero values for all results, unless +// overwritten. +func NewMockAutoIndexingService() *MockAutoIndexingService { + return &MockAutoIndexingService{ + InsertDependencyIndexingJobFunc: &AutoIndexingServiceInsertDependencyIndexingJobFunc{ + defaultHook: func(context.Context, int, string, time.Time) (r0 int, r1 error) { + return + }, + }, + QueueIndexesFunc: &AutoIndexingServiceQueueIndexesFunc{ + defaultHook: func(context.Context, int, string, string, bool, bool) (r0 []types.Index, r1 error) { + return + }, + }, + QueueIndexesForPackageFunc: &AutoIndexingServiceQueueIndexesForPackageFunc{ + defaultHook: func(context.Context, precise.Package) (r0 error) { + return + }, + }, + } +} + +// NewStrictMockAutoIndexingService creates a new mock of the +// AutoIndexingService interface. All methods panic on invocation, unless +// overwritten. +func NewStrictMockAutoIndexingService() *MockAutoIndexingService { + return &MockAutoIndexingService{ + InsertDependencyIndexingJobFunc: &AutoIndexingServiceInsertDependencyIndexingJobFunc{ + defaultHook: func(context.Context, int, string, time.Time) (int, error) { + panic("unexpected invocation of MockAutoIndexingService.InsertDependencyIndexingJob") + }, + }, + QueueIndexesFunc: &AutoIndexingServiceQueueIndexesFunc{ + defaultHook: func(context.Context, int, string, string, bool, bool) ([]types.Index, error) { + panic("unexpected invocation of MockAutoIndexingService.QueueIndexes") + }, + }, + QueueIndexesForPackageFunc: &AutoIndexingServiceQueueIndexesForPackageFunc{ + defaultHook: func(context.Context, precise.Package) error { + panic("unexpected invocation of MockAutoIndexingService.QueueIndexesForPackage") + }, + }, + } +} + +// NewMockAutoIndexingServiceFrom creates a new mock of the +// MockAutoIndexingService interface. All methods delegate to the given +// implementation, unless overwritten. +func NewMockAutoIndexingServiceFrom(i AutoIndexingService) *MockAutoIndexingService { + return &MockAutoIndexingService{ + InsertDependencyIndexingJobFunc: &AutoIndexingServiceInsertDependencyIndexingJobFunc{ + defaultHook: i.InsertDependencyIndexingJob, + }, + QueueIndexesFunc: &AutoIndexingServiceQueueIndexesFunc{ + defaultHook: i.QueueIndexes, + }, + QueueIndexesForPackageFunc: &AutoIndexingServiceQueueIndexesForPackageFunc{ + defaultHook: i.QueueIndexesForPackage, + }, + } +} + +// AutoIndexingServiceInsertDependencyIndexingJobFunc describes the behavior +// when the InsertDependencyIndexingJob method of the parent +// MockAutoIndexingService instance is invoked. +type AutoIndexingServiceInsertDependencyIndexingJobFunc struct { + defaultHook func(context.Context, int, string, time.Time) (int, error) + hooks []func(context.Context, int, string, time.Time) (int, error) + history []AutoIndexingServiceInsertDependencyIndexingJobFuncCall + mutex sync.Mutex +} + +// InsertDependencyIndexingJob delegates to the next hook function in the +// queue and stores the parameter and result values of this invocation. +func (m *MockAutoIndexingService) InsertDependencyIndexingJob(v0 context.Context, v1 int, v2 string, v3 time.Time) (int, error) { + r0, r1 := m.InsertDependencyIndexingJobFunc.nextHook()(v0, v1, v2, v3) + m.InsertDependencyIndexingJobFunc.appendCall(AutoIndexingServiceInsertDependencyIndexingJobFuncCall{v0, v1, v2, v3, r0, r1}) + return r0, r1 +} + +// SetDefaultHook sets function that is called when the +// InsertDependencyIndexingJob method of the parent MockAutoIndexingService +// instance is invoked and the hook queue is empty. +func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) SetDefaultHook(hook func(context.Context, int, string, time.Time) (int, error)) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// InsertDependencyIndexingJob method of the parent MockAutoIndexingService +// instance invokes the hook at the front of the queue and discards it. +// After the queue is empty, the default hook function is invoked for any +// future action. +func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) PushHook(hook func(context.Context, int, string, time.Time) (int, error)) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) SetDefaultReturn(r0 int, r1 error) { + f.SetDefaultHook(func(context.Context, int, string, time.Time) (int, error) { + return r0, r1 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) PushReturn(r0 int, r1 error) { + f.PushHook(func(context.Context, int, string, time.Time) (int, error) { + return r0, r1 + }) +} + +func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) nextHook() func(context.Context, int, string, time.Time) (int, error) { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) appendCall(r0 AutoIndexingServiceInsertDependencyIndexingJobFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of +// AutoIndexingServiceInsertDependencyIndexingJobFuncCall objects describing +// the invocations of this function. +func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) History() []AutoIndexingServiceInsertDependencyIndexingJobFuncCall { + f.mutex.Lock() + history := make([]AutoIndexingServiceInsertDependencyIndexingJobFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// AutoIndexingServiceInsertDependencyIndexingJobFuncCall is an object that +// describes an invocation of method InsertDependencyIndexingJob on an +// instance of MockAutoIndexingService. +type AutoIndexingServiceInsertDependencyIndexingJobFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 int + // Arg2 is the value of the 3rd argument passed to this method + // invocation. + Arg2 string + // Arg3 is the value of the 4th argument passed to this method + // invocation. + Arg3 time.Time + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 int + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c AutoIndexingServiceInsertDependencyIndexingJobFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c AutoIndexingServiceInsertDependencyIndexingJobFuncCall) Results() []interface{} { + return []interface{}{c.Result0, c.Result1} +} + +// AutoIndexingServiceQueueIndexesFunc describes the behavior when the +// QueueIndexes method of the parent MockAutoIndexingService instance is +// invoked. +type AutoIndexingServiceQueueIndexesFunc struct { + defaultHook func(context.Context, int, string, string, bool, bool) ([]types.Index, error) + hooks []func(context.Context, int, string, string, bool, bool) ([]types.Index, error) + history []AutoIndexingServiceQueueIndexesFuncCall + mutex sync.Mutex +} + +// QueueIndexes delegates to the next hook function in the queue and stores +// the parameter and result values of this invocation. +func (m *MockAutoIndexingService) QueueIndexes(v0 context.Context, v1 int, v2 string, v3 string, v4 bool, v5 bool) ([]types.Index, error) { + r0, r1 := m.QueueIndexesFunc.nextHook()(v0, v1, v2, v3, v4, v5) + m.QueueIndexesFunc.appendCall(AutoIndexingServiceQueueIndexesFuncCall{v0, v1, v2, v3, v4, v5, r0, r1}) + return r0, r1 +} + +// SetDefaultHook sets function that is called when the QueueIndexes method +// of the parent MockAutoIndexingService instance is invoked and the hook +// queue is empty. +func (f *AutoIndexingServiceQueueIndexesFunc) SetDefaultHook(hook func(context.Context, int, string, string, bool, bool) ([]types.Index, error)) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// QueueIndexes method of the parent MockAutoIndexingService instance +// invokes the hook at the front of the queue and discards it. After the +// queue is empty, the default hook function is invoked for any future +// action. +func (f *AutoIndexingServiceQueueIndexesFunc) PushHook(hook func(context.Context, int, string, string, bool, bool) ([]types.Index, error)) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *AutoIndexingServiceQueueIndexesFunc) SetDefaultReturn(r0 []types.Index, r1 error) { + f.SetDefaultHook(func(context.Context, int, string, string, bool, bool) ([]types.Index, error) { + return r0, r1 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *AutoIndexingServiceQueueIndexesFunc) PushReturn(r0 []types.Index, r1 error) { + f.PushHook(func(context.Context, int, string, string, bool, bool) ([]types.Index, error) { + return r0, r1 + }) +} + +func (f *AutoIndexingServiceQueueIndexesFunc) nextHook() func(context.Context, int, string, string, bool, bool) ([]types.Index, error) { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *AutoIndexingServiceQueueIndexesFunc) appendCall(r0 AutoIndexingServiceQueueIndexesFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of AutoIndexingServiceQueueIndexesFuncCall +// objects describing the invocations of this function. +func (f *AutoIndexingServiceQueueIndexesFunc) History() []AutoIndexingServiceQueueIndexesFuncCall { + f.mutex.Lock() + history := make([]AutoIndexingServiceQueueIndexesFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// AutoIndexingServiceQueueIndexesFuncCall is an object that describes an +// invocation of method QueueIndexes on an instance of +// MockAutoIndexingService. +type AutoIndexingServiceQueueIndexesFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 int + // Arg2 is the value of the 3rd argument passed to this method + // invocation. + Arg2 string + // Arg3 is the value of the 4th argument passed to this method + // invocation. + Arg3 string + // Arg4 is the value of the 5th argument passed to this method + // invocation. + Arg4 bool + // Arg5 is the value of the 6th argument passed to this method + // invocation. + Arg5 bool + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 []types.Index + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c AutoIndexingServiceQueueIndexesFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3, c.Arg4, c.Arg5} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c AutoIndexingServiceQueueIndexesFuncCall) Results() []interface{} { + return []interface{}{c.Result0, c.Result1} +} + +// AutoIndexingServiceQueueIndexesForPackageFunc describes the behavior when +// the QueueIndexesForPackage method of the parent MockAutoIndexingService +// instance is invoked. +type AutoIndexingServiceQueueIndexesForPackageFunc struct { + defaultHook func(context.Context, precise.Package) error + hooks []func(context.Context, precise.Package) error + history []AutoIndexingServiceQueueIndexesForPackageFuncCall + mutex sync.Mutex +} + +// QueueIndexesForPackage delegates to the next hook function in the queue +// and stores the parameter and result values of this invocation. +func (m *MockAutoIndexingService) QueueIndexesForPackage(v0 context.Context, v1 precise.Package) error { + r0 := m.QueueIndexesForPackageFunc.nextHook()(v0, v1) + m.QueueIndexesForPackageFunc.appendCall(AutoIndexingServiceQueueIndexesForPackageFuncCall{v0, v1, r0}) + return r0 +} + +// SetDefaultHook sets function that is called when the +// QueueIndexesForPackage method of the parent MockAutoIndexingService +// instance is invoked and the hook queue is empty. +func (f *AutoIndexingServiceQueueIndexesForPackageFunc) SetDefaultHook(hook func(context.Context, precise.Package) error) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// QueueIndexesForPackage method of the parent MockAutoIndexingService +// instance invokes the hook at the front of the queue and discards it. +// After the queue is empty, the default hook function is invoked for any +// future action. +func (f *AutoIndexingServiceQueueIndexesForPackageFunc) PushHook(hook func(context.Context, precise.Package) error) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *AutoIndexingServiceQueueIndexesForPackageFunc) SetDefaultReturn(r0 error) { + f.SetDefaultHook(func(context.Context, precise.Package) error { + return r0 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *AutoIndexingServiceQueueIndexesForPackageFunc) PushReturn(r0 error) { + f.PushHook(func(context.Context, precise.Package) error { + return r0 + }) +} + +func (f *AutoIndexingServiceQueueIndexesForPackageFunc) nextHook() func(context.Context, precise.Package) error { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *AutoIndexingServiceQueueIndexesForPackageFunc) appendCall(r0 AutoIndexingServiceQueueIndexesForPackageFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of +// AutoIndexingServiceQueueIndexesForPackageFuncCall objects describing the +// invocations of this function. +func (f *AutoIndexingServiceQueueIndexesForPackageFunc) History() []AutoIndexingServiceQueueIndexesForPackageFuncCall { + f.mutex.Lock() + history := make([]AutoIndexingServiceQueueIndexesForPackageFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// AutoIndexingServiceQueueIndexesForPackageFuncCall is an object that +// describes an invocation of method QueueIndexesForPackage on an instance +// of MockAutoIndexingService. +type AutoIndexingServiceQueueIndexesForPackageFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 precise.Package + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c AutoIndexingServiceQueueIndexesForPackageFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c AutoIndexingServiceQueueIndexesForPackageFuncCall) Results() []interface{} { + return []interface{}{c.Result0} +} + +// MockDependenciesService is a mock implementation of the +// DependenciesService interface (from the package +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) +// used for unit testing. +type MockDependenciesService struct { + // UpsertDependencyReposFunc is an instance of a mock function object + // controlling the behavior of the method UpsertDependencyRepos. + UpsertDependencyReposFunc *DependenciesServiceUpsertDependencyReposFunc +} + +// NewMockDependenciesService creates a new mock of the DependenciesService +// interface. All methods return zero values for all results, unless +// overwritten. +func NewMockDependenciesService() *MockDependenciesService { + return &MockDependenciesService{ + UpsertDependencyReposFunc: &DependenciesServiceUpsertDependencyReposFunc{ + defaultHook: func(context.Context, []shared1.Repo) (r0 []shared1.Repo, r1 error) { + return + }, + }, + } +} + +// NewStrictMockDependenciesService creates a new mock of the +// DependenciesService interface. All methods panic on invocation, unless +// overwritten. +func NewStrictMockDependenciesService() *MockDependenciesService { + return &MockDependenciesService{ + UpsertDependencyReposFunc: &DependenciesServiceUpsertDependencyReposFunc{ + defaultHook: func(context.Context, []shared1.Repo) ([]shared1.Repo, error) { + panic("unexpected invocation of MockDependenciesService.UpsertDependencyRepos") + }, + }, + } +} + +// NewMockDependenciesServiceFrom creates a new mock of the +// MockDependenciesService interface. All methods delegate to the given +// implementation, unless overwritten. +func NewMockDependenciesServiceFrom(i DependenciesService) *MockDependenciesService { + return &MockDependenciesService{ + UpsertDependencyReposFunc: &DependenciesServiceUpsertDependencyReposFunc{ + defaultHook: i.UpsertDependencyRepos, + }, + } +} + +// DependenciesServiceUpsertDependencyReposFunc describes the behavior when +// the UpsertDependencyRepos method of the parent MockDependenciesService +// instance is invoked. +type DependenciesServiceUpsertDependencyReposFunc struct { + defaultHook func(context.Context, []shared1.Repo) ([]shared1.Repo, error) + hooks []func(context.Context, []shared1.Repo) ([]shared1.Repo, error) + history []DependenciesServiceUpsertDependencyReposFuncCall + mutex sync.Mutex +} + +// UpsertDependencyRepos delegates to the next hook function in the queue +// and stores the parameter and result values of this invocation. +func (m *MockDependenciesService) UpsertDependencyRepos(v0 context.Context, v1 []shared1.Repo) ([]shared1.Repo, error) { + r0, r1 := m.UpsertDependencyReposFunc.nextHook()(v0, v1) + m.UpsertDependencyReposFunc.appendCall(DependenciesServiceUpsertDependencyReposFuncCall{v0, v1, r0, r1}) + return r0, r1 +} + +// SetDefaultHook sets function that is called when the +// UpsertDependencyRepos method of the parent MockDependenciesService +// instance is invoked and the hook queue is empty. +func (f *DependenciesServiceUpsertDependencyReposFunc) SetDefaultHook(hook func(context.Context, []shared1.Repo) ([]shared1.Repo, error)) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// UpsertDependencyRepos method of the parent MockDependenciesService +// instance invokes the hook at the front of the queue and discards it. +// After the queue is empty, the default hook function is invoked for any +// future action. +func (f *DependenciesServiceUpsertDependencyReposFunc) PushHook(hook func(context.Context, []shared1.Repo) ([]shared1.Repo, error)) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *DependenciesServiceUpsertDependencyReposFunc) SetDefaultReturn(r0 []shared1.Repo, r1 error) { + f.SetDefaultHook(func(context.Context, []shared1.Repo) ([]shared1.Repo, error) { + return r0, r1 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *DependenciesServiceUpsertDependencyReposFunc) PushReturn(r0 []shared1.Repo, r1 error) { + f.PushHook(func(context.Context, []shared1.Repo) ([]shared1.Repo, error) { + return r0, r1 + }) +} + +func (f *DependenciesServiceUpsertDependencyReposFunc) nextHook() func(context.Context, []shared1.Repo) ([]shared1.Repo, error) { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *DependenciesServiceUpsertDependencyReposFunc) appendCall(r0 DependenciesServiceUpsertDependencyReposFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of +// DependenciesServiceUpsertDependencyReposFuncCall objects describing the +// invocations of this function. +func (f *DependenciesServiceUpsertDependencyReposFunc) History() []DependenciesServiceUpsertDependencyReposFuncCall { + f.mutex.Lock() + history := make([]DependenciesServiceUpsertDependencyReposFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// DependenciesServiceUpsertDependencyReposFuncCall is an object that +// describes an invocation of method UpsertDependencyRepos on an instance of +// MockDependenciesService. +type DependenciesServiceUpsertDependencyReposFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 []shared1.Repo + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 []shared1.Repo + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c DependenciesServiceUpsertDependencyReposFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c DependenciesServiceUpsertDependencyReposFuncCall) Results() []interface{} { + return []interface{}{c.Result0, c.Result1} +} + +// MockExternalServiceStore is a mock implementation of the +// ExternalServiceStore interface (from the package +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) +// used for unit testing. +type MockExternalServiceStore struct { + // ListFunc is an instance of a mock function object controlling the + // behavior of the method List. + ListFunc *ExternalServiceStoreListFunc + // UpsertFunc is an instance of a mock function object controlling the + // behavior of the method Upsert. + UpsertFunc *ExternalServiceStoreUpsertFunc +} + +// NewMockExternalServiceStore creates a new mock of the +// ExternalServiceStore interface. All methods return zero values for all +// results, unless overwritten. +func NewMockExternalServiceStore() *MockExternalServiceStore { + return &MockExternalServiceStore{ + ListFunc: &ExternalServiceStoreListFunc{ + defaultHook: func(context.Context, database.ExternalServicesListOptions) (r0 []*types1.ExternalService, r1 error) { + return + }, + }, + UpsertFunc: &ExternalServiceStoreUpsertFunc{ + defaultHook: func(context.Context, ...*types1.ExternalService) (r0 error) { + return + }, + }, + } +} + +// NewStrictMockExternalServiceStore creates a new mock of the +// ExternalServiceStore interface. All methods panic on invocation, unless +// overwritten. +func NewStrictMockExternalServiceStore() *MockExternalServiceStore { + return &MockExternalServiceStore{ + ListFunc: &ExternalServiceStoreListFunc{ + defaultHook: func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) { + panic("unexpected invocation of MockExternalServiceStore.List") + }, + }, + UpsertFunc: &ExternalServiceStoreUpsertFunc{ + defaultHook: func(context.Context, ...*types1.ExternalService) error { + panic("unexpected invocation of MockExternalServiceStore.Upsert") + }, + }, + } +} + +// NewMockExternalServiceStoreFrom creates a new mock of the +// MockExternalServiceStore interface. All methods delegate to the given +// implementation, unless overwritten. +func NewMockExternalServiceStoreFrom(i ExternalServiceStore) *MockExternalServiceStore { + return &MockExternalServiceStore{ + ListFunc: &ExternalServiceStoreListFunc{ + defaultHook: i.List, + }, + UpsertFunc: &ExternalServiceStoreUpsertFunc{ + defaultHook: i.Upsert, + }, + } +} + +// ExternalServiceStoreListFunc describes the behavior when the List method +// of the parent MockExternalServiceStore instance is invoked. +type ExternalServiceStoreListFunc struct { + defaultHook func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) + hooks []func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) + history []ExternalServiceStoreListFuncCall + mutex sync.Mutex +} + +// List delegates to the next hook function in the queue and stores the +// parameter and result values of this invocation. +func (m *MockExternalServiceStore) List(v0 context.Context, v1 database.ExternalServicesListOptions) ([]*types1.ExternalService, error) { + r0, r1 := m.ListFunc.nextHook()(v0, v1) + m.ListFunc.appendCall(ExternalServiceStoreListFuncCall{v0, v1, r0, r1}) + return r0, r1 +} + +// SetDefaultHook sets function that is called when the List method of the +// parent MockExternalServiceStore instance is invoked and the hook queue is +// empty. +func (f *ExternalServiceStoreListFunc) SetDefaultHook(hook func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error)) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// List method of the parent MockExternalServiceStore instance invokes the +// hook at the front of the queue and discards it. After the queue is empty, +// the default hook function is invoked for any future action. +func (f *ExternalServiceStoreListFunc) PushHook(hook func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error)) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *ExternalServiceStoreListFunc) SetDefaultReturn(r0 []*types1.ExternalService, r1 error) { + f.SetDefaultHook(func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) { + return r0, r1 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *ExternalServiceStoreListFunc) PushReturn(r0 []*types1.ExternalService, r1 error) { + f.PushHook(func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) { + return r0, r1 + }) +} + +func (f *ExternalServiceStoreListFunc) nextHook() func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *ExternalServiceStoreListFunc) appendCall(r0 ExternalServiceStoreListFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of ExternalServiceStoreListFuncCall objects +// describing the invocations of this function. +func (f *ExternalServiceStoreListFunc) History() []ExternalServiceStoreListFuncCall { + f.mutex.Lock() + history := make([]ExternalServiceStoreListFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// ExternalServiceStoreListFuncCall is an object that describes an +// invocation of method List on an instance of MockExternalServiceStore. +type ExternalServiceStoreListFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 database.ExternalServicesListOptions + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 []*types1.ExternalService + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c ExternalServiceStoreListFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c ExternalServiceStoreListFuncCall) Results() []interface{} { + return []interface{}{c.Result0, c.Result1} +} + +// ExternalServiceStoreUpsertFunc describes the behavior when the Upsert +// method of the parent MockExternalServiceStore instance is invoked. +type ExternalServiceStoreUpsertFunc struct { + defaultHook func(context.Context, ...*types1.ExternalService) error + hooks []func(context.Context, ...*types1.ExternalService) error + history []ExternalServiceStoreUpsertFuncCall + mutex sync.Mutex +} + +// Upsert delegates to the next hook function in the queue and stores the +// parameter and result values of this invocation. +func (m *MockExternalServiceStore) Upsert(v0 context.Context, v1 ...*types1.ExternalService) error { + r0 := m.UpsertFunc.nextHook()(v0, v1...) + m.UpsertFunc.appendCall(ExternalServiceStoreUpsertFuncCall{v0, v1, r0}) + return r0 +} + +// SetDefaultHook sets function that is called when the Upsert method of the +// parent MockExternalServiceStore instance is invoked and the hook queue is +// empty. +func (f *ExternalServiceStoreUpsertFunc) SetDefaultHook(hook func(context.Context, ...*types1.ExternalService) error) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// Upsert method of the parent MockExternalServiceStore instance invokes the +// hook at the front of the queue and discards it. After the queue is empty, +// the default hook function is invoked for any future action. +func (f *ExternalServiceStoreUpsertFunc) PushHook(hook func(context.Context, ...*types1.ExternalService) error) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *ExternalServiceStoreUpsertFunc) SetDefaultReturn(r0 error) { + f.SetDefaultHook(func(context.Context, ...*types1.ExternalService) error { + return r0 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *ExternalServiceStoreUpsertFunc) PushReturn(r0 error) { + f.PushHook(func(context.Context, ...*types1.ExternalService) error { + return r0 + }) +} + +func (f *ExternalServiceStoreUpsertFunc) nextHook() func(context.Context, ...*types1.ExternalService) error { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *ExternalServiceStoreUpsertFunc) appendCall(r0 ExternalServiceStoreUpsertFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of ExternalServiceStoreUpsertFuncCall objects +// describing the invocations of this function. +func (f *ExternalServiceStoreUpsertFunc) History() []ExternalServiceStoreUpsertFuncCall { + f.mutex.Lock() + history := make([]ExternalServiceStoreUpsertFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// ExternalServiceStoreUpsertFuncCall is an object that describes an +// invocation of method Upsert on an instance of MockExternalServiceStore. +type ExternalServiceStoreUpsertFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is a slice containing the values of the variadic arguments + // passed to this method invocation. + Arg1 []*types1.ExternalService + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. The variadic slice argument is flattened in this array such +// that one positional argument and three variadic arguments would result in +// a slice of four, not two. +func (c ExternalServiceStoreUpsertFuncCall) Args() []interface{} { + trailing := []interface{}{} + for _, val := range c.Arg1 { + trailing = append(trailing, val) + } + + return append([]interface{}{c.Arg0}, trailing...) +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c ExternalServiceStoreUpsertFuncCall) Results() []interface{} { + return []interface{}{c.Result0} +} + // MockGitserverClient is a mock implementation of the GitserverClient // interface (from the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared) +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) // used for unit testing. type MockGitserverClient struct { // CommitDateFunc is an instance of a mock function object controlling @@ -3467,7 +4341,7 @@ func NewStrictMockGitserverClient() *MockGitserverClient { // NewMockGitserverClientFrom creates a new mock of the MockGitserverClient // interface. All methods delegate to the given implementation, unless // overwritten. -func NewMockGitserverClientFrom(i shared.GitserverClient) *MockGitserverClient { +func NewMockGitserverClientFrom(i GitserverClient) *MockGitserverClient { return &MockGitserverClient{ CommitDateFunc: &GitserverClientCommitDateFunc{ defaultHook: i.CommitDate, @@ -4656,9 +5530,641 @@ func (c GitserverClientResolveRevisionFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } +// MockGitserverRepoStore is a mock implementation of the GitserverRepoStore +// interface (from the package +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) +// used for unit testing. +type MockGitserverRepoStore struct { + // GetByNamesFunc is an instance of a mock function object controlling + // the behavior of the method GetByNames. + GetByNamesFunc *GitserverRepoStoreGetByNamesFunc +} + +// NewMockGitserverRepoStore creates a new mock of the GitserverRepoStore +// interface. All methods return zero values for all results, unless +// overwritten. +func NewMockGitserverRepoStore() *MockGitserverRepoStore { + return &MockGitserverRepoStore{ + GetByNamesFunc: &GitserverRepoStoreGetByNamesFunc{ + defaultHook: func(context.Context, ...api.RepoName) (r0 map[api.RepoName]*types1.GitserverRepo, r1 error) { + return + }, + }, + } +} + +// NewStrictMockGitserverRepoStore creates a new mock of the +// GitserverRepoStore interface. All methods panic on invocation, unless +// overwritten. +func NewStrictMockGitserverRepoStore() *MockGitserverRepoStore { + return &MockGitserverRepoStore{ + GetByNamesFunc: &GitserverRepoStoreGetByNamesFunc{ + defaultHook: func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) { + panic("unexpected invocation of MockGitserverRepoStore.GetByNames") + }, + }, + } +} + +// NewMockGitserverRepoStoreFrom creates a new mock of the +// MockGitserverRepoStore interface. All methods delegate to the given +// implementation, unless overwritten. +func NewMockGitserverRepoStoreFrom(i GitserverRepoStore) *MockGitserverRepoStore { + return &MockGitserverRepoStore{ + GetByNamesFunc: &GitserverRepoStoreGetByNamesFunc{ + defaultHook: i.GetByNames, + }, + } +} + +// GitserverRepoStoreGetByNamesFunc describes the behavior when the +// GetByNames method of the parent MockGitserverRepoStore instance is +// invoked. +type GitserverRepoStoreGetByNamesFunc struct { + defaultHook func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) + hooks []func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) + history []GitserverRepoStoreGetByNamesFuncCall + mutex sync.Mutex +} + +// GetByNames delegates to the next hook function in the queue and stores +// the parameter and result values of this invocation. +func (m *MockGitserverRepoStore) GetByNames(v0 context.Context, v1 ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) { + r0, r1 := m.GetByNamesFunc.nextHook()(v0, v1...) + m.GetByNamesFunc.appendCall(GitserverRepoStoreGetByNamesFuncCall{v0, v1, r0, r1}) + return r0, r1 +} + +// SetDefaultHook sets function that is called when the GetByNames method of +// the parent MockGitserverRepoStore instance is invoked and the hook queue +// is empty. +func (f *GitserverRepoStoreGetByNamesFunc) SetDefaultHook(hook func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error)) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// GetByNames method of the parent MockGitserverRepoStore instance invokes +// the hook at the front of the queue and discards it. After the queue is +// empty, the default hook function is invoked for any future action. +func (f *GitserverRepoStoreGetByNamesFunc) PushHook(hook func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error)) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *GitserverRepoStoreGetByNamesFunc) SetDefaultReturn(r0 map[api.RepoName]*types1.GitserverRepo, r1 error) { + f.SetDefaultHook(func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) { + return r0, r1 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *GitserverRepoStoreGetByNamesFunc) PushReturn(r0 map[api.RepoName]*types1.GitserverRepo, r1 error) { + f.PushHook(func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) { + return r0, r1 + }) +} + +func (f *GitserverRepoStoreGetByNamesFunc) nextHook() func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *GitserverRepoStoreGetByNamesFunc) appendCall(r0 GitserverRepoStoreGetByNamesFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of GitserverRepoStoreGetByNamesFuncCall +// objects describing the invocations of this function. +func (f *GitserverRepoStoreGetByNamesFunc) History() []GitserverRepoStoreGetByNamesFuncCall { + f.mutex.Lock() + history := make([]GitserverRepoStoreGetByNamesFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// GitserverRepoStoreGetByNamesFuncCall is an object that describes an +// invocation of method GetByNames on an instance of MockGitserverRepoStore. +type GitserverRepoStoreGetByNamesFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is a slice containing the values of the variadic arguments + // passed to this method invocation. + Arg1 []api.RepoName + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 map[api.RepoName]*types1.GitserverRepo + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. The variadic slice argument is flattened in this array such +// that one positional argument and three variadic arguments would result in +// a slice of four, not two. +func (c GitserverRepoStoreGetByNamesFuncCall) Args() []interface{} { + trailing := []interface{}{} + for _, val := range c.Arg1 { + trailing = append(trailing, val) + } + + return append([]interface{}{c.Arg0}, trailing...) +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c GitserverRepoStoreGetByNamesFuncCall) Results() []interface{} { + return []interface{}{c.Result0, c.Result1} +} + +// MockInferenceService is a mock implementation of the InferenceService +// interface (from the package +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) +// used for unit testing. +type MockInferenceService struct { + // InferIndexJobHintsFunc is an instance of a mock function object + // controlling the behavior of the method InferIndexJobHints. + InferIndexJobHintsFunc *InferenceServiceInferIndexJobHintsFunc + // InferIndexJobsFunc is an instance of a mock function object + // controlling the behavior of the method InferIndexJobs. + InferIndexJobsFunc *InferenceServiceInferIndexJobsFunc +} + +// NewMockInferenceService creates a new mock of the InferenceService +// interface. All methods return zero values for all results, unless +// overwritten. +func NewMockInferenceService() *MockInferenceService { + return &MockInferenceService{ + InferIndexJobHintsFunc: &InferenceServiceInferIndexJobHintsFunc{ + defaultHook: func(context.Context, api.RepoName, string, string) (r0 []config.IndexJobHint, r1 error) { + return + }, + }, + InferIndexJobsFunc: &InferenceServiceInferIndexJobsFunc{ + defaultHook: func(context.Context, api.RepoName, string, string) (r0 []config.IndexJob, r1 error) { + return + }, + }, + } +} + +// NewStrictMockInferenceService creates a new mock of the InferenceService +// interface. All methods panic on invocation, unless overwritten. +func NewStrictMockInferenceService() *MockInferenceService { + return &MockInferenceService{ + InferIndexJobHintsFunc: &InferenceServiceInferIndexJobHintsFunc{ + defaultHook: func(context.Context, api.RepoName, string, string) ([]config.IndexJobHint, error) { + panic("unexpected invocation of MockInferenceService.InferIndexJobHints") + }, + }, + InferIndexJobsFunc: &InferenceServiceInferIndexJobsFunc{ + defaultHook: func(context.Context, api.RepoName, string, string) ([]config.IndexJob, error) { + panic("unexpected invocation of MockInferenceService.InferIndexJobs") + }, + }, + } +} + +// NewMockInferenceServiceFrom creates a new mock of the +// MockInferenceService interface. All methods delegate to the given +// implementation, unless overwritten. +func NewMockInferenceServiceFrom(i InferenceService) *MockInferenceService { + return &MockInferenceService{ + InferIndexJobHintsFunc: &InferenceServiceInferIndexJobHintsFunc{ + defaultHook: i.InferIndexJobHints, + }, + InferIndexJobsFunc: &InferenceServiceInferIndexJobsFunc{ + defaultHook: i.InferIndexJobs, + }, + } +} + +// InferenceServiceInferIndexJobHintsFunc describes the behavior when the +// InferIndexJobHints method of the parent MockInferenceService instance is +// invoked. +type InferenceServiceInferIndexJobHintsFunc struct { + defaultHook func(context.Context, api.RepoName, string, string) ([]config.IndexJobHint, error) + hooks []func(context.Context, api.RepoName, string, string) ([]config.IndexJobHint, error) + history []InferenceServiceInferIndexJobHintsFuncCall + mutex sync.Mutex +} + +// InferIndexJobHints delegates to the next hook function in the queue and +// stores the parameter and result values of this invocation. +func (m *MockInferenceService) InferIndexJobHints(v0 context.Context, v1 api.RepoName, v2 string, v3 string) ([]config.IndexJobHint, error) { + r0, r1 := m.InferIndexJobHintsFunc.nextHook()(v0, v1, v2, v3) + m.InferIndexJobHintsFunc.appendCall(InferenceServiceInferIndexJobHintsFuncCall{v0, v1, v2, v3, r0, r1}) + return r0, r1 +} + +// SetDefaultHook sets function that is called when the InferIndexJobHints +// method of the parent MockInferenceService instance is invoked and the +// hook queue is empty. +func (f *InferenceServiceInferIndexJobHintsFunc) SetDefaultHook(hook func(context.Context, api.RepoName, string, string) ([]config.IndexJobHint, error)) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// InferIndexJobHints method of the parent MockInferenceService instance +// invokes the hook at the front of the queue and discards it. After the +// queue is empty, the default hook function is invoked for any future +// action. +func (f *InferenceServiceInferIndexJobHintsFunc) PushHook(hook func(context.Context, api.RepoName, string, string) ([]config.IndexJobHint, error)) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *InferenceServiceInferIndexJobHintsFunc) SetDefaultReturn(r0 []config.IndexJobHint, r1 error) { + f.SetDefaultHook(func(context.Context, api.RepoName, string, string) ([]config.IndexJobHint, error) { + return r0, r1 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *InferenceServiceInferIndexJobHintsFunc) PushReturn(r0 []config.IndexJobHint, r1 error) { + f.PushHook(func(context.Context, api.RepoName, string, string) ([]config.IndexJobHint, error) { + return r0, r1 + }) +} + +func (f *InferenceServiceInferIndexJobHintsFunc) nextHook() func(context.Context, api.RepoName, string, string) ([]config.IndexJobHint, error) { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *InferenceServiceInferIndexJobHintsFunc) appendCall(r0 InferenceServiceInferIndexJobHintsFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of InferenceServiceInferIndexJobHintsFuncCall +// objects describing the invocations of this function. +func (f *InferenceServiceInferIndexJobHintsFunc) History() []InferenceServiceInferIndexJobHintsFuncCall { + f.mutex.Lock() + history := make([]InferenceServiceInferIndexJobHintsFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// InferenceServiceInferIndexJobHintsFuncCall is an object that describes an +// invocation of method InferIndexJobHints on an instance of +// MockInferenceService. +type InferenceServiceInferIndexJobHintsFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 api.RepoName + // Arg2 is the value of the 3rd argument passed to this method + // invocation. + Arg2 string + // Arg3 is the value of the 4th argument passed to this method + // invocation. + Arg3 string + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 []config.IndexJobHint + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c InferenceServiceInferIndexJobHintsFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c InferenceServiceInferIndexJobHintsFuncCall) Results() []interface{} { + return []interface{}{c.Result0, c.Result1} +} + +// InferenceServiceInferIndexJobsFunc describes the behavior when the +// InferIndexJobs method of the parent MockInferenceService instance is +// invoked. +type InferenceServiceInferIndexJobsFunc struct { + defaultHook func(context.Context, api.RepoName, string, string) ([]config.IndexJob, error) + hooks []func(context.Context, api.RepoName, string, string) ([]config.IndexJob, error) + history []InferenceServiceInferIndexJobsFuncCall + mutex sync.Mutex +} + +// InferIndexJobs delegates to the next hook function in the queue and +// stores the parameter and result values of this invocation. +func (m *MockInferenceService) InferIndexJobs(v0 context.Context, v1 api.RepoName, v2 string, v3 string) ([]config.IndexJob, error) { + r0, r1 := m.InferIndexJobsFunc.nextHook()(v0, v1, v2, v3) + m.InferIndexJobsFunc.appendCall(InferenceServiceInferIndexJobsFuncCall{v0, v1, v2, v3, r0, r1}) + return r0, r1 +} + +// SetDefaultHook sets function that is called when the InferIndexJobs +// method of the parent MockInferenceService instance is invoked and the +// hook queue is empty. +func (f *InferenceServiceInferIndexJobsFunc) SetDefaultHook(hook func(context.Context, api.RepoName, string, string) ([]config.IndexJob, error)) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// InferIndexJobs method of the parent MockInferenceService instance invokes +// the hook at the front of the queue and discards it. After the queue is +// empty, the default hook function is invoked for any future action. +func (f *InferenceServiceInferIndexJobsFunc) PushHook(hook func(context.Context, api.RepoName, string, string) ([]config.IndexJob, error)) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *InferenceServiceInferIndexJobsFunc) SetDefaultReturn(r0 []config.IndexJob, r1 error) { + f.SetDefaultHook(func(context.Context, api.RepoName, string, string) ([]config.IndexJob, error) { + return r0, r1 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *InferenceServiceInferIndexJobsFunc) PushReturn(r0 []config.IndexJob, r1 error) { + f.PushHook(func(context.Context, api.RepoName, string, string) ([]config.IndexJob, error) { + return r0, r1 + }) +} + +func (f *InferenceServiceInferIndexJobsFunc) nextHook() func(context.Context, api.RepoName, string, string) ([]config.IndexJob, error) { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *InferenceServiceInferIndexJobsFunc) appendCall(r0 InferenceServiceInferIndexJobsFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of InferenceServiceInferIndexJobsFuncCall +// objects describing the invocations of this function. +func (f *InferenceServiceInferIndexJobsFunc) History() []InferenceServiceInferIndexJobsFuncCall { + f.mutex.Lock() + history := make([]InferenceServiceInferIndexJobsFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// InferenceServiceInferIndexJobsFuncCall is an object that describes an +// invocation of method InferIndexJobs on an instance of +// MockInferenceService. +type InferenceServiceInferIndexJobsFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 api.RepoName + // Arg2 is the value of the 3rd argument passed to this method + // invocation. + Arg2 string + // Arg3 is the value of the 4th argument passed to this method + // invocation. + Arg3 string + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 []config.IndexJob + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c InferenceServiceInferIndexJobsFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c InferenceServiceInferIndexJobsFuncCall) Results() []interface{} { + return []interface{}{c.Result0, c.Result1} +} + +// MockPolicyMatcher is a mock implementation of the PolicyMatcher interface +// (from the package +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) +// used for unit testing. +type MockPolicyMatcher struct { + // CommitsDescribedByPolicyInternalFunc is an instance of a mock + // function object controlling the behavior of the method + // CommitsDescribedByPolicyInternal. + CommitsDescribedByPolicyInternalFunc *PolicyMatcherCommitsDescribedByPolicyInternalFunc +} + +// NewMockPolicyMatcher creates a new mock of the PolicyMatcher interface. +// All methods return zero values for all results, unless overwritten. +func NewMockPolicyMatcher() *MockPolicyMatcher { + return &MockPolicyMatcher{ + CommitsDescribedByPolicyInternalFunc: &PolicyMatcherCommitsDescribedByPolicyInternalFunc{ + defaultHook: func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (r0 map[string][]enterprise.PolicyMatch, r1 error) { + return + }, + }, + } +} + +// NewStrictMockPolicyMatcher creates a new mock of the PolicyMatcher +// interface. All methods panic on invocation, unless overwritten. +func NewStrictMockPolicyMatcher() *MockPolicyMatcher { + return &MockPolicyMatcher{ + CommitsDescribedByPolicyInternalFunc: &PolicyMatcherCommitsDescribedByPolicyInternalFunc{ + defaultHook: func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) { + panic("unexpected invocation of MockPolicyMatcher.CommitsDescribedByPolicyInternal") + }, + }, + } +} + +// NewMockPolicyMatcherFrom creates a new mock of the MockPolicyMatcher +// interface. All methods delegate to the given implementation, unless +// overwritten. +func NewMockPolicyMatcherFrom(i PolicyMatcher) *MockPolicyMatcher { + return &MockPolicyMatcher{ + CommitsDescribedByPolicyInternalFunc: &PolicyMatcherCommitsDescribedByPolicyInternalFunc{ + defaultHook: i.CommitsDescribedByPolicyInternal, + }, + } +} + +// PolicyMatcherCommitsDescribedByPolicyInternalFunc describes the behavior +// when the CommitsDescribedByPolicyInternal method of the parent +// MockPolicyMatcher instance is invoked. +type PolicyMatcherCommitsDescribedByPolicyInternalFunc struct { + defaultHook func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) + hooks []func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) + history []PolicyMatcherCommitsDescribedByPolicyInternalFuncCall + mutex sync.Mutex +} + +// CommitsDescribedByPolicyInternal delegates to the next hook function in +// the queue and stores the parameter and result values of this invocation. +func (m *MockPolicyMatcher) CommitsDescribedByPolicyInternal(v0 context.Context, v1 int, v2 []types.ConfigurationPolicy, v3 time.Time, v4 ...string) (map[string][]enterprise.PolicyMatch, error) { + r0, r1 := m.CommitsDescribedByPolicyInternalFunc.nextHook()(v0, v1, v2, v3, v4...) + m.CommitsDescribedByPolicyInternalFunc.appendCall(PolicyMatcherCommitsDescribedByPolicyInternalFuncCall{v0, v1, v2, v3, v4, r0, r1}) + return r0, r1 +} + +// SetDefaultHook sets function that is called when the +// CommitsDescribedByPolicyInternal method of the parent MockPolicyMatcher +// instance is invoked and the hook queue is empty. +func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) SetDefaultHook(hook func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error)) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// CommitsDescribedByPolicyInternal method of the parent MockPolicyMatcher +// instance invokes the hook at the front of the queue and discards it. +// After the queue is empty, the default hook function is invoked for any +// future action. +func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) PushHook(hook func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error)) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) SetDefaultReturn(r0 map[string][]enterprise.PolicyMatch, r1 error) { + f.SetDefaultHook(func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) { + return r0, r1 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) PushReturn(r0 map[string][]enterprise.PolicyMatch, r1 error) { + f.PushHook(func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) { + return r0, r1 + }) +} + +func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) nextHook() func(context.Context, int, []types.ConfigurationPolicy, time.Time, ...string) (map[string][]enterprise.PolicyMatch, error) { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) appendCall(r0 PolicyMatcherCommitsDescribedByPolicyInternalFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of +// PolicyMatcherCommitsDescribedByPolicyInternalFuncCall objects describing +// the invocations of this function. +func (f *PolicyMatcherCommitsDescribedByPolicyInternalFunc) History() []PolicyMatcherCommitsDescribedByPolicyInternalFuncCall { + f.mutex.Lock() + history := make([]PolicyMatcherCommitsDescribedByPolicyInternalFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// PolicyMatcherCommitsDescribedByPolicyInternalFuncCall is an object that +// describes an invocation of method CommitsDescribedByPolicyInternal on an +// instance of MockPolicyMatcher. +type PolicyMatcherCommitsDescribedByPolicyInternalFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 int + // Arg2 is the value of the 3rd argument passed to this method + // invocation. + Arg2 []types.ConfigurationPolicy + // Arg3 is the value of the 4th argument passed to this method + // invocation. + Arg3 time.Time + // Arg4 is a slice containing the values of the variadic arguments + // passed to this method invocation. + Arg4 []string + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 map[string][]enterprise.PolicyMatch + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. The variadic slice argument is flattened in this array such +// that one positional argument and three variadic arguments would result in +// a slice of four, not two. +func (c PolicyMatcherCommitsDescribedByPolicyInternalFuncCall) Args() []interface{} { + trailing := []interface{}{} + for _, val := range c.Arg4 { + trailing = append(trailing, val) + } + + return append([]interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3}, trailing...) +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c PolicyMatcherCommitsDescribedByPolicyInternalFuncCall) Results() []interface{} { + return []interface{}{c.Result0, c.Result1} +} + // MockRepoUpdaterClient is a mock implementation of the RepoUpdaterClient // interface (from the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared) +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) // used for unit testing. type MockRepoUpdaterClient struct { // EnqueueRepoUpdateFunc is an instance of a mock function object @@ -4708,7 +6214,7 @@ func NewStrictMockRepoUpdaterClient() *MockRepoUpdaterClient { // NewMockRepoUpdaterClientFrom creates a new mock of the // MockRepoUpdaterClient interface. All methods delegate to the given // implementation, unless overwritten. -func NewMockRepoUpdaterClientFrom(i shared.RepoUpdaterClient) *MockRepoUpdaterClient { +func NewMockRepoUpdaterClientFrom(i RepoUpdaterClient) *MockRepoUpdaterClient { return &MockRepoUpdaterClient{ EnqueueRepoUpdateFunc: &RepoUpdaterClientEnqueueRepoUpdateFunc{ defaultHook: i.EnqueueRepoUpdate, @@ -4939,9 +6445,161 @@ func (c RepoUpdaterClientRepoLookupFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } +// MockReposStore is a mock implementation of the ReposStore interface (from +// the package +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) +// used for unit testing. +type MockReposStore struct { + // ListMinimalReposFunc is an instance of a mock function object + // controlling the behavior of the method ListMinimalRepos. + ListMinimalReposFunc *ReposStoreListMinimalReposFunc +} + +// NewMockReposStore creates a new mock of the ReposStore interface. All +// methods return zero values for all results, unless overwritten. +func NewMockReposStore() *MockReposStore { + return &MockReposStore{ + ListMinimalReposFunc: &ReposStoreListMinimalReposFunc{ + defaultHook: func(context.Context, database.ReposListOptions) (r0 []types1.MinimalRepo, r1 error) { + return + }, + }, + } +} + +// NewStrictMockReposStore creates a new mock of the ReposStore interface. +// All methods panic on invocation, unless overwritten. +func NewStrictMockReposStore() *MockReposStore { + return &MockReposStore{ + ListMinimalReposFunc: &ReposStoreListMinimalReposFunc{ + defaultHook: func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) { + panic("unexpected invocation of MockReposStore.ListMinimalRepos") + }, + }, + } +} + +// NewMockReposStoreFrom creates a new mock of the MockReposStore interface. +// All methods delegate to the given implementation, unless overwritten. +func NewMockReposStoreFrom(i ReposStore) *MockReposStore { + return &MockReposStore{ + ListMinimalReposFunc: &ReposStoreListMinimalReposFunc{ + defaultHook: i.ListMinimalRepos, + }, + } +} + +// ReposStoreListMinimalReposFunc describes the behavior when the +// ListMinimalRepos method of the parent MockReposStore instance is invoked. +type ReposStoreListMinimalReposFunc struct { + defaultHook func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) + hooks []func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) + history []ReposStoreListMinimalReposFuncCall + mutex sync.Mutex +} + +// ListMinimalRepos delegates to the next hook function in the queue and +// stores the parameter and result values of this invocation. +func (m *MockReposStore) ListMinimalRepos(v0 context.Context, v1 database.ReposListOptions) ([]types1.MinimalRepo, error) { + r0, r1 := m.ListMinimalReposFunc.nextHook()(v0, v1) + m.ListMinimalReposFunc.appendCall(ReposStoreListMinimalReposFuncCall{v0, v1, r0, r1}) + return r0, r1 +} + +// SetDefaultHook sets function that is called when the ListMinimalRepos +// method of the parent MockReposStore instance is invoked and the hook +// queue is empty. +func (f *ReposStoreListMinimalReposFunc) SetDefaultHook(hook func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error)) { + f.defaultHook = hook +} + +// PushHook adds a function to the end of hook queue. Each invocation of the +// ListMinimalRepos method of the parent MockReposStore instance invokes the +// hook at the front of the queue and discards it. After the queue is empty, +// the default hook function is invoked for any future action. +func (f *ReposStoreListMinimalReposFunc) PushHook(hook func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error)) { + f.mutex.Lock() + f.hooks = append(f.hooks, hook) + f.mutex.Unlock() +} + +// SetDefaultReturn calls SetDefaultHook with a function that returns the +// given values. +func (f *ReposStoreListMinimalReposFunc) SetDefaultReturn(r0 []types1.MinimalRepo, r1 error) { + f.SetDefaultHook(func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) { + return r0, r1 + }) +} + +// PushReturn calls PushHook with a function that returns the given values. +func (f *ReposStoreListMinimalReposFunc) PushReturn(r0 []types1.MinimalRepo, r1 error) { + f.PushHook(func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) { + return r0, r1 + }) +} + +func (f *ReposStoreListMinimalReposFunc) nextHook() func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) { + f.mutex.Lock() + defer f.mutex.Unlock() + + if len(f.hooks) == 0 { + return f.defaultHook + } + + hook := f.hooks[0] + f.hooks = f.hooks[1:] + return hook +} + +func (f *ReposStoreListMinimalReposFunc) appendCall(r0 ReposStoreListMinimalReposFuncCall) { + f.mutex.Lock() + f.history = append(f.history, r0) + f.mutex.Unlock() +} + +// History returns a sequence of ReposStoreListMinimalReposFuncCall objects +// describing the invocations of this function. +func (f *ReposStoreListMinimalReposFunc) History() []ReposStoreListMinimalReposFuncCall { + f.mutex.Lock() + history := make([]ReposStoreListMinimalReposFuncCall, len(f.history)) + copy(history, f.history) + f.mutex.Unlock() + + return history +} + +// ReposStoreListMinimalReposFuncCall is an object that describes an +// invocation of method ListMinimalRepos on an instance of MockReposStore. +type ReposStoreListMinimalReposFuncCall struct { + // Arg0 is the value of the 1st argument passed to this method + // invocation. + Arg0 context.Context + // Arg1 is the value of the 2nd argument passed to this method + // invocation. + Arg1 database.ReposListOptions + // Result0 is the value of the 1st result returned from this method + // invocation. + Result0 []types1.MinimalRepo + // Result1 is the value of the 2nd result returned from this method + // invocation. + Result1 error +} + +// Args returns an interface slice containing the arguments of this +// invocation. +func (c ReposStoreListMinimalReposFuncCall) Args() []interface{} { + return []interface{}{c.Arg0, c.Arg1} +} + +// Results returns an interface slice containing the results of this +// invocation. +func (c ReposStoreListMinimalReposFuncCall) Results() []interface{} { + return []interface{}{c.Result0, c.Result1} +} + // MockUploadService is a mock implementation of the UploadService interface // (from the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared) +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) // used for unit testing. type MockUploadService struct { // GetDirtyRepositoriesFunc is an instance of a mock function object @@ -4995,7 +6653,7 @@ func NewMockUploadService() *MockUploadService { }, }, ReferencesForUploadFunc: &UploadServiceReferencesForUploadFunc{ - defaultHook: func(context.Context, int) (r0 shared1.PackageReferenceScanner, r1 error) { + defaultHook: func(context.Context, int) (r0 shared2.PackageReferenceScanner, r1 error) { return }, }, @@ -5032,7 +6690,7 @@ func NewStrictMockUploadService() *MockUploadService { }, }, ReferencesForUploadFunc: &UploadServiceReferencesForUploadFunc{ - defaultHook: func(context.Context, int) (shared1.PackageReferenceScanner, error) { + defaultHook: func(context.Context, int) (shared2.PackageReferenceScanner, error) { panic("unexpected invocation of MockUploadService.ReferencesForUpload") }, }, @@ -5042,7 +6700,7 @@ func NewStrictMockUploadService() *MockUploadService { // NewMockUploadServiceFrom creates a new mock of the MockUploadService // interface. All methods delegate to the given implementation, unless // overwritten. -func NewMockUploadServiceFrom(i shared.UploadService) *MockUploadService { +func NewMockUploadServiceFrom(i UploadService) *MockUploadService { return &MockUploadService{ GetDirtyRepositoriesFunc: &UploadServiceGetDirtyRepositoriesFunc{ defaultHook: i.GetDirtyRepositories, @@ -5642,15 +7300,15 @@ func (c UploadServiceGetUploadsByIDsFuncCall) Results() []interface{} { // ReferencesForUpload method of the parent MockUploadService instance is // invoked. type UploadServiceReferencesForUploadFunc struct { - defaultHook func(context.Context, int) (shared1.PackageReferenceScanner, error) - hooks []func(context.Context, int) (shared1.PackageReferenceScanner, error) + defaultHook func(context.Context, int) (shared2.PackageReferenceScanner, error) + hooks []func(context.Context, int) (shared2.PackageReferenceScanner, error) history []UploadServiceReferencesForUploadFuncCall mutex sync.Mutex } // ReferencesForUpload delegates to the next hook function in the queue and // stores the parameter and result values of this invocation. -func (m *MockUploadService) ReferencesForUpload(v0 context.Context, v1 int) (shared1.PackageReferenceScanner, error) { +func (m *MockUploadService) ReferencesForUpload(v0 context.Context, v1 int) (shared2.PackageReferenceScanner, error) { r0, r1 := m.ReferencesForUploadFunc.nextHook()(v0, v1) m.ReferencesForUploadFunc.appendCall(UploadServiceReferencesForUploadFuncCall{v0, v1, r0, r1}) return r0, r1 @@ -5659,7 +7317,7 @@ func (m *MockUploadService) ReferencesForUpload(v0 context.Context, v1 int) (sha // SetDefaultHook sets function that is called when the ReferencesForUpload // method of the parent MockUploadService instance is invoked and the hook // queue is empty. -func (f *UploadServiceReferencesForUploadFunc) SetDefaultHook(hook func(context.Context, int) (shared1.PackageReferenceScanner, error)) { +func (f *UploadServiceReferencesForUploadFunc) SetDefaultHook(hook func(context.Context, int) (shared2.PackageReferenceScanner, error)) { f.defaultHook = hook } @@ -5668,7 +7326,7 @@ func (f *UploadServiceReferencesForUploadFunc) SetDefaultHook(hook func(context. // invokes the hook at the front of the queue and discards it. After the // queue is empty, the default hook function is invoked for any future // action. -func (f *UploadServiceReferencesForUploadFunc) PushHook(hook func(context.Context, int) (shared1.PackageReferenceScanner, error)) { +func (f *UploadServiceReferencesForUploadFunc) PushHook(hook func(context.Context, int) (shared2.PackageReferenceScanner, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -5676,20 +7334,20 @@ func (f *UploadServiceReferencesForUploadFunc) PushHook(hook func(context.Contex // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *UploadServiceReferencesForUploadFunc) SetDefaultReturn(r0 shared1.PackageReferenceScanner, r1 error) { - f.SetDefaultHook(func(context.Context, int) (shared1.PackageReferenceScanner, error) { +func (f *UploadServiceReferencesForUploadFunc) SetDefaultReturn(r0 shared2.PackageReferenceScanner, r1 error) { + f.SetDefaultHook(func(context.Context, int) (shared2.PackageReferenceScanner, error) { return r0, r1 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *UploadServiceReferencesForUploadFunc) PushReturn(r0 shared1.PackageReferenceScanner, r1 error) { - f.PushHook(func(context.Context, int) (shared1.PackageReferenceScanner, error) { +func (f *UploadServiceReferencesForUploadFunc) PushReturn(r0 shared2.PackageReferenceScanner, r1 error) { + f.PushHook(func(context.Context, int) (shared2.PackageReferenceScanner, error) { return r0, r1 }) } -func (f *UploadServiceReferencesForUploadFunc) nextHook() func(context.Context, int) (shared1.PackageReferenceScanner, error) { +func (f *UploadServiceReferencesForUploadFunc) nextHook() func(context.Context, int) (shared2.PackageReferenceScanner, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -5731,7 +7389,7 @@ type UploadServiceReferencesForUploadFuncCall struct { Arg1 int // Result0 is the value of the 1st result returned from this method // invocation. - Result0 shared1.PackageReferenceScanner + Result0 shared2.PackageReferenceScanner // Result1 is the value of the 2nd result returned from this method // invocation. Result1 error @@ -5749,1193 +7407,6 @@ func (c UploadServiceReferencesForUploadFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } -// MockAutoIndexingService is a mock implementation of the -// AutoIndexingService interface (from the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) -// used for unit testing. -type MockAutoIndexingService struct { - // InsertDependencyIndexingJobFunc is an instance of a mock function - // object controlling the behavior of the method - // InsertDependencyIndexingJob. - InsertDependencyIndexingJobFunc *AutoIndexingServiceInsertDependencyIndexingJobFunc - // QueueIndexesFunc is an instance of a mock function object controlling - // the behavior of the method QueueIndexes. - QueueIndexesFunc *AutoIndexingServiceQueueIndexesFunc - // QueueIndexesForPackageFunc is an instance of a mock function object - // controlling the behavior of the method QueueIndexesForPackage. - QueueIndexesForPackageFunc *AutoIndexingServiceQueueIndexesForPackageFunc -} - -// NewMockAutoIndexingService creates a new mock of the AutoIndexingService -// interface. All methods return zero values for all results, unless -// overwritten. -func NewMockAutoIndexingService() *MockAutoIndexingService { - return &MockAutoIndexingService{ - InsertDependencyIndexingJobFunc: &AutoIndexingServiceInsertDependencyIndexingJobFunc{ - defaultHook: func(context.Context, int, string, time.Time) (r0 int, r1 error) { - return - }, - }, - QueueIndexesFunc: &AutoIndexingServiceQueueIndexesFunc{ - defaultHook: func(context.Context, int, string, string, bool, bool) (r0 []types.Index, r1 error) { - return - }, - }, - QueueIndexesForPackageFunc: &AutoIndexingServiceQueueIndexesForPackageFunc{ - defaultHook: func(context.Context, precise.Package) (r0 error) { - return - }, - }, - } -} - -// NewStrictMockAutoIndexingService creates a new mock of the -// AutoIndexingService interface. All methods panic on invocation, unless -// overwritten. -func NewStrictMockAutoIndexingService() *MockAutoIndexingService { - return &MockAutoIndexingService{ - InsertDependencyIndexingJobFunc: &AutoIndexingServiceInsertDependencyIndexingJobFunc{ - defaultHook: func(context.Context, int, string, time.Time) (int, error) { - panic("unexpected invocation of MockAutoIndexingService.InsertDependencyIndexingJob") - }, - }, - QueueIndexesFunc: &AutoIndexingServiceQueueIndexesFunc{ - defaultHook: func(context.Context, int, string, string, bool, bool) ([]types.Index, error) { - panic("unexpected invocation of MockAutoIndexingService.QueueIndexes") - }, - }, - QueueIndexesForPackageFunc: &AutoIndexingServiceQueueIndexesForPackageFunc{ - defaultHook: func(context.Context, precise.Package) error { - panic("unexpected invocation of MockAutoIndexingService.QueueIndexesForPackage") - }, - }, - } -} - -// NewMockAutoIndexingServiceFrom creates a new mock of the -// MockAutoIndexingService interface. All methods delegate to the given -// implementation, unless overwritten. -func NewMockAutoIndexingServiceFrom(i AutoIndexingService) *MockAutoIndexingService { - return &MockAutoIndexingService{ - InsertDependencyIndexingJobFunc: &AutoIndexingServiceInsertDependencyIndexingJobFunc{ - defaultHook: i.InsertDependencyIndexingJob, - }, - QueueIndexesFunc: &AutoIndexingServiceQueueIndexesFunc{ - defaultHook: i.QueueIndexes, - }, - QueueIndexesForPackageFunc: &AutoIndexingServiceQueueIndexesForPackageFunc{ - defaultHook: i.QueueIndexesForPackage, - }, - } -} - -// AutoIndexingServiceInsertDependencyIndexingJobFunc describes the behavior -// when the InsertDependencyIndexingJob method of the parent -// MockAutoIndexingService instance is invoked. -type AutoIndexingServiceInsertDependencyIndexingJobFunc struct { - defaultHook func(context.Context, int, string, time.Time) (int, error) - hooks []func(context.Context, int, string, time.Time) (int, error) - history []AutoIndexingServiceInsertDependencyIndexingJobFuncCall - mutex sync.Mutex -} - -// InsertDependencyIndexingJob delegates to the next hook function in the -// queue and stores the parameter and result values of this invocation. -func (m *MockAutoIndexingService) InsertDependencyIndexingJob(v0 context.Context, v1 int, v2 string, v3 time.Time) (int, error) { - r0, r1 := m.InsertDependencyIndexingJobFunc.nextHook()(v0, v1, v2, v3) - m.InsertDependencyIndexingJobFunc.appendCall(AutoIndexingServiceInsertDependencyIndexingJobFuncCall{v0, v1, v2, v3, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the -// InsertDependencyIndexingJob method of the parent MockAutoIndexingService -// instance is invoked and the hook queue is empty. -func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) SetDefaultHook(hook func(context.Context, int, string, time.Time) (int, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// InsertDependencyIndexingJob method of the parent MockAutoIndexingService -// instance invokes the hook at the front of the queue and discards it. -// After the queue is empty, the default hook function is invoked for any -// future action. -func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) PushHook(hook func(context.Context, int, string, time.Time) (int, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) SetDefaultReturn(r0 int, r1 error) { - f.SetDefaultHook(func(context.Context, int, string, time.Time) (int, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) PushReturn(r0 int, r1 error) { - f.PushHook(func(context.Context, int, string, time.Time) (int, error) { - return r0, r1 - }) -} - -func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) nextHook() func(context.Context, int, string, time.Time) (int, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) appendCall(r0 AutoIndexingServiceInsertDependencyIndexingJobFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of -// AutoIndexingServiceInsertDependencyIndexingJobFuncCall objects describing -// the invocations of this function. -func (f *AutoIndexingServiceInsertDependencyIndexingJobFunc) History() []AutoIndexingServiceInsertDependencyIndexingJobFuncCall { - f.mutex.Lock() - history := make([]AutoIndexingServiceInsertDependencyIndexingJobFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// AutoIndexingServiceInsertDependencyIndexingJobFuncCall is an object that -// describes an invocation of method InsertDependencyIndexingJob on an -// instance of MockAutoIndexingService. -type AutoIndexingServiceInsertDependencyIndexingJobFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 context.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 int - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 string - // Arg3 is the value of the 4th argument passed to this method - // invocation. - Arg3 time.Time - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 int - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c AutoIndexingServiceInsertDependencyIndexingJobFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c AutoIndexingServiceInsertDependencyIndexingJobFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// AutoIndexingServiceQueueIndexesFunc describes the behavior when the -// QueueIndexes method of the parent MockAutoIndexingService instance is -// invoked. -type AutoIndexingServiceQueueIndexesFunc struct { - defaultHook func(context.Context, int, string, string, bool, bool) ([]types.Index, error) - hooks []func(context.Context, int, string, string, bool, bool) ([]types.Index, error) - history []AutoIndexingServiceQueueIndexesFuncCall - mutex sync.Mutex -} - -// QueueIndexes delegates to the next hook function in the queue and stores -// the parameter and result values of this invocation. -func (m *MockAutoIndexingService) QueueIndexes(v0 context.Context, v1 int, v2 string, v3 string, v4 bool, v5 bool) ([]types.Index, error) { - r0, r1 := m.QueueIndexesFunc.nextHook()(v0, v1, v2, v3, v4, v5) - m.QueueIndexesFunc.appendCall(AutoIndexingServiceQueueIndexesFuncCall{v0, v1, v2, v3, v4, v5, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the QueueIndexes method -// of the parent MockAutoIndexingService instance is invoked and the hook -// queue is empty. -func (f *AutoIndexingServiceQueueIndexesFunc) SetDefaultHook(hook func(context.Context, int, string, string, bool, bool) ([]types.Index, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// QueueIndexes method of the parent MockAutoIndexingService instance -// invokes the hook at the front of the queue and discards it. After the -// queue is empty, the default hook function is invoked for any future -// action. -func (f *AutoIndexingServiceQueueIndexesFunc) PushHook(hook func(context.Context, int, string, string, bool, bool) ([]types.Index, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *AutoIndexingServiceQueueIndexesFunc) SetDefaultReturn(r0 []types.Index, r1 error) { - f.SetDefaultHook(func(context.Context, int, string, string, bool, bool) ([]types.Index, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *AutoIndexingServiceQueueIndexesFunc) PushReturn(r0 []types.Index, r1 error) { - f.PushHook(func(context.Context, int, string, string, bool, bool) ([]types.Index, error) { - return r0, r1 - }) -} - -func (f *AutoIndexingServiceQueueIndexesFunc) nextHook() func(context.Context, int, string, string, bool, bool) ([]types.Index, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *AutoIndexingServiceQueueIndexesFunc) appendCall(r0 AutoIndexingServiceQueueIndexesFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of AutoIndexingServiceQueueIndexesFuncCall -// objects describing the invocations of this function. -func (f *AutoIndexingServiceQueueIndexesFunc) History() []AutoIndexingServiceQueueIndexesFuncCall { - f.mutex.Lock() - history := make([]AutoIndexingServiceQueueIndexesFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// AutoIndexingServiceQueueIndexesFuncCall is an object that describes an -// invocation of method QueueIndexes on an instance of -// MockAutoIndexingService. -type AutoIndexingServiceQueueIndexesFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 context.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 int - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 string - // Arg3 is the value of the 4th argument passed to this method - // invocation. - Arg3 string - // Arg4 is the value of the 5th argument passed to this method - // invocation. - Arg4 bool - // Arg5 is the value of the 6th argument passed to this method - // invocation. - Arg5 bool - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 []types.Index - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c AutoIndexingServiceQueueIndexesFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3, c.Arg4, c.Arg5} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c AutoIndexingServiceQueueIndexesFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// AutoIndexingServiceQueueIndexesForPackageFunc describes the behavior when -// the QueueIndexesForPackage method of the parent MockAutoIndexingService -// instance is invoked. -type AutoIndexingServiceQueueIndexesForPackageFunc struct { - defaultHook func(context.Context, precise.Package) error - hooks []func(context.Context, precise.Package) error - history []AutoIndexingServiceQueueIndexesForPackageFuncCall - mutex sync.Mutex -} - -// QueueIndexesForPackage delegates to the next hook function in the queue -// and stores the parameter and result values of this invocation. -func (m *MockAutoIndexingService) QueueIndexesForPackage(v0 context.Context, v1 precise.Package) error { - r0 := m.QueueIndexesForPackageFunc.nextHook()(v0, v1) - m.QueueIndexesForPackageFunc.appendCall(AutoIndexingServiceQueueIndexesForPackageFuncCall{v0, v1, r0}) - return r0 -} - -// SetDefaultHook sets function that is called when the -// QueueIndexesForPackage method of the parent MockAutoIndexingService -// instance is invoked and the hook queue is empty. -func (f *AutoIndexingServiceQueueIndexesForPackageFunc) SetDefaultHook(hook func(context.Context, precise.Package) error) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// QueueIndexesForPackage method of the parent MockAutoIndexingService -// instance invokes the hook at the front of the queue and discards it. -// After the queue is empty, the default hook function is invoked for any -// future action. -func (f *AutoIndexingServiceQueueIndexesForPackageFunc) PushHook(hook func(context.Context, precise.Package) error) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *AutoIndexingServiceQueueIndexesForPackageFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(context.Context, precise.Package) error { - return r0 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *AutoIndexingServiceQueueIndexesForPackageFunc) PushReturn(r0 error) { - f.PushHook(func(context.Context, precise.Package) error { - return r0 - }) -} - -func (f *AutoIndexingServiceQueueIndexesForPackageFunc) nextHook() func(context.Context, precise.Package) error { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *AutoIndexingServiceQueueIndexesForPackageFunc) appendCall(r0 AutoIndexingServiceQueueIndexesForPackageFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of -// AutoIndexingServiceQueueIndexesForPackageFuncCall objects describing the -// invocations of this function. -func (f *AutoIndexingServiceQueueIndexesForPackageFunc) History() []AutoIndexingServiceQueueIndexesForPackageFuncCall { - f.mutex.Lock() - history := make([]AutoIndexingServiceQueueIndexesForPackageFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// AutoIndexingServiceQueueIndexesForPackageFuncCall is an object that -// describes an invocation of method QueueIndexesForPackage on an instance -// of MockAutoIndexingService. -type AutoIndexingServiceQueueIndexesForPackageFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 context.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 precise.Package - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c AutoIndexingServiceQueueIndexesForPackageFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c AutoIndexingServiceQueueIndexesForPackageFuncCall) Results() []interface{} { - return []interface{}{c.Result0} -} - -// MockDependenciesService is a mock implementation of the -// DependenciesService interface (from the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) -// used for unit testing. -type MockDependenciesService struct { - // UpsertDependencyReposFunc is an instance of a mock function object - // controlling the behavior of the method UpsertDependencyRepos. - UpsertDependencyReposFunc *DependenciesServiceUpsertDependencyReposFunc -} - -// NewMockDependenciesService creates a new mock of the DependenciesService -// interface. All methods return zero values for all results, unless -// overwritten. -func NewMockDependenciesService() *MockDependenciesService { - return &MockDependenciesService{ - UpsertDependencyReposFunc: &DependenciesServiceUpsertDependencyReposFunc{ - defaultHook: func(context.Context, []shared2.Repo) (r0 []shared2.Repo, r1 error) { - return - }, - }, - } -} - -// NewStrictMockDependenciesService creates a new mock of the -// DependenciesService interface. All methods panic on invocation, unless -// overwritten. -func NewStrictMockDependenciesService() *MockDependenciesService { - return &MockDependenciesService{ - UpsertDependencyReposFunc: &DependenciesServiceUpsertDependencyReposFunc{ - defaultHook: func(context.Context, []shared2.Repo) ([]shared2.Repo, error) { - panic("unexpected invocation of MockDependenciesService.UpsertDependencyRepos") - }, - }, - } -} - -// NewMockDependenciesServiceFrom creates a new mock of the -// MockDependenciesService interface. All methods delegate to the given -// implementation, unless overwritten. -func NewMockDependenciesServiceFrom(i DependenciesService) *MockDependenciesService { - return &MockDependenciesService{ - UpsertDependencyReposFunc: &DependenciesServiceUpsertDependencyReposFunc{ - defaultHook: i.UpsertDependencyRepos, - }, - } -} - -// DependenciesServiceUpsertDependencyReposFunc describes the behavior when -// the UpsertDependencyRepos method of the parent MockDependenciesService -// instance is invoked. -type DependenciesServiceUpsertDependencyReposFunc struct { - defaultHook func(context.Context, []shared2.Repo) ([]shared2.Repo, error) - hooks []func(context.Context, []shared2.Repo) ([]shared2.Repo, error) - history []DependenciesServiceUpsertDependencyReposFuncCall - mutex sync.Mutex -} - -// UpsertDependencyRepos delegates to the next hook function in the queue -// and stores the parameter and result values of this invocation. -func (m *MockDependenciesService) UpsertDependencyRepos(v0 context.Context, v1 []shared2.Repo) ([]shared2.Repo, error) { - r0, r1 := m.UpsertDependencyReposFunc.nextHook()(v0, v1) - m.UpsertDependencyReposFunc.appendCall(DependenciesServiceUpsertDependencyReposFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the -// UpsertDependencyRepos method of the parent MockDependenciesService -// instance is invoked and the hook queue is empty. -func (f *DependenciesServiceUpsertDependencyReposFunc) SetDefaultHook(hook func(context.Context, []shared2.Repo) ([]shared2.Repo, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// UpsertDependencyRepos method of the parent MockDependenciesService -// instance invokes the hook at the front of the queue and discards it. -// After the queue is empty, the default hook function is invoked for any -// future action. -func (f *DependenciesServiceUpsertDependencyReposFunc) PushHook(hook func(context.Context, []shared2.Repo) ([]shared2.Repo, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *DependenciesServiceUpsertDependencyReposFunc) SetDefaultReturn(r0 []shared2.Repo, r1 error) { - f.SetDefaultHook(func(context.Context, []shared2.Repo) ([]shared2.Repo, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *DependenciesServiceUpsertDependencyReposFunc) PushReturn(r0 []shared2.Repo, r1 error) { - f.PushHook(func(context.Context, []shared2.Repo) ([]shared2.Repo, error) { - return r0, r1 - }) -} - -func (f *DependenciesServiceUpsertDependencyReposFunc) nextHook() func(context.Context, []shared2.Repo) ([]shared2.Repo, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *DependenciesServiceUpsertDependencyReposFunc) appendCall(r0 DependenciesServiceUpsertDependencyReposFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of -// DependenciesServiceUpsertDependencyReposFuncCall objects describing the -// invocations of this function. -func (f *DependenciesServiceUpsertDependencyReposFunc) History() []DependenciesServiceUpsertDependencyReposFuncCall { - f.mutex.Lock() - history := make([]DependenciesServiceUpsertDependencyReposFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// DependenciesServiceUpsertDependencyReposFuncCall is an object that -// describes an invocation of method UpsertDependencyRepos on an instance of -// MockDependenciesService. -type DependenciesServiceUpsertDependencyReposFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 context.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 []shared2.Repo - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 []shared2.Repo - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c DependenciesServiceUpsertDependencyReposFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c DependenciesServiceUpsertDependencyReposFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// MockExternalServiceStore is a mock implementation of the -// ExternalServiceStore interface (from the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) -// used for unit testing. -type MockExternalServiceStore struct { - // ListFunc is an instance of a mock function object controlling the - // behavior of the method List. - ListFunc *ExternalServiceStoreListFunc - // UpsertFunc is an instance of a mock function object controlling the - // behavior of the method Upsert. - UpsertFunc *ExternalServiceStoreUpsertFunc -} - -// NewMockExternalServiceStore creates a new mock of the -// ExternalServiceStore interface. All methods return zero values for all -// results, unless overwritten. -func NewMockExternalServiceStore() *MockExternalServiceStore { - return &MockExternalServiceStore{ - ListFunc: &ExternalServiceStoreListFunc{ - defaultHook: func(context.Context, database.ExternalServicesListOptions) (r0 []*types1.ExternalService, r1 error) { - return - }, - }, - UpsertFunc: &ExternalServiceStoreUpsertFunc{ - defaultHook: func(context.Context, ...*types1.ExternalService) (r0 error) { - return - }, - }, - } -} - -// NewStrictMockExternalServiceStore creates a new mock of the -// ExternalServiceStore interface. All methods panic on invocation, unless -// overwritten. -func NewStrictMockExternalServiceStore() *MockExternalServiceStore { - return &MockExternalServiceStore{ - ListFunc: &ExternalServiceStoreListFunc{ - defaultHook: func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) { - panic("unexpected invocation of MockExternalServiceStore.List") - }, - }, - UpsertFunc: &ExternalServiceStoreUpsertFunc{ - defaultHook: func(context.Context, ...*types1.ExternalService) error { - panic("unexpected invocation of MockExternalServiceStore.Upsert") - }, - }, - } -} - -// NewMockExternalServiceStoreFrom creates a new mock of the -// MockExternalServiceStore interface. All methods delegate to the given -// implementation, unless overwritten. -func NewMockExternalServiceStoreFrom(i ExternalServiceStore) *MockExternalServiceStore { - return &MockExternalServiceStore{ - ListFunc: &ExternalServiceStoreListFunc{ - defaultHook: i.List, - }, - UpsertFunc: &ExternalServiceStoreUpsertFunc{ - defaultHook: i.Upsert, - }, - } -} - -// ExternalServiceStoreListFunc describes the behavior when the List method -// of the parent MockExternalServiceStore instance is invoked. -type ExternalServiceStoreListFunc struct { - defaultHook func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) - hooks []func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) - history []ExternalServiceStoreListFuncCall - mutex sync.Mutex -} - -// List delegates to the next hook function in the queue and stores the -// parameter and result values of this invocation. -func (m *MockExternalServiceStore) List(v0 context.Context, v1 database.ExternalServicesListOptions) ([]*types1.ExternalService, error) { - r0, r1 := m.ListFunc.nextHook()(v0, v1) - m.ListFunc.appendCall(ExternalServiceStoreListFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the List method of the -// parent MockExternalServiceStore instance is invoked and the hook queue is -// empty. -func (f *ExternalServiceStoreListFunc) SetDefaultHook(hook func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// List method of the parent MockExternalServiceStore instance invokes the -// hook at the front of the queue and discards it. After the queue is empty, -// the default hook function is invoked for any future action. -func (f *ExternalServiceStoreListFunc) PushHook(hook func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *ExternalServiceStoreListFunc) SetDefaultReturn(r0 []*types1.ExternalService, r1 error) { - f.SetDefaultHook(func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *ExternalServiceStoreListFunc) PushReturn(r0 []*types1.ExternalService, r1 error) { - f.PushHook(func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) { - return r0, r1 - }) -} - -func (f *ExternalServiceStoreListFunc) nextHook() func(context.Context, database.ExternalServicesListOptions) ([]*types1.ExternalService, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *ExternalServiceStoreListFunc) appendCall(r0 ExternalServiceStoreListFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of ExternalServiceStoreListFuncCall objects -// describing the invocations of this function. -func (f *ExternalServiceStoreListFunc) History() []ExternalServiceStoreListFuncCall { - f.mutex.Lock() - history := make([]ExternalServiceStoreListFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// ExternalServiceStoreListFuncCall is an object that describes an -// invocation of method List on an instance of MockExternalServiceStore. -type ExternalServiceStoreListFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 context.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 database.ExternalServicesListOptions - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 []*types1.ExternalService - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c ExternalServiceStoreListFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c ExternalServiceStoreListFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// ExternalServiceStoreUpsertFunc describes the behavior when the Upsert -// method of the parent MockExternalServiceStore instance is invoked. -type ExternalServiceStoreUpsertFunc struct { - defaultHook func(context.Context, ...*types1.ExternalService) error - hooks []func(context.Context, ...*types1.ExternalService) error - history []ExternalServiceStoreUpsertFuncCall - mutex sync.Mutex -} - -// Upsert delegates to the next hook function in the queue and stores the -// parameter and result values of this invocation. -func (m *MockExternalServiceStore) Upsert(v0 context.Context, v1 ...*types1.ExternalService) error { - r0 := m.UpsertFunc.nextHook()(v0, v1...) - m.UpsertFunc.appendCall(ExternalServiceStoreUpsertFuncCall{v0, v1, r0}) - return r0 -} - -// SetDefaultHook sets function that is called when the Upsert method of the -// parent MockExternalServiceStore instance is invoked and the hook queue is -// empty. -func (f *ExternalServiceStoreUpsertFunc) SetDefaultHook(hook func(context.Context, ...*types1.ExternalService) error) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// Upsert method of the parent MockExternalServiceStore instance invokes the -// hook at the front of the queue and discards it. After the queue is empty, -// the default hook function is invoked for any future action. -func (f *ExternalServiceStoreUpsertFunc) PushHook(hook func(context.Context, ...*types1.ExternalService) error) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *ExternalServiceStoreUpsertFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(context.Context, ...*types1.ExternalService) error { - return r0 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *ExternalServiceStoreUpsertFunc) PushReturn(r0 error) { - f.PushHook(func(context.Context, ...*types1.ExternalService) error { - return r0 - }) -} - -func (f *ExternalServiceStoreUpsertFunc) nextHook() func(context.Context, ...*types1.ExternalService) error { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *ExternalServiceStoreUpsertFunc) appendCall(r0 ExternalServiceStoreUpsertFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of ExternalServiceStoreUpsertFuncCall objects -// describing the invocations of this function. -func (f *ExternalServiceStoreUpsertFunc) History() []ExternalServiceStoreUpsertFuncCall { - f.mutex.Lock() - history := make([]ExternalServiceStoreUpsertFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// ExternalServiceStoreUpsertFuncCall is an object that describes an -// invocation of method Upsert on an instance of MockExternalServiceStore. -type ExternalServiceStoreUpsertFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 context.Context - // Arg1 is a slice containing the values of the variadic arguments - // passed to this method invocation. - Arg1 []*types1.ExternalService - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. The variadic slice argument is flattened in this array such -// that one positional argument and three variadic arguments would result in -// a slice of four, not two. -func (c ExternalServiceStoreUpsertFuncCall) Args() []interface{} { - trailing := []interface{}{} - for _, val := range c.Arg1 { - trailing = append(trailing, val) - } - - return append([]interface{}{c.Arg0}, trailing...) -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c ExternalServiceStoreUpsertFuncCall) Results() []interface{} { - return []interface{}{c.Result0} -} - -// MockGitserverRepoStore is a mock implementation of the GitserverRepoStore -// interface (from the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) -// used for unit testing. -type MockGitserverRepoStore struct { - // GetByNamesFunc is an instance of a mock function object controlling - // the behavior of the method GetByNames. - GetByNamesFunc *GitserverRepoStoreGetByNamesFunc -} - -// NewMockGitserverRepoStore creates a new mock of the GitserverRepoStore -// interface. All methods return zero values for all results, unless -// overwritten. -func NewMockGitserverRepoStore() *MockGitserverRepoStore { - return &MockGitserverRepoStore{ - GetByNamesFunc: &GitserverRepoStoreGetByNamesFunc{ - defaultHook: func(context.Context, ...api.RepoName) (r0 map[api.RepoName]*types1.GitserverRepo, r1 error) { - return - }, - }, - } -} - -// NewStrictMockGitserverRepoStore creates a new mock of the -// GitserverRepoStore interface. All methods panic on invocation, unless -// overwritten. -func NewStrictMockGitserverRepoStore() *MockGitserverRepoStore { - return &MockGitserverRepoStore{ - GetByNamesFunc: &GitserverRepoStoreGetByNamesFunc{ - defaultHook: func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) { - panic("unexpected invocation of MockGitserverRepoStore.GetByNames") - }, - }, - } -} - -// NewMockGitserverRepoStoreFrom creates a new mock of the -// MockGitserverRepoStore interface. All methods delegate to the given -// implementation, unless overwritten. -func NewMockGitserverRepoStoreFrom(i GitserverRepoStore) *MockGitserverRepoStore { - return &MockGitserverRepoStore{ - GetByNamesFunc: &GitserverRepoStoreGetByNamesFunc{ - defaultHook: i.GetByNames, - }, - } -} - -// GitserverRepoStoreGetByNamesFunc describes the behavior when the -// GetByNames method of the parent MockGitserverRepoStore instance is -// invoked. -type GitserverRepoStoreGetByNamesFunc struct { - defaultHook func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) - hooks []func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) - history []GitserverRepoStoreGetByNamesFuncCall - mutex sync.Mutex -} - -// GetByNames delegates to the next hook function in the queue and stores -// the parameter and result values of this invocation. -func (m *MockGitserverRepoStore) GetByNames(v0 context.Context, v1 ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) { - r0, r1 := m.GetByNamesFunc.nextHook()(v0, v1...) - m.GetByNamesFunc.appendCall(GitserverRepoStoreGetByNamesFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the GetByNames method of -// the parent MockGitserverRepoStore instance is invoked and the hook queue -// is empty. -func (f *GitserverRepoStoreGetByNamesFunc) SetDefaultHook(hook func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// GetByNames method of the parent MockGitserverRepoStore instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *GitserverRepoStoreGetByNamesFunc) PushHook(hook func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *GitserverRepoStoreGetByNamesFunc) SetDefaultReturn(r0 map[api.RepoName]*types1.GitserverRepo, r1 error) { - f.SetDefaultHook(func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *GitserverRepoStoreGetByNamesFunc) PushReturn(r0 map[api.RepoName]*types1.GitserverRepo, r1 error) { - f.PushHook(func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) { - return r0, r1 - }) -} - -func (f *GitserverRepoStoreGetByNamesFunc) nextHook() func(context.Context, ...api.RepoName) (map[api.RepoName]*types1.GitserverRepo, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *GitserverRepoStoreGetByNamesFunc) appendCall(r0 GitserverRepoStoreGetByNamesFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of GitserverRepoStoreGetByNamesFuncCall -// objects describing the invocations of this function. -func (f *GitserverRepoStoreGetByNamesFunc) History() []GitserverRepoStoreGetByNamesFuncCall { - f.mutex.Lock() - history := make([]GitserverRepoStoreGetByNamesFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// GitserverRepoStoreGetByNamesFuncCall is an object that describes an -// invocation of method GetByNames on an instance of MockGitserverRepoStore. -type GitserverRepoStoreGetByNamesFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 context.Context - // Arg1 is a slice containing the values of the variadic arguments - // passed to this method invocation. - Arg1 []api.RepoName - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 map[api.RepoName]*types1.GitserverRepo - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. The variadic slice argument is flattened in this array such -// that one positional argument and three variadic arguments would result in -// a slice of four, not two. -func (c GitserverRepoStoreGetByNamesFuncCall) Args() []interface{} { - trailing := []interface{}{} - for _, val := range c.Arg1 { - trailing = append(trailing, val) - } - - return append([]interface{}{c.Arg0}, trailing...) -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c GitserverRepoStoreGetByNamesFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// MockReposStore is a mock implementation of the ReposStore interface (from -// the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background) -// used for unit testing. -type MockReposStore struct { - // ListMinimalReposFunc is an instance of a mock function object - // controlling the behavior of the method ListMinimalRepos. - ListMinimalReposFunc *ReposStoreListMinimalReposFunc -} - -// NewMockReposStore creates a new mock of the ReposStore interface. All -// methods return zero values for all results, unless overwritten. -func NewMockReposStore() *MockReposStore { - return &MockReposStore{ - ListMinimalReposFunc: &ReposStoreListMinimalReposFunc{ - defaultHook: func(context.Context, database.ReposListOptions) (r0 []types1.MinimalRepo, r1 error) { - return - }, - }, - } -} - -// NewStrictMockReposStore creates a new mock of the ReposStore interface. -// All methods panic on invocation, unless overwritten. -func NewStrictMockReposStore() *MockReposStore { - return &MockReposStore{ - ListMinimalReposFunc: &ReposStoreListMinimalReposFunc{ - defaultHook: func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) { - panic("unexpected invocation of MockReposStore.ListMinimalRepos") - }, - }, - } -} - -// NewMockReposStoreFrom creates a new mock of the MockReposStore interface. -// All methods delegate to the given implementation, unless overwritten. -func NewMockReposStoreFrom(i ReposStore) *MockReposStore { - return &MockReposStore{ - ListMinimalReposFunc: &ReposStoreListMinimalReposFunc{ - defaultHook: i.ListMinimalRepos, - }, - } -} - -// ReposStoreListMinimalReposFunc describes the behavior when the -// ListMinimalRepos method of the parent MockReposStore instance is invoked. -type ReposStoreListMinimalReposFunc struct { - defaultHook func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) - hooks []func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) - history []ReposStoreListMinimalReposFuncCall - mutex sync.Mutex -} - -// ListMinimalRepos delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockReposStore) ListMinimalRepos(v0 context.Context, v1 database.ReposListOptions) ([]types1.MinimalRepo, error) { - r0, r1 := m.ListMinimalReposFunc.nextHook()(v0, v1) - m.ListMinimalReposFunc.appendCall(ReposStoreListMinimalReposFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the ListMinimalRepos -// method of the parent MockReposStore instance is invoked and the hook -// queue is empty. -func (f *ReposStoreListMinimalReposFunc) SetDefaultHook(hook func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// ListMinimalRepos method of the parent MockReposStore instance invokes the -// hook at the front of the queue and discards it. After the queue is empty, -// the default hook function is invoked for any future action. -func (f *ReposStoreListMinimalReposFunc) PushHook(hook func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *ReposStoreListMinimalReposFunc) SetDefaultReturn(r0 []types1.MinimalRepo, r1 error) { - f.SetDefaultHook(func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *ReposStoreListMinimalReposFunc) PushReturn(r0 []types1.MinimalRepo, r1 error) { - f.PushHook(func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) { - return r0, r1 - }) -} - -func (f *ReposStoreListMinimalReposFunc) nextHook() func(context.Context, database.ReposListOptions) ([]types1.MinimalRepo, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *ReposStoreListMinimalReposFunc) appendCall(r0 ReposStoreListMinimalReposFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of ReposStoreListMinimalReposFuncCall objects -// describing the invocations of this function. -func (f *ReposStoreListMinimalReposFunc) History() []ReposStoreListMinimalReposFuncCall { - f.mutex.Lock() - history := make([]ReposStoreListMinimalReposFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// ReposStoreListMinimalReposFuncCall is an object that describes an -// invocation of method ListMinimalRepos on an instance of MockReposStore. -type ReposStoreListMinimalReposFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 context.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 database.ReposListOptions - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 []types1.MinimalRepo - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c ReposStoreListMinimalReposFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c ReposStoreListMinimalReposFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - // MockPackageReferenceScanner is a mock implementation of the // PackageReferenceScanner interface (from the package // github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared) @@ -6960,7 +7431,7 @@ func NewMockPackageReferenceScanner() *MockPackageReferenceScanner { }, }, NextFunc: &PackageReferenceScannerNextFunc{ - defaultHook: func() (r0 shared1.PackageReference, r1 bool, r2 error) { + defaultHook: func() (r0 shared2.PackageReference, r1 bool, r2 error) { return }, }, @@ -6978,7 +7449,7 @@ func NewStrictMockPackageReferenceScanner() *MockPackageReferenceScanner { }, }, NextFunc: &PackageReferenceScannerNextFunc{ - defaultHook: func() (shared1.PackageReference, bool, error) { + defaultHook: func() (shared2.PackageReference, bool, error) { panic("unexpected invocation of MockPackageReferenceScanner.Next") }, }, @@ -6988,7 +7459,7 @@ func NewStrictMockPackageReferenceScanner() *MockPackageReferenceScanner { // NewMockPackageReferenceScannerFrom creates a new mock of the // MockPackageReferenceScanner interface. All methods delegate to the given // implementation, unless overwritten. -func NewMockPackageReferenceScannerFrom(i shared1.PackageReferenceScanner) *MockPackageReferenceScanner { +func NewMockPackageReferenceScannerFrom(i shared2.PackageReferenceScanner) *MockPackageReferenceScanner { return &MockPackageReferenceScanner{ CloseFunc: &PackageReferenceScannerCloseFunc{ defaultHook: i.Close, @@ -7101,15 +7572,15 @@ func (c PackageReferenceScannerCloseFuncCall) Results() []interface{} { // PackageReferenceScannerNextFunc describes the behavior when the Next // method of the parent MockPackageReferenceScanner instance is invoked. type PackageReferenceScannerNextFunc struct { - defaultHook func() (shared1.PackageReference, bool, error) - hooks []func() (shared1.PackageReference, bool, error) + defaultHook func() (shared2.PackageReference, bool, error) + hooks []func() (shared2.PackageReference, bool, error) history []PackageReferenceScannerNextFuncCall mutex sync.Mutex } // Next delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockPackageReferenceScanner) Next() (shared1.PackageReference, bool, error) { +func (m *MockPackageReferenceScanner) Next() (shared2.PackageReference, bool, error) { r0, r1, r2 := m.NextFunc.nextHook()() m.NextFunc.appendCall(PackageReferenceScannerNextFuncCall{r0, r1, r2}) return r0, r1, r2 @@ -7118,7 +7589,7 @@ func (m *MockPackageReferenceScanner) Next() (shared1.PackageReference, bool, er // SetDefaultHook sets function that is called when the Next method of the // parent MockPackageReferenceScanner instance is invoked and the hook queue // is empty. -func (f *PackageReferenceScannerNextFunc) SetDefaultHook(hook func() (shared1.PackageReference, bool, error)) { +func (f *PackageReferenceScannerNextFunc) SetDefaultHook(hook func() (shared2.PackageReference, bool, error)) { f.defaultHook = hook } @@ -7126,7 +7597,7 @@ func (f *PackageReferenceScannerNextFunc) SetDefaultHook(hook func() (shared1.Pa // Next method of the parent MockPackageReferenceScanner instance invokes // the hook at the front of the queue and discards it. After the queue is // empty, the default hook function is invoked for any future action. -func (f *PackageReferenceScannerNextFunc) PushHook(hook func() (shared1.PackageReference, bool, error)) { +func (f *PackageReferenceScannerNextFunc) PushHook(hook func() (shared2.PackageReference, bool, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -7134,20 +7605,20 @@ func (f *PackageReferenceScannerNextFunc) PushHook(hook func() (shared1.PackageR // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *PackageReferenceScannerNextFunc) SetDefaultReturn(r0 shared1.PackageReference, r1 bool, r2 error) { - f.SetDefaultHook(func() (shared1.PackageReference, bool, error) { +func (f *PackageReferenceScannerNextFunc) SetDefaultReturn(r0 shared2.PackageReference, r1 bool, r2 error) { + f.SetDefaultHook(func() (shared2.PackageReference, bool, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *PackageReferenceScannerNextFunc) PushReturn(r0 shared1.PackageReference, r1 bool, r2 error) { - f.PushHook(func() (shared1.PackageReference, bool, error) { +func (f *PackageReferenceScannerNextFunc) PushReturn(r0 shared2.PackageReference, r1 bool, r2 error) { + f.PushHook(func() (shared2.PackageReference, bool, error) { return r0, r1, r2 }) } -func (f *PackageReferenceScannerNextFunc) nextHook() func() (shared1.PackageReference, bool, error) { +func (f *PackageReferenceScannerNextFunc) nextHook() func() (shared2.PackageReference, bool, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -7182,7 +7653,7 @@ func (f *PackageReferenceScannerNextFunc) History() []PackageReferenceScannerNex type PackageReferenceScannerNextFuncCall struct { // Result0 is the value of the 1st result returned from this method // invocation. - Result0 shared1.PackageReference + Result0 shared2.PackageReference // Result1 is the value of the 2nd result returned from this method // invocation. Result1 bool diff --git a/internal/codeintel/autoindexing/internal/store/store.go b/internal/codeintel/autoindexing/internal/store/store.go index 1235a4f18a1..f9df5e001bc 100644 --- a/internal/codeintel/autoindexing/internal/store/store.go +++ b/internal/codeintel/autoindexing/internal/store/store.go @@ -26,13 +26,13 @@ type Store interface { // Indexes InsertIndexes(ctx context.Context, indexes []types.Index) (_ []types.Index, err error) - GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error) + GetIndexes(ctx context.Context, opts shared.GetIndexesOptions) (_ []types.Index, _ int, err error) GetIndexByID(ctx context.Context, id int) (_ types.Index, _ bool, err error) GetIndexesByIDs(ctx context.Context, ids ...int) (_ []types.Index, err error) GetRecentIndexesSummary(ctx context.Context, repositoryID int) (summaries []shared.IndexesWithRepositoryNamespace, err error) GetLastIndexScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error) DeleteIndexByID(ctx context.Context, id int) (_ bool, err error) - DeleteIndexes(ctx context.Context, opts types.DeleteIndexesOptions) (err error) + DeleteIndexes(ctx context.Context, opts shared.DeleteIndexesOptions) (err error) DeleteIndexesWithoutRepository(ctx context.Context, now time.Time) (_ map[int]int, err error) IsQueued(ctx context.Context, repositoryID int, commit string) (_ bool, err error) QueueRepoRev(ctx context.Context, repositoryID int, commit string) error diff --git a/internal/codeintel/autoindexing/internal/store/store_indexes.go b/internal/codeintel/autoindexing/internal/store/store_indexes.go index 4b5d9dc580c..210537d1fd2 100644 --- a/internal/codeintel/autoindexing/internal/store/store_indexes.go +++ b/internal/codeintel/autoindexing/internal/store/store_indexes.go @@ -89,7 +89,7 @@ RETURNING id ` // GetIndexes returns a list of indexes and the total count of records matching the given conditions. -func (s *store) GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error) { +func (s *store) GetIndexes(ctx context.Context, opts shared.GetIndexesOptions) (_ []types.Index, _ int, err error) { ctx, trace, endObservation := s.operations.getIndexes.With(ctx, &err, observation.Args{LogFields: []log.Field{ log.Int("repositoryID", opts.RepositoryID), log.String("state", opts.State), @@ -168,7 +168,7 @@ WHERE repo.deleted_at IS NULL AND %s ORDER BY queued_at DESC, u.id LIMIT %d OFFS ` // DeleteIndexes deletes indexes matching the given filter criteria. -func (s *store) DeleteIndexes(ctx context.Context, opts types.DeleteIndexesOptions) (err error) { +func (s *store) DeleteIndexes(ctx context.Context, opts shared.DeleteIndexesOptions) (err error) { ctx, _, endObservation := s.operations.deleteIndexes.With(ctx, &err, observation.Args{LogFields: []log.Field{ log.Int("repositoryID", opts.RepositoryID), log.String("state", opts.State), diff --git a/internal/codeintel/autoindexing/internal/store/store_indexes_test.go b/internal/codeintel/autoindexing/internal/store/store_indexes_test.go index ee5efe26aa3..d0f9299816c 100644 --- a/internal/codeintel/autoindexing/internal/store/store_indexes_test.go +++ b/internal/codeintel/autoindexing/internal/store/store_indexes_test.go @@ -223,7 +223,7 @@ func TestGetIndexes(t *testing.T) { ) t.Run(name, func(t *testing.T) { - indexes, totalCount, err := store.GetIndexes(ctx, types.GetIndexesOptions{ + indexes, totalCount, err := store.GetIndexes(ctx, shared.GetIndexesOptions{ RepositoryID: testCase.repositoryID, State: testCase.state, Term: testCase.term, @@ -258,7 +258,7 @@ func TestGetIndexes(t *testing.T) { defer globals.SetPermissionsUserMapping(before) indexes, totalCount, err := store.GetIndexes(ctx, - types.GetIndexesOptions{ + shared.GetIndexesOptions{ Limit: 1, }, ) @@ -580,7 +580,7 @@ func TestDeleteIndexes(t *testing.T) { insertIndexes(t, db, types.Index{ID: 1, State: "completed"}) insertIndexes(t, db, types.Index{ID: 2, State: "errored"}) - if err := store.DeleteIndexes(context.Background(), types.DeleteIndexesOptions{ + if err := store.DeleteIndexes(context.Background(), shared.DeleteIndexesOptions{ State: "errored", Term: "", RepositoryID: 0, diff --git a/internal/codeintel/autoindexing/mocks_test.go b/internal/codeintel/autoindexing/mocks_test.go index 5272b1890da..d2f54a77a5b 100644 --- a/internal/codeintel/autoindexing/mocks_test.go +++ b/internal/codeintel/autoindexing/mocks_test.go @@ -124,7 +124,7 @@ func NewMockStore() *MockStore { }, }, DeleteIndexesFunc: &StoreDeleteIndexesFunc{ - defaultHook: func(context.Context, types.DeleteIndexesOptions) (r0 error) { + defaultHook: func(context.Context, shared.DeleteIndexesOptions) (r0 error) { return }, }, @@ -154,7 +154,7 @@ func NewMockStore() *MockStore { }, }, GetIndexesFunc: &StoreGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { return }, }, @@ -261,7 +261,7 @@ func NewStrictMockStore() *MockStore { }, }, DeleteIndexesFunc: &StoreDeleteIndexesFunc{ - defaultHook: func(context.Context, types.DeleteIndexesOptions) error { + defaultHook: func(context.Context, shared.DeleteIndexesOptions) error { panic("unexpected invocation of MockStore.DeleteIndexes") }, }, @@ -291,7 +291,7 @@ func NewStrictMockStore() *MockStore { }, }, GetIndexesFunc: &StoreGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { panic("unexpected invocation of MockStore.GetIndexes") }, }, @@ -584,15 +584,15 @@ func (c StoreDeleteIndexByIDFuncCall) Results() []interface{} { // StoreDeleteIndexesFunc describes the behavior when the DeleteIndexes // method of the parent MockStore instance is invoked. type StoreDeleteIndexesFunc struct { - defaultHook func(context.Context, types.DeleteIndexesOptions) error - hooks []func(context.Context, types.DeleteIndexesOptions) error + defaultHook func(context.Context, shared.DeleteIndexesOptions) error + hooks []func(context.Context, shared.DeleteIndexesOptions) error history []StoreDeleteIndexesFuncCall mutex sync.Mutex } // DeleteIndexes delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockStore) DeleteIndexes(v0 context.Context, v1 types.DeleteIndexesOptions) error { +func (m *MockStore) DeleteIndexes(v0 context.Context, v1 shared.DeleteIndexesOptions) error { r0 := m.DeleteIndexesFunc.nextHook()(v0, v1) m.DeleteIndexesFunc.appendCall(StoreDeleteIndexesFuncCall{v0, v1, r0}) return r0 @@ -600,7 +600,7 @@ func (m *MockStore) DeleteIndexes(v0 context.Context, v1 types.DeleteIndexesOpti // SetDefaultHook sets function that is called when the DeleteIndexes method // of the parent MockStore instance is invoked and the hook queue is empty. -func (f *StoreDeleteIndexesFunc) SetDefaultHook(hook func(context.Context, types.DeleteIndexesOptions) error) { +func (f *StoreDeleteIndexesFunc) SetDefaultHook(hook func(context.Context, shared.DeleteIndexesOptions) error) { f.defaultHook = hook } @@ -608,7 +608,7 @@ func (f *StoreDeleteIndexesFunc) SetDefaultHook(hook func(context.Context, types // DeleteIndexes method of the parent MockStore instance invokes the hook at // the front of the queue and discards it. After the queue is empty, the // default hook function is invoked for any future action. -func (f *StoreDeleteIndexesFunc) PushHook(hook func(context.Context, types.DeleteIndexesOptions) error) { +func (f *StoreDeleteIndexesFunc) PushHook(hook func(context.Context, shared.DeleteIndexesOptions) error) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -617,19 +617,19 @@ func (f *StoreDeleteIndexesFunc) PushHook(hook func(context.Context, types.Delet // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *StoreDeleteIndexesFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(context.Context, types.DeleteIndexesOptions) error { + f.SetDefaultHook(func(context.Context, shared.DeleteIndexesOptions) error { return r0 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *StoreDeleteIndexesFunc) PushReturn(r0 error) { - f.PushHook(func(context.Context, types.DeleteIndexesOptions) error { + f.PushHook(func(context.Context, shared.DeleteIndexesOptions) error { return r0 }) } -func (f *StoreDeleteIndexesFunc) nextHook() func(context.Context, types.DeleteIndexesOptions) error { +func (f *StoreDeleteIndexesFunc) nextHook() func(context.Context, shared.DeleteIndexesOptions) error { f.mutex.Lock() defer f.mutex.Unlock() @@ -667,7 +667,7 @@ type StoreDeleteIndexesFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.DeleteIndexesOptions + Arg1 shared.DeleteIndexesOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 error @@ -1240,15 +1240,15 @@ func (c StoreGetIndexConfigurationByRepositoryIDFuncCall) Results() []interface{ // StoreGetIndexesFunc describes the behavior when the GetIndexes method of // the parent MockStore instance is invoked. type StoreGetIndexesFunc struct { - defaultHook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) - hooks []func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) + defaultHook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) + hooks []func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) history []StoreGetIndexesFuncCall mutex sync.Mutex } // GetIndexes delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockStore) GetIndexes(v0 context.Context, v1 types.GetIndexesOptions) ([]types.Index, int, error) { +func (m *MockStore) GetIndexes(v0 context.Context, v1 shared.GetIndexesOptions) ([]types.Index, int, error) { r0, r1, r2 := m.GetIndexesFunc.nextHook()(v0, v1) m.GetIndexesFunc.appendCall(StoreGetIndexesFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -1256,7 +1256,7 @@ func (m *MockStore) GetIndexes(v0 context.Context, v1 types.GetIndexesOptions) ( // SetDefaultHook sets function that is called when the GetIndexes method of // the parent MockStore instance is invoked and the hook queue is empty. -func (f *StoreGetIndexesFunc) SetDefaultHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *StoreGetIndexesFunc) SetDefaultHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.defaultHook = hook } @@ -1264,7 +1264,7 @@ func (f *StoreGetIndexesFunc) SetDefaultHook(hook func(context.Context, types.Ge // GetIndexes method of the parent MockStore instance invokes the hook at // the front of the queue and discards it. After the queue is empty, the // default hook function is invoked for any future action. -func (f *StoreGetIndexesFunc) PushHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *StoreGetIndexesFunc) PushHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -1273,19 +1273,19 @@ func (f *StoreGetIndexesFunc) PushHook(hook func(context.Context, types.GetIndex // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *StoreGetIndexesFunc) SetDefaultReturn(r0 []types.Index, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.SetDefaultHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *StoreGetIndexesFunc) PushReturn(r0 []types.Index, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.PushHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } -func (f *StoreGetIndexesFunc) nextHook() func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { +func (f *StoreGetIndexesFunc) nextHook() func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -1323,7 +1323,7 @@ type StoreGetIndexesFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetIndexesOptions + Arg1 shared.GetIndexesOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Index @@ -3312,8 +3312,8 @@ func (c StoreUpdateSourcedCommitsFuncCall) Results() []interface{} { // MockGitserverClient is a mock implementation of the GitserverClient // interface (from the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared) -// used for unit testing. +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing) used +// for unit testing. type MockGitserverClient struct { // CommitDateFunc is an instance of a mock function object controlling // the behavior of the method CommitDate. @@ -3465,7 +3465,7 @@ func NewStrictMockGitserverClient() *MockGitserverClient { // NewMockGitserverClientFrom creates a new mock of the MockGitserverClient // interface. All methods delegate to the given implementation, unless // overwritten. -func NewMockGitserverClientFrom(i shared.GitserverClient) *MockGitserverClient { +func NewMockGitserverClientFrom(i GitserverClient) *MockGitserverClient { return &MockGitserverClient{ CommitDateFunc: &GitserverClientCommitDateFunc{ defaultHook: i.CommitDate, @@ -4656,8 +4656,8 @@ func (c GitserverClientResolveRevisionFuncCall) Results() []interface{} { // MockInferenceService is a mock implementation of the InferenceService // interface (from the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared) -// used for unit testing. +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing) used +// for unit testing. type MockInferenceService struct { // InferIndexJobHintsFunc is an instance of a mock function object // controlling the behavior of the method InferIndexJobHints. @@ -4705,7 +4705,7 @@ func NewStrictMockInferenceService() *MockInferenceService { // NewMockInferenceServiceFrom creates a new mock of the // MockInferenceService interface. All methods delegate to the given // implementation, unless overwritten. -func NewMockInferenceServiceFrom(i shared.InferenceService) *MockInferenceService { +func NewMockInferenceServiceFrom(i InferenceService) *MockInferenceService { return &MockInferenceService{ InferIndexJobHintsFunc: &InferenceServiceInferIndexJobHintsFunc{ defaultHook: i.InferIndexJobHints, @@ -4951,8 +4951,8 @@ func (c InferenceServiceInferIndexJobsFuncCall) Results() []interface{} { // MockRepoUpdaterClient is a mock implementation of the RepoUpdaterClient // interface (from the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared) -// used for unit testing. +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing) used +// for unit testing. type MockRepoUpdaterClient struct { // EnqueueRepoUpdateFunc is an instance of a mock function object // controlling the behavior of the method EnqueueRepoUpdate. @@ -5001,7 +5001,7 @@ func NewStrictMockRepoUpdaterClient() *MockRepoUpdaterClient { // NewMockRepoUpdaterClientFrom creates a new mock of the // MockRepoUpdaterClient interface. All methods delegate to the given // implementation, unless overwritten. -func NewMockRepoUpdaterClientFrom(i shared.RepoUpdaterClient) *MockRepoUpdaterClient { +func NewMockRepoUpdaterClientFrom(i RepoUpdaterClient) *MockRepoUpdaterClient { return &MockRepoUpdaterClient{ EnqueueRepoUpdateFunc: &RepoUpdaterClientEnqueueRepoUpdateFunc{ defaultHook: i.EnqueueRepoUpdate, @@ -5234,8 +5234,8 @@ func (c RepoUpdaterClientRepoLookupFuncCall) Results() []interface{} { // MockUploadService is a mock implementation of the UploadService interface // (from the package -// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared) -// used for unit testing. +// github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing) used +// for unit testing. type MockUploadService struct { // GetDirtyRepositoriesFunc is an instance of a mock function object // controlling the behavior of the method GetDirtyRepositories. @@ -5335,7 +5335,7 @@ func NewStrictMockUploadService() *MockUploadService { // NewMockUploadServiceFrom creates a new mock of the MockUploadService // interface. All methods delegate to the given implementation, unless // overwritten. -func NewMockUploadServiceFrom(i shared.UploadService) *MockUploadService { +func NewMockUploadServiceFrom(i UploadService) *MockUploadService { return &MockUploadService{ GetDirtyRepositoriesFunc: &UploadServiceGetDirtyRepositoriesFunc{ defaultHook: i.GetDirtyRepositories, diff --git a/internal/codeintel/autoindexing/service.go b/internal/codeintel/autoindexing/service.go index 5aa947623fe..0240c8e2a71 100644 --- a/internal/codeintel/autoindexing/service.go +++ b/internal/codeintel/autoindexing/service.go @@ -31,10 +31,10 @@ import ( type Service struct { store store.Store - uploadSvc shared.UploadService - inferenceSvc shared.InferenceService - repoUpdater shared.RepoUpdaterClient - gitserverClient shared.GitserverClient + uploadSvc UploadService + inferenceSvc InferenceService + repoUpdater RepoUpdaterClient + gitserverClient GitserverClient symbolsClient *symbols.Client backgroundJobs background.BackgroundJob @@ -44,10 +44,10 @@ type Service struct { func newService( store store.Store, - uploadSvc shared.UploadService, - inferenceSvc shared.InferenceService, - repoUpdater shared.RepoUpdaterClient, - gitserver shared.GitserverClient, + uploadSvc UploadService, + inferenceSvc InferenceService, + repoUpdater RepoUpdaterClient, + gitserver GitserverClient, symbolsClient *symbols.Client, backgroundJobs background.BackgroundJob, observationContext *observation.Context, @@ -77,7 +77,7 @@ func GetDependencyIndexingStore(s *Service) dbworkerstore.Store { return s.backgroundJobs.DependencyIndexingStore() } -func (s *Service) GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error) { +func (s *Service) GetIndexes(ctx context.Context, opts shared.GetIndexesOptions) (_ []types.Index, _ int, err error) { ctx, _, endObservation := s.operations.getIndexes.With(ctx, &err, observation.Args{}) defer endObservation(1, observation.Args{}) @@ -119,7 +119,7 @@ func (s *Service) DeleteIndexByID(ctx context.Context, id int) (_ bool, err erro return s.store.DeleteIndexByID(ctx, id) } -func (s *Service) DeleteIndexes(ctx context.Context, opts types.DeleteIndexesOptions) (err error) { +func (s *Service) DeleteIndexes(ctx context.Context, opts shared.DeleteIndexesOptions) (err error) { ctx, _, endObservation := s.operations.deleteIndexes.With(ctx, &err, observation.Args{}) defer endObservation(1, observation.Args{}) diff --git a/internal/codeintel/autoindexing/shared/iface.go b/internal/codeintel/autoindexing/shared/iface.go deleted file mode 100644 index 5850f4b92b6..00000000000 --- a/internal/codeintel/autoindexing/shared/iface.go +++ /dev/null @@ -1,48 +0,0 @@ -package shared - -import ( - "context" - "time" - - "github.com/grafana/regexp" - - "github.com/sourcegraph/sourcegraph/internal/api" - "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" - "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" - "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" - "github.com/sourcegraph/sourcegraph/internal/repoupdater/protocol" - "github.com/sourcegraph/sourcegraph/lib/codeintel/autoindex/config" -) - -type RepoUpdaterClient interface { - RepoLookup(ctx context.Context, args protocol.RepoLookupArgs) (*protocol.RepoLookupResult, error) - EnqueueRepoUpdate(ctx context.Context, repo api.RepoName) (*protocol.RepoUpdateResponse, error) -} - -type GitserverClient interface { - Head(ctx context.Context, repositoryID int) (string, bool, error) - CommitExists(ctx context.Context, repositoryID int, commit string) (bool, error) - ListFiles(ctx context.Context, repositoryID int, commit string, pattern *regexp.Regexp) ([]string, error) - FileExists(ctx context.Context, repositoryID int, commit, file string) (bool, error) - RawContents(ctx context.Context, repositoryID int, commit, file string) ([]byte, error) - ResolveRevision(ctx context.Context, repositoryID int, versionString string) (api.CommitID, error) - ListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error) - - CommitDate(ctx context.Context, repositoryID int, commit string) (string, time.Time, bool, error) - RefDescriptions(ctx context.Context, repositoryID int, gitOjbs ...string) (map[string][]gitdomain.RefDescription, error) - CommitsUniqueToBranch(ctx context.Context, repositoryID int, branchName string, isDefaultBranch bool, maxAge *time.Time) (map[string]time.Time, error) -} - -type InferenceService interface { - InferIndexJobs(ctx context.Context, repo api.RepoName, commit, overrideScript string) ([]config.IndexJob, error) - InferIndexJobHints(ctx context.Context, repo api.RepoName, commit, overrideScript string) ([]config.IndexJobHint, error) -} - -type UploadService interface { - GetRepoName(ctx context.Context, repositoryID int) (_ string, err error) // upload service - GetDirtyRepositories(ctx context.Context) (_ map[int]int, err error) // upload service - GetUploadsByIDs(ctx context.Context, ids ...int) (_ []types.Upload, err error) // upload service - GetUploadByID(ctx context.Context, id int) (types.Upload, bool, error) - ReferencesForUpload(ctx context.Context, uploadID int) (shared.PackageReferenceScanner, error) - GetRepositoriesForIndexScan(ctx context.Context, table, column string, processDelay time.Duration, allowGlobalPolicies bool, repositoryMatchLimit *int, limit int, now time.Time) (_ []int, err error) -} diff --git a/internal/codeintel/autoindexing/shared/types.go b/internal/codeintel/autoindexing/shared/types.go index fba0895989e..8b1af7724a1 100644 --- a/internal/codeintel/autoindexing/shared/types.go +++ b/internal/codeintel/autoindexing/shared/types.go @@ -1,13 +1,15 @@ package shared import ( - "time" - "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" ) -type IndexJob struct { - Indexer string +type GetIndexesOptions struct { + RepositoryID int + State string + Term string + Limit int + Offset int } type SourcedCommits struct { @@ -29,50 +31,8 @@ type IndexesWithRepositoryNamespace struct { Indexes []types.Index } -// UploadLocation is a path and range pair from within a particular upload. The target commit -// denotes the target commit for which the location was set (the originally requested commit). -type UploadLocation struct { - Dump Dump - Path string - TargetCommit string - TargetRange Range -} - -// Dump is a subset of the lsif_uploads table (queried via the lsif_dumps_with_repository_name view) -// and stores only processed records. -type Dump struct { - ID int `json:"id"` - Commit string `json:"commit"` - Root string `json:"root"` - VisibleAtTip bool `json:"visibleAtTip"` - UploadedAt time.Time `json:"uploadedAt"` - State string `json:"state"` - FailureMessage *string `json:"failureMessage"` - StartedAt *time.Time `json:"startedAt"` - FinishedAt *time.Time `json:"finishedAt"` - ProcessAfter *time.Time `json:"processAfter"` - NumResets int `json:"numResets"` - NumFailures int `json:"numFailures"` - RepositoryID int `json:"repositoryId"` - RepositoryName string `json:"repositoryName"` - Indexer string `json:"indexer"` - IndexerVersion string `json:"indexerVersion"` - AssociatedIndexID *int `json:"associatedIndex"` -} - -// Range is an inclusive bounds within a file. -type Range struct { - Start Position - End Position -} - -// Position is a unique position within a file. -type Position struct { - Line int - Character int -} - -type DeleteUploadsOptions struct { - State string - Term string +type DeleteIndexesOptions struct { + State string + Term string + RepositoryID int } diff --git a/internal/codeintel/autoindexing/transport/graphql/codeintel_tree_info_resolver.go b/internal/codeintel/autoindexing/transport/graphql/codeintel_tree_info_resolver.go index ed0021e589c..2f85a9baddf 100644 --- a/internal/codeintel/autoindexing/transport/graphql/codeintel_tree_info_resolver.go +++ b/internal/codeintel/autoindexing/transport/graphql/codeintel_tree_info_resolver.go @@ -81,7 +81,7 @@ func (r *codeIntelTreeInfoResolver) PreciseSupport(ctx context.Context) (*[]GitT resolvers = append(resolvers, &codeIntelTreePreciseCoverageResolver{ confidence: indexJobInfered, // drop the tag if it exists - indexer: codeinteltypes.ImageToIndexer[strings.Split(job.Indexer, ":")[0]], + indexer: codeinteltypes.NewCodeIntelIndexerResolverFrom(codeinteltypes.ImageToIndexer[strings.Split(job.Indexer, ":")[0]]), }) } } @@ -106,7 +106,7 @@ func (r *codeIntelTreeInfoResolver) PreciseSupport(ctx context.Context) (*[]GitT resolvers = append(resolvers, &codeIntelTreePreciseCoverageResolver{ confidence: confidence, // expected that job hints don't include a tag in the indexer name - indexer: codeinteltypes.ImageToIndexer[hint.Indexer], + indexer: codeinteltypes.NewCodeIntelIndexerResolverFrom(codeinteltypes.ImageToIndexer[hint.Indexer]), }) } } diff --git a/internal/codeintel/autoindexing/transport/graphql/iface.go b/internal/codeintel/autoindexing/transport/graphql/iface.go index 7beae045b79..b5b022de6cb 100644 --- a/internal/codeintel/autoindexing/transport/graphql/iface.go +++ b/internal/codeintel/autoindexing/transport/graphql/iface.go @@ -17,14 +17,14 @@ import ( type AutoIndexingService interface { GetIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int) (_ shared.IndexConfiguration, _ bool, err error) - GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error) + GetIndexes(ctx context.Context, opts shared.GetIndexesOptions) (_ []types.Index, _ int, err error) GetIndexByID(ctx context.Context, id int) (_ types.Index, _ bool, err error) GetIndexesByIDs(ctx context.Context, ids ...int) (_ []types.Index, err error) GetRecentIndexesSummary(ctx context.Context, repositoryID int) (summaries []shared.IndexesWithRepositoryNamespace, err error) GetLastIndexScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error) UpdateIndexConfigurationByRepositoryID(ctx context.Context, repositoryID int, data []byte) (err error) DeleteIndexByID(ctx context.Context, id int) (_ bool, err error) - DeleteIndexes(ctx context.Context, opts types.DeleteIndexesOptions) (err error) + DeleteIndexes(ctx context.Context, opts shared.DeleteIndexesOptions) (err error) GetInferenceScript(ctx context.Context) (script string, err error) SetInferenceScript(ctx context.Context, script string) (err error) @@ -44,7 +44,7 @@ type AutoIndexingService interface { type UploadsService interface { GetLastUploadRetentionScanForRepository(ctx context.Context, repositoryID int) (_ *time.Time, err error) GetRecentUploadsSummary(ctx context.Context, repositoryID int) (upload []uploadshared.UploadsWithRepositoryNamespace, err error) - GetUploads(ctx context.Context, opts types.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) + GetUploads(ctx context.Context, opts uploadshared.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) GetAuditLogsForUpload(ctx context.Context, uploadID int) (_ []types.UploadLog, err error) GetListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error) GetUploadDocumentsForPath(ctx context.Context, bundleID int, pathPattern string) ([]string, int, error) diff --git a/internal/codeintel/autoindexing/transport/graphql/mocks_temp.go b/internal/codeintel/autoindexing/transport/graphql/mocks_temp.go index 5f32a6a76ed..edc97cde791 100644 --- a/internal/codeintel/autoindexing/transport/graphql/mocks_temp.go +++ b/internal/codeintel/autoindexing/transport/graphql/mocks_temp.go @@ -100,7 +100,7 @@ func NewMockAutoIndexingService() *MockAutoIndexingService { }, }, DeleteIndexesFunc: &AutoIndexingServiceDeleteIndexesFunc{ - defaultHook: func(context.Context, types.DeleteIndexesOptions) (r0 error) { + defaultHook: func(context.Context, shared.DeleteIndexesOptions) (r0 error) { return }, }, @@ -115,7 +115,7 @@ func NewMockAutoIndexingService() *MockAutoIndexingService { }, }, GetIndexesFunc: &AutoIndexingServiceGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { return }, }, @@ -203,7 +203,7 @@ func NewStrictMockAutoIndexingService() *MockAutoIndexingService { }, }, DeleteIndexesFunc: &AutoIndexingServiceDeleteIndexesFunc{ - defaultHook: func(context.Context, types.DeleteIndexesOptions) error { + defaultHook: func(context.Context, shared.DeleteIndexesOptions) error { panic("unexpected invocation of MockAutoIndexingService.DeleteIndexes") }, }, @@ -218,7 +218,7 @@ func NewStrictMockAutoIndexingService() *MockAutoIndexingService { }, }, GetIndexesFunc: &AutoIndexingServiceGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { panic("unexpected invocation of MockAutoIndexingService.GetIndexes") }, }, @@ -475,15 +475,15 @@ func (c AutoIndexingServiceDeleteIndexByIDFuncCall) Results() []interface{} { // DeleteIndexes method of the parent MockAutoIndexingService instance is // invoked. type AutoIndexingServiceDeleteIndexesFunc struct { - defaultHook func(context.Context, types.DeleteIndexesOptions) error - hooks []func(context.Context, types.DeleteIndexesOptions) error + defaultHook func(context.Context, shared.DeleteIndexesOptions) error + hooks []func(context.Context, shared.DeleteIndexesOptions) error history []AutoIndexingServiceDeleteIndexesFuncCall mutex sync.Mutex } // DeleteIndexes delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockAutoIndexingService) DeleteIndexes(v0 context.Context, v1 types.DeleteIndexesOptions) error { +func (m *MockAutoIndexingService) DeleteIndexes(v0 context.Context, v1 shared.DeleteIndexesOptions) error { r0 := m.DeleteIndexesFunc.nextHook()(v0, v1) m.DeleteIndexesFunc.appendCall(AutoIndexingServiceDeleteIndexesFuncCall{v0, v1, r0}) return r0 @@ -492,7 +492,7 @@ func (m *MockAutoIndexingService) DeleteIndexes(v0 context.Context, v1 types.Del // SetDefaultHook sets function that is called when the DeleteIndexes method // of the parent MockAutoIndexingService instance is invoked and the hook // queue is empty. -func (f *AutoIndexingServiceDeleteIndexesFunc) SetDefaultHook(hook func(context.Context, types.DeleteIndexesOptions) error) { +func (f *AutoIndexingServiceDeleteIndexesFunc) SetDefaultHook(hook func(context.Context, shared.DeleteIndexesOptions) error) { f.defaultHook = hook } @@ -501,7 +501,7 @@ func (f *AutoIndexingServiceDeleteIndexesFunc) SetDefaultHook(hook func(context. // invokes the hook at the front of the queue and discards it. After the // queue is empty, the default hook function is invoked for any future // action. -func (f *AutoIndexingServiceDeleteIndexesFunc) PushHook(hook func(context.Context, types.DeleteIndexesOptions) error) { +func (f *AutoIndexingServiceDeleteIndexesFunc) PushHook(hook func(context.Context, shared.DeleteIndexesOptions) error) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -510,19 +510,19 @@ func (f *AutoIndexingServiceDeleteIndexesFunc) PushHook(hook func(context.Contex // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *AutoIndexingServiceDeleteIndexesFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(context.Context, types.DeleteIndexesOptions) error { + f.SetDefaultHook(func(context.Context, shared.DeleteIndexesOptions) error { return r0 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *AutoIndexingServiceDeleteIndexesFunc) PushReturn(r0 error) { - f.PushHook(func(context.Context, types.DeleteIndexesOptions) error { + f.PushHook(func(context.Context, shared.DeleteIndexesOptions) error { return r0 }) } -func (f *AutoIndexingServiceDeleteIndexesFunc) nextHook() func(context.Context, types.DeleteIndexesOptions) error { +func (f *AutoIndexingServiceDeleteIndexesFunc) nextHook() func(context.Context, shared.DeleteIndexesOptions) error { f.mutex.Lock() defer f.mutex.Unlock() @@ -561,7 +561,7 @@ type AutoIndexingServiceDeleteIndexesFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.DeleteIndexesOptions + Arg1 shared.DeleteIndexesOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 error @@ -814,15 +814,15 @@ func (c AutoIndexingServiceGetIndexConfigurationByRepositoryIDFuncCall) Results( // GetIndexes method of the parent MockAutoIndexingService instance is // invoked. type AutoIndexingServiceGetIndexesFunc struct { - defaultHook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) - hooks []func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) + defaultHook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) + hooks []func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) history []AutoIndexingServiceGetIndexesFuncCall mutex sync.Mutex } // GetIndexes delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 types.GetIndexesOptions) ([]types.Index, int, error) { +func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 shared.GetIndexesOptions) ([]types.Index, int, error) { r0, r1, r2 := m.GetIndexesFunc.nextHook()(v0, v1) m.GetIndexesFunc.appendCall(AutoIndexingServiceGetIndexesFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -831,7 +831,7 @@ func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 types.GetInd // SetDefaultHook sets function that is called when the GetIndexes method of // the parent MockAutoIndexingService instance is invoked and the hook queue // is empty. -func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.defaultHook = hook } @@ -839,7 +839,7 @@ func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Con // GetIndexes method of the parent MockAutoIndexingService instance invokes // the hook at the front of the queue and discards it. After the queue is // empty, the default hook function is invoked for any future action. -func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -848,19 +848,19 @@ func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultReturn(r0 []types.Index, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.SetDefaultHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *AutoIndexingServiceGetIndexesFunc) PushReturn(r0 []types.Index, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.PushHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } -func (f *AutoIndexingServiceGetIndexesFunc) nextHook() func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { +func (f *AutoIndexingServiceGetIndexesFunc) nextHook() func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -899,7 +899,7 @@ type AutoIndexingServiceGetIndexesFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetIndexesOptions + Arg1 shared.GetIndexesOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Index @@ -2755,7 +2755,7 @@ func NewMockUploadsService() *MockUploadsService { }, }, GetUploadsFunc: &UploadsServiceGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { + defaultHook: func(context.Context, shared1.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { return }, }, @@ -2797,7 +2797,7 @@ func NewStrictMockUploadsService() *MockUploadsService { }, }, GetUploadsFunc: &UploadsServiceGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + defaultHook: func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { panic("unexpected invocation of MockUploadsService.GetUploads") }, }, @@ -3414,15 +3414,15 @@ func (c UploadsServiceGetUploadDocumentsForPathFuncCall) Results() []interface{} // UploadsServiceGetUploadsFunc describes the behavior when the GetUploads // method of the parent MockUploadsService instance is invoked. type UploadsServiceGetUploadsFunc struct { - defaultHook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) - hooks []func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) + defaultHook func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) + hooks []func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) history []UploadsServiceGetUploadsFuncCall mutex sync.Mutex } // GetUploads delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockUploadsService) GetUploads(v0 context.Context, v1 types.GetUploadsOptions) ([]types.Upload, int, error) { +func (m *MockUploadsService) GetUploads(v0 context.Context, v1 shared1.GetUploadsOptions) ([]types.Upload, int, error) { r0, r1, r2 := m.GetUploadsFunc.nextHook()(v0, v1) m.GetUploadsFunc.appendCall(UploadsServiceGetUploadsFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -3431,7 +3431,7 @@ func (m *MockUploadsService) GetUploads(v0 context.Context, v1 types.GetUploadsO // SetDefaultHook sets function that is called when the GetUploads method of // the parent MockUploadsService instance is invoked and the hook queue is // empty. -func (f *UploadsServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *UploadsServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error)) { f.defaultHook = hook } @@ -3439,7 +3439,7 @@ func (f *UploadsServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, // GetUploads method of the parent MockUploadsService instance invokes the // hook at the front of the queue and discards it. After the queue is empty, // the default hook function is invoked for any future action. -func (f *UploadsServiceGetUploadsFunc) PushHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *UploadsServiceGetUploadsFunc) PushHook(hook func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -3448,19 +3448,19 @@ func (f *UploadsServiceGetUploadsFunc) PushHook(hook func(context.Context, types // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *UploadsServiceGetUploadsFunc) SetDefaultReturn(r0 []types.Upload, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.SetDefaultHook(func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *UploadsServiceGetUploadsFunc) PushReturn(r0 []types.Upload, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.PushHook(func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } -func (f *UploadsServiceGetUploadsFunc) nextHook() func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { +func (f *UploadsServiceGetUploadsFunc) nextHook() func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -3498,7 +3498,7 @@ type UploadsServiceGetUploadsFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetUploadsOptions + Arg1 shared1.GetUploadsOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Upload diff --git a/internal/codeintel/autoindexing/transport/graphql/precise_based_support_resolver.go b/internal/codeintel/autoindexing/transport/graphql/precise_based_support_resolver.go index de4438b2c4e..ab19a257be3 100644 --- a/internal/codeintel/autoindexing/transport/graphql/precise_based_support_resolver.go +++ b/internal/codeintel/autoindexing/transport/graphql/precise_based_support_resolver.go @@ -25,8 +25,15 @@ type preciseCodeIntelSupportResolver struct { } func NewPreciseCodeIntelSupportResolver(filepath string) PreciseSupportResolver { + indexers := types.LanguageToIndexer[path.Ext(filepath)] + + resolvers := make([]types.CodeIntelIndexerResolver, len(indexers)) + for _, indexer := range indexers { + resolvers = append(resolvers, types.NewCodeIntelIndexerResolverFrom(indexer)) + } + return &preciseCodeIntelSupportResolver{ - indexers: types.LanguageToIndexer[path.Ext(filepath)], + indexers: resolvers, } } diff --git a/internal/codeintel/autoindexing/transport/graphql/utils.go b/internal/codeintel/autoindexing/transport/graphql/utils.go index 18dbc6997bd..c7cae375f09 100644 --- a/internal/codeintel/autoindexing/transport/graphql/utils.go +++ b/internal/codeintel/autoindexing/transport/graphql/utils.go @@ -12,7 +12,7 @@ import ( "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" "github.com/sourcegraph/sourcegraph/internal/api" - "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -77,18 +77,18 @@ const DefaultIndexPageSize = 50 // makeGetIndexesOptions translates the given GraphQL arguments into options defined by the // store.GetIndexes operations. -func makeGetIndexesOptions(args *LSIFRepositoryIndexesQueryArgs) (types.GetIndexesOptions, error) { +func makeGetIndexesOptions(args *LSIFRepositoryIndexesQueryArgs) (shared.GetIndexesOptions, error) { repositoryID, err := resolveRepositoryID(args.RepositoryID) if err != nil { - return types.GetIndexesOptions{}, err + return shared.GetIndexesOptions{}, err } offset, err := graphqlutil.DecodeIntCursor(args.After) if err != nil { - return types.GetIndexesOptions{}, err + return shared.GetIndexesOptions{}, err } - return types.GetIndexesOptions{ + return shared.GetIndexesOptions{ RepositoryID: repositoryID, State: strings.ToLower(derefString(args.State, "")), Term: derefString(args.Query, ""), @@ -223,17 +223,17 @@ func EncodeCursor(val *string) *PageInfo { // makeDeleteIndexesOptions translates the given GraphQL arguments into options defined by the // store.DeleteIndexes operations. -func makeDeleteIndexesOptions(args *DeleteLSIFIndexesArgs) (types.DeleteIndexesOptions, error) { +func makeDeleteIndexesOptions(args *DeleteLSIFIndexesArgs) (shared.DeleteIndexesOptions, error) { var repository int if args.Repository != nil { var err error repository, err = resolveRepositoryID(*args.Repository) if err != nil { - return types.DeleteIndexesOptions{}, err + return shared.DeleteIndexesOptions{}, err } } - return types.DeleteIndexesOptions{ + return shared.DeleteIndexesOptions{ State: strings.ToLower(derefString(args.State, "")), Term: derefString(args.Query, ""), RepositoryID: repository, diff --git a/internal/codeintel/autoindexing/transport/graphql/utils_test.go b/internal/codeintel/autoindexing/transport/graphql/utils_test.go index 41aa5744e8e..7022cccf891 100644 --- a/internal/codeintel/autoindexing/transport/graphql/utils_test.go +++ b/internal/codeintel/autoindexing/transport/graphql/utils_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/graph-gophers/graphql-go" - codeinteltypes "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" ) func TestMakeGetIndexesOptions(t *testing.T) { @@ -26,7 +26,7 @@ func TestMakeGetIndexesOptions(t *testing.T) { t.Fatalf("unexpected error making options: %s", err) } - expected := codeinteltypes.GetIndexesOptions{ + expected := shared.GetIndexesOptions{ RepositoryID: 50, State: "s", Term: "q", @@ -46,7 +46,7 @@ func TestMakeGetIndexesOptionsDefaults(t *testing.T) { t.Fatalf("unexpected error making options: %s", err) } - expected := codeinteltypes.GetIndexesOptions{ + expected := shared.GetIndexesOptions{ RepositoryID: 0, State: "", Term: "", diff --git a/internal/codeintel/codenav/commit_cache.go b/internal/codeintel/codenav/commit_cache.go index 3480b0dbb56..0c29c2f09df 100644 --- a/internal/codeintel/codenav/commit_cache.go +++ b/internal/codeintel/codenav/commit_cache.go @@ -6,7 +6,6 @@ import ( "strings" "sync" - "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/gitserver" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -18,12 +17,12 @@ type CommitCache interface { } type commitCache struct { - gitserverClient shared.GitserverClient + gitserverClient GitserverClient mutex sync.RWMutex cache map[int]map[string]bool } -func NewCommitCache(client shared.GitserverClient) CommitCache { +func NewCommitCache(client GitserverClient) CommitCache { return &commitCache{ gitserverClient: client, cache: map[int]map[string]bool{}, diff --git a/internal/codeintel/codenav/gittree_translator.go b/internal/codeintel/codenav/gittree_translator.go index 90f13adb5b1..2d2d4c7bd8b 100644 --- a/internal/codeintel/codenav/gittree_translator.go +++ b/internal/codeintel/codenav/gittree_translator.go @@ -9,7 +9,6 @@ import ( "github.com/sourcegraph/go-diff/diff" "github.com/sourcegraph/sourcegraph/internal/authz" - "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" sgtypes "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -38,7 +37,7 @@ type GitTreeTranslator interface { } type gitTreeTranslator struct { - client shared.GitserverClient + client GitserverClient localRequestArgs *requestArgs hunkCache HunkCache } @@ -74,7 +73,7 @@ func NewHunkCache(size int) (HunkCache, error) { } // NewGitTreeTranslator creates a new GitTreeTranslator with the given repository and source commit. -func NewGitTreeTranslator(client shared.GitserverClient, args *requestArgs, hunkCache HunkCache) GitTreeTranslator { +func NewGitTreeTranslator(client GitserverClient, args *requestArgs, hunkCache HunkCache) GitTreeTranslator { return &gitTreeTranslator{ client: client, hunkCache: hunkCache, diff --git a/internal/codeintel/codenav/request_state.go b/internal/codeintel/codenav/request_state.go index 1e59b0b83c8..27f3f7f6e7e 100644 --- a/internal/codeintel/codenav/request_state.go +++ b/internal/codeintel/codenav/request_state.go @@ -4,7 +4,6 @@ import ( "sync" "github.com/sourcegraph/sourcegraph/internal/authz" - "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" sgTypes "github.com/sourcegraph/sourcegraph/internal/types" ) @@ -28,7 +27,7 @@ type RequestState struct { func NewRequestState( uploads []types.Dump, authChecker authz.SubRepoPermissionChecker, - gitclient shared.GitserverClient, repo *sgTypes.Repo, commit, path string, + gitclient GitserverClient, repo *sgTypes.Repo, commit, path string, maxIndexes int, hunkCacheSize int, ) RequestState { @@ -65,7 +64,7 @@ func (r *RequestState) SetUploadsDataLoader(uploads []types.Dump) { } } -func (r *RequestState) SetLocalGitTreeTranslator(client shared.GitserverClient, repo *sgTypes.Repo, commit, path string, hunkCacheSize int) error { +func (r *RequestState) SetLocalGitTreeTranslator(client GitserverClient, repo *sgTypes.Repo, commit, path string, hunkCacheSize int) error { hunkCache, err := NewHunkCache(hunkCacheSize) if err != nil { return err @@ -82,7 +81,7 @@ func (r *RequestState) SetLocalGitTreeTranslator(client shared.GitserverClient, return nil } -func (r *RequestState) SetLocalCommitCache(client shared.GitserverClient) { +func (r *RequestState) SetLocalCommitCache(client GitserverClient) { r.commitCache = NewCommitCache(client) } diff --git a/internal/codeintel/codenav/shared/iface.go b/internal/codeintel/codenav/shared/iface.go deleted file mode 100644 index f09ba10a21a..00000000000 --- a/internal/codeintel/codenav/shared/iface.go +++ /dev/null @@ -1,16 +0,0 @@ -package shared - -import ( - "context" - - "github.com/sourcegraph/go-diff/diff" - - "github.com/sourcegraph/sourcegraph/internal/api" - "github.com/sourcegraph/sourcegraph/internal/authz" - "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/gitserver" -) - -type GitserverClient interface { - CommitsExist(ctx context.Context, commits []gitserver.RepositoryCommit) ([]bool, error) - DiffPath(ctx context.Context, checker authz.SubRepoPermissionChecker, repo api.RepoName, sourceCommit, targetCommit, path string) ([]*diff.Hunk, error) -} diff --git a/internal/codeintel/codenav/shared/types.go b/internal/codeintel/codenav/shared/types.go index 3ed17139ef9..e1058e03e31 100644 --- a/internal/codeintel/codenav/shared/types.go +++ b/internal/codeintel/codenav/shared/types.go @@ -5,10 +5,6 @@ import ( "github.com/sourcegraph/sourcegraph/lib/codeintel/precise" ) -type Symbol struct { - Name string -} - // Location is an LSP-like location scoped to a dump. type Location struct { DumpID int diff --git a/internal/codeintel/codenav/transport/graphql/iface.go b/internal/codeintel/codenav/transport/graphql/iface.go index b317a0a2c3b..21cce088d11 100644 --- a/internal/codeintel/codenav/transport/graphql/iface.go +++ b/internal/codeintel/codenav/transport/graphql/iface.go @@ -8,10 +8,12 @@ import ( "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/authz" + autoindexingShared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav" "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/gitserver" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + uploadsshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" ) @@ -38,7 +40,7 @@ type GitserverClient interface { } type AutoIndexingService interface { - GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error) + GetIndexes(ctx context.Context, opts autoindexingShared.GetIndexesOptions) (_ []types.Index, _ int, err error) GetIndexByID(ctx context.Context, id int) (_ types.Index, _ bool, err error) GetIndexesByIDs(ctx context.Context, ids ...int) (_ []types.Index, err error) GetUnsafeDB() database.DB @@ -47,7 +49,7 @@ type AutoIndexingService interface { } type UploadsService interface { - GetUploads(ctx context.Context, opts types.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) + GetUploads(ctx context.Context, opts uploadsshared.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) GetAuditLogsForUpload(ctx context.Context, uploadID int) (_ []types.UploadLog, err error) GetListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error) GetUploadDocumentsForPath(ctx context.Context, bundleID int, pathPattern string) ([]string, int, error) diff --git a/internal/codeintel/codenav/transport/graphql/mocks_test.go b/internal/codeintel/codenav/transport/graphql/mocks_test.go index 7c064f82b8c..bec71f2f113 100644 --- a/internal/codeintel/codenav/transport/graphql/mocks_test.go +++ b/internal/codeintel/codenav/transport/graphql/mocks_test.go @@ -14,9 +14,11 @@ import ( diff "github.com/sourcegraph/go-diff/diff" api "github.com/sourcegraph/sourcegraph/internal/api" authz "github.com/sourcegraph/sourcegraph/internal/authz" - shared "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared" + shared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" + shared1 "github.com/sourcegraph/sourcegraph/internal/codeintel/codenav/shared" gitserver "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/gitserver" types "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + shared2 "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" database "github.com/sourcegraph/sourcegraph/internal/database" gitdomain "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" ) @@ -57,7 +59,7 @@ func NewMockAutoIndexingService() *MockAutoIndexingService { }, }, GetIndexesFunc: &AutoIndexingServiceGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { return }, }, @@ -95,7 +97,7 @@ func NewStrictMockAutoIndexingService() *MockAutoIndexingService { }, }, GetIndexesFunc: &AutoIndexingServiceGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { panic("unexpected invocation of MockAutoIndexingService.GetIndexes") }, }, @@ -266,15 +268,15 @@ func (c AutoIndexingServiceGetIndexByIDFuncCall) Results() []interface{} { // GetIndexes method of the parent MockAutoIndexingService instance is // invoked. type AutoIndexingServiceGetIndexesFunc struct { - defaultHook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) - hooks []func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) + defaultHook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) + hooks []func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) history []AutoIndexingServiceGetIndexesFuncCall mutex sync.Mutex } // GetIndexes delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 types.GetIndexesOptions) ([]types.Index, int, error) { +func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 shared.GetIndexesOptions) ([]types.Index, int, error) { r0, r1, r2 := m.GetIndexesFunc.nextHook()(v0, v1) m.GetIndexesFunc.appendCall(AutoIndexingServiceGetIndexesFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -283,7 +285,7 @@ func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 types.GetInd // SetDefaultHook sets function that is called when the GetIndexes method of // the parent MockAutoIndexingService instance is invoked and the hook queue // is empty. -func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.defaultHook = hook } @@ -291,7 +293,7 @@ func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Con // GetIndexes method of the parent MockAutoIndexingService instance invokes // the hook at the front of the queue and discards it. After the queue is // empty, the default hook function is invoked for any future action. -func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -300,19 +302,19 @@ func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultReturn(r0 []types.Index, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.SetDefaultHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *AutoIndexingServiceGetIndexesFunc) PushReturn(r0 []types.Index, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.PushHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } -func (f *AutoIndexingServiceGetIndexesFunc) nextHook() func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { +func (f *AutoIndexingServiceGetIndexesFunc) nextHook() func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -351,7 +353,7 @@ type AutoIndexingServiceGetIndexesFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetIndexesOptions + Arg1 shared.GetIndexesOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Index @@ -867,7 +869,7 @@ func NewMockGitBlobResolver() *MockGitBlobResolver { }, }, DiagnosticsFunc: &GitBlobResolverDiagnosticsFunc{ - defaultHook: func(context.Context, int) (r0 []shared.DiagnosticAtUpload, r1 int, r2 error) { + defaultHook: func(context.Context, int) (r0 []shared1.DiagnosticAtUpload, r1 int, r2 error) { return }, }, @@ -887,7 +889,7 @@ func NewMockGitBlobResolver() *MockGitBlobResolver { }, }, RangesFunc: &GitBlobResolverRangesFunc{ - defaultHook: func(context.Context, int, int) (r0 []shared.AdjustedCodeIntelligenceRange, r1 error) { + defaultHook: func(context.Context, int, int) (r0 []shared1.AdjustedCodeIntelligenceRange, r1 error) { return }, }, @@ -914,7 +916,7 @@ func NewStrictMockGitBlobResolver() *MockGitBlobResolver { }, }, DiagnosticsFunc: &GitBlobResolverDiagnosticsFunc{ - defaultHook: func(context.Context, int) ([]shared.DiagnosticAtUpload, int, error) { + defaultHook: func(context.Context, int) ([]shared1.DiagnosticAtUpload, int, error) { panic("unexpected invocation of MockGitBlobResolver.Diagnostics") }, }, @@ -934,7 +936,7 @@ func NewStrictMockGitBlobResolver() *MockGitBlobResolver { }, }, RangesFunc: &GitBlobResolverRangesFunc{ - defaultHook: func(context.Context, int, int) ([]shared.AdjustedCodeIntelligenceRange, error) { + defaultHook: func(context.Context, int, int) ([]shared1.AdjustedCodeIntelligenceRange, error) { panic("unexpected invocation of MockGitBlobResolver.Ranges") }, }, @@ -1097,15 +1099,15 @@ func (c GitBlobResolverDefinitionsFuncCall) Results() []interface{} { // GitBlobResolverDiagnosticsFunc describes the behavior when the // Diagnostics method of the parent MockGitBlobResolver instance is invoked. type GitBlobResolverDiagnosticsFunc struct { - defaultHook func(context.Context, int) ([]shared.DiagnosticAtUpload, int, error) - hooks []func(context.Context, int) ([]shared.DiagnosticAtUpload, int, error) + defaultHook func(context.Context, int) ([]shared1.DiagnosticAtUpload, int, error) + hooks []func(context.Context, int) ([]shared1.DiagnosticAtUpload, int, error) history []GitBlobResolverDiagnosticsFuncCall mutex sync.Mutex } // Diagnostics delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockGitBlobResolver) Diagnostics(v0 context.Context, v1 int) ([]shared.DiagnosticAtUpload, int, error) { +func (m *MockGitBlobResolver) Diagnostics(v0 context.Context, v1 int) ([]shared1.DiagnosticAtUpload, int, error) { r0, r1, r2 := m.DiagnosticsFunc.nextHook()(v0, v1) m.DiagnosticsFunc.appendCall(GitBlobResolverDiagnosticsFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -1114,7 +1116,7 @@ func (m *MockGitBlobResolver) Diagnostics(v0 context.Context, v1 int) ([]shared. // SetDefaultHook sets function that is called when the Diagnostics method // of the parent MockGitBlobResolver instance is invoked and the hook queue // is empty. -func (f *GitBlobResolverDiagnosticsFunc) SetDefaultHook(hook func(context.Context, int) ([]shared.DiagnosticAtUpload, int, error)) { +func (f *GitBlobResolverDiagnosticsFunc) SetDefaultHook(hook func(context.Context, int) ([]shared1.DiagnosticAtUpload, int, error)) { f.defaultHook = hook } @@ -1122,7 +1124,7 @@ func (f *GitBlobResolverDiagnosticsFunc) SetDefaultHook(hook func(context.Contex // Diagnostics method of the parent MockGitBlobResolver instance invokes the // hook at the front of the queue and discards it. After the queue is empty, // the default hook function is invoked for any future action. -func (f *GitBlobResolverDiagnosticsFunc) PushHook(hook func(context.Context, int) ([]shared.DiagnosticAtUpload, int, error)) { +func (f *GitBlobResolverDiagnosticsFunc) PushHook(hook func(context.Context, int) ([]shared1.DiagnosticAtUpload, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -1130,20 +1132,20 @@ func (f *GitBlobResolverDiagnosticsFunc) PushHook(hook func(context.Context, int // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *GitBlobResolverDiagnosticsFunc) SetDefaultReturn(r0 []shared.DiagnosticAtUpload, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, int) ([]shared.DiagnosticAtUpload, int, error) { +func (f *GitBlobResolverDiagnosticsFunc) SetDefaultReturn(r0 []shared1.DiagnosticAtUpload, r1 int, r2 error) { + f.SetDefaultHook(func(context.Context, int) ([]shared1.DiagnosticAtUpload, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *GitBlobResolverDiagnosticsFunc) PushReturn(r0 []shared.DiagnosticAtUpload, r1 int, r2 error) { - f.PushHook(func(context.Context, int) ([]shared.DiagnosticAtUpload, int, error) { +func (f *GitBlobResolverDiagnosticsFunc) PushReturn(r0 []shared1.DiagnosticAtUpload, r1 int, r2 error) { + f.PushHook(func(context.Context, int) ([]shared1.DiagnosticAtUpload, int, error) { return r0, r1, r2 }) } -func (f *GitBlobResolverDiagnosticsFunc) nextHook() func(context.Context, int) ([]shared.DiagnosticAtUpload, int, error) { +func (f *GitBlobResolverDiagnosticsFunc) nextHook() func(context.Context, int) ([]shared1.DiagnosticAtUpload, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -1184,7 +1186,7 @@ type GitBlobResolverDiagnosticsFuncCall struct { Arg1 int // Result0 is the value of the 1st result returned from this method // invocation. - Result0 []shared.DiagnosticAtUpload + Result0 []shared1.DiagnosticAtUpload // Result1 is the value of the 2nd result returned from this method // invocation. Result1 int @@ -1552,15 +1554,15 @@ func (c GitBlobResolverLSIFUploadsFuncCall) Results() []interface{} { // GitBlobResolverRangesFunc describes the behavior when the Ranges method // of the parent MockGitBlobResolver instance is invoked. type GitBlobResolverRangesFunc struct { - defaultHook func(context.Context, int, int) ([]shared.AdjustedCodeIntelligenceRange, error) - hooks []func(context.Context, int, int) ([]shared.AdjustedCodeIntelligenceRange, error) + defaultHook func(context.Context, int, int) ([]shared1.AdjustedCodeIntelligenceRange, error) + hooks []func(context.Context, int, int) ([]shared1.AdjustedCodeIntelligenceRange, error) history []GitBlobResolverRangesFuncCall mutex sync.Mutex } // Ranges delegates to the next hook function in the queue and stores the // parameter and result values of this invocation. -func (m *MockGitBlobResolver) Ranges(v0 context.Context, v1 int, v2 int) ([]shared.AdjustedCodeIntelligenceRange, error) { +func (m *MockGitBlobResolver) Ranges(v0 context.Context, v1 int, v2 int) ([]shared1.AdjustedCodeIntelligenceRange, error) { r0, r1 := m.RangesFunc.nextHook()(v0, v1, v2) m.RangesFunc.appendCall(GitBlobResolverRangesFuncCall{v0, v1, v2, r0, r1}) return r0, r1 @@ -1569,7 +1571,7 @@ func (m *MockGitBlobResolver) Ranges(v0 context.Context, v1 int, v2 int) ([]shar // SetDefaultHook sets function that is called when the Ranges method of the // parent MockGitBlobResolver instance is invoked and the hook queue is // empty. -func (f *GitBlobResolverRangesFunc) SetDefaultHook(hook func(context.Context, int, int) ([]shared.AdjustedCodeIntelligenceRange, error)) { +func (f *GitBlobResolverRangesFunc) SetDefaultHook(hook func(context.Context, int, int) ([]shared1.AdjustedCodeIntelligenceRange, error)) { f.defaultHook = hook } @@ -1577,7 +1579,7 @@ func (f *GitBlobResolverRangesFunc) SetDefaultHook(hook func(context.Context, in // Ranges method of the parent MockGitBlobResolver instance invokes the hook // at the front of the queue and discards it. After the queue is empty, the // default hook function is invoked for any future action. -func (f *GitBlobResolverRangesFunc) PushHook(hook func(context.Context, int, int) ([]shared.AdjustedCodeIntelligenceRange, error)) { +func (f *GitBlobResolverRangesFunc) PushHook(hook func(context.Context, int, int) ([]shared1.AdjustedCodeIntelligenceRange, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -1585,20 +1587,20 @@ func (f *GitBlobResolverRangesFunc) PushHook(hook func(context.Context, int, int // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *GitBlobResolverRangesFunc) SetDefaultReturn(r0 []shared.AdjustedCodeIntelligenceRange, r1 error) { - f.SetDefaultHook(func(context.Context, int, int) ([]shared.AdjustedCodeIntelligenceRange, error) { +func (f *GitBlobResolverRangesFunc) SetDefaultReturn(r0 []shared1.AdjustedCodeIntelligenceRange, r1 error) { + f.SetDefaultHook(func(context.Context, int, int) ([]shared1.AdjustedCodeIntelligenceRange, error) { return r0, r1 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *GitBlobResolverRangesFunc) PushReturn(r0 []shared.AdjustedCodeIntelligenceRange, r1 error) { - f.PushHook(func(context.Context, int, int) ([]shared.AdjustedCodeIntelligenceRange, error) { +func (f *GitBlobResolverRangesFunc) PushReturn(r0 []shared1.AdjustedCodeIntelligenceRange, r1 error) { + f.PushHook(func(context.Context, int, int) ([]shared1.AdjustedCodeIntelligenceRange, error) { return r0, r1 }) } -func (f *GitBlobResolverRangesFunc) nextHook() func(context.Context, int, int) ([]shared.AdjustedCodeIntelligenceRange, error) { +func (f *GitBlobResolverRangesFunc) nextHook() func(context.Context, int, int) ([]shared1.AdjustedCodeIntelligenceRange, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -1642,7 +1644,7 @@ type GitBlobResolverRangesFuncCall struct { Arg2 int // Result0 is the value of the 1st result returned from this method // invocation. - Result0 []shared.AdjustedCodeIntelligenceRange + Result0 []shared1.AdjustedCodeIntelligenceRange // Result1 is the value of the 2nd result returned from this method // invocation. Result1 error @@ -2395,7 +2397,7 @@ func NewMockUploadsService() *MockUploadsService { }, }, GetUploadsFunc: &UploadsServiceGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { + defaultHook: func(context.Context, shared2.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { return }, }, @@ -2427,7 +2429,7 @@ func NewStrictMockUploadsService() *MockUploadsService { }, }, GetUploadsFunc: &UploadsServiceGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + defaultHook: func(context.Context, shared2.GetUploadsOptions) ([]types.Upload, int, error) { panic("unexpected invocation of MockUploadsService.GetUploads") }, }, @@ -2812,15 +2814,15 @@ func (c UploadsServiceGetUploadDocumentsForPathFuncCall) Results() []interface{} // UploadsServiceGetUploadsFunc describes the behavior when the GetUploads // method of the parent MockUploadsService instance is invoked. type UploadsServiceGetUploadsFunc struct { - defaultHook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) - hooks []func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) + defaultHook func(context.Context, shared2.GetUploadsOptions) ([]types.Upload, int, error) + hooks []func(context.Context, shared2.GetUploadsOptions) ([]types.Upload, int, error) history []UploadsServiceGetUploadsFuncCall mutex sync.Mutex } // GetUploads delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockUploadsService) GetUploads(v0 context.Context, v1 types.GetUploadsOptions) ([]types.Upload, int, error) { +func (m *MockUploadsService) GetUploads(v0 context.Context, v1 shared2.GetUploadsOptions) ([]types.Upload, int, error) { r0, r1, r2 := m.GetUploadsFunc.nextHook()(v0, v1) m.GetUploadsFunc.appendCall(UploadsServiceGetUploadsFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -2829,7 +2831,7 @@ func (m *MockUploadsService) GetUploads(v0 context.Context, v1 types.GetUploadsO // SetDefaultHook sets function that is called when the GetUploads method of // the parent MockUploadsService instance is invoked and the hook queue is // empty. -func (f *UploadsServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *UploadsServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, shared2.GetUploadsOptions) ([]types.Upload, int, error)) { f.defaultHook = hook } @@ -2837,7 +2839,7 @@ func (f *UploadsServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, // GetUploads method of the parent MockUploadsService instance invokes the // hook at the front of the queue and discards it. After the queue is empty, // the default hook function is invoked for any future action. -func (f *UploadsServiceGetUploadsFunc) PushHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *UploadsServiceGetUploadsFunc) PushHook(hook func(context.Context, shared2.GetUploadsOptions) ([]types.Upload, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -2846,19 +2848,19 @@ func (f *UploadsServiceGetUploadsFunc) PushHook(hook func(context.Context, types // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *UploadsServiceGetUploadsFunc) SetDefaultReturn(r0 []types.Upload, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.SetDefaultHook(func(context.Context, shared2.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *UploadsServiceGetUploadsFunc) PushReturn(r0 []types.Upload, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.PushHook(func(context.Context, shared2.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } -func (f *UploadsServiceGetUploadsFunc) nextHook() func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { +func (f *UploadsServiceGetUploadsFunc) nextHook() func(context.Context, shared2.GetUploadsOptions) ([]types.Upload, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -2896,7 +2898,7 @@ type UploadsServiceGetUploadsFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetUploadsOptions + Arg1 shared2.GetUploadsOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Upload diff --git a/internal/codeintel/policies/internal/store/store.go b/internal/codeintel/policies/internal/store/store.go index 2fcefb1e541..61b03e31e90 100644 --- a/internal/codeintel/policies/internal/store/store.go +++ b/internal/codeintel/policies/internal/store/store.go @@ -5,6 +5,7 @@ import ( logger "github.com/sourcegraph/log" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/database/basestore" @@ -14,7 +15,7 @@ import ( // Store provides the interface for policies storage. type Store interface { // Configurations - GetConfigurationPolicies(ctx context.Context, opts types.GetConfigurationPoliciesOptions) (_ []types.ConfigurationPolicy, totalCount int, err error) + GetConfigurationPolicies(ctx context.Context, opts policiesshared.GetConfigurationPoliciesOptions) (_ []types.ConfigurationPolicy, totalCount int, err error) GetConfigurationPolicyByID(ctx context.Context, id int) (_ types.ConfigurationPolicy, _ bool, err error) CreateConfigurationPolicy(ctx context.Context, configurationPolicy types.ConfigurationPolicy) (types.ConfigurationPolicy, error) UpdateConfigurationPolicy(ctx context.Context, policy types.ConfigurationPolicy) (err error) diff --git a/internal/codeintel/policies/internal/store/store_configuration.go b/internal/codeintel/policies/internal/store/store_configuration.go index eaf24e9e0bd..806b20b1502 100644 --- a/internal/codeintel/policies/internal/store/store_configuration.go +++ b/internal/codeintel/policies/internal/store/store_configuration.go @@ -9,6 +9,7 @@ import ( "github.com/lib/pq" "github.com/opentracing/opentracing-go/log" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/database/basestore" @@ -18,7 +19,7 @@ import ( // GetConfigurationPolicies retrieves the set of configuration policies matching the the given options. // If a repository identifier is supplied (is non-zero), then only the configuration policies that apply // to repository are returned. If repository is not supplied, then all policies may be returned. -func (s *store) GetConfigurationPolicies(ctx context.Context, opts types.GetConfigurationPoliciesOptions) (_ []types.ConfigurationPolicy, totalCount int, err error) { +func (s *store) GetConfigurationPolicies(ctx context.Context, opts policiesshared.GetConfigurationPoliciesOptions) (_ []types.ConfigurationPolicy, totalCount int, err error) { ctx, trace, endObservation := s.operations.getConfigurationPolicies.With(ctx, &err, observation.Args{LogFields: []log.Field{ log.Int("repositoryID", opts.RepositoryID), log.String("term", opts.Term), diff --git a/internal/codeintel/policies/internal/store/store_configuration_test.go b/internal/codeintel/policies/internal/store/store_configuration_test.go index 8e60f2beae8..a19c31ac3f2 100644 --- a/internal/codeintel/policies/internal/store/store_configuration_test.go +++ b/internal/codeintel/policies/internal/store/store_configuration_test.go @@ -12,6 +12,7 @@ import ( "github.com/keegancsmith/sqlf" "github.com/sourcegraph/log/logtest" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/database/dbtest" @@ -108,7 +109,7 @@ func TestGetConfigurationPolicies(t *testing.T) { ) t.Run(name, func(t *testing.T) { - policies, totalCount, err := store.GetConfigurationPolicies(ctx, types.GetConfigurationPoliciesOptions{ + policies, totalCount, err := store.GetConfigurationPolicies(ctx, policiesshared.GetConfigurationPoliciesOptions{ RepositoryID: testCase.repositoryID, Term: testCase.term, ForDataRetention: testCase.forDataRetention, diff --git a/internal/codeintel/policies/mocks_test.go b/internal/codeintel/policies/mocks_test.go index 6494c783115..9512f0707f9 100644 --- a/internal/codeintel/policies/mocks_test.go +++ b/internal/codeintel/policies/mocks_test.go @@ -12,6 +12,7 @@ import ( "time" store "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/internal/store" + shared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" types "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" database "github.com/sourcegraph/sourcegraph/internal/database" gitdomain "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" @@ -72,7 +73,7 @@ func NewMockStore() *MockStore { }, }, GetConfigurationPoliciesFunc: &StoreGetConfigurationPoliciesFunc{ - defaultHook: func(context.Context, types.GetConfigurationPoliciesOptions) (r0 []types.ConfigurationPolicy, r1 int, r2 error) { + defaultHook: func(context.Context, shared.GetConfigurationPoliciesOptions) (r0 []types.ConfigurationPolicy, r1 int, r2 error) { return }, }, @@ -124,7 +125,7 @@ func NewStrictMockStore() *MockStore { }, }, GetConfigurationPoliciesFunc: &StoreGetConfigurationPoliciesFunc{ - defaultHook: func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { + defaultHook: func(context.Context, shared.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { panic("unexpected invocation of MockStore.GetConfigurationPolicies") }, }, @@ -417,15 +418,15 @@ func (c StoreDeleteConfigurationPolicyByIDFuncCall) Results() []interface{} { // GetConfigurationPolicies method of the parent MockStore instance is // invoked. type StoreGetConfigurationPoliciesFunc struct { - defaultHook func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) - hooks []func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) + defaultHook func(context.Context, shared.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) + hooks []func(context.Context, shared.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) history []StoreGetConfigurationPoliciesFuncCall mutex sync.Mutex } // GetConfigurationPolicies delegates to the next hook function in the queue // and stores the parameter and result values of this invocation. -func (m *MockStore) GetConfigurationPolicies(v0 context.Context, v1 types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { +func (m *MockStore) GetConfigurationPolicies(v0 context.Context, v1 shared.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { r0, r1, r2 := m.GetConfigurationPoliciesFunc.nextHook()(v0, v1) m.GetConfigurationPoliciesFunc.appendCall(StoreGetConfigurationPoliciesFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -434,7 +435,7 @@ func (m *MockStore) GetConfigurationPolicies(v0 context.Context, v1 types.GetCon // SetDefaultHook sets function that is called when the // GetConfigurationPolicies method of the parent MockStore instance is // invoked and the hook queue is empty. -func (f *StoreGetConfigurationPoliciesFunc) SetDefaultHook(hook func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error)) { +func (f *StoreGetConfigurationPoliciesFunc) SetDefaultHook(hook func(context.Context, shared.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error)) { f.defaultHook = hook } @@ -442,7 +443,7 @@ func (f *StoreGetConfigurationPoliciesFunc) SetDefaultHook(hook func(context.Con // GetConfigurationPolicies method of the parent MockStore instance invokes // the hook at the front of the queue and discards it. After the queue is // empty, the default hook function is invoked for any future action. -func (f *StoreGetConfigurationPoliciesFunc) PushHook(hook func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error)) { +func (f *StoreGetConfigurationPoliciesFunc) PushHook(hook func(context.Context, shared.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -451,19 +452,19 @@ func (f *StoreGetConfigurationPoliciesFunc) PushHook(hook func(context.Context, // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *StoreGetConfigurationPoliciesFunc) SetDefaultReturn(r0 []types.ConfigurationPolicy, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { + f.SetDefaultHook(func(context.Context, shared.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *StoreGetConfigurationPoliciesFunc) PushReturn(r0 []types.ConfigurationPolicy, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { + f.PushHook(func(context.Context, shared.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { return r0, r1, r2 }) } -func (f *StoreGetConfigurationPoliciesFunc) nextHook() func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { +func (f *StoreGetConfigurationPoliciesFunc) nextHook() func(context.Context, shared.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -502,7 +503,7 @@ type StoreGetConfigurationPoliciesFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetConfigurationPoliciesOptions + Arg1 shared.GetConfigurationPoliciesOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.ConfigurationPolicy diff --git a/internal/codeintel/policies/service.go b/internal/codeintel/policies/service.go index e7767c3f4a7..f116ee1abf3 100644 --- a/internal/codeintel/policies/service.go +++ b/internal/codeintel/policies/service.go @@ -7,6 +7,7 @@ import ( policies "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise" "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/internal/store" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" "github.com/sourcegraph/sourcegraph/internal/conf" "github.com/sourcegraph/sourcegraph/internal/database" @@ -42,7 +43,7 @@ func (s *Service) getPolicyMatcherFromFactory(gitserver GitserverClient, extract return policies.NewMatcher(gitserver, extractor, includeTipOfDefaultBranch, filterByCreatedDate) } -func (s *Service) GetConfigurationPolicies(ctx context.Context, opts types.GetConfigurationPoliciesOptions) (_ []types.ConfigurationPolicy, totalCount int, err error) { +func (s *Service) GetConfigurationPolicies(ctx context.Context, opts policiesshared.GetConfigurationPoliciesOptions) (_ []types.ConfigurationPolicy, totalCount int, err error) { ctx, _, endObservation := s.operations.getConfigurationPolicies.With(ctx, &err, observation.Args{}) defer endObservation(1, observation.Args{}) @@ -118,7 +119,7 @@ func (s *Service) GetRetentionPolicyOverview(ctx context.Context, upload types.U policyMatcher := s.getPolicyMatcherFromFactory(s.gitserver, policies.RetentionExtractor, true, false) - configPolicies, _, err := s.GetConfigurationPolicies(ctx, types.GetConfigurationPoliciesOptions{ + configPolicies, _, err := s.GetConfigurationPolicies(ctx, policiesshared.GetConfigurationPoliciesOptions{ RepositoryID: upload.RepositoryID, Term: query, ForDataRetention: true, diff --git a/internal/codeintel/policies/shared/types.go b/internal/codeintel/policies/shared/types.go index 84c8d4eb430..8356c6a4ce9 100644 --- a/internal/codeintel/policies/shared/types.go +++ b/internal/codeintel/policies/shared/types.go @@ -1,5 +1,25 @@ package shared -type Policy struct { - ID int +type GetConfigurationPoliciesOptions struct { + // RepositoryID indicates that only configuration policies that apply to the + // specified repository (directly or via pattern) should be returned. This value + // has no effect when equal to zero. + RepositoryID int + + // Term is a string to search within the configuration title. + Term string + + // ForIndexing indicates that only configuration policies with data retention enabled + // should be returned. + ForDataRetention bool + + // ForIndexing indicates that only configuration policies with indexing enabled should + // be returned. + ForIndexing bool + + // Limit indicates the number of results to take from the result set. + Limit int + + // Offset indicates the number of results to skip in the result set. + Offset int } diff --git a/internal/codeintel/policies/transport/graphql/iface.go b/internal/codeintel/policies/transport/graphql/iface.go index 61d9f255a5c..aa5e1da21c5 100644 --- a/internal/codeintel/policies/transport/graphql/iface.go +++ b/internal/codeintel/policies/transport/graphql/iface.go @@ -4,12 +4,13 @@ import ( "context" "time" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" ) type Service interface { // Configurations - GetConfigurationPolicies(ctx context.Context, opts types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) + GetConfigurationPolicies(ctx context.Context, opts policiesshared.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) GetConfigurationPolicyByID(ctx context.Context, id int) (_ types.ConfigurationPolicy, _ bool, err error) CreateConfigurationPolicy(ctx context.Context, configurationPolicy types.ConfigurationPolicy) (types.ConfigurationPolicy, error) UpdateConfigurationPolicy(ctx context.Context, policy types.ConfigurationPolicy) (err error) diff --git a/internal/codeintel/policies/transport/graphql/root_resolver.go b/internal/codeintel/policies/transport/graphql/root_resolver.go index fdb0a0fa5a0..134ad2e21f5 100644 --- a/internal/codeintel/policies/transport/graphql/root_resolver.go +++ b/internal/codeintel/policies/transport/graphql/root_resolver.go @@ -14,6 +14,7 @@ import ( "github.com/sourcegraph/sourcegraph/internal/api" "github.com/sourcegraph/sourcegraph/internal/auth" "github.com/sourcegraph/sourcegraph/internal/codeintel/policies" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" sharedresolvers "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/resolvers" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" "github.com/sourcegraph/sourcegraph/internal/gitserver" @@ -91,7 +92,7 @@ func (r *rootResolver) CodeIntelligenceConfigurationPolicies(ctx context.Context pageSize = int(*args.First) } - opts := types.GetConfigurationPoliciesOptions{ + opts := policiesshared.GetConfigurationPoliciesOptions{ Limit: pageSize, Offset: offset, } diff --git a/internal/codeintel/shared/resolvers/iface.go b/internal/codeintel/shared/resolvers/iface.go index 155539c754f..117e010f0a5 100644 --- a/internal/codeintel/shared/resolvers/iface.go +++ b/internal/codeintel/shared/resolvers/iface.go @@ -7,13 +7,14 @@ import ( "github.com/sourcegraph/sourcegraph/internal/api" autoindexingShared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" uploadsShared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" ) type AutoIndexingService interface { - GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error) + GetIndexes(ctx context.Context, opts autoindexingShared.GetIndexesOptions) (_ []types.Index, _ int, err error) GetIndexByID(ctx context.Context, id int) (_ types.Index, _ bool, err error) GetIndexesByIDs(ctx context.Context, ids ...int) (_ []types.Index, err error) GetUnsafeDB() database.DB @@ -21,7 +22,7 @@ type AutoIndexingService interface { } type UploadsService interface { - GetUploads(ctx context.Context, opts types.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) + GetUploads(ctx context.Context, opts shared.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) GetAuditLogsForUpload(ctx context.Context, uploadID int) (_ []types.UploadLog, err error) GetListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error) GetUploadDocumentsForPath(ctx context.Context, bundleID int, pathPattern string) ([]string, int, error) diff --git a/internal/codeintel/shared/resolvers/index_resolvers.go b/internal/codeintel/shared/resolvers/index_resolvers.go index d5147b9e9f0..48ce3d1c112 100644 --- a/internal/codeintel/shared/resolvers/index_resolvers.go +++ b/internal/codeintel/shared/resolvers/index_resolvers.go @@ -120,7 +120,7 @@ func (r *indexResolver) ProjectRoot(ctx context.Context) (_ *GitTreeEntryResolve func (r *indexResolver) Indexer() types.CodeIntelIndexerResolver { // drop the tag if it exists if idx, ok := types.ImageToIndexer[strings.Split(r.index.Indexer, ":")[0]]; ok { - return idx + return types.NewCodeIntelIndexerResolverFrom(idx) } return types.NewCodeIntelIndexerResolver(r.index.Indexer) diff --git a/internal/codeintel/shared/resolvers/indexes_repository_namespace_resolver.go b/internal/codeintel/shared/resolvers/indexes_repository_namespace_resolver.go index cd99c61a17a..fd1ce6bc247 100644 --- a/internal/codeintel/shared/resolvers/indexes_repository_namespace_resolver.go +++ b/internal/codeintel/shared/resolvers/indexes_repository_namespace_resolver.go @@ -32,7 +32,7 @@ func (r *lsifIndexesWithRepositoryNamespaceResolver) Root() string { func (r *lsifIndexesWithRepositoryNamespaceResolver) Indexer() types.CodeIntelIndexerResolver { // drop the tag if it exists if idx, ok := types.ImageToIndexer[strings.Split(r.indexesSummary.Indexer, ":")[0]]; ok { - return idx + return types.NewCodeIntelIndexerResolverFrom(idx) } return types.NewCodeIntelIndexerResolver(r.indexesSummary.Indexer) diff --git a/internal/codeintel/shared/resolvers/indexes_resolver.go b/internal/codeintel/shared/resolvers/indexes_resolver.go index 27b9d70c295..041ff87d1b4 100644 --- a/internal/codeintel/shared/resolvers/indexes_resolver.go +++ b/internal/codeintel/shared/resolvers/indexes_resolver.go @@ -5,6 +5,7 @@ import ( "sync" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" + "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" ) @@ -12,7 +13,7 @@ import ( // invoked lazily and its results memoized. type IndexesResolver struct { svc AutoIndexingService - opts types.GetIndexesOptions + opts shared.GetIndexesOptions once sync.Once // Indexes []types.Index @@ -23,7 +24,7 @@ type IndexesResolver struct { // NewIndexesResolver creates a new IndexesResolver which wil invoke store.GetIndexes // with the given options. -func NewIndexesResolver(svc AutoIndexingService, opts types.GetIndexesOptions) *IndexesResolver { +func NewIndexesResolver(svc AutoIndexingService, opts shared.GetIndexesOptions) *IndexesResolver { return &IndexesResolver{svc: svc, opts: opts} } diff --git a/internal/codeintel/shared/resolvers/mocks_temp.go b/internal/codeintel/shared/resolvers/mocks_temp.go index da5d8755512..3dc6acca3be 100644 --- a/internal/codeintel/shared/resolvers/mocks_temp.go +++ b/internal/codeintel/shared/resolvers/mocks_temp.go @@ -11,7 +11,9 @@ import ( "sync" api "github.com/sourcegraph/sourcegraph/internal/api" + shared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" types "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + shared1 "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" database "github.com/sourcegraph/sourcegraph/internal/database" gitdomain "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" ) @@ -49,7 +51,7 @@ func NewMockAutoIndexingService() *MockAutoIndexingService { }, }, GetIndexesFunc: &AutoIndexingServiceGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { return }, }, @@ -82,7 +84,7 @@ func NewStrictMockAutoIndexingService() *MockAutoIndexingService { }, }, GetIndexesFunc: &AutoIndexingServiceGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { panic("unexpected invocation of MockAutoIndexingService.GetIndexes") }, }, @@ -245,15 +247,15 @@ func (c AutoIndexingServiceGetIndexByIDFuncCall) Results() []interface{} { // GetIndexes method of the parent MockAutoIndexingService instance is // invoked. type AutoIndexingServiceGetIndexesFunc struct { - defaultHook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) - hooks []func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) + defaultHook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) + hooks []func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) history []AutoIndexingServiceGetIndexesFuncCall mutex sync.Mutex } // GetIndexes delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 types.GetIndexesOptions) ([]types.Index, int, error) { +func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 shared.GetIndexesOptions) ([]types.Index, int, error) { r0, r1, r2 := m.GetIndexesFunc.nextHook()(v0, v1) m.GetIndexesFunc.appendCall(AutoIndexingServiceGetIndexesFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -262,7 +264,7 @@ func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 types.GetInd // SetDefaultHook sets function that is called when the GetIndexes method of // the parent MockAutoIndexingService instance is invoked and the hook queue // is empty. -func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.defaultHook = hook } @@ -270,7 +272,7 @@ func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Con // GetIndexes method of the parent MockAutoIndexingService instance invokes // the hook at the front of the queue and discards it. After the queue is // empty, the default hook function is invoked for any future action. -func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -279,19 +281,19 @@ func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultReturn(r0 []types.Index, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.SetDefaultHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *AutoIndexingServiceGetIndexesFunc) PushReturn(r0 []types.Index, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.PushHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } -func (f *AutoIndexingServiceGetIndexesFunc) nextHook() func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { +func (f *AutoIndexingServiceGetIndexesFunc) nextHook() func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -330,7 +332,7 @@ type AutoIndexingServiceGetIndexesFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetIndexesOptions + Arg1 shared.GetIndexesOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Index @@ -736,7 +738,7 @@ func NewMockUploadsService() *MockUploadsService { }, }, GetUploadsFunc: &UploadsServiceGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { + defaultHook: func(context.Context, shared1.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { return }, }, @@ -768,7 +770,7 @@ func NewStrictMockUploadsService() *MockUploadsService { }, }, GetUploadsFunc: &UploadsServiceGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + defaultHook: func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { panic("unexpected invocation of MockUploadsService.GetUploads") }, }, @@ -1153,15 +1155,15 @@ func (c UploadsServiceGetUploadDocumentsForPathFuncCall) Results() []interface{} // UploadsServiceGetUploadsFunc describes the behavior when the GetUploads // method of the parent MockUploadsService instance is invoked. type UploadsServiceGetUploadsFunc struct { - defaultHook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) - hooks []func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) + defaultHook func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) + hooks []func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) history []UploadsServiceGetUploadsFuncCall mutex sync.Mutex } // GetUploads delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockUploadsService) GetUploads(v0 context.Context, v1 types.GetUploadsOptions) ([]types.Upload, int, error) { +func (m *MockUploadsService) GetUploads(v0 context.Context, v1 shared1.GetUploadsOptions) ([]types.Upload, int, error) { r0, r1, r2 := m.GetUploadsFunc.nextHook()(v0, v1) m.GetUploadsFunc.appendCall(UploadsServiceGetUploadsFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -1170,7 +1172,7 @@ func (m *MockUploadsService) GetUploads(v0 context.Context, v1 types.GetUploadsO // SetDefaultHook sets function that is called when the GetUploads method of // the parent MockUploadsService instance is invoked and the hook queue is // empty. -func (f *UploadsServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *UploadsServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error)) { f.defaultHook = hook } @@ -1178,7 +1180,7 @@ func (f *UploadsServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, // GetUploads method of the parent MockUploadsService instance invokes the // hook at the front of the queue and discards it. After the queue is empty, // the default hook function is invoked for any future action. -func (f *UploadsServiceGetUploadsFunc) PushHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *UploadsServiceGetUploadsFunc) PushHook(hook func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -1187,19 +1189,19 @@ func (f *UploadsServiceGetUploadsFunc) PushHook(hook func(context.Context, types // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *UploadsServiceGetUploadsFunc) SetDefaultReturn(r0 []types.Upload, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.SetDefaultHook(func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *UploadsServiceGetUploadsFunc) PushReturn(r0 []types.Upload, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.PushHook(func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } -func (f *UploadsServiceGetUploadsFunc) nextHook() func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { +func (f *UploadsServiceGetUploadsFunc) nextHook() func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -1237,7 +1239,7 @@ type UploadsServiceGetUploadsFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetUploadsOptions + Arg1 shared1.GetUploadsOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Upload diff --git a/internal/codeintel/shared/resolvers/upload_resolver.go b/internal/codeintel/shared/resolvers/upload_resolver.go index f0b9ccc4aee..60bc07048b9 100644 --- a/internal/codeintel/shared/resolvers/upload_resolver.go +++ b/internal/codeintel/shared/resolvers/upload_resolver.go @@ -156,8 +156,8 @@ func (r *UploadResolver) RetentionPolicyOverview(ctx context.Context, args *LSIF func (r *UploadResolver) Indexer() types.CodeIntelIndexerResolver { for _, indexer := range types.AllIndexers { - if indexer.Name() == r.upload.Indexer { - return indexer + if indexer.Name == r.upload.Indexer { + return types.NewCodeIntelIndexerResolverFrom(indexer) } } diff --git a/internal/codeintel/shared/resolvers/uploads_repository_namespace_resolver.go b/internal/codeintel/shared/resolvers/uploads_repository_namespace_resolver.go index eacc830f35d..3406a919077 100644 --- a/internal/codeintel/shared/resolvers/uploads_repository_namespace_resolver.go +++ b/internal/codeintel/shared/resolvers/uploads_repository_namespace_resolver.go @@ -29,8 +29,8 @@ func (r *lsifUploadsWithRepositoryNamespaceResolver) Root() string { func (r *lsifUploadsWithRepositoryNamespaceResolver) Indexer() types.CodeIntelIndexerResolver { for _, indexer := range types.AllIndexers { - if indexer.Name() == r.uploadsSummary.Indexer { - return indexer + if indexer.Name == r.uploadsSummary.Indexer { + return types.NewCodeIntelIndexerResolverFrom(indexer) } } diff --git a/internal/codeintel/shared/resolvers/uploads_resolver.go b/internal/codeintel/shared/resolvers/uploads_resolver.go index a5c3acc4633..dd62a795f26 100644 --- a/internal/codeintel/shared/resolvers/uploads_resolver.go +++ b/internal/codeintel/shared/resolvers/uploads_resolver.go @@ -5,13 +5,14 @@ import ( "sync" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" ) // UploadsResolver wraps store.GetUploads so that the underlying function can be // invoked lazily and its results memoized. type UploadsResolver struct { svc UploadsService - opts types.GetUploadsOptions + opts shared.GetUploadsOptions once sync.Once Uploads []types.Upload @@ -22,7 +23,7 @@ type UploadsResolver struct { // NewUploadsResolver creates a new UploadsResolver which wil invoke store.GetUploads // with the given options. -func NewUploadsResolver(svc UploadsService, opts types.GetUploadsOptions) *UploadsResolver { +func NewUploadsResolver(svc UploadsService, opts shared.GetUploadsOptions) *UploadsResolver { return &UploadsResolver{svc: svc, opts: opts} } diff --git a/internal/codeintel/shared/types/codenav.go b/internal/codeintel/shared/types/codenav.go new file mode 100644 index 00000000000..11a6b0870dd --- /dev/null +++ b/internal/codeintel/shared/types/codenav.go @@ -0,0 +1,21 @@ +package types + +// UploadLocation is a path and range pair from within a particular upload. The target commit +// denotes the target commit for which the location was set (the originally requested commit). +type UploadLocation struct { + Dump Dump + Path string + TargetCommit string + TargetRange Range +} + +type Range struct { + Start Position + End Position +} + +// Position is a unique position within a file. +type Position struct { + Line int + Character int +} diff --git a/internal/codeintel/shared/types/dump.go b/internal/codeintel/shared/types/dump.go new file mode 100644 index 00000000000..dd1ae44a769 --- /dev/null +++ b/internal/codeintel/shared/types/dump.go @@ -0,0 +1,25 @@ +package types + +import "time" + +// Dump is a subset of the lsif_uploads table (queried via the lsif_dumps_with_repository_name view) +// and stores only processed records. +type Dump struct { + ID int `json:"id"` + Commit string `json:"commit"` + Root string `json:"root"` + VisibleAtTip bool `json:"visibleAtTip"` + UploadedAt time.Time `json:"uploadedAt"` + State string `json:"state"` + FailureMessage *string `json:"failureMessage"` + StartedAt *time.Time `json:"startedAt"` + FinishedAt *time.Time `json:"finishedAt"` + ProcessAfter *time.Time `json:"processAfter"` + NumResets int `json:"numResets"` + NumFailures int `json:"numFailures"` + RepositoryID int `json:"repositoryId"` + RepositoryName string `json:"repositoryName"` + Indexer string `json:"indexer"` + IndexerVersion string `json:"indexerVersion"` + AssociatedIndexID *int `json:"associatedIndex"` +} diff --git a/internal/codeintel/shared/types/index.go b/internal/codeintel/shared/types/index.go index 7b9bd56e4a9..d8af2cfa73a 100644 --- a/internal/codeintel/shared/types/index.go +++ b/internal/codeintel/shared/types/index.go @@ -37,14 +37,6 @@ func (i Index) RecordID() int { return i.ID } -type GetIndexesOptions struct { - RepositoryID int - State string - Term string - Limit int - Offset int -} - type DockerStep struct { Root string `json:"root"` Image string `json:"image"` diff --git a/internal/codeintel/shared/types/indexer_resolver.go b/internal/codeintel/shared/types/indexer_resolver.go new file mode 100644 index 00000000000..24432ed345b --- /dev/null +++ b/internal/codeintel/shared/types/indexer_resolver.go @@ -0,0 +1,30 @@ +package types + +type CodeIntelIndexerResolver interface { + Name() string + URL() string +} + +type codeIntelIndexerResolver struct { + indexer CodeIntelIndexer +} + +func NewCodeIntelIndexerResolver(name string) CodeIntelIndexerResolver { + return NewCodeIntelIndexerResolverFrom(CodeIntelIndexer{Name: name}) +} + +func NewCodeIntelIndexerResolverFrom(indexer CodeIntelIndexer) CodeIntelIndexerResolver { + return &codeIntelIndexerResolver{indexer: indexer} +} + +func (r *codeIntelIndexerResolver) Name() string { + return r.indexer.Name +} + +func (r *codeIntelIndexerResolver) URL() string { + if r.indexer.URN == "" { + return "" + } + + return "https://" + r.indexer.URN +} diff --git a/internal/codeintel/shared/types/indexers.go b/internal/codeintel/shared/types/indexers.go index 5aa3af8e4a8..a836c7c2c80 100644 --- a/internal/codeintel/shared/types/indexers.go +++ b/internal/codeintel/shared/types/indexers.go @@ -1,162 +1,141 @@ package types -type CodeIntelIndexerResolver interface { - Name() string - URL() string -} - -type codeIntelIndexerResolver struct { - name string - urn string -} - -func NewCodeIntelIndexerResolver(name string) CodeIntelIndexerResolver { - return &codeIntelIndexerResolver{name: name} -} - -func (r *codeIntelIndexerResolver) Name() string { - return r.name -} - -func (r *codeIntelIndexerResolver) URL() string { - if r.urn == "" { - return "" - } - - return "https://" + r.urn +type CodeIntelIndexer struct { + Name string + URN string } var ( - lsifNode = codeIntelIndexerResolver{ - name: "lsif-tsc", - urn: "github.com/sourcegraph/lsif-node", + lsifNode = CodeIntelIndexer{ + Name: "lsif-tsc", + URN: "github.com/sourcegraph/lsif-node", } - msftNode = codeIntelIndexerResolver{ - name: "msft/lsif-node", - urn: "github.com/Microsoft/lsif-node", + msftNode = CodeIntelIndexer{ + Name: "msft/lsif-node", + URN: "github.com/Microsoft/lsif-node", } - lsifTypescript = codeIntelIndexerResolver{ - name: "scip-typescript", - urn: "github.com/sourcegraph/scip-typescript", + lsifTypescript = CodeIntelIndexer{ + Name: "scip-typescript", + URN: "github.com/sourcegraph/scip-typescript", } - scipJava = codeIntelIndexerResolver{ - name: "scip-java", - urn: "github.com/sourcegraph/scip-java", + scipJava = CodeIntelIndexer{ + Name: "scip-java", + URN: "github.com/sourcegraph/scip-java", } - msftJava = codeIntelIndexerResolver{ - name: "msft/lsif-java", - urn: "github.com/Microsoft/lsif-java", + msftJava = CodeIntelIndexer{ + Name: "msft/lsif-java", + URN: "github.com/Microsoft/lsif-java", } - lsifGo = codeIntelIndexerResolver{ - name: "lsif-go", - urn: "github.com/sourcegraph/lsif-go", + lsifGo = CodeIntelIndexer{ + Name: "lsif-go", + URN: "github.com/sourcegraph/lsif-go", } - lsifClang = codeIntelIndexerResolver{ - name: "lsif-clang", - urn: "github.com/sourcegraph/lsif-clang", + lsifClang = CodeIntelIndexer{ + Name: "lsif-clang", + URN: "github.com/sourcegraph/lsif-clang", } - lsifCPP = codeIntelIndexerResolver{ - name: "lsif-cpp", - urn: "github.com/sourcegraph/lsif-cpp", + lsifCPP = CodeIntelIndexer{ + Name: "lsif-cpp", + URN: "github.com/sourcegraph/lsif-cpp", } - lsifDart = codeIntelIndexerResolver{ - name: "lsif-dart", - urn: "github.com/sourcegraph/lsif-dart", + lsifDart = CodeIntelIndexer{ + Name: "lsif-dart", + URN: "github.com/sourcegraph/lsif-dart", } - workivaDart = codeIntelIndexerResolver{ - name: "lsif_indexer", - urn: "github.com/Workiva/lsif_indexer", + workivaDart = CodeIntelIndexer{ + Name: "lsif_indexer", + URN: "github.com/Workiva/lsif_indexer", } - hieLSIF = codeIntelIndexerResolver{ - name: "hie-lsif", - urn: "github.com/mpickering/hie-lsif", + hieLSIF = CodeIntelIndexer{ + Name: "hie-lsif", + URN: "github.com/mpickering/hie-lsif", } - lsifJsonnet = codeIntelIndexerResolver{ - name: "lsif-jsonnet", - urn: "github.com/sourcegraph/lsif-jsonnet", + lsifJsonnet = CodeIntelIndexer{ + Name: "lsif-jsonnet", + URN: "github.com/sourcegraph/lsif-jsonnet", } - lsifOcaml = codeIntelIndexerResolver{ - name: "lsif-ocaml", - urn: "github.com/rvantonder/lsif-ocaml", + lsifOcaml = CodeIntelIndexer{ + Name: "lsif-ocaml", + URN: "github.com/rvantonder/lsif-ocaml", } - scipPython = codeIntelIndexerResolver{ - name: "scip-python", - urn: "github.com/sourcegraph/scip-python", + scipPython = CodeIntelIndexer{ + Name: "scip-python", + URN: "github.com/sourcegraph/scip-python", } - rustAnalyzer = codeIntelIndexerResolver{ - name: "rust-analyzer", - urn: "github.com/rust-analyzer/rust-analyzer", + rustAnalyzer = CodeIntelIndexer{ + Name: "rust-analyzer", + URN: "github.com/rust-analyzer/rust-analyzer", } - lsifPHP = codeIntelIndexerResolver{ - name: "lsif-php", - urn: "github.com/davidrjenni/lsif-php", + lsifPHP = CodeIntelIndexer{ + Name: "lsif-php", + URN: "github.com/davidrjenni/lsif-php", } - lsifTerraform = codeIntelIndexerResolver{ - name: "lsif-terraform", - urn: "github.com/juliosueiras/lsif-terraform", + lsifTerraform = CodeIntelIndexer{ + Name: "lsif-terraform", + URN: "github.com/juliosueiras/lsif-terraform", } - lsifDotnet = codeIntelIndexerResolver{ - name: "lsif-dotnet", - urn: "github.com/tcz717/LsifDotnet", + lsifDotnet = CodeIntelIndexer{ + Name: "lsif-dotnet", + URN: "github.com/tcz717/LsifDotnet", } ) -var AllIndexers = []CodeIntelIndexerResolver{ - &lsifNode, - &msftNode, - &lsifTypescript, - &scipJava, - &msftJava, - &lsifGo, - &lsifClang, - &lsifCPP, - &lsifDart, - &workivaDart, - &hieLSIF, - &lsifJsonnet, - &lsifOcaml, - &scipPython, - &rustAnalyzer, - &lsifPHP, - &lsifTerraform, - &lsifDotnet, +var AllIndexers = []CodeIntelIndexer{ + lsifNode, + msftNode, + lsifTypescript, + scipJava, + msftJava, + lsifGo, + lsifClang, + lsifCPP, + lsifDart, + workivaDart, + hieLSIF, + lsifJsonnet, + lsifOcaml, + scipPython, + rustAnalyzer, + lsifPHP, + lsifTerraform, + lsifDotnet, } // A map of file extension to a list of indexers in order of recommendation // from most to least. -var LanguageToIndexer = map[string][]CodeIntelIndexerResolver{ - ".go": {&lsifGo}, - ".java": {&scipJava, &msftJava}, - ".kt": {&scipJava}, - ".scala": {&scipJava}, - ".js": {&lsifTypescript, &lsifNode, &msftNode}, - ".jsx": {&lsifTypescript, &lsifNode, &msftNode}, - ".ts": {&lsifTypescript, &lsifNode, &msftNode}, - ".tsx": {&lsifTypescript, &lsifNode, &msftNode}, - ".dart": {&workivaDart, &lsifDart}, - ".c": {&lsifClang, &lsifCPP}, - ".cc": {&lsifClang, &lsifCPP}, - ".cpp": {&lsifClang, &lsifCPP}, - ".cxx": {&lsifClang, &lsifCPP}, - ".h": {&lsifClang, &lsifCPP}, - ".hpp": {&lsifClang, &lsifCPP}, - ".hs": {&hieLSIF}, - ".jsonnet": {&lsifJsonnet}, - ".py": {&scipPython}, - ".ml": {&lsifOcaml}, - ".rs": {&rustAnalyzer}, - ".php": {&lsifPHP}, - ".tf": {&lsifTerraform}, - ".cs": {&lsifDotnet}, +var LanguageToIndexer = map[string][]CodeIntelIndexer{ + ".go": {lsifGo}, + ".java": {scipJava, msftJava}, + ".kt": {scipJava}, + ".scala": {scipJava}, + ".js": {lsifTypescript, lsifNode, msftNode}, + ".jsx": {lsifTypescript, lsifNode, msftNode}, + ".ts": {lsifTypescript, lsifNode, msftNode}, + ".tsx": {lsifTypescript, lsifNode, msftNode}, + ".dart": {workivaDart, lsifDart}, + ".c": {lsifClang, lsifCPP}, + ".cc": {lsifClang, lsifCPP}, + ".cpp": {lsifClang, lsifCPP}, + ".cxx": {lsifClang, lsifCPP}, + ".h": {lsifClang, lsifCPP}, + ".hpp": {lsifClang, lsifCPP}, + ".hs": {hieLSIF}, + ".jsonnet": {lsifJsonnet}, + ".py": {scipPython}, + ".ml": {lsifOcaml}, + ".rs": {rustAnalyzer}, + ".php": {lsifPHP}, + ".tf": {lsifTerraform}, + ".cs": {lsifDotnet}, } -var ImageToIndexer = map[string]CodeIntelIndexerResolver{ - "sourcegraph/scip-java": &scipJava, - "sourcegraph/lsif-go": &lsifGo, - "sourcegraph/scip-typescript": &lsifTypescript, - "sourcegraph/lsif-node": &lsifNode, - "sourcegraph/lsif-clang": &lsifClang, - "davidrjenni/lsif-php": &lsifPHP, - "sourcegraph/lsif-rust": &rustAnalyzer, - "sourcegraph/scip-python": &scipPython, +var ImageToIndexer = map[string]CodeIntelIndexer{ + "sourcegraph/scip-java": scipJava, + "sourcegraph/lsif-go": lsifGo, + "sourcegraph/scip-typescript": lsifTypescript, + "sourcegraph/lsif-node": lsifNode, + "sourcegraph/lsif-clang": lsifClang, + "davidrjenni/lsif-php": lsifPHP, + "sourcegraph/lsif-rust": rustAnalyzer, + "sourcegraph/scip-python": scipPython, } diff --git a/internal/codeintel/shared/types/policy.go b/internal/codeintel/shared/types/policy.go new file mode 100644 index 00000000000..77a65cd3c13 --- /dev/null +++ b/internal/codeintel/shared/types/policy.go @@ -0,0 +1,33 @@ +package types + +import "time" + +type ConfigurationPolicy struct { + ID int + RepositoryID *int + RepositoryPatterns *[]string + Name string + Type GitObjectType + Pattern string + Protected bool + RetentionEnabled bool + RetentionDuration *time.Duration + RetainIntermediateCommits bool + IndexingEnabled bool + IndexCommitMaxAge *time.Duration + IndexIntermediateCommits bool +} + +type GitObjectType string + +const ( + GitObjectTypeCommit GitObjectType = "GIT_COMMIT" + GitObjectTypeTag GitObjectType = "GIT_TAG" + GitObjectTypeTree GitObjectType = "GIT_TREE" +) + +type RetentionPolicyMatchCandidate struct { + *ConfigurationPolicy + Matched bool + ProtectingCommits []string +} diff --git a/internal/codeintel/shared/types/types.go b/internal/codeintel/shared/types/types.go deleted file mode 100644 index 01f054e69ed..00000000000 --- a/internal/codeintel/shared/types/types.go +++ /dev/null @@ -1,188 +0,0 @@ -package types - -import ( - "time" - - "github.com/sourcegraph/sourcegraph/internal/api" -) - -// RevSpecSet is a utility type for a set of RevSpecs. -type RevSpecSet map[api.RevSpec]struct{} - -// Dump is a subset of the lsif_uploads table (queried via the lsif_dumps_with_repository_name view) -// and stores only processed records. -type Dump struct { - ID int `json:"id"` - Commit string `json:"commit"` - Root string `json:"root"` - VisibleAtTip bool `json:"visibleAtTip"` - UploadedAt time.Time `json:"uploadedAt"` - State string `json:"state"` - FailureMessage *string `json:"failureMessage"` - StartedAt *time.Time `json:"startedAt"` - FinishedAt *time.Time `json:"finishedAt"` - ProcessAfter *time.Time `json:"processAfter"` - NumResets int `json:"numResets"` - NumFailures int `json:"numFailures"` - RepositoryID int `json:"repositoryId"` - RepositoryName string `json:"repositoryName"` - Indexer string `json:"indexer"` - IndexerVersion string `json:"indexerVersion"` - AssociatedIndexID *int `json:"associatedIndex"` -} - -// UploadLocation is a path and range pair from within a particular upload. The target commit -// denotes the target commit for which the location was set (the originally requested commit). -type UploadLocation struct { - Dump Dump - Path string - TargetCommit string - TargetRange Range -} - -type Range struct { - Start Position - End Position -} - -// Position is a unique position within a file. -type Position struct { - Line int - Character int -} - -type UploadLog struct { - LogTimestamp time.Time - RecordDeletedAt *time.Time - UploadID int - Commit string - Root string - RepositoryID int - UploadedAt time.Time - Indexer string - IndexerVersion *string - UploadSize *int - AssociatedIndexID *int - TransitionColumns []map[string]*string - Reason *string - Operation string -} - -type Upload struct { - ID int - Commit string - Root string - VisibleAtTip bool - UploadedAt time.Time - State string - FailureMessage *string - StartedAt *time.Time - FinishedAt *time.Time - ProcessAfter *time.Time - NumResets int - NumFailures int - RepositoryID int - RepositoryName string - Indexer string - IndexerVersion string - NumParts int - UploadedParts []int - UploadSize *int64 - UncompressedSize *int64 - Rank *int - AssociatedIndexID *int -} - -func (u Upload) RecordID() int { - return u.ID -} - -type GetUploadsOptions struct { - RepositoryID int - State string - Term string - VisibleAtTip bool - DependencyOf int - DependentOf int - UploadedBefore *time.Time - UploadedAfter *time.Time - LastRetentionScanBefore *time.Time - AllowExpired bool - AllowDeletedRepo bool - AllowDeletedUpload bool - OldestFirst bool - Limit int - Offset int - - // InCommitGraph ensures that the repository commit graph was updated strictly - // after this upload was processed. This condition helps us filter out new uploads - // that we might later mistake for unreachable. - InCommitGraph bool -} - -type DeleteUploadsOptions struct { - State string - Term string - VisibleAtTip bool - RepositoryID int -} - -type DeleteIndexesOptions struct { - State string - Term string - RepositoryID int -} - -type GetConfigurationPoliciesOptions struct { - // RepositoryID indicates that only configuration policies that apply to the - // specified repository (directly or via pattern) should be returned. This value - // has no effect when equal to zero. - RepositoryID int - - // Term is a string to search within the configuration title. - Term string - - // ForIndexing indicates that only configuration policies with data retention enabled - // should be returned. - ForDataRetention bool - - // ForIndexing indicates that only configuration policies with indexing enabled should - // be returned. - ForIndexing bool - - // Limit indicates the number of results to take from the result set. - Limit int - - // Offset indicates the number of results to skip in the result set. - Offset int -} - -type ConfigurationPolicy struct { - ID int - RepositoryID *int - RepositoryPatterns *[]string - Name string - Type GitObjectType - Pattern string - Protected bool - RetentionEnabled bool - RetentionDuration *time.Duration - RetainIntermediateCommits bool - IndexingEnabled bool - IndexCommitMaxAge *time.Duration - IndexIntermediateCommits bool -} - -type RetentionPolicyMatchCandidate struct { - *ConfigurationPolicy - Matched bool - ProtectingCommits []string -} - -type GitObjectType string - -const ( - GitObjectTypeCommit GitObjectType = "GIT_COMMIT" - GitObjectTypeTag GitObjectType = "GIT_TAG" - GitObjectTypeTree GitObjectType = "GIT_TREE" -) diff --git a/internal/codeintel/shared/types/upload.go b/internal/codeintel/shared/types/upload.go new file mode 100644 index 00000000000..7d74f1e3ece --- /dev/null +++ b/internal/codeintel/shared/types/upload.go @@ -0,0 +1,49 @@ +package types + +import "time" + +type Upload struct { + ID int + Commit string + Root string + VisibleAtTip bool + UploadedAt time.Time + State string + FailureMessage *string + StartedAt *time.Time + FinishedAt *time.Time + ProcessAfter *time.Time + NumResets int + NumFailures int + RepositoryID int + RepositoryName string + Indexer string + IndexerVersion string + NumParts int + UploadedParts []int + UploadSize *int64 + UncompressedSize *int64 + Rank *int + AssociatedIndexID *int +} + +func (u Upload) RecordID() int { + return u.ID +} + +type UploadLog struct { + LogTimestamp time.Time + RecordDeletedAt *time.Time + UploadID int + Commit string + Root string + RepositoryID int + UploadedAt time.Time + Indexer string + IndexerVersion *string + UploadSize *int + AssociatedIndexID *int + TransitionColumns []map[string]*string + Reason *string + Operation string +} diff --git a/internal/codeintel/uploads/cleanup.go b/internal/codeintel/uploads/cleanup.go index 33000259ac8..a4cea71f953 100644 --- a/internal/codeintel/uploads/cleanup.go +++ b/internal/codeintel/uploads/cleanup.go @@ -219,7 +219,7 @@ func (s *Service) handleHardDeleter(ctx context.Context) error { func (s *Service) hardDeleteExpiredUploads(ctx context.Context) (count int, err error) { const uploadsBatchSize = 100 - options := types.GetUploadsOptions{ + options := shared.GetUploadsOptions{ State: "deleted", Limit: uploadsBatchSize, AllowExpired: true, diff --git a/internal/codeintel/uploads/expirer.go b/internal/codeintel/uploads/expirer.go index cbb7738d746..f9f1bd62529 100644 --- a/internal/codeintel/uploads/expirer.go +++ b/internal/codeintel/uploads/expirer.go @@ -7,7 +7,9 @@ import ( "github.com/sourcegraph/log" policiesEnterprise "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" "github.com/sourcegraph/sourcegraph/internal/goroutine" "github.com/sourcegraph/sourcegraph/internal/timeutil" "github.com/sourcegraph/sourcegraph/lib/errors" @@ -112,7 +114,7 @@ func (e *Service) handleRepository(ctx context.Context, repositoryID int, cfg ex // out new uploads that would happen to be visible to no commits since they were never // installed into the commit graph. - uploads, _, err := e.GetUploads(ctx, types.GetUploadsOptions{ + uploads, _, err := e.GetUploads(ctx, shared.GetUploadsOptions{ State: "completed", RepositoryID: repositoryID, AllowExpired: false, @@ -144,7 +146,7 @@ func (e *Service) buildCommitMap(ctx context.Context, repositoryID int, cfg expi for { // Retrieve the complete set of configuration policies that affect data retention for this repository - policyBatch, totalCount, err := e.policySvc.GetConfigurationPolicies(ctx, types.GetConfigurationPoliciesOptions{ + policyBatch, totalCount, err := e.policySvc.GetConfigurationPolicies(ctx, policiesshared.GetConfigurationPoliciesOptions{ RepositoryID: repositoryID, ForDataRetention: true, Limit: cfg.policyBatchSize, diff --git a/internal/codeintel/uploads/expirer_test.go b/internal/codeintel/uploads/expirer_test.go index 0265a70d66a..e0ea29d1c10 100644 --- a/internal/codeintel/uploads/expirer_test.go +++ b/internal/codeintel/uploads/expirer_test.go @@ -8,11 +8,12 @@ import ( "github.com/derision-test/glock" "github.com/google/go-cmp/cmp" - "github.com/sourcegraph/log/logtest" policiesEnterprise "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + uploadsshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" "github.com/sourcegraph/sourcegraph/internal/observation" "github.com/sourcegraph/sourcegraph/internal/timeutil" ) @@ -99,7 +100,7 @@ func setupMockPolicyService() *MockPolicyService { {ID: 5, RepositoryID: intPtr(50)}, } - getConfigurationPolicies := func(ctx context.Context, opts types.GetConfigurationPoliciesOptions) (filtered []types.ConfigurationPolicy, _ int, _ error) { + getConfigurationPolicies := func(ctx context.Context, opts policiesshared.GetConfigurationPoliciesOptions) (filtered []types.ConfigurationPolicy, _ int, _ error) { for _, policy := range policies { if policy.RepositoryID == nil || *policy.RepositoryID == opts.RepositoryID { filtered = append(filtered, policy) @@ -162,7 +163,7 @@ func setupMockUploadService(now time.Time) *MockStore { return scannedIDs, nil } - getUploads := func(ctx context.Context, opts types.GetUploadsOptions) ([]types.Upload, int, error) { + getUploads := func(ctx context.Context, opts uploadsshared.GetUploadsOptions) ([]types.Upload, int, error) { var filtered []types.Upload for _, upload := range uploads { if upload.RepositoryID != opts.RepositoryID { diff --git a/internal/codeintel/uploads/iface.go b/internal/codeintel/uploads/iface.go index b718d46a5cb..314c34caa64 100644 --- a/internal/codeintel/uploads/iface.go +++ b/internal/codeintel/uploads/iface.go @@ -11,8 +11,10 @@ import ( "github.com/sourcegraph/sourcegraph/internal/authz" sharedIndexes "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" policies "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise" + policiesshared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" codeintelgitserver "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/gitserver" codeinteltypes "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" sharedUploads "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" "github.com/sourcegraph/sourcegraph/internal/database/locker" "github.com/sourcegraph/sourcegraph/internal/gitserver" @@ -58,7 +60,7 @@ type RepoStore interface { type UploadServiceForExpiration interface { // Uploads - GetUploads(ctx context.Context, opts codeinteltypes.GetUploadsOptions) (uploads []codeinteltypes.Upload, totalCount int, err error) + GetUploads(ctx context.Context, opts shared.GetUploadsOptions) (uploads []codeinteltypes.Upload, totalCount int, err error) UpdateUploadRetention(ctx context.Context, protectedIDs, expiredIDs []int) (err error) BackfillReferenceCountBatch(ctx context.Context, batchSize int) error @@ -70,7 +72,7 @@ type UploadServiceForExpiration interface { } type PolicyService interface { - GetConfigurationPolicies(ctx context.Context, opts codeinteltypes.GetConfigurationPoliciesOptions) ([]codeinteltypes.ConfigurationPolicy, int, error) + GetConfigurationPolicies(ctx context.Context, opts policiesshared.GetConfigurationPoliciesOptions) ([]codeinteltypes.ConfigurationPolicy, int, error) } type PolicyMatcher interface { diff --git a/internal/codeintel/uploads/internal/store/store.go b/internal/codeintel/uploads/internal/store/store.go index 268e0063759..39f815702a1 100644 --- a/internal/codeintel/uploads/internal/store/store.go +++ b/internal/codeintel/uploads/internal/store/store.go @@ -43,7 +43,7 @@ type Store interface { HasRepository(ctx context.Context, repositoryID int) (_ bool, err error) // Uploads - GetUploads(ctx context.Context, opts types.GetUploadsOptions) (_ []types.Upload, _ int, err error) + GetUploads(ctx context.Context, opts shared.GetUploadsOptions) (_ []types.Upload, _ int, err error) GetUploadByID(ctx context.Context, id int) (_ types.Upload, _ bool, err error) GetUploadsByIDs(ctx context.Context, ids ...int) (_ []types.Upload, err error) GetUploadIDsWithReferences(ctx context.Context, orderedMonikers []precise.QualifiedMonikerData, ignoreIDs []int, repositoryID int, commit string, limit int, offset int, trace observation.TraceLogger) (ids []int, recordsScanned int, totalCount int, err error) @@ -61,7 +61,7 @@ type Store interface { DeleteUploadsStuckUploading(ctx context.Context, uploadedBefore time.Time) (_ int, err error) DeleteUploadsWithoutRepository(ctx context.Context, now time.Time) (_ map[int]int, err error) DeleteUploadByID(ctx context.Context, id int) (_ bool, err error) - DeleteUploads(ctx context.Context, opts types.DeleteUploadsOptions) (err error) + DeleteUploads(ctx context.Context, opts shared.DeleteUploadsOptions) (err error) // Uploads (uploading) InsertUpload(ctx context.Context, upload types.Upload) (int, error) diff --git a/internal/codeintel/uploads/internal/store/store_uploads.go b/internal/codeintel/uploads/internal/store/store_uploads.go index 116b798e64c..8dc2ea88746 100644 --- a/internal/codeintel/uploads/internal/store/store_uploads.go +++ b/internal/codeintel/uploads/internal/store/store_uploads.go @@ -27,7 +27,7 @@ import ( ) // GetUploads returns a list of uploads and the total count of records matching the given conditions. -func (s *store) GetUploads(ctx context.Context, opts types.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) { +func (s *store) GetUploads(ctx context.Context, opts shared.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) { ctx, trace, endObservation := s.operations.getUploads.With(ctx, &err, observation.Args{LogFields: buildGetUploadsLogFields(opts)}) defer endObservation(1, observation.Args{}) @@ -686,7 +686,7 @@ UPDATE lsif_uploads u SET state = CASE WHEN u.state = 'completed' THEN 'deleting // DeleteUploads deletes uploads by filter criteria. The associated repositories will be marked as dirty // so that their commit graphs will be updated in the background. -func (s *store) DeleteUploads(ctx context.Context, opts types.DeleteUploadsOptions) (err error) { +func (s *store) DeleteUploads(ctx context.Context, opts shared.DeleteUploadsOptions) (err error) { ctx, _, endObservation := s.operations.deleteUploads.With(ctx, &err, observation.Args{LogFields: buildDeleteUploadsLogFields(opts)}) defer endObservation(1, observation.Args{}) @@ -1996,7 +1996,7 @@ func nilTimeToString(t *time.Time) string { return t.String() } -func buildGetConditionsAndCte(opts types.GetUploadsOptions) (*sqlf.Query, []*sqlf.Query, []cteDefinition) { +func buildGetConditionsAndCte(opts shared.GetUploadsOptions) (*sqlf.Query, []*sqlf.Query, []cteDefinition) { conds := make([]*sqlf.Query, 0, 12) allowDeletedUploads := (opts.AllowDeletedUpload && opts.State == "") || opts.State == "deleted" @@ -2112,7 +2112,7 @@ func buildGetConditionsAndCte(opts types.GetUploadsOptions) (*sqlf.Query, []*sql return sourceTableExpr, conds, cteDefinitions } -func buildDeleteConditions(opts types.DeleteUploadsOptions) []*sqlf.Query { +func buildDeleteConditions(opts shared.DeleteUploadsOptions) []*sqlf.Query { conds := []*sqlf.Query{} if opts.RepositoryID != 0 { conds = append(conds, sqlf.Sprintf("u.repository_id = %s", opts.RepositoryID)) @@ -2183,7 +2183,7 @@ func buildCTEPrefix(cteDefinitions []cteDefinition) *sqlf.Query { return sqlf.Sprintf("WITH\n%s", sqlf.Join(cteQueries, ",\n")) } -func buildGetUploadsLogFields(opts types.GetUploadsOptions) []log.Field { +func buildGetUploadsLogFields(opts shared.GetUploadsOptions) []log.Field { return []log.Field{ log.Int("repositoryID", opts.RepositoryID), log.String("state", opts.State), @@ -2202,7 +2202,7 @@ func buildGetUploadsLogFields(opts types.GetUploadsOptions) []log.Field { } } -func buildDeleteUploadsLogFields(opts types.DeleteUploadsOptions) []log.Field { +func buildDeleteUploadsLogFields(opts shared.DeleteUploadsOptions) []log.Field { return []log.Field{ log.String("state", opts.State), log.String("term", opts.Term), diff --git a/internal/codeintel/uploads/internal/store/store_uploads_test.go b/internal/codeintel/uploads/internal/store/store_uploads_test.go index e1a28e92dd8..353aa942bcc 100644 --- a/internal/codeintel/uploads/internal/store/store_uploads_test.go +++ b/internal/codeintel/uploads/internal/store/store_uploads_test.go @@ -179,7 +179,7 @@ func TestGetUploads(t *testing.T) { ) t.Run(name, func(t *testing.T) { - uploads, totalCount, err := store.GetUploads(ctx, types.GetUploadsOptions{ + uploads, totalCount, err := store.GetUploads(ctx, shared.GetUploadsOptions{ RepositoryID: testCase.repositoryID, State: testCase.state, Term: testCase.term, @@ -238,7 +238,7 @@ func TestGetUploads(t *testing.T) { defer globals.SetPermissionsUserMapping(before) uploads, totalCount, err := store.GetUploads(ctx, - types.GetUploadsOptions{ + shared.GetUploadsOptions{ Limit: 1, }, ) @@ -617,7 +617,7 @@ func TestDeleteUploadsStuckUploading(t *testing.T) { t.Errorf("unexpected count. want=%d have=%d", 2, count) } - uploads, totalCount, err := store.GetUploads(context.Background(), types.GetUploadsOptions{Limit: 5}) + uploads, totalCount, err := store.GetUploads(context.Background(), shared.GetUploadsOptions{Limit: 5}) if err != nil { t.Fatalf("unexpected error getting uploads: %s", err) } @@ -657,7 +657,7 @@ func TestDeleteUploads(t *testing.T) { types.Upload{ID: 5, Commit: makeCommit(1115), UploadedAt: t5, State: "uploading"}, // will be deleted ) - err := store.DeleteUploads(context.Background(), types.DeleteUploadsOptions{ + err := store.DeleteUploads(context.Background(), shared.DeleteUploadsOptions{ State: "uploading", Term: "", VisibleAtTip: false, @@ -666,7 +666,7 @@ func TestDeleteUploads(t *testing.T) { t.Fatalf("unexpected error deleting uploads: %s", err) } - uploads, totalCount, err := store.GetUploads(context.Background(), types.GetUploadsOptions{Limit: 5}) + uploads, totalCount, err := store.GetUploads(context.Background(), shared.GetUploadsOptions{Limit: 5}) if err != nil { t.Fatalf("unexpected error getting uploads: %s", err) } diff --git a/internal/codeintel/uploads/mocks_test.go b/internal/codeintel/uploads/mocks_test.go index e8148c83d13..386387b0395 100644 --- a/internal/codeintel/uploads/mocks_test.go +++ b/internal/codeintel/uploads/mocks_test.go @@ -17,6 +17,7 @@ import ( authz "github.com/sourcegraph/sourcegraph/internal/authz" shared1 "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" enterprise "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/enterprise" + shared2 "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared" types "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" lsifstore "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/lsifstore" store "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/store" @@ -248,7 +249,7 @@ func NewMockStore() *MockStore { }, }, DeleteUploadsFunc: &StoreDeleteUploadsFunc{ - defaultHook: func(context.Context, types.DeleteUploadsOptions) (r0 error) { + defaultHook: func(context.Context, shared.DeleteUploadsOptions) (r0 error) { return }, }, @@ -348,7 +349,7 @@ func NewMockStore() *MockStore { }, }, GetUploadsFunc: &StoreGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { + defaultHook: func(context.Context, shared.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { return }, }, @@ -520,7 +521,7 @@ func NewStrictMockStore() *MockStore { }, }, DeleteUploadsFunc: &StoreDeleteUploadsFunc{ - defaultHook: func(context.Context, types.DeleteUploadsOptions) error { + defaultHook: func(context.Context, shared.DeleteUploadsOptions) error { panic("unexpected invocation of MockStore.DeleteUploads") }, }, @@ -620,7 +621,7 @@ func NewStrictMockStore() *MockStore { }, }, GetUploadsFunc: &StoreGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + defaultHook: func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) { panic("unexpected invocation of MockStore.GetUploads") }, }, @@ -1595,15 +1596,15 @@ func (c StoreDeleteUploadByIDFuncCall) Results() []interface{} { // StoreDeleteUploadsFunc describes the behavior when the DeleteUploads // method of the parent MockStore instance is invoked. type StoreDeleteUploadsFunc struct { - defaultHook func(context.Context, types.DeleteUploadsOptions) error - hooks []func(context.Context, types.DeleteUploadsOptions) error + defaultHook func(context.Context, shared.DeleteUploadsOptions) error + hooks []func(context.Context, shared.DeleteUploadsOptions) error history []StoreDeleteUploadsFuncCall mutex sync.Mutex } // DeleteUploads delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockStore) DeleteUploads(v0 context.Context, v1 types.DeleteUploadsOptions) error { +func (m *MockStore) DeleteUploads(v0 context.Context, v1 shared.DeleteUploadsOptions) error { r0 := m.DeleteUploadsFunc.nextHook()(v0, v1) m.DeleteUploadsFunc.appendCall(StoreDeleteUploadsFuncCall{v0, v1, r0}) return r0 @@ -1611,7 +1612,7 @@ func (m *MockStore) DeleteUploads(v0 context.Context, v1 types.DeleteUploadsOpti // SetDefaultHook sets function that is called when the DeleteUploads method // of the parent MockStore instance is invoked and the hook queue is empty. -func (f *StoreDeleteUploadsFunc) SetDefaultHook(hook func(context.Context, types.DeleteUploadsOptions) error) { +func (f *StoreDeleteUploadsFunc) SetDefaultHook(hook func(context.Context, shared.DeleteUploadsOptions) error) { f.defaultHook = hook } @@ -1619,7 +1620,7 @@ func (f *StoreDeleteUploadsFunc) SetDefaultHook(hook func(context.Context, types // DeleteUploads method of the parent MockStore instance invokes the hook at // the front of the queue and discards it. After the queue is empty, the // default hook function is invoked for any future action. -func (f *StoreDeleteUploadsFunc) PushHook(hook func(context.Context, types.DeleteUploadsOptions) error) { +func (f *StoreDeleteUploadsFunc) PushHook(hook func(context.Context, shared.DeleteUploadsOptions) error) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -1628,19 +1629,19 @@ func (f *StoreDeleteUploadsFunc) PushHook(hook func(context.Context, types.Delet // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *StoreDeleteUploadsFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(context.Context, types.DeleteUploadsOptions) error { + f.SetDefaultHook(func(context.Context, shared.DeleteUploadsOptions) error { return r0 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *StoreDeleteUploadsFunc) PushReturn(r0 error) { - f.PushHook(func(context.Context, types.DeleteUploadsOptions) error { + f.PushHook(func(context.Context, shared.DeleteUploadsOptions) error { return r0 }) } -func (f *StoreDeleteUploadsFunc) nextHook() func(context.Context, types.DeleteUploadsOptions) error { +func (f *StoreDeleteUploadsFunc) nextHook() func(context.Context, shared.DeleteUploadsOptions) error { f.mutex.Lock() defer f.mutex.Unlock() @@ -1678,7 +1679,7 @@ type StoreDeleteUploadsFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.DeleteUploadsOptions + Arg1 shared.DeleteUploadsOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 error @@ -3862,15 +3863,15 @@ func (c StoreGetUploadIDsWithReferencesFuncCall) Results() []interface{} { // StoreGetUploadsFunc describes the behavior when the GetUploads method of // the parent MockStore instance is invoked. type StoreGetUploadsFunc struct { - defaultHook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) - hooks []func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) + defaultHook func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) + hooks []func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) history []StoreGetUploadsFuncCall mutex sync.Mutex } // GetUploads delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockStore) GetUploads(v0 context.Context, v1 types.GetUploadsOptions) ([]types.Upload, int, error) { +func (m *MockStore) GetUploads(v0 context.Context, v1 shared.GetUploadsOptions) ([]types.Upload, int, error) { r0, r1, r2 := m.GetUploadsFunc.nextHook()(v0, v1) m.GetUploadsFunc.appendCall(StoreGetUploadsFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -3878,7 +3879,7 @@ func (m *MockStore) GetUploads(v0 context.Context, v1 types.GetUploadsOptions) ( // SetDefaultHook sets function that is called when the GetUploads method of // the parent MockStore instance is invoked and the hook queue is empty. -func (f *StoreGetUploadsFunc) SetDefaultHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *StoreGetUploadsFunc) SetDefaultHook(hook func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error)) { f.defaultHook = hook } @@ -3886,7 +3887,7 @@ func (f *StoreGetUploadsFunc) SetDefaultHook(hook func(context.Context, types.Ge // GetUploads method of the parent MockStore instance invokes the hook at // the front of the queue and discards it. After the queue is empty, the // default hook function is invoked for any future action. -func (f *StoreGetUploadsFunc) PushHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *StoreGetUploadsFunc) PushHook(hook func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -3895,19 +3896,19 @@ func (f *StoreGetUploadsFunc) PushHook(hook func(context.Context, types.GetUploa // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *StoreGetUploadsFunc) SetDefaultReturn(r0 []types.Upload, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.SetDefaultHook(func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *StoreGetUploadsFunc) PushReturn(r0 []types.Upload, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.PushHook(func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } -func (f *StoreGetUploadsFunc) nextHook() func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { +func (f *StoreGetUploadsFunc) nextHook() func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -3945,7 +3946,7 @@ type StoreGetUploadsFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetUploadsOptions + Arg1 shared.GetUploadsOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Upload @@ -11173,7 +11174,7 @@ type MockPolicyService struct { func NewMockPolicyService() *MockPolicyService { return &MockPolicyService{ GetConfigurationPoliciesFunc: &PolicyServiceGetConfigurationPoliciesFunc{ - defaultHook: func(context.Context, types.GetConfigurationPoliciesOptions) (r0 []types.ConfigurationPolicy, r1 int, r2 error) { + defaultHook: func(context.Context, shared2.GetConfigurationPoliciesOptions) (r0 []types.ConfigurationPolicy, r1 int, r2 error) { return }, }, @@ -11185,7 +11186,7 @@ func NewMockPolicyService() *MockPolicyService { func NewStrictMockPolicyService() *MockPolicyService { return &MockPolicyService{ GetConfigurationPoliciesFunc: &PolicyServiceGetConfigurationPoliciesFunc{ - defaultHook: func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { + defaultHook: func(context.Context, shared2.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { panic("unexpected invocation of MockPolicyService.GetConfigurationPolicies") }, }, @@ -11207,15 +11208,15 @@ func NewMockPolicyServiceFrom(i PolicyService) *MockPolicyService { // GetConfigurationPolicies method of the parent MockPolicyService instance // is invoked. type PolicyServiceGetConfigurationPoliciesFunc struct { - defaultHook func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) - hooks []func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) + defaultHook func(context.Context, shared2.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) + hooks []func(context.Context, shared2.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) history []PolicyServiceGetConfigurationPoliciesFuncCall mutex sync.Mutex } // GetConfigurationPolicies delegates to the next hook function in the queue // and stores the parameter and result values of this invocation. -func (m *MockPolicyService) GetConfigurationPolicies(v0 context.Context, v1 types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { +func (m *MockPolicyService) GetConfigurationPolicies(v0 context.Context, v1 shared2.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { r0, r1, r2 := m.GetConfigurationPoliciesFunc.nextHook()(v0, v1) m.GetConfigurationPoliciesFunc.appendCall(PolicyServiceGetConfigurationPoliciesFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -11224,7 +11225,7 @@ func (m *MockPolicyService) GetConfigurationPolicies(v0 context.Context, v1 type // SetDefaultHook sets function that is called when the // GetConfigurationPolicies method of the parent MockPolicyService instance // is invoked and the hook queue is empty. -func (f *PolicyServiceGetConfigurationPoliciesFunc) SetDefaultHook(hook func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error)) { +func (f *PolicyServiceGetConfigurationPoliciesFunc) SetDefaultHook(hook func(context.Context, shared2.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error)) { f.defaultHook = hook } @@ -11233,7 +11234,7 @@ func (f *PolicyServiceGetConfigurationPoliciesFunc) SetDefaultHook(hook func(con // invokes the hook at the front of the queue and discards it. After the // queue is empty, the default hook function is invoked for any future // action. -func (f *PolicyServiceGetConfigurationPoliciesFunc) PushHook(hook func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error)) { +func (f *PolicyServiceGetConfigurationPoliciesFunc) PushHook(hook func(context.Context, shared2.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -11242,19 +11243,19 @@ func (f *PolicyServiceGetConfigurationPoliciesFunc) PushHook(hook func(context.C // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *PolicyServiceGetConfigurationPoliciesFunc) SetDefaultReturn(r0 []types.ConfigurationPolicy, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { + f.SetDefaultHook(func(context.Context, shared2.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *PolicyServiceGetConfigurationPoliciesFunc) PushReturn(r0 []types.ConfigurationPolicy, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { + f.PushHook(func(context.Context, shared2.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { return r0, r1, r2 }) } -func (f *PolicyServiceGetConfigurationPoliciesFunc) nextHook() func(context.Context, types.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { +func (f *PolicyServiceGetConfigurationPoliciesFunc) nextHook() func(context.Context, shared2.GetConfigurationPoliciesOptions) ([]types.ConfigurationPolicy, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -11294,7 +11295,7 @@ type PolicyServiceGetConfigurationPoliciesFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetConfigurationPoliciesOptions + Arg1 shared2.GetConfigurationPoliciesOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.ConfigurationPolicy @@ -12559,7 +12560,7 @@ func NewMockUploadServiceForExpiration() *MockUploadServiceForExpiration { }, }, GetUploadsFunc: &UploadServiceForExpirationGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { + defaultHook: func(context.Context, shared.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { return }, }, @@ -12592,7 +12593,7 @@ func NewStrictMockUploadServiceForExpiration() *MockUploadServiceForExpiration { }, }, GetUploadsFunc: &UploadServiceForExpirationGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + defaultHook: func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) { panic("unexpected invocation of MockUploadServiceForExpiration.GetUploads") }, }, @@ -12868,15 +12869,15 @@ func (c UploadServiceForExpirationGetCommitsVisibleToUploadFuncCall) Results() [ // GetUploads method of the parent MockUploadServiceForExpiration instance // is invoked. type UploadServiceForExpirationGetUploadsFunc struct { - defaultHook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) - hooks []func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) + defaultHook func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) + hooks []func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) history []UploadServiceForExpirationGetUploadsFuncCall mutex sync.Mutex } // GetUploads delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockUploadServiceForExpiration) GetUploads(v0 context.Context, v1 types.GetUploadsOptions) ([]types.Upload, int, error) { +func (m *MockUploadServiceForExpiration) GetUploads(v0 context.Context, v1 shared.GetUploadsOptions) ([]types.Upload, int, error) { r0, r1, r2 := m.GetUploadsFunc.nextHook()(v0, v1) m.GetUploadsFunc.appendCall(UploadServiceForExpirationGetUploadsFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -12885,7 +12886,7 @@ func (m *MockUploadServiceForExpiration) GetUploads(v0 context.Context, v1 types // SetDefaultHook sets function that is called when the GetUploads method of // the parent MockUploadServiceForExpiration instance is invoked and the // hook queue is empty. -func (f *UploadServiceForExpirationGetUploadsFunc) SetDefaultHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *UploadServiceForExpirationGetUploadsFunc) SetDefaultHook(hook func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error)) { f.defaultHook = hook } @@ -12894,7 +12895,7 @@ func (f *UploadServiceForExpirationGetUploadsFunc) SetDefaultHook(hook func(cont // invokes the hook at the front of the queue and discards it. After the // queue is empty, the default hook function is invoked for any future // action. -func (f *UploadServiceForExpirationGetUploadsFunc) PushHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *UploadServiceForExpirationGetUploadsFunc) PushHook(hook func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -12903,19 +12904,19 @@ func (f *UploadServiceForExpirationGetUploadsFunc) PushHook(hook func(context.Co // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *UploadServiceForExpirationGetUploadsFunc) SetDefaultReturn(r0 []types.Upload, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.SetDefaultHook(func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *UploadServiceForExpirationGetUploadsFunc) PushReturn(r0 []types.Upload, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.PushHook(func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } -func (f *UploadServiceForExpirationGetUploadsFunc) nextHook() func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { +func (f *UploadServiceForExpirationGetUploadsFunc) nextHook() func(context.Context, shared.GetUploadsOptions) ([]types.Upload, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -12955,7 +12956,7 @@ type UploadServiceForExpirationGetUploadsFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetUploadsOptions + Arg1 shared.GetUploadsOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Upload diff --git a/internal/codeintel/uploads/service.go b/internal/codeintel/uploads/service.go index 6b4212953ba..d09a3ba75c5 100644 --- a/internal/codeintel/uploads/service.go +++ b/internal/codeintel/uploads/service.go @@ -121,7 +121,7 @@ func (s *Service) GetDirtyRepositories(ctx context.Context) (_ map[int]int, err return s.store.GetDirtyRepositories(ctx) } -func (s *Service) GetUploads(ctx context.Context, opts types.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) { +func (s *Service) GetUploads(ctx context.Context, opts shared.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) { ctx, _, endObservation := s.operations.getUploads.With(ctx, &err, observation.Args{ LogFields: []log.Field{log.Int("repositoryID", opts.RepositoryID), log.String("state", opts.State), log.String("term", opts.Term)}, }) @@ -168,7 +168,7 @@ func (s *Service) DeleteUploadByID(ctx context.Context, id int) (_ bool, err err return s.store.DeleteUploadByID(ctx, id) } -func (s *Service) DeleteUploads(ctx context.Context, opts types.DeleteUploadsOptions) (err error) { +func (s *Service) DeleteUploads(ctx context.Context, opts shared.DeleteUploadsOptions) (err error) { ctx, _, endObservation := s.operations.deleteUploadByID.With(ctx, &err, observation.Args{}) defer endObservation(1, observation.Args{}) diff --git a/internal/codeintel/uploads/shared/types.go b/internal/codeintel/uploads/shared/types.go index dbb93143eb2..2513f7c9cd9 100644 --- a/internal/codeintel/uploads/shared/types.go +++ b/internal/codeintel/uploads/shared/types.go @@ -2,13 +2,10 @@ package shared import ( "database/sql" - "database/sql/driver" - "encoding/json" "time" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" "github.com/sourcegraph/sourcegraph/internal/database/basestore" - "github.com/sourcegraph/sourcegraph/lib/errors" ) type SourcedCommits struct { @@ -41,6 +38,7 @@ type GetUploadsOptions struct { } type DeleteUploadsOptions struct { + RepositoryID int State string Term string VisibleAtTip bool @@ -191,71 +189,3 @@ type UploadLog struct { Reason *string Operation string } - -// Index is a subset of the lsif_indexes table and stores both processed and unprocessed -// records. -type Index struct { - ID int `json:"id"` - Commit string `json:"commit"` - QueuedAt time.Time `json:"queuedAt"` - State string `json:"state"` - FailureMessage *string `json:"failureMessage"` - StartedAt *time.Time `json:"startedAt"` - FinishedAt *time.Time `json:"finishedAt"` - ProcessAfter *time.Time `json:"processAfter"` - NumResets int `json:"numResets"` - NumFailures int `json:"numFailures"` - RepositoryID int `json:"repositoryId"` - LocalSteps []string `json:"local_steps"` - RepositoryName string `json:"repositoryName"` - DockerSteps []DockerStep `json:"docker_steps"` - Root string `json:"root"` - Indexer string `json:"indexer"` - IndexerArgs []string `json:"indexer_args"` // TODO - convert this to `IndexCommand string` - Outfile string `json:"outfile"` - ExecutionLogs []ExecutionLogEntry `json:"execution_logs"` - Rank *int `json:"placeInQueue"` - AssociatedUploadID *int `json:"associatedUpload"` -} - -type DockerStep struct { - Root string `json:"root"` - Image string `json:"image"` - Commands []string `json:"commands"` -} - -func (s *DockerStep) Scan(value any) error { - b, ok := value.([]byte) - if !ok { - return errors.Errorf("value is not []byte: %T", value) - } - - return json.Unmarshal(b, &s) -} - -func (s DockerStep) Value() (driver.Value, error) { - return json.Marshal(s) -} - -// ExecutionLogEntry represents a command run by the executor. -type ExecutionLogEntry struct { - Key string `json:"key"` - Command []string `json:"command"` - StartTime time.Time `json:"startTime"` - ExitCode *int `json:"exitCode,omitempty"` - Out string `json:"out,omitempty"` - DurationMs *int `json:"durationMs,omitempty"` -} - -func (e *ExecutionLogEntry) Scan(value any) error { - b, ok := value.([]byte) - if !ok { - return errors.Errorf("value is not []byte: %T", value) - } - - return json.Unmarshal(b, &e) -} - -func (e ExecutionLogEntry) Value() (driver.Value, error) { - return json.Marshal(e) -} diff --git a/internal/codeintel/uploads/transport/graphql/iface.go b/internal/codeintel/uploads/transport/graphql/iface.go index 7b45cbbb91a..ce8e644a908 100644 --- a/internal/codeintel/uploads/transport/graphql/iface.go +++ b/internal/codeintel/uploads/transport/graphql/iface.go @@ -5,7 +5,9 @@ import ( "time" "github.com/sourcegraph/sourcegraph/internal/api" + "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + uploadsshared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" ) @@ -15,15 +17,15 @@ type UploadService interface { GetAuditLogsForUpload(ctx context.Context, uploadID int) (_ []types.UploadLog, err error) GetListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error) GetUploadDocumentsForPath(ctx context.Context, bundleID int, pathPattern string) (_ []string, _ int, err error) - GetUploads(ctx context.Context, opts types.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) + GetUploads(ctx context.Context, opts uploadsshared.GetUploadsOptions) (uploads []types.Upload, totalCount int, err error) GetUploadsByIDs(ctx context.Context, ids ...int) (_ []types.Upload, err error) DeleteUploadByID(ctx context.Context, id int) (_ bool, err error) - DeleteUploads(ctx context.Context, opts types.DeleteUploadsOptions) (err error) + DeleteUploads(ctx context.Context, opts uploadsshared.DeleteUploadsOptions) (err error) } type AutoIndexingService interface { GetIndexByID(ctx context.Context, id int) (_ types.Index, _ bool, err error) - GetIndexes(ctx context.Context, opts types.GetIndexesOptions) (_ []types.Index, _ int, err error) + GetIndexes(ctx context.Context, opts shared.GetIndexesOptions) (_ []types.Index, _ int, err error) GetIndexesByIDs(ctx context.Context, ids ...int) (_ []types.Index, err error) GetListTags(ctx context.Context, repo api.RepoName, commitObjs ...string) (_ []*gitdomain.Tag, err error) GetUnsafeDB() database.DB diff --git a/internal/codeintel/uploads/transport/graphql/mocks_temp.go b/internal/codeintel/uploads/transport/graphql/mocks_temp.go index be93978df38..6df34f911dd 100644 --- a/internal/codeintel/uploads/transport/graphql/mocks_temp.go +++ b/internal/codeintel/uploads/transport/graphql/mocks_temp.go @@ -12,7 +12,9 @@ import ( "time" api "github.com/sourcegraph/sourcegraph/internal/api" + shared "github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared" types "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + shared1 "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" database "github.com/sourcegraph/sourcegraph/internal/database" gitdomain "github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain" ) @@ -50,7 +52,7 @@ func NewMockAutoIndexingService() *MockAutoIndexingService { }, }, GetIndexesFunc: &AutoIndexingServiceGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) (r0 []types.Index, r1 int, r2 error) { return }, }, @@ -83,7 +85,7 @@ func NewStrictMockAutoIndexingService() *MockAutoIndexingService { }, }, GetIndexesFunc: &AutoIndexingServiceGetIndexesFunc{ - defaultHook: func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + defaultHook: func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { panic("unexpected invocation of MockAutoIndexingService.GetIndexes") }, }, @@ -246,15 +248,15 @@ func (c AutoIndexingServiceGetIndexByIDFuncCall) Results() []interface{} { // GetIndexes method of the parent MockAutoIndexingService instance is // invoked. type AutoIndexingServiceGetIndexesFunc struct { - defaultHook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) - hooks []func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) + defaultHook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) + hooks []func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) history []AutoIndexingServiceGetIndexesFuncCall mutex sync.Mutex } // GetIndexes delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 types.GetIndexesOptions) ([]types.Index, int, error) { +func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 shared.GetIndexesOptions) ([]types.Index, int, error) { r0, r1, r2 := m.GetIndexesFunc.nextHook()(v0, v1) m.GetIndexesFunc.appendCall(AutoIndexingServiceGetIndexesFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -263,7 +265,7 @@ func (m *MockAutoIndexingService) GetIndexes(v0 context.Context, v1 types.GetInd // SetDefaultHook sets function that is called when the GetIndexes method of // the parent MockAutoIndexingService instance is invoked and the hook queue // is empty. -func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.defaultHook = hook } @@ -271,7 +273,7 @@ func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultHook(hook func(context.Con // GetIndexes method of the parent MockAutoIndexingService instance invokes // the hook at the front of the queue and discards it. After the queue is // empty, the default hook function is invoked for any future action. -func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error)) { +func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -280,19 +282,19 @@ func (f *AutoIndexingServiceGetIndexesFunc) PushHook(hook func(context.Context, // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *AutoIndexingServiceGetIndexesFunc) SetDefaultReturn(r0 []types.Index, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.SetDefaultHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *AutoIndexingServiceGetIndexesFunc) PushReturn(r0 []types.Index, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { + f.PushHook(func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { return r0, r1, r2 }) } -func (f *AutoIndexingServiceGetIndexesFunc) nextHook() func(context.Context, types.GetIndexesOptions) ([]types.Index, int, error) { +func (f *AutoIndexingServiceGetIndexesFunc) nextHook() func(context.Context, shared.GetIndexesOptions) ([]types.Index, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -331,7 +333,7 @@ type AutoIndexingServiceGetIndexesFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetIndexesOptions + Arg1 shared.GetIndexesOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Index @@ -912,7 +914,7 @@ func NewMockUploadService() *MockUploadService { }, }, DeleteUploadsFunc: &UploadServiceDeleteUploadsFunc{ - defaultHook: func(context.Context, types.DeleteUploadsOptions) (r0 error) { + defaultHook: func(context.Context, shared1.DeleteUploadsOptions) (r0 error) { return }, }, @@ -937,7 +939,7 @@ func NewMockUploadService() *MockUploadService { }, }, GetUploadsFunc: &UploadServiceGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { + defaultHook: func(context.Context, shared1.GetUploadsOptions) (r0 []types.Upload, r1 int, r2 error) { return }, }, @@ -959,7 +961,7 @@ func NewStrictMockUploadService() *MockUploadService { }, }, DeleteUploadsFunc: &UploadServiceDeleteUploadsFunc{ - defaultHook: func(context.Context, types.DeleteUploadsOptions) error { + defaultHook: func(context.Context, shared1.DeleteUploadsOptions) error { panic("unexpected invocation of MockUploadService.DeleteUploads") }, }, @@ -984,7 +986,7 @@ func NewStrictMockUploadService() *MockUploadService { }, }, GetUploadsFunc: &UploadServiceGetUploadsFunc{ - defaultHook: func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + defaultHook: func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { panic("unexpected invocation of MockUploadService.GetUploads") }, }, @@ -1141,15 +1143,15 @@ func (c UploadServiceDeleteUploadByIDFuncCall) Results() []interface{} { // UploadServiceDeleteUploadsFunc describes the behavior when the // DeleteUploads method of the parent MockUploadService instance is invoked. type UploadServiceDeleteUploadsFunc struct { - defaultHook func(context.Context, types.DeleteUploadsOptions) error - hooks []func(context.Context, types.DeleteUploadsOptions) error + defaultHook func(context.Context, shared1.DeleteUploadsOptions) error + hooks []func(context.Context, shared1.DeleteUploadsOptions) error history []UploadServiceDeleteUploadsFuncCall mutex sync.Mutex } // DeleteUploads delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockUploadService) DeleteUploads(v0 context.Context, v1 types.DeleteUploadsOptions) error { +func (m *MockUploadService) DeleteUploads(v0 context.Context, v1 shared1.DeleteUploadsOptions) error { r0 := m.DeleteUploadsFunc.nextHook()(v0, v1) m.DeleteUploadsFunc.appendCall(UploadServiceDeleteUploadsFuncCall{v0, v1, r0}) return r0 @@ -1158,7 +1160,7 @@ func (m *MockUploadService) DeleteUploads(v0 context.Context, v1 types.DeleteUpl // SetDefaultHook sets function that is called when the DeleteUploads method // of the parent MockUploadService instance is invoked and the hook queue is // empty. -func (f *UploadServiceDeleteUploadsFunc) SetDefaultHook(hook func(context.Context, types.DeleteUploadsOptions) error) { +func (f *UploadServiceDeleteUploadsFunc) SetDefaultHook(hook func(context.Context, shared1.DeleteUploadsOptions) error) { f.defaultHook = hook } @@ -1166,7 +1168,7 @@ func (f *UploadServiceDeleteUploadsFunc) SetDefaultHook(hook func(context.Contex // DeleteUploads method of the parent MockUploadService instance invokes the // hook at the front of the queue and discards it. After the queue is empty, // the default hook function is invoked for any future action. -func (f *UploadServiceDeleteUploadsFunc) PushHook(hook func(context.Context, types.DeleteUploadsOptions) error) { +func (f *UploadServiceDeleteUploadsFunc) PushHook(hook func(context.Context, shared1.DeleteUploadsOptions) error) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -1175,19 +1177,19 @@ func (f *UploadServiceDeleteUploadsFunc) PushHook(hook func(context.Context, typ // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *UploadServiceDeleteUploadsFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(context.Context, types.DeleteUploadsOptions) error { + f.SetDefaultHook(func(context.Context, shared1.DeleteUploadsOptions) error { return r0 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *UploadServiceDeleteUploadsFunc) PushReturn(r0 error) { - f.PushHook(func(context.Context, types.DeleteUploadsOptions) error { + f.PushHook(func(context.Context, shared1.DeleteUploadsOptions) error { return r0 }) } -func (f *UploadServiceDeleteUploadsFunc) nextHook() func(context.Context, types.DeleteUploadsOptions) error { +func (f *UploadServiceDeleteUploadsFunc) nextHook() func(context.Context, shared1.DeleteUploadsOptions) error { f.mutex.Lock() defer f.mutex.Unlock() @@ -1225,7 +1227,7 @@ type UploadServiceDeleteUploadsFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.DeleteUploadsOptions + Arg1 shared1.DeleteUploadsOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 error @@ -1707,15 +1709,15 @@ func (c UploadServiceGetUploadDocumentsForPathFuncCall) Results() []interface{} // UploadServiceGetUploadsFunc describes the behavior when the GetUploads // method of the parent MockUploadService instance is invoked. type UploadServiceGetUploadsFunc struct { - defaultHook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) - hooks []func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) + defaultHook func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) + hooks []func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) history []UploadServiceGetUploadsFuncCall mutex sync.Mutex } // GetUploads delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockUploadService) GetUploads(v0 context.Context, v1 types.GetUploadsOptions) ([]types.Upload, int, error) { +func (m *MockUploadService) GetUploads(v0 context.Context, v1 shared1.GetUploadsOptions) ([]types.Upload, int, error) { r0, r1, r2 := m.GetUploadsFunc.nextHook()(v0, v1) m.GetUploadsFunc.appendCall(UploadServiceGetUploadsFuncCall{v0, v1, r0, r1, r2}) return r0, r1, r2 @@ -1724,7 +1726,7 @@ func (m *MockUploadService) GetUploads(v0 context.Context, v1 types.GetUploadsOp // SetDefaultHook sets function that is called when the GetUploads method of // the parent MockUploadService instance is invoked and the hook queue is // empty. -func (f *UploadServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *UploadServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error)) { f.defaultHook = hook } @@ -1732,7 +1734,7 @@ func (f *UploadServiceGetUploadsFunc) SetDefaultHook(hook func(context.Context, // GetUploads method of the parent MockUploadService instance invokes the // hook at the front of the queue and discards it. After the queue is empty, // the default hook function is invoked for any future action. -func (f *UploadServiceGetUploadsFunc) PushHook(hook func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error)) { +func (f *UploadServiceGetUploadsFunc) PushHook(hook func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -1741,19 +1743,19 @@ func (f *UploadServiceGetUploadsFunc) PushHook(hook func(context.Context, types. // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. func (f *UploadServiceGetUploadsFunc) SetDefaultReturn(r0 []types.Upload, r1 int, r2 error) { - f.SetDefaultHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.SetDefaultHook(func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } // PushReturn calls PushHook with a function that returns the given values. func (f *UploadServiceGetUploadsFunc) PushReturn(r0 []types.Upload, r1 int, r2 error) { - f.PushHook(func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { + f.PushHook(func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { return r0, r1, r2 }) } -func (f *UploadServiceGetUploadsFunc) nextHook() func(context.Context, types.GetUploadsOptions) ([]types.Upload, int, error) { +func (f *UploadServiceGetUploadsFunc) nextHook() func(context.Context, shared1.GetUploadsOptions) ([]types.Upload, int, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -1791,7 +1793,7 @@ type UploadServiceGetUploadsFuncCall struct { Arg0 context.Context // Arg1 is the value of the 2nd argument passed to this method // invocation. - Arg1 types.GetUploadsOptions + Arg1 shared1.GetUploadsOptions // Result0 is the value of the 1st result returned from this method // invocation. Result0 []types.Upload diff --git a/internal/codeintel/uploads/transport/graphql/utils.go b/internal/codeintel/uploads/transport/graphql/utils.go index 95fc6ba4b33..a534c45b8c1 100644 --- a/internal/codeintel/uploads/transport/graphql/utils.go +++ b/internal/codeintel/uploads/transport/graphql/utils.go @@ -11,7 +11,7 @@ import ( "github.com/graph-gophers/graphql-go/relay" "github.com/sourcegraph/sourcegraph/internal/api" - "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" "github.com/sourcegraph/sourcegraph/internal/database" "github.com/sourcegraph/sourcegraph/lib/errors" ) @@ -79,17 +79,17 @@ const DefaultUploadPageSize = 50 // makeGetUploadsOptions translates the given GraphQL arguments into options defined by the // store.GetUploads operations. -func makeGetUploadsOptions(args *LSIFRepositoryUploadsQueryArgs) (types.GetUploadsOptions, error) { +func makeGetUploadsOptions(args *LSIFRepositoryUploadsQueryArgs) (shared.GetUploadsOptions, error) { repositoryID, err := resolveRepositoryID(args.RepositoryID) if err != nil { - return types.GetUploadsOptions{}, err + return shared.GetUploadsOptions{}, err } var dependencyOf int64 if args.DependencyOf != nil { dependencyOf, err = unmarshalLSIFUploadGQLID(*args.DependencyOf) if err != nil { - return types.GetUploadsOptions{}, err + return shared.GetUploadsOptions{}, err } } @@ -97,16 +97,16 @@ func makeGetUploadsOptions(args *LSIFRepositoryUploadsQueryArgs) (types.GetUploa if args.DependentOf != nil { dependentOf, err = unmarshalLSIFUploadGQLID(*args.DependentOf) if err != nil { - return types.GetUploadsOptions{}, err + return shared.GetUploadsOptions{}, err } } offset, err := decodeIntCursor(args.After) if err != nil { - return types.GetUploadsOptions{}, err + return shared.GetUploadsOptions{}, err } - return types.GetUploadsOptions{ + return shared.GetUploadsOptions{ RepositoryID: repositoryID, State: strings.ToLower(derefString(args.State, "")), Term: derefString(args.Query, ""), @@ -122,17 +122,17 @@ func makeGetUploadsOptions(args *LSIFRepositoryUploadsQueryArgs) (types.GetUploa // makeDeleteUploadsOptions translates the given GraphQL arguments into options defined by the // store.DeleteUploads operations. -func makeDeleteUploadsOptions(args *DeleteLSIFUploadsArgs) (types.DeleteUploadsOptions, error) { +func makeDeleteUploadsOptions(args *DeleteLSIFUploadsArgs) (shared.DeleteUploadsOptions, error) { var repository int if args.Repository != nil { var err error repository, err = resolveRepositoryID(*args.Repository) if err != nil { - return types.DeleteUploadsOptions{}, err + return shared.DeleteUploadsOptions{}, err } } - return types.DeleteUploadsOptions{ + return shared.DeleteUploadsOptions{ State: strings.ToLower(derefString(args.State, "")), Term: derefString(args.Query, ""), VisibleAtTip: derefBool(args.IsLatestForRepo, false), diff --git a/internal/codeintel/uploads/transport/graphql/utils_test.go b/internal/codeintel/uploads/transport/graphql/utils_test.go index ea08f2cf679..ac299286936 100644 --- a/internal/codeintel/uploads/transport/graphql/utils_test.go +++ b/internal/codeintel/uploads/transport/graphql/utils_test.go @@ -8,7 +8,7 @@ import ( "github.com/graph-gophers/graphql-go" "github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend/graphqlutil" - "github.com/sourcegraph/sourcegraph/internal/codeintel/shared/types" + "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared" ) func TestMakeGetUploadsOptions(t *testing.T) { @@ -28,7 +28,7 @@ func TestMakeGetUploadsOptions(t *testing.T) { t.Fatalf("unexpected error making options: %s", err) } - expected := types.GetUploadsOptions{ + expected := shared.GetUploadsOptions{ RepositoryID: 50, State: "s", Term: "q", @@ -50,7 +50,7 @@ func TestMakeGetUploadsOptionsDefaults(t *testing.T) { t.Fatalf("unexpected error making options: %s", err) } - expected := types.GetUploadsOptions{ + expected := shared.GetUploadsOptions{ RepositoryID: 0, State: "", Term: "", diff --git a/mockgen.test.yaml b/mockgen.test.yaml index 92b6f2700d3..4efc4eb40d8 100644 --- a/mockgen.test.yaml +++ b/mockgen.test.yaml @@ -77,17 +77,17 @@ - path: github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/store interfaces: - Store - - path: github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared - interfaces: - - RepoUpdaterClient - - GitServerClient - - UploadService - path: github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/background interfaces: - DependenciesService - ReposStore - ExternalServiceStore - GitserverRepoStore + - PolicyMatcher + - RepoUpdaterClient + - GitserverClient + - InferenceService + - UploadService - AutoIndexingService - path: github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared interfaces: @@ -107,14 +107,13 @@ - path: github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/store interfaces: - Store - - path: github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/shared + - path: github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing interfaces: - - GitServerClient + - GitserverClient - RepoUpdaterClient - InferenceService - UploadService - - filename: internal/codeintel/autoindexing/internal/inference/mocks_test.go path: github.com/sourcegraph/sourcegraph/internal/codeintel/autoindexing/internal/inference interfaces: