From 71a3996d91e959448f9ee4e310b49b2d53682445 Mon Sep 17 00:00:00 2001 From: Gary Date: Mon, 15 Jul 2024 14:14:26 +0800 Subject: [PATCH] feat(KB): chunk catalog api (#39) Because we are going to provide chunk catalog page This commit implemented the chunk related APIs --- .env | 2 +- .gitignore | 1 + go.mod | 4 +- pkg/handler/chunks.go | 168 +++ pkg/handler/knowledgebase.go | 32 +- pkg/handler/knowledgebasefiles.go | 54 +- pkg/mock/repository_i_mock.gen.go | 1688 ++++++++++++++++++++++++--- pkg/repository/chunk.go | 31 + pkg/repository/knowledgebasefile.go | 141 ++- pkg/service/pipeline.go | 13 +- 10 files changed, 1867 insertions(+), 267 deletions(-) create mode 100644 pkg/handler/chunks.go diff --git a/.env b/.env index 6eaa9dd..f39e80a 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ # version -GOLANG_VERSION=1.21 +GOLANG_VERSION=1.22 K6_VERSION=0.42.0 # service diff --git a/.gitignore b/.gitignore index 72fa501..e7d57b9 100644 --- a/.gitignore +++ b/.gitignore @@ -123,3 +123,4 @@ test_.md test_pdf_base64.txt .DS_Store cmd/main/__debug_bin* +.test diff --git a/go.mod b/go.mod index b9e60db..5b19e00 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/instill-ai/artifact-backend -go 1.21.1 - -toolchain go1.21.3 +go 1.22 require ( github.com/frankban/quicktest v1.14.6 diff --git a/pkg/handler/chunks.go b/pkg/handler/chunks.go new file mode 100644 index 0000000..3e4533d --- /dev/null +++ b/pkg/handler/chunks.go @@ -0,0 +1,168 @@ +package handler + +import ( + "context" + "fmt" + + "github.com/google/uuid" + "github.com/instill-ai/artifact-backend/pkg/customerror" + "github.com/instill-ai/artifact-backend/pkg/logger" + "github.com/instill-ai/artifact-backend/pkg/repository" + artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" + "go.uber.org/zap" + "google.golang.org/protobuf/types/known/timestamppb" +) + +func (ph *PublicHandler) ListChunks(ctx context.Context, req *artifactpb.ListChunksRequest) (*artifactpb.ListChunksResponse, error) { + log, _ := logger.GetZapLogger(ctx) + uid, err := getUserUIDFromContext(ctx) + if err != nil { + log.Error("failed to get user id from header", zap.Error(err)) + return nil, fmt.Errorf("failed to get user id from header: %v. err: %w", err, customerror.ErrUnauthenticated) + } + fileUID, err := uuid.Parse(req.FileUid) + if err != nil { + log.Error("failed to parse file uid", zap.Error(err)) + return nil, fmt.Errorf("failed to parse file uid: %v. err: %w", err, customerror.ErrInvalidArgument) + } + // TODO: ACL - check if the user(uid from context) has access to the chunk. get knowledge base id and owner id and check if the user has access to the knowledge base + { + _ = uid + _ = req.OwnerId + _ = req.KbId + } + + fileUIDs := []uuid.UUID{fileUID} + files, err := ph.service.Repository.GetKnowledgeBaseFilesByFileUIDs(ctx, fileUIDs) + if err != nil { + log.Error("failed to get knowledge base files by file uids", zap.Error(err)) + return nil, fmt.Errorf("failed to get knowledge base files by file uids") + } + if len(files) == 0 { + log.Error("no files found for the given file uids") + return nil, fmt.Errorf("no files found for the given file uids: %v. err: %w", fileUIDs, customerror.ErrNotFound) + } + file := files[0] + + sources, err := ph.service.Repository.GetSourceTableAndUIDByFileUIDs(ctx, []repository.KnowledgeBaseFile{file}) + if err != nil { + log.Error("failed to get source table and uid by file uids", zap.Error(err)) + return nil, fmt.Errorf("failed to get source table and uid by file uids ") + } + + source, ok := sources[fileUID] + if !ok { + // source not found. if some files(e.g. pdf) don't have been converted yet. there is not source file for chunks. + return nil, nil + } + + chunks, err := ph.service.Repository.GetTextChunksBySource(ctx, source.SourceTable, source.SourceUID) + if err != nil { + log.Error("failed to get text chunks by source", zap.Error(err)) + return nil, fmt.Errorf("failed to get text chunks by source: %w ", err) + + } + + res := make([]*artifactpb.Chunk, 0, len(chunks)) + for _, chunk := range chunks { + res = append(res, &artifactpb.Chunk{ + ChunkUid: chunk.UID.String(), + Retrievable: chunk.Retrievable, + StartPos: uint32(chunk.StartPos), + EndPos: uint32(chunk.EndPos), + Tokens: uint32(chunk.Tokens), + CreateTime: timestamppb.New(*chunk.CreateTime), + OriginalFileUid: file.UID.String(), + }) + } + + return &artifactpb.ListChunksResponse{ + Chunks: res, + }, nil +} + +func (ph *PublicHandler) UpdateChunk(ctx context.Context, req *artifactpb.UpdateChunkRequest) (*artifactpb.UpdateChunkResponse, error) { + log, _ := logger.GetZapLogger(ctx) + uid, err := getUserUIDFromContext(ctx) + if err != nil { + log.Error("failed to get user id from header", zap.Error(err)) + return nil, fmt.Errorf("failed to get user id from header: %v. err: %w", err, customerror.ErrUnauthenticated) + } + + // TODO: ACL - check if the user(uid from context) has access to the chunk. get chunk's kb uid and check if the uid has access to the knowledge base + { + _ = uid + _ = req.ChunkUid + // use chunk uid to get the knowledge base id + // .... + // check ACL + } + + retrievable := req.Retrievable + update := map[string]interface{}{ + repository.TextChunkColumn.Retrievable: retrievable, + } + + chunk, err := ph.service.Repository.UpdateChunk(ctx, req.ChunkUid, update) + if err != nil { + log.Error("failed to update text chunk", zap.Error(err)) + return nil, fmt.Errorf("failed to update text chunk: %w", err) + } + + return &artifactpb.UpdateChunkResponse{ + // Populate the response fields appropriately + Chunk: &artifactpb.Chunk{ + ChunkUid: chunk.UID.String(), + Retrievable: chunk.Retrievable, + StartPos: uint32(chunk.StartPos), + EndPos: uint32(chunk.EndPos), + Tokens: uint32(chunk.Tokens), + CreateTime: timestamppb.New(*chunk.CreateTime), + // OriginalFileUid: chunk.FileUID.String(), + }, + }, nil +} + +func (ph *PublicHandler) GetSourceFile(ctx context.Context, req *artifactpb.GetSourceFileRequest) (*artifactpb.GetSourceFileResponse, error) { + log, _ := logger.GetZapLogger(ctx) + uid, err := getUserUIDFromContext(ctx) + if err != nil { + log.Error("failed to get user id from header", zap.Error(err)) + return nil, fmt.Errorf("failed to get user id from header: %v. err: %w", err, customerror.ErrUnauthenticated) + } + fileUID, err := uuid.Parse(req.FileUid) + if err != nil { + log.Error("failed to parse file uid", zap.Error(err)) + return nil, fmt.Errorf("failed to parse file uid: %v. err: %w", err, customerror.ErrInvalidArgument) + } + + // TODO ACL - check if the user(uid from context) has access to the source file. + { + _ = uid + _ = req.FileUid + // use file uid to get the knowledge base id + // .... + // check ACL + // ... + } + source, err := ph.service.Repository.GetTruthSourceByFileUID(ctx, fileUID) + if err != nil { + log.Error("failed to get truth source by file uid", zap.Error(err)) + return nil, fmt.Errorf("failed to get truth source by file uid. err: %w", err) + } + // get the source file content from minIO using dest of source + content, err := ph.service.MinIO.GetFile(ctx, source.Dest) + if err != nil { + log.Error("failed to get file from minio", zap.Error(err)) + return nil, fmt.Errorf("failed to get file from minio. err: %w", err) + } + + return &artifactpb.GetSourceFileResponse{ + // Populate the response fields appropriately + SourceFile: &artifactpb.SourceFile{ + Content: string(content), + CreateTime: timestamppb.New(source.CreateTime), + UpdateTime: timestamppb.New(source.CreateTime), + }, + }, nil +} diff --git a/pkg/handler/knowledgebase.go b/pkg/handler/knowledgebase.go index 761ed4d..ccfa860 100644 --- a/pkg/handler/knowledgebase.go +++ b/pkg/handler/knowledgebase.go @@ -32,7 +32,7 @@ func (ph *PublicHandler) CreateKnowledgeBase(ctx context.Context, req *artifactp return nil, err } - // TODO: check user's permission to create knowledge base in the user or org context + // TODO: ACL check user's permission to create knowledge base in the user or org context // 1. if it is user namespace, it is okay // 2. if it is org namespace, check if the user has permission to create knowledge base in the org // .... @@ -175,8 +175,8 @@ func (ph *PublicHandler) ListKnowledgeBases(ctx context.Context, req *artifactpb DownstreamApps: []string{}, TotalFiles: uint32(fileCounts[kb.UID]), TotalTokens: uint32(tokenCounts[kb.UID]), - // TODO: get used storage - UsedStorage: 0, + // TODO: get used storage of kb + UsedStorage: 0, } } return &artifactpb.ListKnowledgeBasesResponse{ @@ -252,7 +252,7 @@ func (ph *PublicHandler) UpdateKnowledgeBase(ctx context.Context, req *artifactp TotalFiles: uint32(fileCounts[kb.UID]), TotalTokens: uint32(tokenCounts[kb.UID]), // TODO: get used storage - UsedStorage: 0, + UsedStorage: 0, }, }, nil } @@ -284,19 +284,19 @@ func (ph *PublicHandler) DeleteKnowledgeBase(ctx context.Context, req *artifactp return &artifactpb.DeleteKnowledgeBaseResponse{ KnowledgeBase: &artifactpb.KnowledgeBase{ - Name: deletedKb.Name, - KbId: deletedKb.KbID, - Description: deletedKb.Description, - Tags: deletedKb.Tags, - CreateTime: deletedKb.CreateTime.String(), - UpdateTime: deletedKb.UpdateTime.String(), - OwnerName: deletedKb.Owner, + Name: deletedKb.Name, + KbId: deletedKb.KbID, + Description: deletedKb.Description, + Tags: deletedKb.Tags, + CreateTime: deletedKb.CreateTime.String(), + UpdateTime: deletedKb.UpdateTime.String(), + OwnerName: deletedKb.Owner, ConvertingPipelines: []string{}, - EmbeddingPipelines: []string{}, - DownstreamApps: []string{}, - TotalFiles: 0, - TotalTokens: 0, - UsedStorage: 0, + EmbeddingPipelines: []string{}, + DownstreamApps: []string{}, + TotalFiles: 0, + TotalTokens: 0, + UsedStorage: 0, }, }, nil } diff --git a/pkg/handler/knowledgebasefiles.go b/pkg/handler/knowledgebasefiles.go index 795a8c3..c3afdf6 100644 --- a/pkg/handler/knowledgebasefiles.go +++ b/pkg/handler/knowledgebasefiles.go @@ -2,7 +2,6 @@ package handler import ( "context" - "errors" "fmt" "strings" @@ -14,7 +13,6 @@ import ( mgmtpb "github.com/instill-ai/protogen-go/core/mgmt/v1beta" "go.uber.org/zap" "google.golang.org/protobuf/types/known/timestamppb" - "gorm.io/gorm" ) func (ph *PublicHandler) UploadKnowledgeBaseFile(ctx context.Context, req *artifactpb.UploadKnowledgeBaseFileRequest) (*artifactpb.UploadKnowledgeBaseFileResponse, error) { @@ -227,18 +225,18 @@ func (ph *PublicHandler) ListKnowledgeBaseFiles(ctx context.Context, req *artifa return nil, err } // get the tokens and chunks using the source table and source uid - sources, err := ph.findSourceTableAndSourceUIDByFileUID(ctx, kbFiles) + sources, err := ph.service.Repository.GetSourceTableAndUIDByFileUIDs(ctx, kbFiles) if err != nil { log.Error("failed to find source table and source uid by file uid", zap.Error(err)) return nil, err } - // TODO need test from file upload to file to embeded text then check the total tokens + totalTokens, err := ph.service.Repository.GetFilesTotalTokens(ctx, sources) if err != nil { log.Error("failed to get files total tokens", zap.Error(err)) return nil, err } - // TODO get total chunks + totalChunks, err := ph.service.Repository.GetTotalChunksBySources(ctx, sources) if err != nil { log.Error("failed to get files total chunks", zap.Error(err)) @@ -272,52 +270,6 @@ func (ph *PublicHandler) ListKnowledgeBaseFiles(ctx context.Context, req *artifa }, nil } -// findSourceTableAndSourceUIDByFiles find the source table and source uid by file uid. -func (ph *PublicHandler) findSourceTableAndSourceUIDByFileUID(ctx context.Context, files []repository.KnowledgeBaseFile) ( - map[uuid.UUID]struct { - SourceTable string - SourceUID uuid.UUID - }, error) { - result := make(map[uuid.UUID]struct { - SourceTable string - SourceUID uuid.UUID - }) - logger, _ := logger.GetZapLogger(ctx) - for _, file := range files { - // find the source table and source uid by file uid - // check if the file is is text or markdown - switch file.Type { - case artifactpb.FileType_FILE_TYPE_TEXT.String(), artifactpb.FileType_FILE_TYPE_MARKDOWN.String(): - result[file.UID] = struct { - SourceTable string - SourceUID uuid.UUID - }{ - SourceTable: ph.service.Repository.KnowledgeBaseFileTableName(), - SourceUID: file.UID, - } - case artifactpb.FileType_FILE_TYPE_PDF.String(): - convertedFile, err := ph.service.Repository.GetConvertedFileByFileUID(ctx, file.UID) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - continue - } else { - logger.Error("failed to get converted file by file uid", zap.Error(err)) - return nil, err - } - } - result[file.UID] = struct { - SourceTable string - SourceUID uuid.UUID - }{ - SourceTable: ph.service.Repository.ConvertedFileTableName(), - SourceUID: convertedFile.UID, - } - } - } - - return result, nil -} - func (ph *PublicHandler) DeleteKnowledgeBaseFile( ctx context.Context, req *artifactpb.DeleteKnowledgeBaseFileRequest) ( diff --git a/pkg/mock/repository_i_mock.gen.go b/pkg/mock/repository_i_mock.gen.go index 7387c7e..a5960b7 100644 --- a/pkg/mock/repository_i_mock.gen.go +++ b/pkg/mock/repository_i_mock.gen.go @@ -104,8 +104,8 @@ type RepositoryIMock struct { beforeGetConvertedFileByFileUIDCounter uint64 GetConvertedFileByFileUIDMock mRepositoryIMockGetConvertedFileByFileUID - funcGetCountFilesByListKnowledgeBaseUID func(ctx context.Context, kbUIDs []uuid.UUID) (m1 map[uuid.UUID]int64, err error) - inspectFuncGetCountFilesByListKnowledgeBaseUID func(ctx context.Context, kbUIDs []uuid.UUID) + funcGetCountFilesByListKnowledgeBaseUID func(ctx context.Context, kbUIDs []mm_repository.KbUID) (m1 map[mm_repository.KbUID]int64, err error) + inspectFuncGetCountFilesByListKnowledgeBaseUID func(ctx context.Context, kbUIDs []mm_repository.KbUID) afterGetCountFilesByListKnowledgeBaseUIDCounter uint64 beforeGetCountFilesByListKnowledgeBaseUIDCounter uint64 GetCountFilesByListKnowledgeBaseUIDMock mRepositoryIMockGetCountFilesByListKnowledgeBaseUID @@ -140,12 +140,27 @@ type RepositoryIMock struct { beforeGetKnowledgeBaseByOwnerAndIDCounter uint64 GetKnowledgeBaseByOwnerAndIDMock mRepositoryIMockGetKnowledgeBaseByOwnerAndID + funcGetKnowledgeBaseFilesByFileUIDs func(ctx context.Context, fileUIDs []uuid.UUID) (ka1 []mm_repository.KnowledgeBaseFile, err error) + inspectFuncGetKnowledgeBaseFilesByFileUIDs func(ctx context.Context, fileUIDs []uuid.UUID) + afterGetKnowledgeBaseFilesByFileUIDsCounter uint64 + beforeGetKnowledgeBaseFilesByFileUIDsCounter uint64 + GetKnowledgeBaseFilesByFileUIDsMock mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs + funcGetRepositoryTag func(ctx context.Context, r1 utils.RepositoryTagName) (rp1 *pb.RepositoryTag, err error) inspectFuncGetRepositoryTag func(ctx context.Context, r1 utils.RepositoryTagName) afterGetRepositoryTagCounter uint64 beforeGetRepositoryTagCounter uint64 GetRepositoryTagMock mRepositoryIMockGetRepositoryTag + funcGetSourceTableAndUIDByFileUIDs func(ctx context.Context, files []mm_repository.KnowledgeBaseFile) (m1 map[mm_repository.FileUID]struct { + SourceTable string + SourceUID uuid.UUID + }, err error) + inspectFuncGetSourceTableAndUIDByFileUIDs func(ctx context.Context, files []mm_repository.KnowledgeBaseFile) + afterGetSourceTableAndUIDByFileUIDsCounter uint64 + beforeGetSourceTableAndUIDByFileUIDsCounter uint64 + GetSourceTableAndUIDByFileUIDsMock mRepositoryIMockGetSourceTableAndUIDByFileUIDs + funcGetTextChunksBySource func(ctx context.Context, sourceTable string, sourceUID uuid.UUID) (ta1 []mm_repository.TextChunk, err error) inspectFuncGetTextChunksBySource func(ctx context.Context, sourceTable string, sourceUID uuid.UUID) afterGetTextChunksBySourceCounter uint64 @@ -170,6 +185,12 @@ type RepositoryIMock struct { beforeGetTotalTokensByListKBUIDsCounter uint64 GetTotalTokensByListKBUIDsMock mRepositoryIMockGetTotalTokensByListKBUIDs + funcGetTruthSourceByFileUID func(ctx context.Context, fileUID uuid.UUID) (sp1 *mm_repository.SourceMeta, err error) + inspectFuncGetTruthSourceByFileUID func(ctx context.Context, fileUID uuid.UUID) + afterGetTruthSourceByFileUIDCounter uint64 + beforeGetTruthSourceByFileUIDCounter uint64 + GetTruthSourceByFileUIDMock mRepositoryIMockGetTruthSourceByFileUID + funcKnowledgeBaseFileTableName func() (s1 string) inspectFuncKnowledgeBaseFileTableName func() afterKnowledgeBaseFileTableNameCounter uint64 @@ -200,6 +221,12 @@ type RepositoryIMock struct { beforeTextChunkTableNameCounter uint64 TextChunkTableNameMock mRepositoryIMockTextChunkTableName + funcUpdateChunk func(ctx context.Context, chunkUID string, updates map[string]interface{}) (tp1 *mm_repository.TextChunk, err error) + inspectFuncUpdateChunk func(ctx context.Context, chunkUID string, updates map[string]interface{}) + afterUpdateChunkCounter uint64 + beforeUpdateChunkCounter uint64 + UpdateChunkMock mRepositoryIMockUpdateChunk + funcUpdateKnowledgeBase func(ctx context.Context, ownerUID string, kb mm_repository.KnowledgeBase) (kp1 *mm_repository.KnowledgeBase, err error) inspectFuncUpdateKnowledgeBase func(ctx context.Context, ownerUID string, kb mm_repository.KnowledgeBase) afterUpdateKnowledgeBaseCounter uint64 @@ -289,9 +316,15 @@ func NewRepositoryIMock(t minimock.Tester) *RepositoryIMock { m.GetKnowledgeBaseByOwnerAndIDMock = mRepositoryIMockGetKnowledgeBaseByOwnerAndID{mock: m} m.GetKnowledgeBaseByOwnerAndIDMock.callArgs = []*RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams{} + m.GetKnowledgeBaseFilesByFileUIDsMock = mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs{mock: m} + m.GetKnowledgeBaseFilesByFileUIDsMock.callArgs = []*RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParams{} + m.GetRepositoryTagMock = mRepositoryIMockGetRepositoryTag{mock: m} m.GetRepositoryTagMock.callArgs = []*RepositoryIMockGetRepositoryTagParams{} + m.GetSourceTableAndUIDByFileUIDsMock = mRepositoryIMockGetSourceTableAndUIDByFileUIDs{mock: m} + m.GetSourceTableAndUIDByFileUIDsMock.callArgs = []*RepositoryIMockGetSourceTableAndUIDByFileUIDsParams{} + m.GetTextChunksBySourceMock = mRepositoryIMockGetTextChunksBySource{mock: m} m.GetTextChunksBySourceMock.callArgs = []*RepositoryIMockGetTextChunksBySourceParams{} @@ -301,6 +334,9 @@ func NewRepositoryIMock(t minimock.Tester) *RepositoryIMock { m.GetTotalTokensByListKBUIDsMock = mRepositoryIMockGetTotalTokensByListKBUIDs{mock: m} m.GetTotalTokensByListKBUIDsMock.callArgs = []*RepositoryIMockGetTotalTokensByListKBUIDsParams{} + m.GetTruthSourceByFileUIDMock = mRepositoryIMockGetTruthSourceByFileUID{mock: m} + m.GetTruthSourceByFileUIDMock.callArgs = []*RepositoryIMockGetTruthSourceByFileUIDParams{} + m.KnowledgeBaseFileTableNameMock = mRepositoryIMockKnowledgeBaseFileTableName{mock: m} m.ListKnowledgeBaseFilesMock = mRepositoryIMockListKnowledgeBaseFiles{mock: m} @@ -314,6 +350,9 @@ func NewRepositoryIMock(t minimock.Tester) *RepositoryIMock { m.TextChunkTableNameMock = mRepositoryIMockTextChunkTableName{mock: m} + m.UpdateChunkMock = mRepositoryIMockUpdateChunk{mock: m} + m.UpdateChunkMock.callArgs = []*RepositoryIMockUpdateChunkParams{} + m.UpdateKnowledgeBaseMock = mRepositoryIMockUpdateKnowledgeBase{mock: m} m.UpdateKnowledgeBaseMock.callArgs = []*RepositoryIMockUpdateKnowledgeBaseParams{} @@ -4727,23 +4766,23 @@ type RepositoryIMockGetCountFilesByListKnowledgeBaseUIDExpectation struct { // RepositoryIMockGetCountFilesByListKnowledgeBaseUIDParams contains parameters of the RepositoryI.GetCountFilesByListKnowledgeBaseUID type RepositoryIMockGetCountFilesByListKnowledgeBaseUIDParams struct { ctx context.Context - kbUIDs []uuid.UUID + kbUIDs []mm_repository.KbUID } // RepositoryIMockGetCountFilesByListKnowledgeBaseUIDParamPtrs contains pointers to parameters of the RepositoryI.GetCountFilesByListKnowledgeBaseUID type RepositoryIMockGetCountFilesByListKnowledgeBaseUIDParamPtrs struct { ctx *context.Context - kbUIDs *[]uuid.UUID + kbUIDs *[]mm_repository.KbUID } // RepositoryIMockGetCountFilesByListKnowledgeBaseUIDResults contains results of the RepositoryI.GetCountFilesByListKnowledgeBaseUID type RepositoryIMockGetCountFilesByListKnowledgeBaseUIDResults struct { - m1 map[uuid.UUID]int64 + m1 map[mm_repository.KbUID]int64 err error } // Expect sets up expected params for RepositoryI.GetCountFilesByListKnowledgeBaseUID -func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) Expect(ctx context.Context, kbUIDs []uuid.UUID) *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID { +func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) Expect(ctx context.Context, kbUIDs []mm_repository.KbUID) *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID { if mmGetCountFilesByListKnowledgeBaseUID.mock.funcGetCountFilesByListKnowledgeBaseUID != nil { mmGetCountFilesByListKnowledgeBaseUID.mock.t.Fatalf("RepositoryIMock.GetCountFilesByListKnowledgeBaseUID mock is already set by Set") } @@ -4789,7 +4828,7 @@ func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByList } // ExpectKbUIDsParam2 sets up expected param kbUIDs for RepositoryI.GetCountFilesByListKnowledgeBaseUID -func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) ExpectKbUIDsParam2(kbUIDs []uuid.UUID) *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID { +func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) ExpectKbUIDsParam2(kbUIDs []mm_repository.KbUID) *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID { if mmGetCountFilesByListKnowledgeBaseUID.mock.funcGetCountFilesByListKnowledgeBaseUID != nil { mmGetCountFilesByListKnowledgeBaseUID.mock.t.Fatalf("RepositoryIMock.GetCountFilesByListKnowledgeBaseUID mock is already set by Set") } @@ -4811,7 +4850,7 @@ func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByList } // Inspect accepts an inspector function that has same arguments as the RepositoryI.GetCountFilesByListKnowledgeBaseUID -func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) Inspect(f func(ctx context.Context, kbUIDs []uuid.UUID)) *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID { +func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) Inspect(f func(ctx context.Context, kbUIDs []mm_repository.KbUID)) *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID { if mmGetCountFilesByListKnowledgeBaseUID.mock.inspectFuncGetCountFilesByListKnowledgeBaseUID != nil { mmGetCountFilesByListKnowledgeBaseUID.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.GetCountFilesByListKnowledgeBaseUID") } @@ -4822,7 +4861,7 @@ func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByList } // Return sets up results that will be returned by RepositoryI.GetCountFilesByListKnowledgeBaseUID -func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) Return(m1 map[uuid.UUID]int64, err error) *RepositoryIMock { +func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) Return(m1 map[mm_repository.KbUID]int64, err error) *RepositoryIMock { if mmGetCountFilesByListKnowledgeBaseUID.mock.funcGetCountFilesByListKnowledgeBaseUID != nil { mmGetCountFilesByListKnowledgeBaseUID.mock.t.Fatalf("RepositoryIMock.GetCountFilesByListKnowledgeBaseUID mock is already set by Set") } @@ -4835,7 +4874,7 @@ func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByList } // Set uses given function f to mock the RepositoryI.GetCountFilesByListKnowledgeBaseUID method -func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) Set(f func(ctx context.Context, kbUIDs []uuid.UUID) (m1 map[uuid.UUID]int64, err error)) *RepositoryIMock { +func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) Set(f func(ctx context.Context, kbUIDs []mm_repository.KbUID) (m1 map[mm_repository.KbUID]int64, err error)) *RepositoryIMock { if mmGetCountFilesByListKnowledgeBaseUID.defaultExpectation != nil { mmGetCountFilesByListKnowledgeBaseUID.mock.t.Fatalf("Default expectation is already set for the RepositoryI.GetCountFilesByListKnowledgeBaseUID method") } @@ -4850,7 +4889,7 @@ func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByList // When sets expectation for the RepositoryI.GetCountFilesByListKnowledgeBaseUID which will trigger the result defined by the following // Then helper -func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) When(ctx context.Context, kbUIDs []uuid.UUID) *RepositoryIMockGetCountFilesByListKnowledgeBaseUIDExpectation { +func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByListKnowledgeBaseUID) When(ctx context.Context, kbUIDs []mm_repository.KbUID) *RepositoryIMockGetCountFilesByListKnowledgeBaseUIDExpectation { if mmGetCountFilesByListKnowledgeBaseUID.mock.funcGetCountFilesByListKnowledgeBaseUID != nil { mmGetCountFilesByListKnowledgeBaseUID.mock.t.Fatalf("RepositoryIMock.GetCountFilesByListKnowledgeBaseUID mock is already set by Set") } @@ -4864,7 +4903,7 @@ func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByList } // Then sets up RepositoryI.GetCountFilesByListKnowledgeBaseUID return parameters for the expectation previously defined by the When method -func (e *RepositoryIMockGetCountFilesByListKnowledgeBaseUIDExpectation) Then(m1 map[uuid.UUID]int64, err error) *RepositoryIMock { +func (e *RepositoryIMockGetCountFilesByListKnowledgeBaseUIDExpectation) Then(m1 map[mm_repository.KbUID]int64, err error) *RepositoryIMock { e.results = &RepositoryIMockGetCountFilesByListKnowledgeBaseUIDResults{m1, err} return e.mock } @@ -4890,7 +4929,7 @@ func (mmGetCountFilesByListKnowledgeBaseUID *mRepositoryIMockGetCountFilesByList } // GetCountFilesByListKnowledgeBaseUID implements repository.RepositoryI -func (mmGetCountFilesByListKnowledgeBaseUID *RepositoryIMock) GetCountFilesByListKnowledgeBaseUID(ctx context.Context, kbUIDs []uuid.UUID) (m1 map[uuid.UUID]int64, err error) { +func (mmGetCountFilesByListKnowledgeBaseUID *RepositoryIMock) GetCountFilesByListKnowledgeBaseUID(ctx context.Context, kbUIDs []mm_repository.KbUID) (m1 map[mm_repository.KbUID]int64, err error) { mm_atomic.AddUint64(&mmGetCountFilesByListKnowledgeBaseUID.beforeGetCountFilesByListKnowledgeBaseUIDCounter, 1) defer mm_atomic.AddUint64(&mmGetCountFilesByListKnowledgeBaseUID.afterGetCountFilesByListKnowledgeBaseUIDCounter, 1) @@ -6252,6 +6291,311 @@ func (m *RepositoryIMock) MinimockGetKnowledgeBaseByOwnerAndIDInspect() { } } +type mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockGetKnowledgeBaseFilesByFileUIDsExpectation + expectations []*RepositoryIMockGetKnowledgeBaseFilesByFileUIDsExpectation + + callArgs []*RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockGetKnowledgeBaseFilesByFileUIDsExpectation specifies expectation struct of the RepositoryI.GetKnowledgeBaseFilesByFileUIDs +type RepositoryIMockGetKnowledgeBaseFilesByFileUIDsExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParams + paramPtrs *RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParamPtrs + results *RepositoryIMockGetKnowledgeBaseFilesByFileUIDsResults + Counter uint64 +} + +// RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParams contains parameters of the RepositoryI.GetKnowledgeBaseFilesByFileUIDs +type RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParams struct { + ctx context.Context + fileUIDs []uuid.UUID +} + +// RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParamPtrs contains pointers to parameters of the RepositoryI.GetKnowledgeBaseFilesByFileUIDs +type RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParamPtrs struct { + ctx *context.Context + fileUIDs *[]uuid.UUID +} + +// RepositoryIMockGetKnowledgeBaseFilesByFileUIDsResults contains results of the RepositoryI.GetKnowledgeBaseFilesByFileUIDs +type RepositoryIMockGetKnowledgeBaseFilesByFileUIDsResults struct { + ka1 []mm_repository.KnowledgeBaseFile + err error +} + +// Expect sets up expected params for RepositoryI.GetKnowledgeBaseFilesByFileUIDs +func (mmGetKnowledgeBaseFilesByFileUIDs *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs) Expect(ctx context.Context, fileUIDs []uuid.UUID) *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs { + if mmGetKnowledgeBaseFilesByFileUIDs.mock.funcGetKnowledgeBaseFilesByFileUIDs != nil { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs mock is already set by Set") + } + + if mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation == nil { + mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation = &RepositoryIMockGetKnowledgeBaseFilesByFileUIDsExpectation{} + } + + if mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.paramPtrs != nil { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs mock is already set by ExpectParams functions") + } + + mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.params = &RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParams{ctx, fileUIDs} + for _, e := range mmGetKnowledgeBaseFilesByFileUIDs.expectations { + if minimock.Equal(e.params, mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.params) { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.params) + } + } + + return mmGetKnowledgeBaseFilesByFileUIDs +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.GetKnowledgeBaseFilesByFileUIDs +func (mmGetKnowledgeBaseFilesByFileUIDs *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs { + if mmGetKnowledgeBaseFilesByFileUIDs.mock.funcGetKnowledgeBaseFilesByFileUIDs != nil { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs mock is already set by Set") + } + + if mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation == nil { + mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation = &RepositoryIMockGetKnowledgeBaseFilesByFileUIDsExpectation{} + } + + if mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.params != nil { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs mock is already set by Expect") + } + + if mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.paramPtrs == nil { + mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.paramPtrs = &RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParamPtrs{} + } + mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.paramPtrs.ctx = &ctx + + return mmGetKnowledgeBaseFilesByFileUIDs +} + +// ExpectFileUIDsParam2 sets up expected param fileUIDs for RepositoryI.GetKnowledgeBaseFilesByFileUIDs +func (mmGetKnowledgeBaseFilesByFileUIDs *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs) ExpectFileUIDsParam2(fileUIDs []uuid.UUID) *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs { + if mmGetKnowledgeBaseFilesByFileUIDs.mock.funcGetKnowledgeBaseFilesByFileUIDs != nil { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs mock is already set by Set") + } + + if mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation == nil { + mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation = &RepositoryIMockGetKnowledgeBaseFilesByFileUIDsExpectation{} + } + + if mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.params != nil { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs mock is already set by Expect") + } + + if mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.paramPtrs == nil { + mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.paramPtrs = &RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParamPtrs{} + } + mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.paramPtrs.fileUIDs = &fileUIDs + + return mmGetKnowledgeBaseFilesByFileUIDs +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.GetKnowledgeBaseFilesByFileUIDs +func (mmGetKnowledgeBaseFilesByFileUIDs *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs) Inspect(f func(ctx context.Context, fileUIDs []uuid.UUID)) *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs { + if mmGetKnowledgeBaseFilesByFileUIDs.mock.inspectFuncGetKnowledgeBaseFilesByFileUIDs != nil { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs") + } + + mmGetKnowledgeBaseFilesByFileUIDs.mock.inspectFuncGetKnowledgeBaseFilesByFileUIDs = f + + return mmGetKnowledgeBaseFilesByFileUIDs +} + +// Return sets up results that will be returned by RepositoryI.GetKnowledgeBaseFilesByFileUIDs +func (mmGetKnowledgeBaseFilesByFileUIDs *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs) Return(ka1 []mm_repository.KnowledgeBaseFile, err error) *RepositoryIMock { + if mmGetKnowledgeBaseFilesByFileUIDs.mock.funcGetKnowledgeBaseFilesByFileUIDs != nil { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs mock is already set by Set") + } + + if mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation == nil { + mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation = &RepositoryIMockGetKnowledgeBaseFilesByFileUIDsExpectation{mock: mmGetKnowledgeBaseFilesByFileUIDs.mock} + } + mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation.results = &RepositoryIMockGetKnowledgeBaseFilesByFileUIDsResults{ka1, err} + return mmGetKnowledgeBaseFilesByFileUIDs.mock +} + +// Set uses given function f to mock the RepositoryI.GetKnowledgeBaseFilesByFileUIDs method +func (mmGetKnowledgeBaseFilesByFileUIDs *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs) Set(f func(ctx context.Context, fileUIDs []uuid.UUID) (ka1 []mm_repository.KnowledgeBaseFile, err error)) *RepositoryIMock { + if mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation != nil { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("Default expectation is already set for the RepositoryI.GetKnowledgeBaseFilesByFileUIDs method") + } + + if len(mmGetKnowledgeBaseFilesByFileUIDs.expectations) > 0 { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("Some expectations are already set for the RepositoryI.GetKnowledgeBaseFilesByFileUIDs method") + } + + mmGetKnowledgeBaseFilesByFileUIDs.mock.funcGetKnowledgeBaseFilesByFileUIDs = f + return mmGetKnowledgeBaseFilesByFileUIDs.mock +} + +// When sets expectation for the RepositoryI.GetKnowledgeBaseFilesByFileUIDs which will trigger the result defined by the following +// Then helper +func (mmGetKnowledgeBaseFilesByFileUIDs *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs) When(ctx context.Context, fileUIDs []uuid.UUID) *RepositoryIMockGetKnowledgeBaseFilesByFileUIDsExpectation { + if mmGetKnowledgeBaseFilesByFileUIDs.mock.funcGetKnowledgeBaseFilesByFileUIDs != nil { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs mock is already set by Set") + } + + expectation := &RepositoryIMockGetKnowledgeBaseFilesByFileUIDsExpectation{ + mock: mmGetKnowledgeBaseFilesByFileUIDs.mock, + params: &RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParams{ctx, fileUIDs}, + } + mmGetKnowledgeBaseFilesByFileUIDs.expectations = append(mmGetKnowledgeBaseFilesByFileUIDs.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.GetKnowledgeBaseFilesByFileUIDs return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockGetKnowledgeBaseFilesByFileUIDsExpectation) Then(ka1 []mm_repository.KnowledgeBaseFile, err error) *RepositoryIMock { + e.results = &RepositoryIMockGetKnowledgeBaseFilesByFileUIDsResults{ka1, err} + return e.mock +} + +// Times sets number of times RepositoryI.GetKnowledgeBaseFilesByFileUIDs should be invoked +func (mmGetKnowledgeBaseFilesByFileUIDs *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs) Times(n uint64) *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs { + if n == 0 { + mmGetKnowledgeBaseFilesByFileUIDs.mock.t.Fatalf("Times of RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs mock can not be zero") + } + mm_atomic.StoreUint64(&mmGetKnowledgeBaseFilesByFileUIDs.expectedInvocations, n) + return mmGetKnowledgeBaseFilesByFileUIDs +} + +func (mmGetKnowledgeBaseFilesByFileUIDs *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs) invocationsDone() bool { + if len(mmGetKnowledgeBaseFilesByFileUIDs.expectations) == 0 && mmGetKnowledgeBaseFilesByFileUIDs.defaultExpectation == nil && mmGetKnowledgeBaseFilesByFileUIDs.mock.funcGetKnowledgeBaseFilesByFileUIDs == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmGetKnowledgeBaseFilesByFileUIDs.mock.afterGetKnowledgeBaseFilesByFileUIDsCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmGetKnowledgeBaseFilesByFileUIDs.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// GetKnowledgeBaseFilesByFileUIDs implements repository.RepositoryI +func (mmGetKnowledgeBaseFilesByFileUIDs *RepositoryIMock) GetKnowledgeBaseFilesByFileUIDs(ctx context.Context, fileUIDs []uuid.UUID) (ka1 []mm_repository.KnowledgeBaseFile, err error) { + mm_atomic.AddUint64(&mmGetKnowledgeBaseFilesByFileUIDs.beforeGetKnowledgeBaseFilesByFileUIDsCounter, 1) + defer mm_atomic.AddUint64(&mmGetKnowledgeBaseFilesByFileUIDs.afterGetKnowledgeBaseFilesByFileUIDsCounter, 1) + + if mmGetKnowledgeBaseFilesByFileUIDs.inspectFuncGetKnowledgeBaseFilesByFileUIDs != nil { + mmGetKnowledgeBaseFilesByFileUIDs.inspectFuncGetKnowledgeBaseFilesByFileUIDs(ctx, fileUIDs) + } + + mm_params := RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParams{ctx, fileUIDs} + + // Record call args + mmGetKnowledgeBaseFilesByFileUIDs.GetKnowledgeBaseFilesByFileUIDsMock.mutex.Lock() + mmGetKnowledgeBaseFilesByFileUIDs.GetKnowledgeBaseFilesByFileUIDsMock.callArgs = append(mmGetKnowledgeBaseFilesByFileUIDs.GetKnowledgeBaseFilesByFileUIDsMock.callArgs, &mm_params) + mmGetKnowledgeBaseFilesByFileUIDs.GetKnowledgeBaseFilesByFileUIDsMock.mutex.Unlock() + + for _, e := range mmGetKnowledgeBaseFilesByFileUIDs.GetKnowledgeBaseFilesByFileUIDsMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.ka1, e.results.err + } + } + + if mmGetKnowledgeBaseFilesByFileUIDs.GetKnowledgeBaseFilesByFileUIDsMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmGetKnowledgeBaseFilesByFileUIDs.GetKnowledgeBaseFilesByFileUIDsMock.defaultExpectation.Counter, 1) + mm_want := mmGetKnowledgeBaseFilesByFileUIDs.GetKnowledgeBaseFilesByFileUIDsMock.defaultExpectation.params + mm_want_ptrs := mmGetKnowledgeBaseFilesByFileUIDs.GetKnowledgeBaseFilesByFileUIDsMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParams{ctx, fileUIDs} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmGetKnowledgeBaseFilesByFileUIDs.t.Errorf("RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.fileUIDs != nil && !minimock.Equal(*mm_want_ptrs.fileUIDs, mm_got.fileUIDs) { + mmGetKnowledgeBaseFilesByFileUIDs.t.Errorf("RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs got unexpected parameter fileUIDs, want: %#v, got: %#v%s\n", *mm_want_ptrs.fileUIDs, mm_got.fileUIDs, minimock.Diff(*mm_want_ptrs.fileUIDs, mm_got.fileUIDs)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmGetKnowledgeBaseFilesByFileUIDs.t.Errorf("RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmGetKnowledgeBaseFilesByFileUIDs.GetKnowledgeBaseFilesByFileUIDsMock.defaultExpectation.results + if mm_results == nil { + mmGetKnowledgeBaseFilesByFileUIDs.t.Fatal("No results are set for the RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs") + } + return (*mm_results).ka1, (*mm_results).err + } + if mmGetKnowledgeBaseFilesByFileUIDs.funcGetKnowledgeBaseFilesByFileUIDs != nil { + return mmGetKnowledgeBaseFilesByFileUIDs.funcGetKnowledgeBaseFilesByFileUIDs(ctx, fileUIDs) + } + mmGetKnowledgeBaseFilesByFileUIDs.t.Fatalf("Unexpected call to RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs. %v %v", ctx, fileUIDs) + return +} + +// GetKnowledgeBaseFilesByFileUIDsAfterCounter returns a count of finished RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs invocations +func (mmGetKnowledgeBaseFilesByFileUIDs *RepositoryIMock) GetKnowledgeBaseFilesByFileUIDsAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetKnowledgeBaseFilesByFileUIDs.afterGetKnowledgeBaseFilesByFileUIDsCounter) +} + +// GetKnowledgeBaseFilesByFileUIDsBeforeCounter returns a count of RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs invocations +func (mmGetKnowledgeBaseFilesByFileUIDs *RepositoryIMock) GetKnowledgeBaseFilesByFileUIDsBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetKnowledgeBaseFilesByFileUIDs.beforeGetKnowledgeBaseFilesByFileUIDsCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmGetKnowledgeBaseFilesByFileUIDs *mRepositoryIMockGetKnowledgeBaseFilesByFileUIDs) Calls() []*RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParams { + mmGetKnowledgeBaseFilesByFileUIDs.mutex.RLock() + + argCopy := make([]*RepositoryIMockGetKnowledgeBaseFilesByFileUIDsParams, len(mmGetKnowledgeBaseFilesByFileUIDs.callArgs)) + copy(argCopy, mmGetKnowledgeBaseFilesByFileUIDs.callArgs) + + mmGetKnowledgeBaseFilesByFileUIDs.mutex.RUnlock() + + return argCopy +} + +// MinimockGetKnowledgeBaseFilesByFileUIDsDone returns true if the count of the GetKnowledgeBaseFilesByFileUIDs invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockGetKnowledgeBaseFilesByFileUIDsDone() bool { + for _, e := range m.GetKnowledgeBaseFilesByFileUIDsMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.GetKnowledgeBaseFilesByFileUIDsMock.invocationsDone() +} + +// MinimockGetKnowledgeBaseFilesByFileUIDsInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockGetKnowledgeBaseFilesByFileUIDsInspect() { + for _, e := range m.GetKnowledgeBaseFilesByFileUIDsMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs with params: %#v", *e.params) + } + } + + afterGetKnowledgeBaseFilesByFileUIDsCounter := mm_atomic.LoadUint64(&m.afterGetKnowledgeBaseFilesByFileUIDsCounter) + // if default expectation was set then invocations count should be greater than zero + if m.GetKnowledgeBaseFilesByFileUIDsMock.defaultExpectation != nil && afterGetKnowledgeBaseFilesByFileUIDsCounter < 1 { + if m.GetKnowledgeBaseFilesByFileUIDsMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs") + } else { + m.t.Errorf("Expected call to RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs with params: %#v", *m.GetKnowledgeBaseFilesByFileUIDsMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcGetKnowledgeBaseFilesByFileUIDs != nil && afterGetKnowledgeBaseFilesByFileUIDsCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs") + } + + if !m.GetKnowledgeBaseFilesByFileUIDsMock.invocationsDone() && afterGetKnowledgeBaseFilesByFileUIDsCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.GetKnowledgeBaseFilesByFileUIDs but found %d calls", + mm_atomic.LoadUint64(&m.GetKnowledgeBaseFilesByFileUIDsMock.expectedInvocations), afterGetKnowledgeBaseFilesByFileUIDsCounter) + } +} + type mRepositoryIMockGetRepositoryTag struct { mock *RepositoryIMock defaultExpectation *RepositoryIMockGetRepositoryTagExpectation @@ -6557,158 +6901,478 @@ func (m *RepositoryIMock) MinimockGetRepositoryTagInspect() { } } -type mRepositoryIMockGetTextChunksBySource struct { +type mRepositoryIMockGetSourceTableAndUIDByFileUIDs struct { mock *RepositoryIMock - defaultExpectation *RepositoryIMockGetTextChunksBySourceExpectation - expectations []*RepositoryIMockGetTextChunksBySourceExpectation + defaultExpectation *RepositoryIMockGetSourceTableAndUIDByFileUIDsExpectation + expectations []*RepositoryIMockGetSourceTableAndUIDByFileUIDsExpectation - callArgs []*RepositoryIMockGetTextChunksBySourceParams + callArgs []*RepositoryIMockGetSourceTableAndUIDByFileUIDsParams mutex sync.RWMutex expectedInvocations uint64 } -// RepositoryIMockGetTextChunksBySourceExpectation specifies expectation struct of the RepositoryI.GetTextChunksBySource -type RepositoryIMockGetTextChunksBySourceExpectation struct { +// RepositoryIMockGetSourceTableAndUIDByFileUIDsExpectation specifies expectation struct of the RepositoryI.GetSourceTableAndUIDByFileUIDs +type RepositoryIMockGetSourceTableAndUIDByFileUIDsExpectation struct { mock *RepositoryIMock - params *RepositoryIMockGetTextChunksBySourceParams - paramPtrs *RepositoryIMockGetTextChunksBySourceParamPtrs - results *RepositoryIMockGetTextChunksBySourceResults + params *RepositoryIMockGetSourceTableAndUIDByFileUIDsParams + paramPtrs *RepositoryIMockGetSourceTableAndUIDByFileUIDsParamPtrs + results *RepositoryIMockGetSourceTableAndUIDByFileUIDsResults Counter uint64 } -// RepositoryIMockGetTextChunksBySourceParams contains parameters of the RepositoryI.GetTextChunksBySource -type RepositoryIMockGetTextChunksBySourceParams struct { - ctx context.Context - sourceTable string - sourceUID uuid.UUID +// RepositoryIMockGetSourceTableAndUIDByFileUIDsParams contains parameters of the RepositoryI.GetSourceTableAndUIDByFileUIDs +type RepositoryIMockGetSourceTableAndUIDByFileUIDsParams struct { + ctx context.Context + files []mm_repository.KnowledgeBaseFile } -// RepositoryIMockGetTextChunksBySourceParamPtrs contains pointers to parameters of the RepositoryI.GetTextChunksBySource -type RepositoryIMockGetTextChunksBySourceParamPtrs struct { - ctx *context.Context - sourceTable *string - sourceUID *uuid.UUID +// RepositoryIMockGetSourceTableAndUIDByFileUIDsParamPtrs contains pointers to parameters of the RepositoryI.GetSourceTableAndUIDByFileUIDs +type RepositoryIMockGetSourceTableAndUIDByFileUIDsParamPtrs struct { + ctx *context.Context + files *[]mm_repository.KnowledgeBaseFile } -// RepositoryIMockGetTextChunksBySourceResults contains results of the RepositoryI.GetTextChunksBySource -type RepositoryIMockGetTextChunksBySourceResults struct { - ta1 []mm_repository.TextChunk +// RepositoryIMockGetSourceTableAndUIDByFileUIDsResults contains results of the RepositoryI.GetSourceTableAndUIDByFileUIDs +type RepositoryIMockGetSourceTableAndUIDByFileUIDsResults struct { + m1 map[mm_repository.FileUID]struct { + SourceTable string + SourceUID uuid.UUID + } err error } -// Expect sets up expected params for RepositoryI.GetTextChunksBySource -func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) Expect(ctx context.Context, sourceTable string, sourceUID uuid.UUID) *mRepositoryIMockGetTextChunksBySource { - if mmGetTextChunksBySource.mock.funcGetTextChunksBySource != nil { - mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Set") +// Expect sets up expected params for RepositoryI.GetSourceTableAndUIDByFileUIDs +func (mmGetSourceTableAndUIDByFileUIDs *mRepositoryIMockGetSourceTableAndUIDByFileUIDs) Expect(ctx context.Context, files []mm_repository.KnowledgeBaseFile) *mRepositoryIMockGetSourceTableAndUIDByFileUIDs { + if mmGetSourceTableAndUIDByFileUIDs.mock.funcGetSourceTableAndUIDByFileUIDs != nil { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetSourceTableAndUIDByFileUIDs mock is already set by Set") } - if mmGetTextChunksBySource.defaultExpectation == nil { - mmGetTextChunksBySource.defaultExpectation = &RepositoryIMockGetTextChunksBySourceExpectation{} + if mmGetSourceTableAndUIDByFileUIDs.defaultExpectation == nil { + mmGetSourceTableAndUIDByFileUIDs.defaultExpectation = &RepositoryIMockGetSourceTableAndUIDByFileUIDsExpectation{} } - if mmGetTextChunksBySource.defaultExpectation.paramPtrs != nil { - mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by ExpectParams functions") + if mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.paramPtrs != nil { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetSourceTableAndUIDByFileUIDs mock is already set by ExpectParams functions") } - mmGetTextChunksBySource.defaultExpectation.params = &RepositoryIMockGetTextChunksBySourceParams{ctx, sourceTable, sourceUID} - for _, e := range mmGetTextChunksBySource.expectations { - if minimock.Equal(e.params, mmGetTextChunksBySource.defaultExpectation.params) { - mmGetTextChunksBySource.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetTextChunksBySource.defaultExpectation.params) + mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.params = &RepositoryIMockGetSourceTableAndUIDByFileUIDsParams{ctx, files} + for _, e := range mmGetSourceTableAndUIDByFileUIDs.expectations { + if minimock.Equal(e.params, mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.params) { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.params) } } - return mmGetTextChunksBySource + return mmGetSourceTableAndUIDByFileUIDs } -// ExpectCtxParam1 sets up expected param ctx for RepositoryI.GetTextChunksBySource -func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockGetTextChunksBySource { - if mmGetTextChunksBySource.mock.funcGetTextChunksBySource != nil { - mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Set") +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.GetSourceTableAndUIDByFileUIDs +func (mmGetSourceTableAndUIDByFileUIDs *mRepositoryIMockGetSourceTableAndUIDByFileUIDs) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockGetSourceTableAndUIDByFileUIDs { + if mmGetSourceTableAndUIDByFileUIDs.mock.funcGetSourceTableAndUIDByFileUIDs != nil { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetSourceTableAndUIDByFileUIDs mock is already set by Set") } - if mmGetTextChunksBySource.defaultExpectation == nil { - mmGetTextChunksBySource.defaultExpectation = &RepositoryIMockGetTextChunksBySourceExpectation{} + if mmGetSourceTableAndUIDByFileUIDs.defaultExpectation == nil { + mmGetSourceTableAndUIDByFileUIDs.defaultExpectation = &RepositoryIMockGetSourceTableAndUIDByFileUIDsExpectation{} } - if mmGetTextChunksBySource.defaultExpectation.params != nil { - mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Expect") + if mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.params != nil { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetSourceTableAndUIDByFileUIDs mock is already set by Expect") } - if mmGetTextChunksBySource.defaultExpectation.paramPtrs == nil { - mmGetTextChunksBySource.defaultExpectation.paramPtrs = &RepositoryIMockGetTextChunksBySourceParamPtrs{} + if mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.paramPtrs == nil { + mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.paramPtrs = &RepositoryIMockGetSourceTableAndUIDByFileUIDsParamPtrs{} } - mmGetTextChunksBySource.defaultExpectation.paramPtrs.ctx = &ctx + mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.paramPtrs.ctx = &ctx - return mmGetTextChunksBySource + return mmGetSourceTableAndUIDByFileUIDs } -// ExpectSourceTableParam2 sets up expected param sourceTable for RepositoryI.GetTextChunksBySource -func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) ExpectSourceTableParam2(sourceTable string) *mRepositoryIMockGetTextChunksBySource { - if mmGetTextChunksBySource.mock.funcGetTextChunksBySource != nil { - mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Set") +// ExpectFilesParam2 sets up expected param files for RepositoryI.GetSourceTableAndUIDByFileUIDs +func (mmGetSourceTableAndUIDByFileUIDs *mRepositoryIMockGetSourceTableAndUIDByFileUIDs) ExpectFilesParam2(files []mm_repository.KnowledgeBaseFile) *mRepositoryIMockGetSourceTableAndUIDByFileUIDs { + if mmGetSourceTableAndUIDByFileUIDs.mock.funcGetSourceTableAndUIDByFileUIDs != nil { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetSourceTableAndUIDByFileUIDs mock is already set by Set") } - if mmGetTextChunksBySource.defaultExpectation == nil { - mmGetTextChunksBySource.defaultExpectation = &RepositoryIMockGetTextChunksBySourceExpectation{} + if mmGetSourceTableAndUIDByFileUIDs.defaultExpectation == nil { + mmGetSourceTableAndUIDByFileUIDs.defaultExpectation = &RepositoryIMockGetSourceTableAndUIDByFileUIDsExpectation{} } - if mmGetTextChunksBySource.defaultExpectation.params != nil { - mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Expect") + if mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.params != nil { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetSourceTableAndUIDByFileUIDs mock is already set by Expect") } - if mmGetTextChunksBySource.defaultExpectation.paramPtrs == nil { - mmGetTextChunksBySource.defaultExpectation.paramPtrs = &RepositoryIMockGetTextChunksBySourceParamPtrs{} + if mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.paramPtrs == nil { + mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.paramPtrs = &RepositoryIMockGetSourceTableAndUIDByFileUIDsParamPtrs{} } - mmGetTextChunksBySource.defaultExpectation.paramPtrs.sourceTable = &sourceTable + mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.paramPtrs.files = &files - return mmGetTextChunksBySource + return mmGetSourceTableAndUIDByFileUIDs } -// ExpectSourceUIDParam3 sets up expected param sourceUID for RepositoryI.GetTextChunksBySource -func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) ExpectSourceUIDParam3(sourceUID uuid.UUID) *mRepositoryIMockGetTextChunksBySource { - if mmGetTextChunksBySource.mock.funcGetTextChunksBySource != nil { - mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Set") +// Inspect accepts an inspector function that has same arguments as the RepositoryI.GetSourceTableAndUIDByFileUIDs +func (mmGetSourceTableAndUIDByFileUIDs *mRepositoryIMockGetSourceTableAndUIDByFileUIDs) Inspect(f func(ctx context.Context, files []mm_repository.KnowledgeBaseFile)) *mRepositoryIMockGetSourceTableAndUIDByFileUIDs { + if mmGetSourceTableAndUIDByFileUIDs.mock.inspectFuncGetSourceTableAndUIDByFileUIDs != nil { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.GetSourceTableAndUIDByFileUIDs") } - if mmGetTextChunksBySource.defaultExpectation == nil { - mmGetTextChunksBySource.defaultExpectation = &RepositoryIMockGetTextChunksBySourceExpectation{} - } + mmGetSourceTableAndUIDByFileUIDs.mock.inspectFuncGetSourceTableAndUIDByFileUIDs = f - if mmGetTextChunksBySource.defaultExpectation.params != nil { - mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Expect") - } + return mmGetSourceTableAndUIDByFileUIDs +} - if mmGetTextChunksBySource.defaultExpectation.paramPtrs == nil { - mmGetTextChunksBySource.defaultExpectation.paramPtrs = &RepositoryIMockGetTextChunksBySourceParamPtrs{} +// Return sets up results that will be returned by RepositoryI.GetSourceTableAndUIDByFileUIDs +func (mmGetSourceTableAndUIDByFileUIDs *mRepositoryIMockGetSourceTableAndUIDByFileUIDs) Return(m1 map[mm_repository.FileUID]struct { + SourceTable string + SourceUID uuid.UUID +}, err error) *RepositoryIMock { + if mmGetSourceTableAndUIDByFileUIDs.mock.funcGetSourceTableAndUIDByFileUIDs != nil { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetSourceTableAndUIDByFileUIDs mock is already set by Set") } - mmGetTextChunksBySource.defaultExpectation.paramPtrs.sourceUID = &sourceUID - return mmGetTextChunksBySource + if mmGetSourceTableAndUIDByFileUIDs.defaultExpectation == nil { + mmGetSourceTableAndUIDByFileUIDs.defaultExpectation = &RepositoryIMockGetSourceTableAndUIDByFileUIDsExpectation{mock: mmGetSourceTableAndUIDByFileUIDs.mock} + } + mmGetSourceTableAndUIDByFileUIDs.defaultExpectation.results = &RepositoryIMockGetSourceTableAndUIDByFileUIDsResults{m1, err} + return mmGetSourceTableAndUIDByFileUIDs.mock } -// Inspect accepts an inspector function that has same arguments as the RepositoryI.GetTextChunksBySource -func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) Inspect(f func(ctx context.Context, sourceTable string, sourceUID uuid.UUID)) *mRepositoryIMockGetTextChunksBySource { - if mmGetTextChunksBySource.mock.inspectFuncGetTextChunksBySource != nil { - mmGetTextChunksBySource.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.GetTextChunksBySource") +// Set uses given function f to mock the RepositoryI.GetSourceTableAndUIDByFileUIDs method +func (mmGetSourceTableAndUIDByFileUIDs *mRepositoryIMockGetSourceTableAndUIDByFileUIDs) Set(f func(ctx context.Context, files []mm_repository.KnowledgeBaseFile) (m1 map[mm_repository.FileUID]struct { + SourceTable string + SourceUID uuid.UUID +}, err error)) *RepositoryIMock { + if mmGetSourceTableAndUIDByFileUIDs.defaultExpectation != nil { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("Default expectation is already set for the RepositoryI.GetSourceTableAndUIDByFileUIDs method") } - mmGetTextChunksBySource.mock.inspectFuncGetTextChunksBySource = f + if len(mmGetSourceTableAndUIDByFileUIDs.expectations) > 0 { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("Some expectations are already set for the RepositoryI.GetSourceTableAndUIDByFileUIDs method") + } - return mmGetTextChunksBySource + mmGetSourceTableAndUIDByFileUIDs.mock.funcGetSourceTableAndUIDByFileUIDs = f + return mmGetSourceTableAndUIDByFileUIDs.mock } -// Return sets up results that will be returned by RepositoryI.GetTextChunksBySource -func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) Return(ta1 []mm_repository.TextChunk, err error) *RepositoryIMock { - if mmGetTextChunksBySource.mock.funcGetTextChunksBySource != nil { - mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Set") +// When sets expectation for the RepositoryI.GetSourceTableAndUIDByFileUIDs which will trigger the result defined by the following +// Then helper +func (mmGetSourceTableAndUIDByFileUIDs *mRepositoryIMockGetSourceTableAndUIDByFileUIDs) When(ctx context.Context, files []mm_repository.KnowledgeBaseFile) *RepositoryIMockGetSourceTableAndUIDByFileUIDsExpectation { + if mmGetSourceTableAndUIDByFileUIDs.mock.funcGetSourceTableAndUIDByFileUIDs != nil { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("RepositoryIMock.GetSourceTableAndUIDByFileUIDs mock is already set by Set") } - if mmGetTextChunksBySource.defaultExpectation == nil { - mmGetTextChunksBySource.defaultExpectation = &RepositoryIMockGetTextChunksBySourceExpectation{mock: mmGetTextChunksBySource.mock} + expectation := &RepositoryIMockGetSourceTableAndUIDByFileUIDsExpectation{ + mock: mmGetSourceTableAndUIDByFileUIDs.mock, + params: &RepositoryIMockGetSourceTableAndUIDByFileUIDsParams{ctx, files}, } - mmGetTextChunksBySource.defaultExpectation.results = &RepositoryIMockGetTextChunksBySourceResults{ta1, err} - return mmGetTextChunksBySource.mock + mmGetSourceTableAndUIDByFileUIDs.expectations = append(mmGetSourceTableAndUIDByFileUIDs.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.GetSourceTableAndUIDByFileUIDs return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockGetSourceTableAndUIDByFileUIDsExpectation) Then(m1 map[mm_repository.FileUID]struct { + SourceTable string + SourceUID uuid.UUID +}, err error) *RepositoryIMock { + e.results = &RepositoryIMockGetSourceTableAndUIDByFileUIDsResults{m1, err} + return e.mock +} + +// Times sets number of times RepositoryI.GetSourceTableAndUIDByFileUIDs should be invoked +func (mmGetSourceTableAndUIDByFileUIDs *mRepositoryIMockGetSourceTableAndUIDByFileUIDs) Times(n uint64) *mRepositoryIMockGetSourceTableAndUIDByFileUIDs { + if n == 0 { + mmGetSourceTableAndUIDByFileUIDs.mock.t.Fatalf("Times of RepositoryIMock.GetSourceTableAndUIDByFileUIDs mock can not be zero") + } + mm_atomic.StoreUint64(&mmGetSourceTableAndUIDByFileUIDs.expectedInvocations, n) + return mmGetSourceTableAndUIDByFileUIDs +} + +func (mmGetSourceTableAndUIDByFileUIDs *mRepositoryIMockGetSourceTableAndUIDByFileUIDs) invocationsDone() bool { + if len(mmGetSourceTableAndUIDByFileUIDs.expectations) == 0 && mmGetSourceTableAndUIDByFileUIDs.defaultExpectation == nil && mmGetSourceTableAndUIDByFileUIDs.mock.funcGetSourceTableAndUIDByFileUIDs == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmGetSourceTableAndUIDByFileUIDs.mock.afterGetSourceTableAndUIDByFileUIDsCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmGetSourceTableAndUIDByFileUIDs.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// GetSourceTableAndUIDByFileUIDs implements repository.RepositoryI +func (mmGetSourceTableAndUIDByFileUIDs *RepositoryIMock) GetSourceTableAndUIDByFileUIDs(ctx context.Context, files []mm_repository.KnowledgeBaseFile) (m1 map[mm_repository.FileUID]struct { + SourceTable string + SourceUID uuid.UUID +}, err error) { + mm_atomic.AddUint64(&mmGetSourceTableAndUIDByFileUIDs.beforeGetSourceTableAndUIDByFileUIDsCounter, 1) + defer mm_atomic.AddUint64(&mmGetSourceTableAndUIDByFileUIDs.afterGetSourceTableAndUIDByFileUIDsCounter, 1) + + if mmGetSourceTableAndUIDByFileUIDs.inspectFuncGetSourceTableAndUIDByFileUIDs != nil { + mmGetSourceTableAndUIDByFileUIDs.inspectFuncGetSourceTableAndUIDByFileUIDs(ctx, files) + } + + mm_params := RepositoryIMockGetSourceTableAndUIDByFileUIDsParams{ctx, files} + + // Record call args + mmGetSourceTableAndUIDByFileUIDs.GetSourceTableAndUIDByFileUIDsMock.mutex.Lock() + mmGetSourceTableAndUIDByFileUIDs.GetSourceTableAndUIDByFileUIDsMock.callArgs = append(mmGetSourceTableAndUIDByFileUIDs.GetSourceTableAndUIDByFileUIDsMock.callArgs, &mm_params) + mmGetSourceTableAndUIDByFileUIDs.GetSourceTableAndUIDByFileUIDsMock.mutex.Unlock() + + for _, e := range mmGetSourceTableAndUIDByFileUIDs.GetSourceTableAndUIDByFileUIDsMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.m1, e.results.err + } + } + + if mmGetSourceTableAndUIDByFileUIDs.GetSourceTableAndUIDByFileUIDsMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmGetSourceTableAndUIDByFileUIDs.GetSourceTableAndUIDByFileUIDsMock.defaultExpectation.Counter, 1) + mm_want := mmGetSourceTableAndUIDByFileUIDs.GetSourceTableAndUIDByFileUIDsMock.defaultExpectation.params + mm_want_ptrs := mmGetSourceTableAndUIDByFileUIDs.GetSourceTableAndUIDByFileUIDsMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockGetSourceTableAndUIDByFileUIDsParams{ctx, files} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmGetSourceTableAndUIDByFileUIDs.t.Errorf("RepositoryIMock.GetSourceTableAndUIDByFileUIDs got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.files != nil && !minimock.Equal(*mm_want_ptrs.files, mm_got.files) { + mmGetSourceTableAndUIDByFileUIDs.t.Errorf("RepositoryIMock.GetSourceTableAndUIDByFileUIDs got unexpected parameter files, want: %#v, got: %#v%s\n", *mm_want_ptrs.files, mm_got.files, minimock.Diff(*mm_want_ptrs.files, mm_got.files)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmGetSourceTableAndUIDByFileUIDs.t.Errorf("RepositoryIMock.GetSourceTableAndUIDByFileUIDs got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmGetSourceTableAndUIDByFileUIDs.GetSourceTableAndUIDByFileUIDsMock.defaultExpectation.results + if mm_results == nil { + mmGetSourceTableAndUIDByFileUIDs.t.Fatal("No results are set for the RepositoryIMock.GetSourceTableAndUIDByFileUIDs") + } + return (*mm_results).m1, (*mm_results).err + } + if mmGetSourceTableAndUIDByFileUIDs.funcGetSourceTableAndUIDByFileUIDs != nil { + return mmGetSourceTableAndUIDByFileUIDs.funcGetSourceTableAndUIDByFileUIDs(ctx, files) + } + mmGetSourceTableAndUIDByFileUIDs.t.Fatalf("Unexpected call to RepositoryIMock.GetSourceTableAndUIDByFileUIDs. %v %v", ctx, files) + return +} + +// GetSourceTableAndUIDByFileUIDsAfterCounter returns a count of finished RepositoryIMock.GetSourceTableAndUIDByFileUIDs invocations +func (mmGetSourceTableAndUIDByFileUIDs *RepositoryIMock) GetSourceTableAndUIDByFileUIDsAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetSourceTableAndUIDByFileUIDs.afterGetSourceTableAndUIDByFileUIDsCounter) +} + +// GetSourceTableAndUIDByFileUIDsBeforeCounter returns a count of RepositoryIMock.GetSourceTableAndUIDByFileUIDs invocations +func (mmGetSourceTableAndUIDByFileUIDs *RepositoryIMock) GetSourceTableAndUIDByFileUIDsBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetSourceTableAndUIDByFileUIDs.beforeGetSourceTableAndUIDByFileUIDsCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.GetSourceTableAndUIDByFileUIDs. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmGetSourceTableAndUIDByFileUIDs *mRepositoryIMockGetSourceTableAndUIDByFileUIDs) Calls() []*RepositoryIMockGetSourceTableAndUIDByFileUIDsParams { + mmGetSourceTableAndUIDByFileUIDs.mutex.RLock() + + argCopy := make([]*RepositoryIMockGetSourceTableAndUIDByFileUIDsParams, len(mmGetSourceTableAndUIDByFileUIDs.callArgs)) + copy(argCopy, mmGetSourceTableAndUIDByFileUIDs.callArgs) + + mmGetSourceTableAndUIDByFileUIDs.mutex.RUnlock() + + return argCopy +} + +// MinimockGetSourceTableAndUIDByFileUIDsDone returns true if the count of the GetSourceTableAndUIDByFileUIDs invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockGetSourceTableAndUIDByFileUIDsDone() bool { + for _, e := range m.GetSourceTableAndUIDByFileUIDsMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.GetSourceTableAndUIDByFileUIDsMock.invocationsDone() +} + +// MinimockGetSourceTableAndUIDByFileUIDsInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockGetSourceTableAndUIDByFileUIDsInspect() { + for _, e := range m.GetSourceTableAndUIDByFileUIDsMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.GetSourceTableAndUIDByFileUIDs with params: %#v", *e.params) + } + } + + afterGetSourceTableAndUIDByFileUIDsCounter := mm_atomic.LoadUint64(&m.afterGetSourceTableAndUIDByFileUIDsCounter) + // if default expectation was set then invocations count should be greater than zero + if m.GetSourceTableAndUIDByFileUIDsMock.defaultExpectation != nil && afterGetSourceTableAndUIDByFileUIDsCounter < 1 { + if m.GetSourceTableAndUIDByFileUIDsMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.GetSourceTableAndUIDByFileUIDs") + } else { + m.t.Errorf("Expected call to RepositoryIMock.GetSourceTableAndUIDByFileUIDs with params: %#v", *m.GetSourceTableAndUIDByFileUIDsMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcGetSourceTableAndUIDByFileUIDs != nil && afterGetSourceTableAndUIDByFileUIDsCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.GetSourceTableAndUIDByFileUIDs") + } + + if !m.GetSourceTableAndUIDByFileUIDsMock.invocationsDone() && afterGetSourceTableAndUIDByFileUIDsCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.GetSourceTableAndUIDByFileUIDs but found %d calls", + mm_atomic.LoadUint64(&m.GetSourceTableAndUIDByFileUIDsMock.expectedInvocations), afterGetSourceTableAndUIDByFileUIDsCounter) + } +} + +type mRepositoryIMockGetTextChunksBySource struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockGetTextChunksBySourceExpectation + expectations []*RepositoryIMockGetTextChunksBySourceExpectation + + callArgs []*RepositoryIMockGetTextChunksBySourceParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockGetTextChunksBySourceExpectation specifies expectation struct of the RepositoryI.GetTextChunksBySource +type RepositoryIMockGetTextChunksBySourceExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockGetTextChunksBySourceParams + paramPtrs *RepositoryIMockGetTextChunksBySourceParamPtrs + results *RepositoryIMockGetTextChunksBySourceResults + Counter uint64 +} + +// RepositoryIMockGetTextChunksBySourceParams contains parameters of the RepositoryI.GetTextChunksBySource +type RepositoryIMockGetTextChunksBySourceParams struct { + ctx context.Context + sourceTable string + sourceUID uuid.UUID +} + +// RepositoryIMockGetTextChunksBySourceParamPtrs contains pointers to parameters of the RepositoryI.GetTextChunksBySource +type RepositoryIMockGetTextChunksBySourceParamPtrs struct { + ctx *context.Context + sourceTable *string + sourceUID *uuid.UUID +} + +// RepositoryIMockGetTextChunksBySourceResults contains results of the RepositoryI.GetTextChunksBySource +type RepositoryIMockGetTextChunksBySourceResults struct { + ta1 []mm_repository.TextChunk + err error +} + +// Expect sets up expected params for RepositoryI.GetTextChunksBySource +func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) Expect(ctx context.Context, sourceTable string, sourceUID uuid.UUID) *mRepositoryIMockGetTextChunksBySource { + if mmGetTextChunksBySource.mock.funcGetTextChunksBySource != nil { + mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Set") + } + + if mmGetTextChunksBySource.defaultExpectation == nil { + mmGetTextChunksBySource.defaultExpectation = &RepositoryIMockGetTextChunksBySourceExpectation{} + } + + if mmGetTextChunksBySource.defaultExpectation.paramPtrs != nil { + mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by ExpectParams functions") + } + + mmGetTextChunksBySource.defaultExpectation.params = &RepositoryIMockGetTextChunksBySourceParams{ctx, sourceTable, sourceUID} + for _, e := range mmGetTextChunksBySource.expectations { + if minimock.Equal(e.params, mmGetTextChunksBySource.defaultExpectation.params) { + mmGetTextChunksBySource.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetTextChunksBySource.defaultExpectation.params) + } + } + + return mmGetTextChunksBySource +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.GetTextChunksBySource +func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockGetTextChunksBySource { + if mmGetTextChunksBySource.mock.funcGetTextChunksBySource != nil { + mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Set") + } + + if mmGetTextChunksBySource.defaultExpectation == nil { + mmGetTextChunksBySource.defaultExpectation = &RepositoryIMockGetTextChunksBySourceExpectation{} + } + + if mmGetTextChunksBySource.defaultExpectation.params != nil { + mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Expect") + } + + if mmGetTextChunksBySource.defaultExpectation.paramPtrs == nil { + mmGetTextChunksBySource.defaultExpectation.paramPtrs = &RepositoryIMockGetTextChunksBySourceParamPtrs{} + } + mmGetTextChunksBySource.defaultExpectation.paramPtrs.ctx = &ctx + + return mmGetTextChunksBySource +} + +// ExpectSourceTableParam2 sets up expected param sourceTable for RepositoryI.GetTextChunksBySource +func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) ExpectSourceTableParam2(sourceTable string) *mRepositoryIMockGetTextChunksBySource { + if mmGetTextChunksBySource.mock.funcGetTextChunksBySource != nil { + mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Set") + } + + if mmGetTextChunksBySource.defaultExpectation == nil { + mmGetTextChunksBySource.defaultExpectation = &RepositoryIMockGetTextChunksBySourceExpectation{} + } + + if mmGetTextChunksBySource.defaultExpectation.params != nil { + mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Expect") + } + + if mmGetTextChunksBySource.defaultExpectation.paramPtrs == nil { + mmGetTextChunksBySource.defaultExpectation.paramPtrs = &RepositoryIMockGetTextChunksBySourceParamPtrs{} + } + mmGetTextChunksBySource.defaultExpectation.paramPtrs.sourceTable = &sourceTable + + return mmGetTextChunksBySource +} + +// ExpectSourceUIDParam3 sets up expected param sourceUID for RepositoryI.GetTextChunksBySource +func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) ExpectSourceUIDParam3(sourceUID uuid.UUID) *mRepositoryIMockGetTextChunksBySource { + if mmGetTextChunksBySource.mock.funcGetTextChunksBySource != nil { + mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Set") + } + + if mmGetTextChunksBySource.defaultExpectation == nil { + mmGetTextChunksBySource.defaultExpectation = &RepositoryIMockGetTextChunksBySourceExpectation{} + } + + if mmGetTextChunksBySource.defaultExpectation.params != nil { + mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Expect") + } + + if mmGetTextChunksBySource.defaultExpectation.paramPtrs == nil { + mmGetTextChunksBySource.defaultExpectation.paramPtrs = &RepositoryIMockGetTextChunksBySourceParamPtrs{} + } + mmGetTextChunksBySource.defaultExpectation.paramPtrs.sourceUID = &sourceUID + + return mmGetTextChunksBySource +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.GetTextChunksBySource +func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) Inspect(f func(ctx context.Context, sourceTable string, sourceUID uuid.UUID)) *mRepositoryIMockGetTextChunksBySource { + if mmGetTextChunksBySource.mock.inspectFuncGetTextChunksBySource != nil { + mmGetTextChunksBySource.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.GetTextChunksBySource") + } + + mmGetTextChunksBySource.mock.inspectFuncGetTextChunksBySource = f + + return mmGetTextChunksBySource +} + +// Return sets up results that will be returned by RepositoryI.GetTextChunksBySource +func (mmGetTextChunksBySource *mRepositoryIMockGetTextChunksBySource) Return(ta1 []mm_repository.TextChunk, err error) *RepositoryIMock { + if mmGetTextChunksBySource.mock.funcGetTextChunksBySource != nil { + mmGetTextChunksBySource.mock.t.Fatalf("RepositoryIMock.GetTextChunksBySource mock is already set by Set") + } + + if mmGetTextChunksBySource.defaultExpectation == nil { + mmGetTextChunksBySource.defaultExpectation = &RepositoryIMockGetTextChunksBySourceExpectation{mock: mmGetTextChunksBySource.mock} + } + mmGetTextChunksBySource.defaultExpectation.results = &RepositoryIMockGetTextChunksBySourceResults{ta1, err} + return mmGetTextChunksBySource.mock } // Set uses given function f to mock the RepositoryI.GetTextChunksBySource method @@ -7345,182 +8009,487 @@ func (mmGetTotalTokensByListKBUIDs *mRepositoryIMockGetTotalTokensByListKBUIDs) if mmGetTotalTokensByListKBUIDs.defaultExpectation == nil { mmGetTotalTokensByListKBUIDs.defaultExpectation = &RepositoryIMockGetTotalTokensByListKBUIDsExpectation{mock: mmGetTotalTokensByListKBUIDs.mock} } - mmGetTotalTokensByListKBUIDs.defaultExpectation.results = &RepositoryIMockGetTotalTokensByListKBUIDsResults{m1, err} - return mmGetTotalTokensByListKBUIDs.mock + mmGetTotalTokensByListKBUIDs.defaultExpectation.results = &RepositoryIMockGetTotalTokensByListKBUIDsResults{m1, err} + return mmGetTotalTokensByListKBUIDs.mock +} + +// Set uses given function f to mock the RepositoryI.GetTotalTokensByListKBUIDs method +func (mmGetTotalTokensByListKBUIDs *mRepositoryIMockGetTotalTokensByListKBUIDs) Set(f func(ctx context.Context, kbUIDs []uuid.UUID) (m1 map[uuid.UUID]int, err error)) *RepositoryIMock { + if mmGetTotalTokensByListKBUIDs.defaultExpectation != nil { + mmGetTotalTokensByListKBUIDs.mock.t.Fatalf("Default expectation is already set for the RepositoryI.GetTotalTokensByListKBUIDs method") + } + + if len(mmGetTotalTokensByListKBUIDs.expectations) > 0 { + mmGetTotalTokensByListKBUIDs.mock.t.Fatalf("Some expectations are already set for the RepositoryI.GetTotalTokensByListKBUIDs method") + } + + mmGetTotalTokensByListKBUIDs.mock.funcGetTotalTokensByListKBUIDs = f + return mmGetTotalTokensByListKBUIDs.mock +} + +// When sets expectation for the RepositoryI.GetTotalTokensByListKBUIDs which will trigger the result defined by the following +// Then helper +func (mmGetTotalTokensByListKBUIDs *mRepositoryIMockGetTotalTokensByListKBUIDs) When(ctx context.Context, kbUIDs []uuid.UUID) *RepositoryIMockGetTotalTokensByListKBUIDsExpectation { + if mmGetTotalTokensByListKBUIDs.mock.funcGetTotalTokensByListKBUIDs != nil { + mmGetTotalTokensByListKBUIDs.mock.t.Fatalf("RepositoryIMock.GetTotalTokensByListKBUIDs mock is already set by Set") + } + + expectation := &RepositoryIMockGetTotalTokensByListKBUIDsExpectation{ + mock: mmGetTotalTokensByListKBUIDs.mock, + params: &RepositoryIMockGetTotalTokensByListKBUIDsParams{ctx, kbUIDs}, + } + mmGetTotalTokensByListKBUIDs.expectations = append(mmGetTotalTokensByListKBUIDs.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.GetTotalTokensByListKBUIDs return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockGetTotalTokensByListKBUIDsExpectation) Then(m1 map[uuid.UUID]int, err error) *RepositoryIMock { + e.results = &RepositoryIMockGetTotalTokensByListKBUIDsResults{m1, err} + return e.mock +} + +// Times sets number of times RepositoryI.GetTotalTokensByListKBUIDs should be invoked +func (mmGetTotalTokensByListKBUIDs *mRepositoryIMockGetTotalTokensByListKBUIDs) Times(n uint64) *mRepositoryIMockGetTotalTokensByListKBUIDs { + if n == 0 { + mmGetTotalTokensByListKBUIDs.mock.t.Fatalf("Times of RepositoryIMock.GetTotalTokensByListKBUIDs mock can not be zero") + } + mm_atomic.StoreUint64(&mmGetTotalTokensByListKBUIDs.expectedInvocations, n) + return mmGetTotalTokensByListKBUIDs +} + +func (mmGetTotalTokensByListKBUIDs *mRepositoryIMockGetTotalTokensByListKBUIDs) invocationsDone() bool { + if len(mmGetTotalTokensByListKBUIDs.expectations) == 0 && mmGetTotalTokensByListKBUIDs.defaultExpectation == nil && mmGetTotalTokensByListKBUIDs.mock.funcGetTotalTokensByListKBUIDs == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmGetTotalTokensByListKBUIDs.mock.afterGetTotalTokensByListKBUIDsCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmGetTotalTokensByListKBUIDs.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// GetTotalTokensByListKBUIDs implements repository.RepositoryI +func (mmGetTotalTokensByListKBUIDs *RepositoryIMock) GetTotalTokensByListKBUIDs(ctx context.Context, kbUIDs []uuid.UUID) (m1 map[uuid.UUID]int, err error) { + mm_atomic.AddUint64(&mmGetTotalTokensByListKBUIDs.beforeGetTotalTokensByListKBUIDsCounter, 1) + defer mm_atomic.AddUint64(&mmGetTotalTokensByListKBUIDs.afterGetTotalTokensByListKBUIDsCounter, 1) + + if mmGetTotalTokensByListKBUIDs.inspectFuncGetTotalTokensByListKBUIDs != nil { + mmGetTotalTokensByListKBUIDs.inspectFuncGetTotalTokensByListKBUIDs(ctx, kbUIDs) + } + + mm_params := RepositoryIMockGetTotalTokensByListKBUIDsParams{ctx, kbUIDs} + + // Record call args + mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.mutex.Lock() + mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.callArgs = append(mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.callArgs, &mm_params) + mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.mutex.Unlock() + + for _, e := range mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.m1, e.results.err + } + } + + if mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.defaultExpectation.Counter, 1) + mm_want := mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.defaultExpectation.params + mm_want_ptrs := mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockGetTotalTokensByListKBUIDsParams{ctx, kbUIDs} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmGetTotalTokensByListKBUIDs.t.Errorf("RepositoryIMock.GetTotalTokensByListKBUIDs got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.kbUIDs != nil && !minimock.Equal(*mm_want_ptrs.kbUIDs, mm_got.kbUIDs) { + mmGetTotalTokensByListKBUIDs.t.Errorf("RepositoryIMock.GetTotalTokensByListKBUIDs got unexpected parameter kbUIDs, want: %#v, got: %#v%s\n", *mm_want_ptrs.kbUIDs, mm_got.kbUIDs, minimock.Diff(*mm_want_ptrs.kbUIDs, mm_got.kbUIDs)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmGetTotalTokensByListKBUIDs.t.Errorf("RepositoryIMock.GetTotalTokensByListKBUIDs got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.defaultExpectation.results + if mm_results == nil { + mmGetTotalTokensByListKBUIDs.t.Fatal("No results are set for the RepositoryIMock.GetTotalTokensByListKBUIDs") + } + return (*mm_results).m1, (*mm_results).err + } + if mmGetTotalTokensByListKBUIDs.funcGetTotalTokensByListKBUIDs != nil { + return mmGetTotalTokensByListKBUIDs.funcGetTotalTokensByListKBUIDs(ctx, kbUIDs) + } + mmGetTotalTokensByListKBUIDs.t.Fatalf("Unexpected call to RepositoryIMock.GetTotalTokensByListKBUIDs. %v %v", ctx, kbUIDs) + return +} + +// GetTotalTokensByListKBUIDsAfterCounter returns a count of finished RepositoryIMock.GetTotalTokensByListKBUIDs invocations +func (mmGetTotalTokensByListKBUIDs *RepositoryIMock) GetTotalTokensByListKBUIDsAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetTotalTokensByListKBUIDs.afterGetTotalTokensByListKBUIDsCounter) +} + +// GetTotalTokensByListKBUIDsBeforeCounter returns a count of RepositoryIMock.GetTotalTokensByListKBUIDs invocations +func (mmGetTotalTokensByListKBUIDs *RepositoryIMock) GetTotalTokensByListKBUIDsBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetTotalTokensByListKBUIDs.beforeGetTotalTokensByListKBUIDsCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.GetTotalTokensByListKBUIDs. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmGetTotalTokensByListKBUIDs *mRepositoryIMockGetTotalTokensByListKBUIDs) Calls() []*RepositoryIMockGetTotalTokensByListKBUIDsParams { + mmGetTotalTokensByListKBUIDs.mutex.RLock() + + argCopy := make([]*RepositoryIMockGetTotalTokensByListKBUIDsParams, len(mmGetTotalTokensByListKBUIDs.callArgs)) + copy(argCopy, mmGetTotalTokensByListKBUIDs.callArgs) + + mmGetTotalTokensByListKBUIDs.mutex.RUnlock() + + return argCopy +} + +// MinimockGetTotalTokensByListKBUIDsDone returns true if the count of the GetTotalTokensByListKBUIDs invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockGetTotalTokensByListKBUIDsDone() bool { + for _, e := range m.GetTotalTokensByListKBUIDsMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.GetTotalTokensByListKBUIDsMock.invocationsDone() +} + +// MinimockGetTotalTokensByListKBUIDsInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockGetTotalTokensByListKBUIDsInspect() { + for _, e := range m.GetTotalTokensByListKBUIDsMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.GetTotalTokensByListKBUIDs with params: %#v", *e.params) + } + } + + afterGetTotalTokensByListKBUIDsCounter := mm_atomic.LoadUint64(&m.afterGetTotalTokensByListKBUIDsCounter) + // if default expectation was set then invocations count should be greater than zero + if m.GetTotalTokensByListKBUIDsMock.defaultExpectation != nil && afterGetTotalTokensByListKBUIDsCounter < 1 { + if m.GetTotalTokensByListKBUIDsMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.GetTotalTokensByListKBUIDs") + } else { + m.t.Errorf("Expected call to RepositoryIMock.GetTotalTokensByListKBUIDs with params: %#v", *m.GetTotalTokensByListKBUIDsMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcGetTotalTokensByListKBUIDs != nil && afterGetTotalTokensByListKBUIDsCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.GetTotalTokensByListKBUIDs") + } + + if !m.GetTotalTokensByListKBUIDsMock.invocationsDone() && afterGetTotalTokensByListKBUIDsCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.GetTotalTokensByListKBUIDs but found %d calls", + mm_atomic.LoadUint64(&m.GetTotalTokensByListKBUIDsMock.expectedInvocations), afterGetTotalTokensByListKBUIDsCounter) + } +} + +type mRepositoryIMockGetTruthSourceByFileUID struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockGetTruthSourceByFileUIDExpectation + expectations []*RepositoryIMockGetTruthSourceByFileUIDExpectation + + callArgs []*RepositoryIMockGetTruthSourceByFileUIDParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockGetTruthSourceByFileUIDExpectation specifies expectation struct of the RepositoryI.GetTruthSourceByFileUID +type RepositoryIMockGetTruthSourceByFileUIDExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockGetTruthSourceByFileUIDParams + paramPtrs *RepositoryIMockGetTruthSourceByFileUIDParamPtrs + results *RepositoryIMockGetTruthSourceByFileUIDResults + Counter uint64 +} + +// RepositoryIMockGetTruthSourceByFileUIDParams contains parameters of the RepositoryI.GetTruthSourceByFileUID +type RepositoryIMockGetTruthSourceByFileUIDParams struct { + ctx context.Context + fileUID uuid.UUID +} + +// RepositoryIMockGetTruthSourceByFileUIDParamPtrs contains pointers to parameters of the RepositoryI.GetTruthSourceByFileUID +type RepositoryIMockGetTruthSourceByFileUIDParamPtrs struct { + ctx *context.Context + fileUID *uuid.UUID +} + +// RepositoryIMockGetTruthSourceByFileUIDResults contains results of the RepositoryI.GetTruthSourceByFileUID +type RepositoryIMockGetTruthSourceByFileUIDResults struct { + sp1 *mm_repository.SourceMeta + err error +} + +// Expect sets up expected params for RepositoryI.GetTruthSourceByFileUID +func (mmGetTruthSourceByFileUID *mRepositoryIMockGetTruthSourceByFileUID) Expect(ctx context.Context, fileUID uuid.UUID) *mRepositoryIMockGetTruthSourceByFileUID { + if mmGetTruthSourceByFileUID.mock.funcGetTruthSourceByFileUID != nil { + mmGetTruthSourceByFileUID.mock.t.Fatalf("RepositoryIMock.GetTruthSourceByFileUID mock is already set by Set") + } + + if mmGetTruthSourceByFileUID.defaultExpectation == nil { + mmGetTruthSourceByFileUID.defaultExpectation = &RepositoryIMockGetTruthSourceByFileUIDExpectation{} + } + + if mmGetTruthSourceByFileUID.defaultExpectation.paramPtrs != nil { + mmGetTruthSourceByFileUID.mock.t.Fatalf("RepositoryIMock.GetTruthSourceByFileUID mock is already set by ExpectParams functions") + } + + mmGetTruthSourceByFileUID.defaultExpectation.params = &RepositoryIMockGetTruthSourceByFileUIDParams{ctx, fileUID} + for _, e := range mmGetTruthSourceByFileUID.expectations { + if minimock.Equal(e.params, mmGetTruthSourceByFileUID.defaultExpectation.params) { + mmGetTruthSourceByFileUID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetTruthSourceByFileUID.defaultExpectation.params) + } + } + + return mmGetTruthSourceByFileUID +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.GetTruthSourceByFileUID +func (mmGetTruthSourceByFileUID *mRepositoryIMockGetTruthSourceByFileUID) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockGetTruthSourceByFileUID { + if mmGetTruthSourceByFileUID.mock.funcGetTruthSourceByFileUID != nil { + mmGetTruthSourceByFileUID.mock.t.Fatalf("RepositoryIMock.GetTruthSourceByFileUID mock is already set by Set") + } + + if mmGetTruthSourceByFileUID.defaultExpectation == nil { + mmGetTruthSourceByFileUID.defaultExpectation = &RepositoryIMockGetTruthSourceByFileUIDExpectation{} + } + + if mmGetTruthSourceByFileUID.defaultExpectation.params != nil { + mmGetTruthSourceByFileUID.mock.t.Fatalf("RepositoryIMock.GetTruthSourceByFileUID mock is already set by Expect") + } + + if mmGetTruthSourceByFileUID.defaultExpectation.paramPtrs == nil { + mmGetTruthSourceByFileUID.defaultExpectation.paramPtrs = &RepositoryIMockGetTruthSourceByFileUIDParamPtrs{} + } + mmGetTruthSourceByFileUID.defaultExpectation.paramPtrs.ctx = &ctx + + return mmGetTruthSourceByFileUID +} + +// ExpectFileUIDParam2 sets up expected param fileUID for RepositoryI.GetTruthSourceByFileUID +func (mmGetTruthSourceByFileUID *mRepositoryIMockGetTruthSourceByFileUID) ExpectFileUIDParam2(fileUID uuid.UUID) *mRepositoryIMockGetTruthSourceByFileUID { + if mmGetTruthSourceByFileUID.mock.funcGetTruthSourceByFileUID != nil { + mmGetTruthSourceByFileUID.mock.t.Fatalf("RepositoryIMock.GetTruthSourceByFileUID mock is already set by Set") + } + + if mmGetTruthSourceByFileUID.defaultExpectation == nil { + mmGetTruthSourceByFileUID.defaultExpectation = &RepositoryIMockGetTruthSourceByFileUIDExpectation{} + } + + if mmGetTruthSourceByFileUID.defaultExpectation.params != nil { + mmGetTruthSourceByFileUID.mock.t.Fatalf("RepositoryIMock.GetTruthSourceByFileUID mock is already set by Expect") + } + + if mmGetTruthSourceByFileUID.defaultExpectation.paramPtrs == nil { + mmGetTruthSourceByFileUID.defaultExpectation.paramPtrs = &RepositoryIMockGetTruthSourceByFileUIDParamPtrs{} + } + mmGetTruthSourceByFileUID.defaultExpectation.paramPtrs.fileUID = &fileUID + + return mmGetTruthSourceByFileUID +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.GetTruthSourceByFileUID +func (mmGetTruthSourceByFileUID *mRepositoryIMockGetTruthSourceByFileUID) Inspect(f func(ctx context.Context, fileUID uuid.UUID)) *mRepositoryIMockGetTruthSourceByFileUID { + if mmGetTruthSourceByFileUID.mock.inspectFuncGetTruthSourceByFileUID != nil { + mmGetTruthSourceByFileUID.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.GetTruthSourceByFileUID") + } + + mmGetTruthSourceByFileUID.mock.inspectFuncGetTruthSourceByFileUID = f + + return mmGetTruthSourceByFileUID +} + +// Return sets up results that will be returned by RepositoryI.GetTruthSourceByFileUID +func (mmGetTruthSourceByFileUID *mRepositoryIMockGetTruthSourceByFileUID) Return(sp1 *mm_repository.SourceMeta, err error) *RepositoryIMock { + if mmGetTruthSourceByFileUID.mock.funcGetTruthSourceByFileUID != nil { + mmGetTruthSourceByFileUID.mock.t.Fatalf("RepositoryIMock.GetTruthSourceByFileUID mock is already set by Set") + } + + if mmGetTruthSourceByFileUID.defaultExpectation == nil { + mmGetTruthSourceByFileUID.defaultExpectation = &RepositoryIMockGetTruthSourceByFileUIDExpectation{mock: mmGetTruthSourceByFileUID.mock} + } + mmGetTruthSourceByFileUID.defaultExpectation.results = &RepositoryIMockGetTruthSourceByFileUIDResults{sp1, err} + return mmGetTruthSourceByFileUID.mock } -// Set uses given function f to mock the RepositoryI.GetTotalTokensByListKBUIDs method -func (mmGetTotalTokensByListKBUIDs *mRepositoryIMockGetTotalTokensByListKBUIDs) Set(f func(ctx context.Context, kbUIDs []uuid.UUID) (m1 map[uuid.UUID]int, err error)) *RepositoryIMock { - if mmGetTotalTokensByListKBUIDs.defaultExpectation != nil { - mmGetTotalTokensByListKBUIDs.mock.t.Fatalf("Default expectation is already set for the RepositoryI.GetTotalTokensByListKBUIDs method") +// Set uses given function f to mock the RepositoryI.GetTruthSourceByFileUID method +func (mmGetTruthSourceByFileUID *mRepositoryIMockGetTruthSourceByFileUID) Set(f func(ctx context.Context, fileUID uuid.UUID) (sp1 *mm_repository.SourceMeta, err error)) *RepositoryIMock { + if mmGetTruthSourceByFileUID.defaultExpectation != nil { + mmGetTruthSourceByFileUID.mock.t.Fatalf("Default expectation is already set for the RepositoryI.GetTruthSourceByFileUID method") } - if len(mmGetTotalTokensByListKBUIDs.expectations) > 0 { - mmGetTotalTokensByListKBUIDs.mock.t.Fatalf("Some expectations are already set for the RepositoryI.GetTotalTokensByListKBUIDs method") + if len(mmGetTruthSourceByFileUID.expectations) > 0 { + mmGetTruthSourceByFileUID.mock.t.Fatalf("Some expectations are already set for the RepositoryI.GetTruthSourceByFileUID method") } - mmGetTotalTokensByListKBUIDs.mock.funcGetTotalTokensByListKBUIDs = f - return mmGetTotalTokensByListKBUIDs.mock + mmGetTruthSourceByFileUID.mock.funcGetTruthSourceByFileUID = f + return mmGetTruthSourceByFileUID.mock } -// When sets expectation for the RepositoryI.GetTotalTokensByListKBUIDs which will trigger the result defined by the following +// When sets expectation for the RepositoryI.GetTruthSourceByFileUID which will trigger the result defined by the following // Then helper -func (mmGetTotalTokensByListKBUIDs *mRepositoryIMockGetTotalTokensByListKBUIDs) When(ctx context.Context, kbUIDs []uuid.UUID) *RepositoryIMockGetTotalTokensByListKBUIDsExpectation { - if mmGetTotalTokensByListKBUIDs.mock.funcGetTotalTokensByListKBUIDs != nil { - mmGetTotalTokensByListKBUIDs.mock.t.Fatalf("RepositoryIMock.GetTotalTokensByListKBUIDs mock is already set by Set") +func (mmGetTruthSourceByFileUID *mRepositoryIMockGetTruthSourceByFileUID) When(ctx context.Context, fileUID uuid.UUID) *RepositoryIMockGetTruthSourceByFileUIDExpectation { + if mmGetTruthSourceByFileUID.mock.funcGetTruthSourceByFileUID != nil { + mmGetTruthSourceByFileUID.mock.t.Fatalf("RepositoryIMock.GetTruthSourceByFileUID mock is already set by Set") } - expectation := &RepositoryIMockGetTotalTokensByListKBUIDsExpectation{ - mock: mmGetTotalTokensByListKBUIDs.mock, - params: &RepositoryIMockGetTotalTokensByListKBUIDsParams{ctx, kbUIDs}, + expectation := &RepositoryIMockGetTruthSourceByFileUIDExpectation{ + mock: mmGetTruthSourceByFileUID.mock, + params: &RepositoryIMockGetTruthSourceByFileUIDParams{ctx, fileUID}, } - mmGetTotalTokensByListKBUIDs.expectations = append(mmGetTotalTokensByListKBUIDs.expectations, expectation) + mmGetTruthSourceByFileUID.expectations = append(mmGetTruthSourceByFileUID.expectations, expectation) return expectation } -// Then sets up RepositoryI.GetTotalTokensByListKBUIDs return parameters for the expectation previously defined by the When method -func (e *RepositoryIMockGetTotalTokensByListKBUIDsExpectation) Then(m1 map[uuid.UUID]int, err error) *RepositoryIMock { - e.results = &RepositoryIMockGetTotalTokensByListKBUIDsResults{m1, err} +// Then sets up RepositoryI.GetTruthSourceByFileUID return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockGetTruthSourceByFileUIDExpectation) Then(sp1 *mm_repository.SourceMeta, err error) *RepositoryIMock { + e.results = &RepositoryIMockGetTruthSourceByFileUIDResults{sp1, err} return e.mock } -// Times sets number of times RepositoryI.GetTotalTokensByListKBUIDs should be invoked -func (mmGetTotalTokensByListKBUIDs *mRepositoryIMockGetTotalTokensByListKBUIDs) Times(n uint64) *mRepositoryIMockGetTotalTokensByListKBUIDs { +// Times sets number of times RepositoryI.GetTruthSourceByFileUID should be invoked +func (mmGetTruthSourceByFileUID *mRepositoryIMockGetTruthSourceByFileUID) Times(n uint64) *mRepositoryIMockGetTruthSourceByFileUID { if n == 0 { - mmGetTotalTokensByListKBUIDs.mock.t.Fatalf("Times of RepositoryIMock.GetTotalTokensByListKBUIDs mock can not be zero") + mmGetTruthSourceByFileUID.mock.t.Fatalf("Times of RepositoryIMock.GetTruthSourceByFileUID mock can not be zero") } - mm_atomic.StoreUint64(&mmGetTotalTokensByListKBUIDs.expectedInvocations, n) - return mmGetTotalTokensByListKBUIDs + mm_atomic.StoreUint64(&mmGetTruthSourceByFileUID.expectedInvocations, n) + return mmGetTruthSourceByFileUID } -func (mmGetTotalTokensByListKBUIDs *mRepositoryIMockGetTotalTokensByListKBUIDs) invocationsDone() bool { - if len(mmGetTotalTokensByListKBUIDs.expectations) == 0 && mmGetTotalTokensByListKBUIDs.defaultExpectation == nil && mmGetTotalTokensByListKBUIDs.mock.funcGetTotalTokensByListKBUIDs == nil { +func (mmGetTruthSourceByFileUID *mRepositoryIMockGetTruthSourceByFileUID) invocationsDone() bool { + if len(mmGetTruthSourceByFileUID.expectations) == 0 && mmGetTruthSourceByFileUID.defaultExpectation == nil && mmGetTruthSourceByFileUID.mock.funcGetTruthSourceByFileUID == nil { return true } - totalInvocations := mm_atomic.LoadUint64(&mmGetTotalTokensByListKBUIDs.mock.afterGetTotalTokensByListKBUIDsCounter) - expectedInvocations := mm_atomic.LoadUint64(&mmGetTotalTokensByListKBUIDs.expectedInvocations) + totalInvocations := mm_atomic.LoadUint64(&mmGetTruthSourceByFileUID.mock.afterGetTruthSourceByFileUIDCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmGetTruthSourceByFileUID.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } -// GetTotalTokensByListKBUIDs implements repository.RepositoryI -func (mmGetTotalTokensByListKBUIDs *RepositoryIMock) GetTotalTokensByListKBUIDs(ctx context.Context, kbUIDs []uuid.UUID) (m1 map[uuid.UUID]int, err error) { - mm_atomic.AddUint64(&mmGetTotalTokensByListKBUIDs.beforeGetTotalTokensByListKBUIDsCounter, 1) - defer mm_atomic.AddUint64(&mmGetTotalTokensByListKBUIDs.afterGetTotalTokensByListKBUIDsCounter, 1) +// GetTruthSourceByFileUID implements repository.RepositoryI +func (mmGetTruthSourceByFileUID *RepositoryIMock) GetTruthSourceByFileUID(ctx context.Context, fileUID uuid.UUID) (sp1 *mm_repository.SourceMeta, err error) { + mm_atomic.AddUint64(&mmGetTruthSourceByFileUID.beforeGetTruthSourceByFileUIDCounter, 1) + defer mm_atomic.AddUint64(&mmGetTruthSourceByFileUID.afterGetTruthSourceByFileUIDCounter, 1) - if mmGetTotalTokensByListKBUIDs.inspectFuncGetTotalTokensByListKBUIDs != nil { - mmGetTotalTokensByListKBUIDs.inspectFuncGetTotalTokensByListKBUIDs(ctx, kbUIDs) + if mmGetTruthSourceByFileUID.inspectFuncGetTruthSourceByFileUID != nil { + mmGetTruthSourceByFileUID.inspectFuncGetTruthSourceByFileUID(ctx, fileUID) } - mm_params := RepositoryIMockGetTotalTokensByListKBUIDsParams{ctx, kbUIDs} + mm_params := RepositoryIMockGetTruthSourceByFileUIDParams{ctx, fileUID} // Record call args - mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.mutex.Lock() - mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.callArgs = append(mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.callArgs, &mm_params) - mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.mutex.Unlock() + mmGetTruthSourceByFileUID.GetTruthSourceByFileUIDMock.mutex.Lock() + mmGetTruthSourceByFileUID.GetTruthSourceByFileUIDMock.callArgs = append(mmGetTruthSourceByFileUID.GetTruthSourceByFileUIDMock.callArgs, &mm_params) + mmGetTruthSourceByFileUID.GetTruthSourceByFileUIDMock.mutex.Unlock() - for _, e := range mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.expectations { + for _, e := range mmGetTruthSourceByFileUID.GetTruthSourceByFileUIDMock.expectations { if minimock.Equal(*e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) - return e.results.m1, e.results.err + return e.results.sp1, e.results.err } } - if mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.defaultExpectation != nil { - mm_atomic.AddUint64(&mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.defaultExpectation.Counter, 1) - mm_want := mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.defaultExpectation.params - mm_want_ptrs := mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.defaultExpectation.paramPtrs + if mmGetTruthSourceByFileUID.GetTruthSourceByFileUIDMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmGetTruthSourceByFileUID.GetTruthSourceByFileUIDMock.defaultExpectation.Counter, 1) + mm_want := mmGetTruthSourceByFileUID.GetTruthSourceByFileUIDMock.defaultExpectation.params + mm_want_ptrs := mmGetTruthSourceByFileUID.GetTruthSourceByFileUIDMock.defaultExpectation.paramPtrs - mm_got := RepositoryIMockGetTotalTokensByListKBUIDsParams{ctx, kbUIDs} + mm_got := RepositoryIMockGetTruthSourceByFileUIDParams{ctx, fileUID} if mm_want_ptrs != nil { if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { - mmGetTotalTokensByListKBUIDs.t.Errorf("RepositoryIMock.GetTotalTokensByListKBUIDs got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + mmGetTruthSourceByFileUID.t.Errorf("RepositoryIMock.GetTruthSourceByFileUID got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) } - if mm_want_ptrs.kbUIDs != nil && !minimock.Equal(*mm_want_ptrs.kbUIDs, mm_got.kbUIDs) { - mmGetTotalTokensByListKBUIDs.t.Errorf("RepositoryIMock.GetTotalTokensByListKBUIDs got unexpected parameter kbUIDs, want: %#v, got: %#v%s\n", *mm_want_ptrs.kbUIDs, mm_got.kbUIDs, minimock.Diff(*mm_want_ptrs.kbUIDs, mm_got.kbUIDs)) + if mm_want_ptrs.fileUID != nil && !minimock.Equal(*mm_want_ptrs.fileUID, mm_got.fileUID) { + mmGetTruthSourceByFileUID.t.Errorf("RepositoryIMock.GetTruthSourceByFileUID got unexpected parameter fileUID, want: %#v, got: %#v%s\n", *mm_want_ptrs.fileUID, mm_got.fileUID, minimock.Diff(*mm_want_ptrs.fileUID, mm_got.fileUID)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { - mmGetTotalTokensByListKBUIDs.t.Errorf("RepositoryIMock.GetTotalTokensByListKBUIDs got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + mmGetTruthSourceByFileUID.t.Errorf("RepositoryIMock.GetTruthSourceByFileUID got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } - mm_results := mmGetTotalTokensByListKBUIDs.GetTotalTokensByListKBUIDsMock.defaultExpectation.results + mm_results := mmGetTruthSourceByFileUID.GetTruthSourceByFileUIDMock.defaultExpectation.results if mm_results == nil { - mmGetTotalTokensByListKBUIDs.t.Fatal("No results are set for the RepositoryIMock.GetTotalTokensByListKBUIDs") + mmGetTruthSourceByFileUID.t.Fatal("No results are set for the RepositoryIMock.GetTruthSourceByFileUID") } - return (*mm_results).m1, (*mm_results).err + return (*mm_results).sp1, (*mm_results).err } - if mmGetTotalTokensByListKBUIDs.funcGetTotalTokensByListKBUIDs != nil { - return mmGetTotalTokensByListKBUIDs.funcGetTotalTokensByListKBUIDs(ctx, kbUIDs) + if mmGetTruthSourceByFileUID.funcGetTruthSourceByFileUID != nil { + return mmGetTruthSourceByFileUID.funcGetTruthSourceByFileUID(ctx, fileUID) } - mmGetTotalTokensByListKBUIDs.t.Fatalf("Unexpected call to RepositoryIMock.GetTotalTokensByListKBUIDs. %v %v", ctx, kbUIDs) + mmGetTruthSourceByFileUID.t.Fatalf("Unexpected call to RepositoryIMock.GetTruthSourceByFileUID. %v %v", ctx, fileUID) return } -// GetTotalTokensByListKBUIDsAfterCounter returns a count of finished RepositoryIMock.GetTotalTokensByListKBUIDs invocations -func (mmGetTotalTokensByListKBUIDs *RepositoryIMock) GetTotalTokensByListKBUIDsAfterCounter() uint64 { - return mm_atomic.LoadUint64(&mmGetTotalTokensByListKBUIDs.afterGetTotalTokensByListKBUIDsCounter) +// GetTruthSourceByFileUIDAfterCounter returns a count of finished RepositoryIMock.GetTruthSourceByFileUID invocations +func (mmGetTruthSourceByFileUID *RepositoryIMock) GetTruthSourceByFileUIDAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetTruthSourceByFileUID.afterGetTruthSourceByFileUIDCounter) } -// GetTotalTokensByListKBUIDsBeforeCounter returns a count of RepositoryIMock.GetTotalTokensByListKBUIDs invocations -func (mmGetTotalTokensByListKBUIDs *RepositoryIMock) GetTotalTokensByListKBUIDsBeforeCounter() uint64 { - return mm_atomic.LoadUint64(&mmGetTotalTokensByListKBUIDs.beforeGetTotalTokensByListKBUIDsCounter) +// GetTruthSourceByFileUIDBeforeCounter returns a count of RepositoryIMock.GetTruthSourceByFileUID invocations +func (mmGetTruthSourceByFileUID *RepositoryIMock) GetTruthSourceByFileUIDBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetTruthSourceByFileUID.beforeGetTruthSourceByFileUIDCounter) } -// Calls returns a list of arguments used in each call to RepositoryIMock.GetTotalTokensByListKBUIDs. +// Calls returns a list of arguments used in each call to RepositoryIMock.GetTruthSourceByFileUID. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) -func (mmGetTotalTokensByListKBUIDs *mRepositoryIMockGetTotalTokensByListKBUIDs) Calls() []*RepositoryIMockGetTotalTokensByListKBUIDsParams { - mmGetTotalTokensByListKBUIDs.mutex.RLock() +func (mmGetTruthSourceByFileUID *mRepositoryIMockGetTruthSourceByFileUID) Calls() []*RepositoryIMockGetTruthSourceByFileUIDParams { + mmGetTruthSourceByFileUID.mutex.RLock() - argCopy := make([]*RepositoryIMockGetTotalTokensByListKBUIDsParams, len(mmGetTotalTokensByListKBUIDs.callArgs)) - copy(argCopy, mmGetTotalTokensByListKBUIDs.callArgs) + argCopy := make([]*RepositoryIMockGetTruthSourceByFileUIDParams, len(mmGetTruthSourceByFileUID.callArgs)) + copy(argCopy, mmGetTruthSourceByFileUID.callArgs) - mmGetTotalTokensByListKBUIDs.mutex.RUnlock() + mmGetTruthSourceByFileUID.mutex.RUnlock() return argCopy } -// MinimockGetTotalTokensByListKBUIDsDone returns true if the count of the GetTotalTokensByListKBUIDs invocations corresponds +// MinimockGetTruthSourceByFileUIDDone returns true if the count of the GetTruthSourceByFileUID invocations corresponds // the number of defined expectations -func (m *RepositoryIMock) MinimockGetTotalTokensByListKBUIDsDone() bool { - for _, e := range m.GetTotalTokensByListKBUIDsMock.expectations { +func (m *RepositoryIMock) MinimockGetTruthSourceByFileUIDDone() bool { + for _, e := range m.GetTruthSourceByFileUIDMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } - return m.GetTotalTokensByListKBUIDsMock.invocationsDone() + return m.GetTruthSourceByFileUIDMock.invocationsDone() } -// MinimockGetTotalTokensByListKBUIDsInspect logs each unmet expectation -func (m *RepositoryIMock) MinimockGetTotalTokensByListKBUIDsInspect() { - for _, e := range m.GetTotalTokensByListKBUIDsMock.expectations { +// MinimockGetTruthSourceByFileUIDInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockGetTruthSourceByFileUIDInspect() { + for _, e := range m.GetTruthSourceByFileUIDMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { - m.t.Errorf("Expected call to RepositoryIMock.GetTotalTokensByListKBUIDs with params: %#v", *e.params) + m.t.Errorf("Expected call to RepositoryIMock.GetTruthSourceByFileUID with params: %#v", *e.params) } } - afterGetTotalTokensByListKBUIDsCounter := mm_atomic.LoadUint64(&m.afterGetTotalTokensByListKBUIDsCounter) + afterGetTruthSourceByFileUIDCounter := mm_atomic.LoadUint64(&m.afterGetTruthSourceByFileUIDCounter) // if default expectation was set then invocations count should be greater than zero - if m.GetTotalTokensByListKBUIDsMock.defaultExpectation != nil && afterGetTotalTokensByListKBUIDsCounter < 1 { - if m.GetTotalTokensByListKBUIDsMock.defaultExpectation.params == nil { - m.t.Error("Expected call to RepositoryIMock.GetTotalTokensByListKBUIDs") + if m.GetTruthSourceByFileUIDMock.defaultExpectation != nil && afterGetTruthSourceByFileUIDCounter < 1 { + if m.GetTruthSourceByFileUIDMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.GetTruthSourceByFileUID") } else { - m.t.Errorf("Expected call to RepositoryIMock.GetTotalTokensByListKBUIDs with params: %#v", *m.GetTotalTokensByListKBUIDsMock.defaultExpectation.params) + m.t.Errorf("Expected call to RepositoryIMock.GetTruthSourceByFileUID with params: %#v", *m.GetTruthSourceByFileUIDMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero - if m.funcGetTotalTokensByListKBUIDs != nil && afterGetTotalTokensByListKBUIDsCounter < 1 { - m.t.Error("Expected call to RepositoryIMock.GetTotalTokensByListKBUIDs") + if m.funcGetTruthSourceByFileUID != nil && afterGetTruthSourceByFileUIDCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.GetTruthSourceByFileUID") } - if !m.GetTotalTokensByListKBUIDsMock.invocationsDone() && afterGetTotalTokensByListKBUIDsCounter > 0 { - m.t.Errorf("Expected %d calls to RepositoryIMock.GetTotalTokensByListKBUIDs but found %d calls", - mm_atomic.LoadUint64(&m.GetTotalTokensByListKBUIDsMock.expectedInvocations), afterGetTotalTokensByListKBUIDsCounter) + if !m.GetTruthSourceByFileUIDMock.invocationsDone() && afterGetTruthSourceByFileUIDCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.GetTruthSourceByFileUID but found %d calls", + mm_atomic.LoadUint64(&m.GetTruthSourceByFileUIDMock.expectedInvocations), afterGetTruthSourceByFileUIDCounter) } } @@ -8907,6 +9876,339 @@ func (m *RepositoryIMock) MinimockTextChunkTableNameInspect() { } } +type mRepositoryIMockUpdateChunk struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockUpdateChunkExpectation + expectations []*RepositoryIMockUpdateChunkExpectation + + callArgs []*RepositoryIMockUpdateChunkParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockUpdateChunkExpectation specifies expectation struct of the RepositoryI.UpdateChunk +type RepositoryIMockUpdateChunkExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockUpdateChunkParams + paramPtrs *RepositoryIMockUpdateChunkParamPtrs + results *RepositoryIMockUpdateChunkResults + Counter uint64 +} + +// RepositoryIMockUpdateChunkParams contains parameters of the RepositoryI.UpdateChunk +type RepositoryIMockUpdateChunkParams struct { + ctx context.Context + chunkUID string + updates map[string]interface{} +} + +// RepositoryIMockUpdateChunkParamPtrs contains pointers to parameters of the RepositoryI.UpdateChunk +type RepositoryIMockUpdateChunkParamPtrs struct { + ctx *context.Context + chunkUID *string + updates *map[string]interface{} +} + +// RepositoryIMockUpdateChunkResults contains results of the RepositoryI.UpdateChunk +type RepositoryIMockUpdateChunkResults struct { + tp1 *mm_repository.TextChunk + err error +} + +// Expect sets up expected params for RepositoryI.UpdateChunk +func (mmUpdateChunk *mRepositoryIMockUpdateChunk) Expect(ctx context.Context, chunkUID string, updates map[string]interface{}) *mRepositoryIMockUpdateChunk { + if mmUpdateChunk.mock.funcUpdateChunk != nil { + mmUpdateChunk.mock.t.Fatalf("RepositoryIMock.UpdateChunk mock is already set by Set") + } + + if mmUpdateChunk.defaultExpectation == nil { + mmUpdateChunk.defaultExpectation = &RepositoryIMockUpdateChunkExpectation{} + } + + if mmUpdateChunk.defaultExpectation.paramPtrs != nil { + mmUpdateChunk.mock.t.Fatalf("RepositoryIMock.UpdateChunk mock is already set by ExpectParams functions") + } + + mmUpdateChunk.defaultExpectation.params = &RepositoryIMockUpdateChunkParams{ctx, chunkUID, updates} + for _, e := range mmUpdateChunk.expectations { + if minimock.Equal(e.params, mmUpdateChunk.defaultExpectation.params) { + mmUpdateChunk.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUpdateChunk.defaultExpectation.params) + } + } + + return mmUpdateChunk +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.UpdateChunk +func (mmUpdateChunk *mRepositoryIMockUpdateChunk) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockUpdateChunk { + if mmUpdateChunk.mock.funcUpdateChunk != nil { + mmUpdateChunk.mock.t.Fatalf("RepositoryIMock.UpdateChunk mock is already set by Set") + } + + if mmUpdateChunk.defaultExpectation == nil { + mmUpdateChunk.defaultExpectation = &RepositoryIMockUpdateChunkExpectation{} + } + + if mmUpdateChunk.defaultExpectation.params != nil { + mmUpdateChunk.mock.t.Fatalf("RepositoryIMock.UpdateChunk mock is already set by Expect") + } + + if mmUpdateChunk.defaultExpectation.paramPtrs == nil { + mmUpdateChunk.defaultExpectation.paramPtrs = &RepositoryIMockUpdateChunkParamPtrs{} + } + mmUpdateChunk.defaultExpectation.paramPtrs.ctx = &ctx + + return mmUpdateChunk +} + +// ExpectChunkUIDParam2 sets up expected param chunkUID for RepositoryI.UpdateChunk +func (mmUpdateChunk *mRepositoryIMockUpdateChunk) ExpectChunkUIDParam2(chunkUID string) *mRepositoryIMockUpdateChunk { + if mmUpdateChunk.mock.funcUpdateChunk != nil { + mmUpdateChunk.mock.t.Fatalf("RepositoryIMock.UpdateChunk mock is already set by Set") + } + + if mmUpdateChunk.defaultExpectation == nil { + mmUpdateChunk.defaultExpectation = &RepositoryIMockUpdateChunkExpectation{} + } + + if mmUpdateChunk.defaultExpectation.params != nil { + mmUpdateChunk.mock.t.Fatalf("RepositoryIMock.UpdateChunk mock is already set by Expect") + } + + if mmUpdateChunk.defaultExpectation.paramPtrs == nil { + mmUpdateChunk.defaultExpectation.paramPtrs = &RepositoryIMockUpdateChunkParamPtrs{} + } + mmUpdateChunk.defaultExpectation.paramPtrs.chunkUID = &chunkUID + + return mmUpdateChunk +} + +// ExpectUpdatesParam3 sets up expected param updates for RepositoryI.UpdateChunk +func (mmUpdateChunk *mRepositoryIMockUpdateChunk) ExpectUpdatesParam3(updates map[string]interface{}) *mRepositoryIMockUpdateChunk { + if mmUpdateChunk.mock.funcUpdateChunk != nil { + mmUpdateChunk.mock.t.Fatalf("RepositoryIMock.UpdateChunk mock is already set by Set") + } + + if mmUpdateChunk.defaultExpectation == nil { + mmUpdateChunk.defaultExpectation = &RepositoryIMockUpdateChunkExpectation{} + } + + if mmUpdateChunk.defaultExpectation.params != nil { + mmUpdateChunk.mock.t.Fatalf("RepositoryIMock.UpdateChunk mock is already set by Expect") + } + + if mmUpdateChunk.defaultExpectation.paramPtrs == nil { + mmUpdateChunk.defaultExpectation.paramPtrs = &RepositoryIMockUpdateChunkParamPtrs{} + } + mmUpdateChunk.defaultExpectation.paramPtrs.updates = &updates + + return mmUpdateChunk +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.UpdateChunk +func (mmUpdateChunk *mRepositoryIMockUpdateChunk) Inspect(f func(ctx context.Context, chunkUID string, updates map[string]interface{})) *mRepositoryIMockUpdateChunk { + if mmUpdateChunk.mock.inspectFuncUpdateChunk != nil { + mmUpdateChunk.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.UpdateChunk") + } + + mmUpdateChunk.mock.inspectFuncUpdateChunk = f + + return mmUpdateChunk +} + +// Return sets up results that will be returned by RepositoryI.UpdateChunk +func (mmUpdateChunk *mRepositoryIMockUpdateChunk) Return(tp1 *mm_repository.TextChunk, err error) *RepositoryIMock { + if mmUpdateChunk.mock.funcUpdateChunk != nil { + mmUpdateChunk.mock.t.Fatalf("RepositoryIMock.UpdateChunk mock is already set by Set") + } + + if mmUpdateChunk.defaultExpectation == nil { + mmUpdateChunk.defaultExpectation = &RepositoryIMockUpdateChunkExpectation{mock: mmUpdateChunk.mock} + } + mmUpdateChunk.defaultExpectation.results = &RepositoryIMockUpdateChunkResults{tp1, err} + return mmUpdateChunk.mock +} + +// Set uses given function f to mock the RepositoryI.UpdateChunk method +func (mmUpdateChunk *mRepositoryIMockUpdateChunk) Set(f func(ctx context.Context, chunkUID string, updates map[string]interface{}) (tp1 *mm_repository.TextChunk, err error)) *RepositoryIMock { + if mmUpdateChunk.defaultExpectation != nil { + mmUpdateChunk.mock.t.Fatalf("Default expectation is already set for the RepositoryI.UpdateChunk method") + } + + if len(mmUpdateChunk.expectations) > 0 { + mmUpdateChunk.mock.t.Fatalf("Some expectations are already set for the RepositoryI.UpdateChunk method") + } + + mmUpdateChunk.mock.funcUpdateChunk = f + return mmUpdateChunk.mock +} + +// When sets expectation for the RepositoryI.UpdateChunk which will trigger the result defined by the following +// Then helper +func (mmUpdateChunk *mRepositoryIMockUpdateChunk) When(ctx context.Context, chunkUID string, updates map[string]interface{}) *RepositoryIMockUpdateChunkExpectation { + if mmUpdateChunk.mock.funcUpdateChunk != nil { + mmUpdateChunk.mock.t.Fatalf("RepositoryIMock.UpdateChunk mock is already set by Set") + } + + expectation := &RepositoryIMockUpdateChunkExpectation{ + mock: mmUpdateChunk.mock, + params: &RepositoryIMockUpdateChunkParams{ctx, chunkUID, updates}, + } + mmUpdateChunk.expectations = append(mmUpdateChunk.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.UpdateChunk return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockUpdateChunkExpectation) Then(tp1 *mm_repository.TextChunk, err error) *RepositoryIMock { + e.results = &RepositoryIMockUpdateChunkResults{tp1, err} + return e.mock +} + +// Times sets number of times RepositoryI.UpdateChunk should be invoked +func (mmUpdateChunk *mRepositoryIMockUpdateChunk) Times(n uint64) *mRepositoryIMockUpdateChunk { + if n == 0 { + mmUpdateChunk.mock.t.Fatalf("Times of RepositoryIMock.UpdateChunk mock can not be zero") + } + mm_atomic.StoreUint64(&mmUpdateChunk.expectedInvocations, n) + return mmUpdateChunk +} + +func (mmUpdateChunk *mRepositoryIMockUpdateChunk) invocationsDone() bool { + if len(mmUpdateChunk.expectations) == 0 && mmUpdateChunk.defaultExpectation == nil && mmUpdateChunk.mock.funcUpdateChunk == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmUpdateChunk.mock.afterUpdateChunkCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmUpdateChunk.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// UpdateChunk implements repository.RepositoryI +func (mmUpdateChunk *RepositoryIMock) UpdateChunk(ctx context.Context, chunkUID string, updates map[string]interface{}) (tp1 *mm_repository.TextChunk, err error) { + mm_atomic.AddUint64(&mmUpdateChunk.beforeUpdateChunkCounter, 1) + defer mm_atomic.AddUint64(&mmUpdateChunk.afterUpdateChunkCounter, 1) + + if mmUpdateChunk.inspectFuncUpdateChunk != nil { + mmUpdateChunk.inspectFuncUpdateChunk(ctx, chunkUID, updates) + } + + mm_params := RepositoryIMockUpdateChunkParams{ctx, chunkUID, updates} + + // Record call args + mmUpdateChunk.UpdateChunkMock.mutex.Lock() + mmUpdateChunk.UpdateChunkMock.callArgs = append(mmUpdateChunk.UpdateChunkMock.callArgs, &mm_params) + mmUpdateChunk.UpdateChunkMock.mutex.Unlock() + + for _, e := range mmUpdateChunk.UpdateChunkMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.tp1, e.results.err + } + } + + if mmUpdateChunk.UpdateChunkMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmUpdateChunk.UpdateChunkMock.defaultExpectation.Counter, 1) + mm_want := mmUpdateChunk.UpdateChunkMock.defaultExpectation.params + mm_want_ptrs := mmUpdateChunk.UpdateChunkMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockUpdateChunkParams{ctx, chunkUID, updates} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmUpdateChunk.t.Errorf("RepositoryIMock.UpdateChunk got unexpected parameter ctx, want: %#v, got: %#v%s\n", *mm_want_ptrs.ctx, mm_got.ctx, minimock.Diff(*mm_want_ptrs.ctx, mm_got.ctx)) + } + + if mm_want_ptrs.chunkUID != nil && !minimock.Equal(*mm_want_ptrs.chunkUID, mm_got.chunkUID) { + mmUpdateChunk.t.Errorf("RepositoryIMock.UpdateChunk got unexpected parameter chunkUID, want: %#v, got: %#v%s\n", *mm_want_ptrs.chunkUID, mm_got.chunkUID, minimock.Diff(*mm_want_ptrs.chunkUID, mm_got.chunkUID)) + } + + if mm_want_ptrs.updates != nil && !minimock.Equal(*mm_want_ptrs.updates, mm_got.updates) { + mmUpdateChunk.t.Errorf("RepositoryIMock.UpdateChunk got unexpected parameter updates, want: %#v, got: %#v%s\n", *mm_want_ptrs.updates, mm_got.updates, minimock.Diff(*mm_want_ptrs.updates, mm_got.updates)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmUpdateChunk.t.Errorf("RepositoryIMock.UpdateChunk got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmUpdateChunk.UpdateChunkMock.defaultExpectation.results + if mm_results == nil { + mmUpdateChunk.t.Fatal("No results are set for the RepositoryIMock.UpdateChunk") + } + return (*mm_results).tp1, (*mm_results).err + } + if mmUpdateChunk.funcUpdateChunk != nil { + return mmUpdateChunk.funcUpdateChunk(ctx, chunkUID, updates) + } + mmUpdateChunk.t.Fatalf("Unexpected call to RepositoryIMock.UpdateChunk. %v %v %v", ctx, chunkUID, updates) + return +} + +// UpdateChunkAfterCounter returns a count of finished RepositoryIMock.UpdateChunk invocations +func (mmUpdateChunk *RepositoryIMock) UpdateChunkAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmUpdateChunk.afterUpdateChunkCounter) +} + +// UpdateChunkBeforeCounter returns a count of RepositoryIMock.UpdateChunk invocations +func (mmUpdateChunk *RepositoryIMock) UpdateChunkBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmUpdateChunk.beforeUpdateChunkCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.UpdateChunk. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmUpdateChunk *mRepositoryIMockUpdateChunk) Calls() []*RepositoryIMockUpdateChunkParams { + mmUpdateChunk.mutex.RLock() + + argCopy := make([]*RepositoryIMockUpdateChunkParams, len(mmUpdateChunk.callArgs)) + copy(argCopy, mmUpdateChunk.callArgs) + + mmUpdateChunk.mutex.RUnlock() + + return argCopy +} + +// MinimockUpdateChunkDone returns true if the count of the UpdateChunk invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockUpdateChunkDone() bool { + for _, e := range m.UpdateChunkMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.UpdateChunkMock.invocationsDone() +} + +// MinimockUpdateChunkInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockUpdateChunkInspect() { + for _, e := range m.UpdateChunkMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.UpdateChunk with params: %#v", *e.params) + } + } + + afterUpdateChunkCounter := mm_atomic.LoadUint64(&m.afterUpdateChunkCounter) + // if default expectation was set then invocations count should be greater than zero + if m.UpdateChunkMock.defaultExpectation != nil && afterUpdateChunkCounter < 1 { + if m.UpdateChunkMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.UpdateChunk") + } else { + m.t.Errorf("Expected call to RepositoryIMock.UpdateChunk with params: %#v", *m.UpdateChunkMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcUpdateChunk != nil && afterUpdateChunkCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.UpdateChunk") + } + + if !m.UpdateChunkMock.invocationsDone() && afterUpdateChunkCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.UpdateChunk but found %d calls", + mm_atomic.LoadUint64(&m.UpdateChunkMock.expectedInvocations), afterUpdateChunkCounter) + } +} + type mRepositoryIMockUpdateKnowledgeBase struct { mock *RepositoryIMock defaultExpectation *RepositoryIMockUpdateKnowledgeBaseExpectation @@ -10253,14 +11555,20 @@ func (m *RepositoryIMock) MinimockFinish() { m.MinimockGetKnowledgeBaseByOwnerAndIDInspect() + m.MinimockGetKnowledgeBaseFilesByFileUIDsInspect() + m.MinimockGetRepositoryTagInspect() + m.MinimockGetSourceTableAndUIDByFileUIDsInspect() + m.MinimockGetTextChunksBySourceInspect() m.MinimockGetTotalChunksBySourcesInspect() m.MinimockGetTotalTokensByListKBUIDsInspect() + m.MinimockGetTruthSourceByFileUIDInspect() + m.MinimockKnowledgeBaseFileTableNameInspect() m.MinimockListKnowledgeBaseFilesInspect() @@ -10271,6 +11579,8 @@ func (m *RepositoryIMock) MinimockFinish() { m.MinimockTextChunkTableNameInspect() + m.MinimockUpdateChunkInspect() + m.MinimockUpdateKnowledgeBaseInspect() m.MinimockUpdateKnowledgeBaseFileInspect() @@ -10321,15 +11631,19 @@ func (m *RepositoryIMock) minimockDone() bool { m.MinimockGetFilesTotalTokensDone() && m.MinimockGetIncompleteFileDone() && m.MinimockGetKnowledgeBaseByOwnerAndIDDone() && + m.MinimockGetKnowledgeBaseFilesByFileUIDsDone() && m.MinimockGetRepositoryTagDone() && + m.MinimockGetSourceTableAndUIDByFileUIDsDone() && m.MinimockGetTextChunksBySourceDone() && m.MinimockGetTotalChunksBySourcesDone() && m.MinimockGetTotalTokensByListKBUIDsDone() && + m.MinimockGetTruthSourceByFileUIDDone() && m.MinimockKnowledgeBaseFileTableNameDone() && m.MinimockListKnowledgeBaseFilesDone() && m.MinimockListKnowledgeBasesDone() && m.MinimockProcessKnowledgeBaseFilesDone() && m.MinimockTextChunkTableNameDone() && + m.MinimockUpdateChunkDone() && m.MinimockUpdateKnowledgeBaseDone() && m.MinimockUpdateKnowledgeBaseFileDone() && m.MinimockUpsertEmbeddingsDone() && diff --git a/pkg/repository/chunk.go b/pkg/repository/chunk.go index 16389d0..9cf9923 100644 --- a/pkg/repository/chunk.go +++ b/pkg/repository/chunk.go @@ -2,6 +2,7 @@ package repository import ( "context" + "errors" "fmt" "strings" "time" @@ -27,6 +28,7 @@ type TextChunkI interface { SourceTable SourceTable SourceUID SourceUID }) (map[FileUID]int, error) + UpdateChunk(ctx context.Context, chunkUID string, updates map[string]interface{}) (*TextChunk, error) } // currently, we use minio to store the chunk but in the future, we may just get the content from the source @@ -294,3 +296,32 @@ func (r *Repository) GetTotalChunksBySources(ctx context.Context, sources map[Fi return result, nil } + +// UpdateChunk updates a specific chunk identified by chunkUID with the provided updates map. +func (r *Repository) UpdateChunk(ctx context.Context, chunkUID string, updates map[string]interface{}) (*TextChunk, error) { + // Fetch the existing chunk to ensure it exists + var existingChunk TextChunk + where := fmt.Sprintf("%s = ?", TextChunkColumn.UID) + if err := r.db.WithContext(ctx).Where(where, chunkUID).First(&existingChunk).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, fmt.Errorf("chunk UID not found: %v. err: %w", chunkUID, gorm.ErrRecordNotFound) + } + return nil, err + } + + // Update the specific fields of the chunk + if err := r.db.WithContext(ctx).Model(&existingChunk).Updates(updates).Error; err != nil { + return nil, err + } + + // Fetch the updated chunk + var updatedChunk TextChunk + if err := r.db.WithContext(ctx).Where(where, chunkUID).Take(&updatedChunk).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, fmt.Errorf("chunk UID not found after update: %v. err: %w", chunkUID, gorm.ErrRecordNotFound) + } + return nil, err + } + + return &updatedChunk, nil +} diff --git a/pkg/repository/knowledgebasefile.go b/pkg/repository/knowledgebasefile.go index 4368bb1..6933bad 100644 --- a/pkg/repository/knowledgebasefile.go +++ b/pkg/repository/knowledgebasefile.go @@ -2,11 +2,14 @@ package repository import ( "context" + "errors" "fmt" "time" "github.com/google/uuid" + "github.com/instill-ai/artifact-backend/pkg/logger" artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" + "go.uber.org/zap" "gorm.io/gorm" ) @@ -26,9 +29,20 @@ type KnowledgeBaseFileI interface { // UpdateKnowledgeBaseFile updates the data and retrieves the latest data UpdateKnowledgeBaseFile(ctx context.Context, fileUID string, updateMap map[string]interface{}) (*KnowledgeBaseFile, error) // GetCountFilesByListKnowledgeBaseUID returns the number of files associated with the knowledge base UID - GetCountFilesByListKnowledgeBaseUID(ctx context.Context, kbUIDs []uuid.UUID) (map[uuid.UUID]int64, error) + GetCountFilesByListKnowledgeBaseUID(ctx context.Context, kbUIDs []KbUID) (map[KbUID]int64, error) + // GetSourceTableAndUIDByFileUIDs returns the source table and uid by file UID list + GetSourceTableAndUIDByFileUIDs(ctx context.Context, files []KnowledgeBaseFile) (map[FileUID]struct { + SourceTable string + SourceUID uuid.UUID + }, error) + // GetKnowledgeBaseFilesByFileUIDs returns the knowledge base files by file UIDs + GetKnowledgeBaseFilesByFileUIDs(ctx context.Context, fileUIDs []uuid.UUID) ([]KnowledgeBaseFile, error) + // GetTruthSourceByFileUID returns the truth source file destination of minIO by file UID + GetTruthSourceByFileUID(ctx context.Context, fileUID uuid.UUID) (*SourceMeta, error) } +type KbUID = uuid.UUID + type KnowledgeBaseFile struct { UID uuid.UUID `gorm:"column:uid;type:uuid;default:gen_random_uuid();primaryKey" json:"uid"` Owner uuid.UUID `gorm:"column:owner;type:uuid;not null" json:"owner"` @@ -36,8 +50,9 @@ type KnowledgeBaseFile struct { CreatorUID uuid.UUID `gorm:"column:creator_uid;type:uuid;not null" json:"creator_uid"` Name string `gorm:"column:name;size:255;not null" json:"name"` // Type is defined in the grpc proto file - Type string `gorm:"column:type;not null" json:"type"` - Destination string `gorm:"column:destination;size:255;not null" json:"destination"` + Type string `gorm:"column:type;not null" json:"type"` + Destination string `gorm:"column:destination;size:255;not null" json:"destination"` + // Process status is defined in the grpc proto file ProcessStatus string `gorm:"column:process_status;size:100;not null" json:"process_status"` ExtraMetaData string `gorm:"column:extra_meta_data;type:jsonb" json:"extra_meta_data"` // Content not used yet @@ -283,3 +298,123 @@ func (r *Repository) GetCountFilesByListKnowledgeBaseUID(ctx context.Context, kb return counts, nil } + +// GetSourceTableAndUIDByFileUIDs returns the source table and uid by file UID list +func (r *Repository) GetSourceTableAndUIDByFileUIDs(ctx context.Context, files []KnowledgeBaseFile) ( + map[FileUID]struct { + SourceTable string + SourceUID uuid.UUID + }, error) { + logger, _ := logger.GetZapLogger(ctx) + result := make(map[uuid.UUID]struct { + SourceTable string + SourceUID uuid.UUID + }) + for _, file := range files { + // find the source table and source uid by file uid + // check if the file is is text or markdown + switch file.Type { + case artifactpb.FileType_FILE_TYPE_TEXT.String(), artifactpb.FileType_FILE_TYPE_MARKDOWN.String(): + result[file.UID] = struct { + SourceTable string + SourceUID uuid.UUID + }{ + SourceTable: r.KnowledgeBaseFileTableName(), + SourceUID: file.UID, + } + case artifactpb.FileType_FILE_TYPE_PDF.String(): + convertedFile, err := r.GetConvertedFileByFileUID(ctx, file.UID) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + continue + } else { + logger.Error("failed to get converted file by file uid", zap.Error(err)) + return map[uuid.UUID]struct { + SourceTable string + SourceUID uuid.UUID + }{}, err + } + } + result[file.UID] = struct { + SourceTable string + SourceUID uuid.UUID + }{ + SourceTable: r.ConvertedFileTableName(), + SourceUID: convertedFile.UID, + } + } + } + + return result, nil +} + +func (r *Repository) GetKnowledgeBaseFilesByFileUIDs(ctx context.Context, fileUIDs []uuid.UUID) ([]KnowledgeBaseFile, error) { + var files []KnowledgeBaseFile + // Convert UUIDs to strings as GORM works with strings in queries + var stringUIDs []string + for _, uid := range fileUIDs { + stringUIDs = append(stringUIDs, uid.String()) + } + where := fmt.Sprintf("%v IN ?", KnowledgeBaseFileColumn.UID) + // Query the database for files with the given UIDs + if err := r.db.WithContext(ctx).Where(where, stringUIDs).Find(&files).Error; err != nil { + // If GORM returns ErrRecordNotFound, it's not considered an error in this context + if err == gorm.ErrRecordNotFound { + return []KnowledgeBaseFile{}, nil + } + // Return any other error that might have occurred during the query + return nil, err + } + + // Return the found files, or an empty slice if none were found + return files, nil +} + +type SourceMeta struct { + Dest string + CreateTime time.Time +} + +// GetTruthSourceByFileUID returns the truth source file destination of minIO by file UID +func (r *Repository) GetTruthSourceByFileUID(ctx context.Context, fileUID uuid.UUID) (*SourceMeta, error) { + logger, _ := logger.GetZapLogger(ctx) + // get the file type by file uid + var file KnowledgeBaseFile + where := fmt.Sprintf("%v = ?", KnowledgeBaseFileColumn.UID) + if err := r.db.WithContext(ctx).Where(where, fileUID).First(&file).Error; err != nil { + if err == gorm.ErrRecordNotFound { + return nil, fmt.Errorf("file not found by file uid: %v", fileUID) + } + return nil, err + } + // assign truth source file destination and create time + var dest string + var createTime time.Time + switch file.Type { + // if the file type is text or markdown, the destination is the file destination + case artifactpb.FileType_FILE_TYPE_TEXT.String(), artifactpb.FileType_FILE_TYPE_MARKDOWN.String(): + dest = file.Destination + createTime = *file.CreateTime + // if the file type is pdf, get the converted file destination + case artifactpb.FileType_FILE_TYPE_PDF.String(): + convertedFile, err := r.GetConvertedFileByFileUID(ctx, fileUID) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + err = fmt.Errorf(` + Single source not found for the file UID. + It might be due to the file-to-single-source process not being completed yet + or the file does not exist. err: %w`, err) + logger.Error("converted file not found", zap.String("file_uid", fileUID.String()), zap.Error(err)) + return nil, err + } + return nil, err + } + dest = convertedFile.Destination + createTime = *convertedFile.CreateTime + } + + return &SourceMeta{ + Dest: dest, + CreateTime: createTime, + }, nil +} diff --git a/pkg/service/pipeline.go b/pkg/service/pipeline.go index 8bdff24..36629af 100644 --- a/pkg/service/pipeline.go +++ b/pkg/service/pipeline.go @@ -4,7 +4,6 @@ import ( "context" "errors" - "github.com/google/uuid" "github.com/instill-ai/artifact-backend/pkg/logger" pipelinev1beta "github.com/instill-ai/protogen-go/vdp/pipeline/v1beta" @@ -13,6 +12,8 @@ import ( "google.golang.org/protobuf/types/known/structpb" ) +const chunkLength = 800 +const chunkOverlap = 200 // ConvertPDFToMD using converting pipeline to convert PDF to MD and consume caller's credits func (s *Service) ConvertPDFToMD(ctx context.Context, caller uuid.UUID, pdfBase64 string) (string, error) { @@ -78,8 +79,8 @@ func (s *Service) SplitMarkdown(ctx context.Context, caller uuid.UUID, markdown { Fields: map[string]*structpb.Value{ "text_input": {Kind: &structpb.Value_StringValue{StringValue: markdown}}, - "chunk_length": {Kind: &structpb.Value_NumberValue{NumberValue: 200}}, - "chunk_overlap": {Kind: &structpb.Value_NumberValue{NumberValue: 50}}, + "chunk_length": {Kind: &structpb.Value_NumberValue{NumberValue: chunkLength}}, + "chunk_overlap": {Kind: &structpb.Value_NumberValue{NumberValue: chunkOverlap}}, }, }, }, @@ -134,8 +135,8 @@ func (s *Service) SplitText(ctx context.Context, caller uuid.UUID, text string) { Fields: map[string]*structpb.Value{ "text_input": {Kind: &structpb.Value_StringValue{StringValue: text}}, - "chunk_length": {Kind: &structpb.Value_NumberValue{NumberValue: 200}}, - "chunk_overlap": {Kind: &structpb.Value_NumberValue{NumberValue: 50}}, + "chunk_length": {Kind: &structpb.Value_NumberValue{NumberValue: chunkLength}}, + "chunk_overlap": {Kind: &structpb.Value_NumberValue{NumberValue: chunkOverlap}}, }, }, }, @@ -151,7 +152,7 @@ func (s *Service) SplitText(ctx context.Context, caller uuid.UUID, text string) return result, nil } -// TODO VectorizeText - waiting for CE to implement the global secret +// TODO VectorizeText - waiting for CE to implement the global secret and use it in file-to-embeddings worker // VectorizeText using embedding pipeline to vectorize text and consume caller's credits func (s *Service) VectorizeText(ctx context.Context, caller uuid.UUID, texts []string) ([][]float32, error) { md := metadata.New(map[string]string{"Instill-User-Uid": caller.String(), "Instill-Auth-Type": "user"})