diff --git a/cmd/main/main.go b/cmd/main/main.go index 19d19c6..0dbae65 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -235,6 +235,7 @@ func main() { privatePort := fmt.Sprintf(":%d", config.Config.Server.PrivatePort) // Wait for interrupt signal to gracefully shutdown the server with a timeout of 5 seconds. errSig := make(chan error) + defer close(errSig) go func() { privateListener, err := net.Listen("tcp", privatePort) @@ -266,11 +267,13 @@ func main() { // kill -2 is syscall.SIGINT // kill -9 is syscall.SIGKILL but can't be catch, so don't need add it quitSig := make(chan os.Signal, 1) + defer close(quitSig) signal.Notify(quitSig, syscall.SIGINT, syscall.SIGTERM) select { case err := <-errSig: logger.Error(fmt.Sprintf("Fatal error: %v\n", err)) + os.Exit(1) case <-quitSig: // if config.Config.Server.Usage.Enabled && usg != nil { // usg.TriggerSingleReporter(ctx) @@ -278,9 +281,9 @@ func main() { logger.Info("Shutting down server...") publicGrpcS.GracefulStop() wp.GraceFulStop() - logger.Info("server shutdown 1") + logger.Info("server shutdown due to signal") + os.Exit(0) } - fmt.Println("server shutdown 2") } func newClients(ctx context.Context, logger *zap.Logger) ( diff --git a/pkg/handler/catalog.go b/pkg/handler/catalog.go index d51ad44..9b8da4c 100644 --- a/pkg/handler/catalog.go +++ b/pkg/handler/catalog.go @@ -54,8 +54,7 @@ func (ph *PublicHandler) GetFileCatalog(ctx context.Context, req *artifactpb.Get if err != nil { log.Error("failed to get file by file uid", zap.Error(err)) return nil, fmt.Errorf("failed to get file by file uid. err: %w", err) - } - if len(kbfs) == 0 { + } else if len(kbfs) == 0 { log.Error("no file found by file uid", zap.String("file_uid", fileUID.String())) return nil, fmt.Errorf("no file found by file uid: %s", fileUID.String()) } diff --git a/pkg/handler/chunks.go b/pkg/handler/chunks.go index b0ad030..edd0c54 100644 --- a/pkg/handler/chunks.go +++ b/pkg/handler/chunks.go @@ -32,8 +32,7 @@ func (ph *PublicHandler) ListChunks(ctx context.Context, req *artifactpb.ListChu 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(kbfs) == 0 { + } else if len(kbfs) == 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) } diff --git a/pkg/handler/knowledgebase.go b/pkg/handler/knowledgebase.go index e8c7b89..fb4d941 100644 --- a/pkg/handler/knowledgebase.go +++ b/pkg/handler/knowledgebase.go @@ -15,6 +15,7 @@ import ( "github.com/instill-ai/artifact-backend/pkg/logger" "github.com/instill-ai/artifact-backend/pkg/repository" "github.com/instill-ai/artifact-backend/pkg/service" + "github.com/instill-ai/artifact-backend/pkg/utils" artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" ) @@ -347,50 +348,79 @@ func (ph *PublicHandler) DeleteCatalog(ctx context.Context, req *artifactpb.Dele return nil, fmt.Errorf(ErrorDeleteKnowledgeBaseMsg, customerror.ErrNoPermission) } - // delete acl - err = ph.service.ACLClient.Purge(ctx, "knowledgebase", kb.UID) - if err != nil { - log.Error("failed to purge catalog", zap.Error(err)) - return nil, fmt.Errorf(ErrorDeleteKnowledgeBaseMsg, err) - } + startSignal := make(chan bool) + // TODO: in the future, we should delete the catalog using clean up worker + go utils.GoRecover(func() { + ctx := context.TODO() + log, _ := logger.GetZapLogger(ctx) + // wait for the catalog to be deleted in postgres + canStart := <-startSignal + if !canStart { + log.Error("failed to delete catalog in background", zap.String("catalog_id", kb.UID.String())) + return + } + log.Info("DeleteCatalog starts in background", zap.String("catalog_id", kb.UID.String())) + allPass := true + // delete files in minIO + err = <-ph.service.MinIO.DeleteKnowledgeBase(ctx, kb.UID.String()) + if err != nil { + log.Error("failed to delete files in minIO in background", zap.Error(err)) + allPass = false + } - // delete files in minIO - err = <-ph.service.MinIO.DeleteKnowledgeBase(ctx, kb.UID.String()) - if err != nil { - log.Error("failed to delete files in minIO", zap.Error(err)) - } - // delete database in postgres - err = ph.service.Repository.DeleteAllKnowledgeBaseFiles(ctx, kb.UID.String()) - if err != nil { - log.Error("failed to delete files in postgres", zap.Error(err)) - } - // delete converted files in postgres - err = ph.service.Repository.DeleteAllConvertedFilesinKb(ctx, kb.UID) - if err != nil { - log.Error("failed to delete converted files in postgres", zap.Error(err)) - } - // delete all chunks in postgres - err = ph.service.Repository.HardDeleteChunksByKbUID(ctx, kb.UID) - if err != nil { - log.Error("failed to delete chunks in postgres", zap.Error(err)) - } + // delete the collection in milvus + err = ph.service.MilvusClient.DropKnowledgeBaseCollection(ctx, kb.UID.String()) + if err != nil { + log.Error("failed to delete collection in milvus in background", zap.Error(err)) + allPass = false + } - // delete all embedding in postgres - err = ph.service.Repository.HardDeleteEmbeddingsByKbUID(ctx, kb.UID) - if err != nil { - log.Error("failed to delete embeddings in postgres", zap.Error(err)) - } + // delete all files in postgres + err = ph.service.Repository.DeleteAllKnowledgeBaseFiles(ctx, kb.UID.String()) + if err != nil { + log.Error("failed to delete files in postgres in background", zap.Error(err)) + allPass = false + } + // delete converted files in postgres + err = ph.service.Repository.DeleteAllConvertedFilesInKb(ctx, kb.UID) + if err != nil { + log.Error("failed to delete converted files in postgres in background", zap.Error(err)) + allPass = false + } + // delete all chunks in postgres + err = ph.service.Repository.HardDeleteChunksByKbUID(ctx, kb.UID) + if err != nil { + log.Error("failed to delete chunks in postgres in background", zap.Error(err)) + allPass = false + } + + // delete all embedding in postgres + err = ph.service.Repository.HardDeleteEmbeddingsByKbUID(ctx, kb.UID) + if err != nil { + log.Error("failed to delete embeddings in postgres in background", zap.Error(err)) + allPass = false + } + // delete acl. Note: we need to delete the acl after deleting the catalog + err = ph.service.ACLClient.Purge(ctx, "knowledgebase", kb.UID) + if err != nil { + log.Error("failed to purge catalog", zap.Error(err)) + allPass = false + } + if allPass { + log.Info("successfully deleted catalog in background", zap.String("catalog_id", kb.UID.String())) + } else { + log.Error("failed to delete catalog in background", zap.String("catalog_id", kb.UID.String())) + } + }, "DeleteCatalog") deletedKb, err := ph.service.Repository.DeleteKnowledgeBase(ctx, ns.NsUID.String(), req.CatalogId) if err != nil { + log.Error("failed to delete catalog", zap.Error(err)) + startSignal <- false return nil, err } - - // delete acl. Note: we need to delete the acl after deleting the catalog - err = ph.service.ACLClient.Purge(ctx, "knowledgebase", kb.UID) - if err != nil { - log.Error("failed to purge catalog", zap.Error(err)) - } + // start the background deletion + startSignal <- true return &artifactpb.DeleteCatalogResponse{ Catalog: &artifactpb.Catalog{ diff --git a/pkg/handler/knowledgebasefiles.go b/pkg/handler/knowledgebasefiles.go index 4b0dca2..cd64ead 100644 --- a/pkg/handler/knowledgebasefiles.go +++ b/pkg/handler/knowledgebasefiles.go @@ -15,6 +15,7 @@ import ( artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" "go.uber.org/zap" "google.golang.org/protobuf/types/known/timestamppb" + "gorm.io/gorm" ) func (ph *PublicHandler) UploadCatalogFile(ctx context.Context, req *artifactpb.UploadCatalogFileRequest) (*artifactpb.UploadCatalogFileResponse, error) { @@ -135,8 +136,9 @@ func (ph *PublicHandler) UploadCatalogFile(ctx context.Context, req *artifactpb. return nil, err } - // increase catalog usage - err = ph.service.Repository.IncreaseKnowledgeBaseUsage(ctx, kb.UID.String(), int(fileSize)) + // increase catalog usage. need to increase after the file is created. + // Note: in the future, we need to increase the usage in transaction with creating the file. + err = ph.service.Repository.IncreaseKnowledgeBaseUsage(ctx, nil, kb.UID.String(), int(fileSize)) if err != nil { log.Error("failed to increase catalog usage", zap.Error(err)) return nil, err @@ -318,14 +320,16 @@ func (ph *PublicHandler) DeleteCatalogFile( // ACL - check user's permission to write catalog of kb file kbfs, err := ph.service.Repository.GetKnowledgeBaseFilesByFileUIDs(ctx, []uuid.UUID{uuid.FromStringOrNil(req.FileUid)}) - if err != nil && len(kbfs) == 0 { - log.Error("failed to get catalog", zap.Error(err)) - return nil, fmt.Errorf(ErrorListKnowledgeBasesMsg, err) + if err != nil { + log.Error("failed to get catalog files", zap.Error(err)) + return nil, fmt.Errorf("failed to get catalog files. err: %w", err) + } else if len(kbfs) == 0 { + return nil, fmt.Errorf("file not found. err: %w", customerror.ErrNotFound) } granted, err := ph.service.ACLClient.CheckPermission(ctx, "knowledgebase", kbfs[0].KnowledgeBaseUID, "writer") if err != nil { log.Error("failed to check permission", zap.Error(err)) - return nil, fmt.Errorf(ErrorUpdateKnowledgeBaseMsg, err) + return nil, fmt.Errorf("failed to check permission. err: %w", err) } if !granted { log.Error("no permission to delete catalog file") @@ -345,66 +349,106 @@ func (ph *PublicHandler) DeleteCatalogFile( files, err := ph.service.Repository.GetKnowledgeBaseFilesByFileUIDs(ctx, []uuid.UUID{fUID}) if err != nil { return nil, err - } - if len(files) == 0 { + } else if len(files) == 0 { return nil, fmt.Errorf("file not found. err: %w", customerror.ErrNotFound) } + startSignal := make(chan bool) // TODO: need to use clean worker in the future go utils.GoRecover( func() { - // to prevent parent context from being cancelled, create a new context + // Create a new context to prevent the parent context from being cancelled ctx := context.TODO() - // delete the file from minio + log, _ := logger.GetZapLogger(ctx) + canStart := <-startSignal + if !canStart { + log.Info("DeleteCatalogFile: received stop signal") + return + } + log.Info("DeleteCatalogFile: start deleting file from minio, database and milvus") + allPass := true + // Delete the file from MinIO objectPaths := []string{} - // kb file in minio + // Add the knowledge base file in MinIO to the list of objects to delete objectPaths = append(objectPaths, files[0].Destination) - // converted file in minio + // Add the converted file in MinIO to the list of objects to delete cf, err := ph.service.Repository.GetConvertedFileByFileUID(ctx, fUID) - if err == nil { + if err != nil { + if err != gorm.ErrRecordNotFound { + log.Error("failed to get converted file by file uid", zap.Error(err)) + allPass = false + } + } else if cf != nil { objectPaths = append(objectPaths, cf.Destination) } - // chunks in minio - chunks, _ := ph.service.Repository.ListChunksByKbFileUID(ctx, fUID) - if len(chunks) > 0 { + // Add the chunks in MinIO to the list of objects to delete + chunks, err := ph.service.Repository.ListChunksByKbFileUID(ctx, fUID) + if err != nil { + log.Error("failed to get chunks by kb file uid", zap.Error(err)) + allPass = false + } else if len(chunks) > 0 { for _, chunk := range chunks { objectPaths = append(objectPaths, chunk.ContentDest) } } - // delete the embeddings in milvus(need to delete first) + // Delete the embeddings in Milvus (this better to be done first) embUIDs := []string{} embeddings, _ := ph.service.Repository.ListEmbeddingsByKbFileUID(ctx, fUID) for _, emb := range embeddings { embUIDs = append(embUIDs, emb.UID.String()) } - _ = ph.service.MilvusClient.DeleteEmbeddingsInKb(ctx, files[0].KnowledgeBaseUID.String(), embUIDs) - - _ = ph.service.MinIO.DeleteFiles(ctx, objectPaths) - // delete the converted file in postgreSQL - _ = ph.service.Repository.HardDeleteConvertedFileByFileUID(ctx, fUID) - // delete the chunks in postgreSQL - _ = ph.service.Repository.HardDeleteChunksByKbFileUID(ctx, fUID) - // delete the embeddings in postgreSQL - _ = ph.service.Repository.HardDeleteEmbeddingsByKbFileUID(ctx, fUID) - // print success message and file uid - log.Info("Successfully deleted file from minio, database and milvus", zap.String("file_uid", fUID.String())) + err = ph.service.MilvusClient.DeleteEmbeddingsInKb(ctx, files[0].KnowledgeBaseUID.String(), embUIDs) + if err != nil { + log.Error("failed to delete embeddings in milvus", zap.Error(err)) + allPass = false + } + + // Delete the files in MinIO + errChan := ph.service.MinIO.DeleteFiles(ctx, objectPaths) + for err := range errChan { + if err != nil { + log.Error("failed to delete files in minio", zap.Error(err)) + allPass = false + } + } + // Delete the converted file in PostgreSQL + err = ph.service.Repository.HardDeleteConvertedFileByFileUID(ctx, fUID) + if err != nil { + log.Error("failed to delete converted file in postgreSQL", zap.Error(err)) + allPass = false + } + // Delete the chunks in PostgreSQL + err = ph.service.Repository.HardDeleteChunksByKbFileUID(ctx, fUID) + if err != nil { + log.Error("failed to delete chunks in postgreSQL", zap.Error(err)) + allPass = false + } + // Delete the embeddings in PostgreSQL + err = ph.service.Repository.HardDeleteEmbeddingsByKbFileUID(ctx, fUID) + if err != nil { + log.Error("failed to delete embeddings in postgreSQL", zap.Error(err)) + allPass = false + } + if allPass { + log.Info("DeleteCatalogFile: successfully deleted file from minio, database and milvus", zap.String("file_uid", fUID.String())) + } else { + log.Error("DeleteCatalogFile: failed to delete file from minio, database and milvus", zap.String("file_uid", fUID.String())) + } }, "DeleteCatalogFile", ) - // delete the file in postgreSQL - err = ph.service.Repository.DeleteKnowledgeBaseFile(ctx, req.FileUid) - if err != nil { - return nil, err - } - // decrease catalog usage - err = ph.service.Repository.IncreaseKnowledgeBaseUsage(ctx, files[0].KnowledgeBaseUID.String(), int(-files[0].Size)) + err = ph.service.Repository.DeleteKnowledgeBaseFileAndDecreaseUsage(ctx, fUID) if err != nil { + log.Error("failed to delete knowledge base file and decrease usage", zap.Error(err)) + startSignal <- false return nil, err } + // start the background deletion + startSignal <- true return &artifactpb.DeleteCatalogFileResponse{ - FileUid: req.FileUid, + FileUid: fUID.String(), }, nil } @@ -425,8 +469,7 @@ func (ph *PublicHandler) ProcessCatalogFiles(ctx context.Context, req *artifactp kbfs, err := ph.service.Repository.GetKnowledgeBaseFilesByFileUIDs(ctx, fileUUIDs) if err != nil { return nil, err - } - if len(kbfs) == 0 { + } else if len(kbfs) == 0 { return nil, fmt.Errorf("file not found. err: %w", customerror.ErrNotFound) } // check write permission for the catalog diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 7d77e9f..3c6b39e 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -2,54 +2,58 @@ package logger import ( "context" + "encoding/json" "os" "sync" + "github.com/instill-ai/artifact-backend/config" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" "go.uber.org/zap" + "go.uber.org/zap/buffer" "go.uber.org/zap/zapcore" - - "github.com/instill-ai/artifact-backend/config" ) var once sync.Once var core zapcore.Core // GetZapLogger returns an instance of zap logger +// GetZapLogger returns an instance of zap logger +// It configures the logger based on the application's debug mode and sets up appropriate log levels and output destinations. +// The function also adds a hook to inject logs into OpenTelemetry traces. func GetZapLogger(ctx context.Context) (*zap.Logger, error) { var err error once.Do(func() { - // debug and info level enabler + // Enable debug and info level logs debugInfoLevel := zap.LevelEnablerFunc(func(level zapcore.Level) bool { return level == zapcore.DebugLevel || level == zapcore.InfoLevel }) - // info level enabler + // Enable only info level logs infoLevel := zap.LevelEnablerFunc(func(level zapcore.Level) bool { return level == zapcore.InfoLevel }) - // warn, error and fatal level enabler + // Enable warn, error, and fatal level logs warnErrorFatalLevel := zap.LevelEnablerFunc(func(level zapcore.Level) bool { return level == zapcore.WarnLevel || level == zapcore.ErrorLevel || level == zapcore.FatalLevel }) - // write syncers + // Set up write syncers for stdout and stderr stdoutSyncer := zapcore.Lock(os.Stdout) stderrSyncer := zapcore.Lock(os.Stderr) - // tee core + // Configure the logger core based on debug mode if config.Config.Server.Debug { core = zapcore.NewTee( zapcore.NewCore( - zapcore.NewJSONEncoder(zap.NewDevelopmentEncoderConfig()), + NewColoredJSONEncoder(zapcore.NewJSONEncoder(getJSONEncoderConfig(true))), stdoutSyncer, debugInfoLevel, ), zapcore.NewCore( - zapcore.NewJSONEncoder(zap.NewDevelopmentEncoderConfig()), + NewColoredJSONEncoder(zapcore.NewJSONEncoder(getJSONEncoderConfig(true))), stderrSyncer, warnErrorFatalLevel, ), @@ -57,20 +61,20 @@ func GetZapLogger(ctx context.Context) (*zap.Logger, error) { } else { core = zapcore.NewTee( zapcore.NewCore( - zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), + NewColoredJSONEncoder(zapcore.NewJSONEncoder(getJSONEncoderConfig(false))), stdoutSyncer, infoLevel, ), zapcore.NewCore( - zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), + NewColoredJSONEncoder(zapcore.NewJSONEncoder(getJSONEncoderConfig(false))), stderrSyncer, warnErrorFatalLevel, ), ) } }) - // finally construct the logger with the tee core - // and add hooks to inject logs to traces + + // Construct the logger with the configured core and add hooks logger := zap.New(core).WithOptions( zap.Hooks(func(entry zapcore.Entry) error { span := trace.SpanFromContext(ctx) @@ -78,6 +82,7 @@ func GetZapLogger(ctx context.Context) (*zap.Logger, error) { return nil } + // Add log entry as an event to the current span span.AddEvent("log", trace.WithAttributes( attribute.KeyValue{ Key: "log.severity", @@ -88,8 +93,10 @@ func GetZapLogger(ctx context.Context) (*zap.Logger, error) { Value: attribute.StringValue(entry.Message), }, )) + + // Set span status based on log level if entry.Level >= zap.ErrorLevel { - span.SetStatus(codes.Error, string(entry.Message)) + span.SetStatus(codes.Error, entry.Message) } else { span.SetStatus(codes.Ok, "") } @@ -97,8 +104,59 @@ func GetZapLogger(ctx context.Context) (*zap.Logger, error) { return nil }), zap.AddCaller(), + // Uncomment the following line to add stack traces for error logs // zap.AddStacktrace(zapcore.ErrorLevel), - ) + ) return logger, err } + +func getJSONEncoderConfig(development bool) zapcore.EncoderConfig { + encoderConfig := zap.NewProductionEncoderConfig() + if development { + encoderConfig = zap.NewDevelopmentEncoderConfig() + } + encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder + encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder + return encoderConfig +} + +type ColoredJSONEncoder struct { + zapcore.Encoder +} + +func NewColoredJSONEncoder(encoder zapcore.Encoder) zapcore.Encoder { + return &ColoredJSONEncoder{Encoder: encoder} +} + +func (e *ColoredJSONEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error) { + buf, err := e.Encoder.EncodeEntry(entry, fields) + if err != nil { + return nil, err + } + + var logMap map[string]interface{} + err = json.Unmarshal(buf.Bytes(), &logMap) + if err != nil { + return buf, nil + } + + colorCode := "\x1b[37m" // Default to white + switch entry.Level { + case zapcore.DebugLevel: + colorCode = "\x1b[34m" // Blue + case zapcore.InfoLevel: + colorCode = "\x1b[32m" // Green + case zapcore.WarnLevel: + colorCode = "\x1b[33m" // Yellow + case zapcore.ErrorLevel: + colorCode = "\x1b[31m" // Red + case zapcore.FatalLevel: + colorCode = "\x1b[35m" // Magenta + } + coloredJSON := colorCode + buf.String() + "\x1b[0m" + + newBuf := buffer.NewPool().Get() + newBuf.AppendString(coloredJSON) + return newBuf, nil +} diff --git a/pkg/minio/minio.go b/pkg/minio/minio.go index cb176a4..a5a14a6 100644 --- a/pkg/minio/minio.go +++ b/pkg/minio/minio.go @@ -118,6 +118,7 @@ func (m *Minio) DeleteFile(ctx context.Context, filePathName string) (err error) // delete bunch of files from minio func (m *Minio) DeleteFiles(ctx context.Context, filePathNames []string) chan error { errCh := make(chan error, len(filePathNames)) + defer close(errCh) log, err := log.GetZapLogger(ctx) if err != nil { errCh <- err @@ -233,10 +234,10 @@ func (m *Minio) GetFilesByPaths(ctx context.Context, filePaths []string) ([]File // delete all files with the same prefix from MinIO func (m *Minio) DeleteFilesWithPrefix(ctx context.Context, prefix string) chan error { errCh := make(chan error) + defer close(errCh) log, err := log.GetZapLogger(ctx) if err != nil { errCh <- err - close(errCh) return errCh } @@ -266,10 +267,7 @@ func (m *Minio) DeleteFilesWithPrefix(ctx context.Context, prefix string) chan e } // Wait for all deletions to complete - go func() { - wg.Wait() - close(errCh) - }() + wg.Wait() return errCh } diff --git a/pkg/mock/repository_i_mock.gen.go b/pkg/mock/repository_i_mock.gen.go index 935b8cf..112fc6e 100644 --- a/pkg/mock/repository_i_mock.gen.go +++ b/pkg/mock/repository_i_mock.gen.go @@ -12,7 +12,8 @@ import ( "github.com/gojuno/minimock/v3" mm_repository "github.com/instill-ai/artifact-backend/pkg/repository" "github.com/instill-ai/artifact-backend/pkg/utils" - pb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" + "gorm.io/gorm" + pb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" ) // RepositoryIMock implements repository.RepositoryI @@ -62,11 +63,11 @@ type RepositoryIMock struct { beforeCreateMessageCounter uint64 CreateMessageMock mRepositoryIMockCreateMessage - funcDeleteAllConvertedFilesinKb func(ctx context.Context, kbUID uuid.UUID) (err error) - inspectFuncDeleteAllConvertedFilesinKb func(ctx context.Context, kbUID uuid.UUID) - afterDeleteAllConvertedFilesinKbCounter uint64 - beforeDeleteAllConvertedFilesinKbCounter uint64 - DeleteAllConvertedFilesinKbMock mRepositoryIMockDeleteAllConvertedFilesinKb + funcDeleteAllConvertedFilesInKb func(ctx context.Context, kbUID uuid.UUID) (err error) + inspectFuncDeleteAllConvertedFilesInKb func(ctx context.Context, kbUID uuid.UUID) + afterDeleteAllConvertedFilesInKbCounter uint64 + beforeDeleteAllConvertedFilesInKbCounter uint64 + DeleteAllConvertedFilesInKbMock mRepositoryIMockDeleteAllConvertedFilesInKb funcDeleteAllKnowledgeBaseFiles func(ctx context.Context, kbUID string) (err error) inspectFuncDeleteAllKnowledgeBaseFiles func(ctx context.Context, kbUID string) @@ -122,6 +123,12 @@ type RepositoryIMock struct { beforeDeleteKnowledgeBaseFileCounter uint64 DeleteKnowledgeBaseFileMock mRepositoryIMockDeleteKnowledgeBaseFile + funcDeleteKnowledgeBaseFileAndDecreaseUsage func(ctx context.Context, fileUID uuid.UUID) (err error) + inspectFuncDeleteKnowledgeBaseFileAndDecreaseUsage func(ctx context.Context, fileUID uuid.UUID) + afterDeleteKnowledgeBaseFileAndDecreaseUsageCounter uint64 + beforeDeleteKnowledgeBaseFileAndDecreaseUsageCounter uint64 + DeleteKnowledgeBaseFileAndDecreaseUsageMock mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage + funcDeleteMessage func(ctx context.Context, messageUID uuid.UUID) (err error) inspectFuncDeleteMessage func(ctx context.Context, messageUID uuid.UUID) afterDeleteMessageCounter uint64 @@ -293,8 +300,8 @@ type RepositoryIMock struct { beforeHardDeleteEmbeddingsByKbUIDCounter uint64 HardDeleteEmbeddingsByKbUIDMock mRepositoryIMockHardDeleteEmbeddingsByKbUID - funcIncreaseKnowledgeBaseUsage func(ctx context.Context, kbUID string, amount int) (err error) - inspectFuncIncreaseKnowledgeBaseUsage func(ctx context.Context, kbUID string, amount int) + funcIncreaseKnowledgeBaseUsage func(ctx context.Context, tx *gorm.DB, kbUID string, amount int) (err error) + inspectFuncIncreaseKnowledgeBaseUsage func(ctx context.Context, tx *gorm.DB, kbUID string, amount int) afterIncreaseKnowledgeBaseUsageCounter uint64 beforeIncreaseKnowledgeBaseUsageCounter uint64 IncreaseKnowledgeBaseUsageMock mRepositoryIMockIncreaseKnowledgeBaseUsage @@ -447,8 +454,8 @@ func NewRepositoryIMock(t minimock.Tester) *RepositoryIMock { m.CreateMessageMock = mRepositoryIMockCreateMessage{mock: m} m.CreateMessageMock.callArgs = []*RepositoryIMockCreateMessageParams{} - m.DeleteAllConvertedFilesinKbMock = mRepositoryIMockDeleteAllConvertedFilesinKb{mock: m} - m.DeleteAllConvertedFilesinKbMock.callArgs = []*RepositoryIMockDeleteAllConvertedFilesinKbParams{} + m.DeleteAllConvertedFilesInKbMock = mRepositoryIMockDeleteAllConvertedFilesInKb{mock: m} + m.DeleteAllConvertedFilesInKbMock.callArgs = []*RepositoryIMockDeleteAllConvertedFilesInKbParams{} m.DeleteAllKnowledgeBaseFilesMock = mRepositoryIMockDeleteAllKnowledgeBaseFiles{mock: m} m.DeleteAllKnowledgeBaseFilesMock.callArgs = []*RepositoryIMockDeleteAllKnowledgeBaseFilesParams{} @@ -477,6 +484,9 @@ func NewRepositoryIMock(t minimock.Tester) *RepositoryIMock { m.DeleteKnowledgeBaseFileMock = mRepositoryIMockDeleteKnowledgeBaseFile{mock: m} m.DeleteKnowledgeBaseFileMock.callArgs = []*RepositoryIMockDeleteKnowledgeBaseFileParams{} + m.DeleteKnowledgeBaseFileAndDecreaseUsageMock = mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage{mock: m} + m.DeleteKnowledgeBaseFileAndDecreaseUsageMock.callArgs = []*RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParams{} + m.DeleteMessageMock = mRepositoryIMockDeleteMessage{mock: m} m.DeleteMessageMock.callArgs = []*RepositoryIMockDeleteMessageParams{} @@ -2555,307 +2565,307 @@ func (m *RepositoryIMock) MinimockCreateMessageInspect() { } } -type mRepositoryIMockDeleteAllConvertedFilesinKb struct { +type mRepositoryIMockDeleteAllConvertedFilesInKb struct { mock *RepositoryIMock - defaultExpectation *RepositoryIMockDeleteAllConvertedFilesinKbExpectation - expectations []*RepositoryIMockDeleteAllConvertedFilesinKbExpectation + defaultExpectation *RepositoryIMockDeleteAllConvertedFilesInKbExpectation + expectations []*RepositoryIMockDeleteAllConvertedFilesInKbExpectation - callArgs []*RepositoryIMockDeleteAllConvertedFilesinKbParams + callArgs []*RepositoryIMockDeleteAllConvertedFilesInKbParams mutex sync.RWMutex expectedInvocations uint64 } -// RepositoryIMockDeleteAllConvertedFilesinKbExpectation specifies expectation struct of the RepositoryI.DeleteAllConvertedFilesinKb -type RepositoryIMockDeleteAllConvertedFilesinKbExpectation struct { +// RepositoryIMockDeleteAllConvertedFilesInKbExpectation specifies expectation struct of the RepositoryI.DeleteAllConvertedFilesInKb +type RepositoryIMockDeleteAllConvertedFilesInKbExpectation struct { mock *RepositoryIMock - params *RepositoryIMockDeleteAllConvertedFilesinKbParams - paramPtrs *RepositoryIMockDeleteAllConvertedFilesinKbParamPtrs - results *RepositoryIMockDeleteAllConvertedFilesinKbResults + params *RepositoryIMockDeleteAllConvertedFilesInKbParams + paramPtrs *RepositoryIMockDeleteAllConvertedFilesInKbParamPtrs + results *RepositoryIMockDeleteAllConvertedFilesInKbResults Counter uint64 } -// RepositoryIMockDeleteAllConvertedFilesinKbParams contains parameters of the RepositoryI.DeleteAllConvertedFilesinKb -type RepositoryIMockDeleteAllConvertedFilesinKbParams struct { +// RepositoryIMockDeleteAllConvertedFilesInKbParams contains parameters of the RepositoryI.DeleteAllConvertedFilesInKb +type RepositoryIMockDeleteAllConvertedFilesInKbParams struct { ctx context.Context kbUID uuid.UUID } -// RepositoryIMockDeleteAllConvertedFilesinKbParamPtrs contains pointers to parameters of the RepositoryI.DeleteAllConvertedFilesinKb -type RepositoryIMockDeleteAllConvertedFilesinKbParamPtrs struct { +// RepositoryIMockDeleteAllConvertedFilesInKbParamPtrs contains pointers to parameters of the RepositoryI.DeleteAllConvertedFilesInKb +type RepositoryIMockDeleteAllConvertedFilesInKbParamPtrs struct { ctx *context.Context kbUID *uuid.UUID } -// RepositoryIMockDeleteAllConvertedFilesinKbResults contains results of the RepositoryI.DeleteAllConvertedFilesinKb -type RepositoryIMockDeleteAllConvertedFilesinKbResults struct { +// RepositoryIMockDeleteAllConvertedFilesInKbResults contains results of the RepositoryI.DeleteAllConvertedFilesInKb +type RepositoryIMockDeleteAllConvertedFilesInKbResults struct { err error } -// Expect sets up expected params for RepositoryI.DeleteAllConvertedFilesinKb -func (mmDeleteAllConvertedFilesinKb *mRepositoryIMockDeleteAllConvertedFilesinKb) Expect(ctx context.Context, kbUID uuid.UUID) *mRepositoryIMockDeleteAllConvertedFilesinKb { - if mmDeleteAllConvertedFilesinKb.mock.funcDeleteAllConvertedFilesinKb != nil { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesinKb mock is already set by Set") +// Expect sets up expected params for RepositoryI.DeleteAllConvertedFilesInKb +func (mmDeleteAllConvertedFilesInKb *mRepositoryIMockDeleteAllConvertedFilesInKb) Expect(ctx context.Context, kbUID uuid.UUID) *mRepositoryIMockDeleteAllConvertedFilesInKb { + if mmDeleteAllConvertedFilesInKb.mock.funcDeleteAllConvertedFilesInKb != nil { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesInKb mock is already set by Set") } - if mmDeleteAllConvertedFilesinKb.defaultExpectation == nil { - mmDeleteAllConvertedFilesinKb.defaultExpectation = &RepositoryIMockDeleteAllConvertedFilesinKbExpectation{} + if mmDeleteAllConvertedFilesInKb.defaultExpectation == nil { + mmDeleteAllConvertedFilesInKb.defaultExpectation = &RepositoryIMockDeleteAllConvertedFilesInKbExpectation{} } - if mmDeleteAllConvertedFilesinKb.defaultExpectation.paramPtrs != nil { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesinKb mock is already set by ExpectParams functions") + if mmDeleteAllConvertedFilesInKb.defaultExpectation.paramPtrs != nil { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesInKb mock is already set by ExpectParams functions") } - mmDeleteAllConvertedFilesinKb.defaultExpectation.params = &RepositoryIMockDeleteAllConvertedFilesinKbParams{ctx, kbUID} - for _, e := range mmDeleteAllConvertedFilesinKb.expectations { - if minimock.Equal(e.params, mmDeleteAllConvertedFilesinKb.defaultExpectation.params) { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteAllConvertedFilesinKb.defaultExpectation.params) + mmDeleteAllConvertedFilesInKb.defaultExpectation.params = &RepositoryIMockDeleteAllConvertedFilesInKbParams{ctx, kbUID} + for _, e := range mmDeleteAllConvertedFilesInKb.expectations { + if minimock.Equal(e.params, mmDeleteAllConvertedFilesInKb.defaultExpectation.params) { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteAllConvertedFilesInKb.defaultExpectation.params) } } - return mmDeleteAllConvertedFilesinKb + return mmDeleteAllConvertedFilesInKb } -// ExpectCtxParam1 sets up expected param ctx for RepositoryI.DeleteAllConvertedFilesinKb -func (mmDeleteAllConvertedFilesinKb *mRepositoryIMockDeleteAllConvertedFilesinKb) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockDeleteAllConvertedFilesinKb { - if mmDeleteAllConvertedFilesinKb.mock.funcDeleteAllConvertedFilesinKb != nil { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesinKb mock is already set by Set") +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.DeleteAllConvertedFilesInKb +func (mmDeleteAllConvertedFilesInKb *mRepositoryIMockDeleteAllConvertedFilesInKb) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockDeleteAllConvertedFilesInKb { + if mmDeleteAllConvertedFilesInKb.mock.funcDeleteAllConvertedFilesInKb != nil { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesInKb mock is already set by Set") } - if mmDeleteAllConvertedFilesinKb.defaultExpectation == nil { - mmDeleteAllConvertedFilesinKb.defaultExpectation = &RepositoryIMockDeleteAllConvertedFilesinKbExpectation{} + if mmDeleteAllConvertedFilesInKb.defaultExpectation == nil { + mmDeleteAllConvertedFilesInKb.defaultExpectation = &RepositoryIMockDeleteAllConvertedFilesInKbExpectation{} } - if mmDeleteAllConvertedFilesinKb.defaultExpectation.params != nil { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesinKb mock is already set by Expect") + if mmDeleteAllConvertedFilesInKb.defaultExpectation.params != nil { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesInKb mock is already set by Expect") } - if mmDeleteAllConvertedFilesinKb.defaultExpectation.paramPtrs == nil { - mmDeleteAllConvertedFilesinKb.defaultExpectation.paramPtrs = &RepositoryIMockDeleteAllConvertedFilesinKbParamPtrs{} + if mmDeleteAllConvertedFilesInKb.defaultExpectation.paramPtrs == nil { + mmDeleteAllConvertedFilesInKb.defaultExpectation.paramPtrs = &RepositoryIMockDeleteAllConvertedFilesInKbParamPtrs{} } - mmDeleteAllConvertedFilesinKb.defaultExpectation.paramPtrs.ctx = &ctx + mmDeleteAllConvertedFilesInKb.defaultExpectation.paramPtrs.ctx = &ctx - return mmDeleteAllConvertedFilesinKb + return mmDeleteAllConvertedFilesInKb } -// ExpectKbUIDParam2 sets up expected param kbUID for RepositoryI.DeleteAllConvertedFilesinKb -func (mmDeleteAllConvertedFilesinKb *mRepositoryIMockDeleteAllConvertedFilesinKb) ExpectKbUIDParam2(kbUID uuid.UUID) *mRepositoryIMockDeleteAllConvertedFilesinKb { - if mmDeleteAllConvertedFilesinKb.mock.funcDeleteAllConvertedFilesinKb != nil { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesinKb mock is already set by Set") +// ExpectKbUIDParam2 sets up expected param kbUID for RepositoryI.DeleteAllConvertedFilesInKb +func (mmDeleteAllConvertedFilesInKb *mRepositoryIMockDeleteAllConvertedFilesInKb) ExpectKbUIDParam2(kbUID uuid.UUID) *mRepositoryIMockDeleteAllConvertedFilesInKb { + if mmDeleteAllConvertedFilesInKb.mock.funcDeleteAllConvertedFilesInKb != nil { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesInKb mock is already set by Set") } - if mmDeleteAllConvertedFilesinKb.defaultExpectation == nil { - mmDeleteAllConvertedFilesinKb.defaultExpectation = &RepositoryIMockDeleteAllConvertedFilesinKbExpectation{} + if mmDeleteAllConvertedFilesInKb.defaultExpectation == nil { + mmDeleteAllConvertedFilesInKb.defaultExpectation = &RepositoryIMockDeleteAllConvertedFilesInKbExpectation{} } - if mmDeleteAllConvertedFilesinKb.defaultExpectation.params != nil { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesinKb mock is already set by Expect") + if mmDeleteAllConvertedFilesInKb.defaultExpectation.params != nil { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesInKb mock is already set by Expect") } - if mmDeleteAllConvertedFilesinKb.defaultExpectation.paramPtrs == nil { - mmDeleteAllConvertedFilesinKb.defaultExpectation.paramPtrs = &RepositoryIMockDeleteAllConvertedFilesinKbParamPtrs{} + if mmDeleteAllConvertedFilesInKb.defaultExpectation.paramPtrs == nil { + mmDeleteAllConvertedFilesInKb.defaultExpectation.paramPtrs = &RepositoryIMockDeleteAllConvertedFilesInKbParamPtrs{} } - mmDeleteAllConvertedFilesinKb.defaultExpectation.paramPtrs.kbUID = &kbUID + mmDeleteAllConvertedFilesInKb.defaultExpectation.paramPtrs.kbUID = &kbUID - return mmDeleteAllConvertedFilesinKb + return mmDeleteAllConvertedFilesInKb } -// Inspect accepts an inspector function that has same arguments as the RepositoryI.DeleteAllConvertedFilesinKb -func (mmDeleteAllConvertedFilesinKb *mRepositoryIMockDeleteAllConvertedFilesinKb) Inspect(f func(ctx context.Context, kbUID uuid.UUID)) *mRepositoryIMockDeleteAllConvertedFilesinKb { - if mmDeleteAllConvertedFilesinKb.mock.inspectFuncDeleteAllConvertedFilesinKb != nil { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.DeleteAllConvertedFilesinKb") +// Inspect accepts an inspector function that has same arguments as the RepositoryI.DeleteAllConvertedFilesInKb +func (mmDeleteAllConvertedFilesInKb *mRepositoryIMockDeleteAllConvertedFilesInKb) Inspect(f func(ctx context.Context, kbUID uuid.UUID)) *mRepositoryIMockDeleteAllConvertedFilesInKb { + if mmDeleteAllConvertedFilesInKb.mock.inspectFuncDeleteAllConvertedFilesInKb != nil { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.DeleteAllConvertedFilesInKb") } - mmDeleteAllConvertedFilesinKb.mock.inspectFuncDeleteAllConvertedFilesinKb = f + mmDeleteAllConvertedFilesInKb.mock.inspectFuncDeleteAllConvertedFilesInKb = f - return mmDeleteAllConvertedFilesinKb + return mmDeleteAllConvertedFilesInKb } -// Return sets up results that will be returned by RepositoryI.DeleteAllConvertedFilesinKb -func (mmDeleteAllConvertedFilesinKb *mRepositoryIMockDeleteAllConvertedFilesinKb) Return(err error) *RepositoryIMock { - if mmDeleteAllConvertedFilesinKb.mock.funcDeleteAllConvertedFilesinKb != nil { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesinKb mock is already set by Set") +// Return sets up results that will be returned by RepositoryI.DeleteAllConvertedFilesInKb +func (mmDeleteAllConvertedFilesInKb *mRepositoryIMockDeleteAllConvertedFilesInKb) Return(err error) *RepositoryIMock { + if mmDeleteAllConvertedFilesInKb.mock.funcDeleteAllConvertedFilesInKb != nil { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesInKb mock is already set by Set") } - if mmDeleteAllConvertedFilesinKb.defaultExpectation == nil { - mmDeleteAllConvertedFilesinKb.defaultExpectation = &RepositoryIMockDeleteAllConvertedFilesinKbExpectation{mock: mmDeleteAllConvertedFilesinKb.mock} + if mmDeleteAllConvertedFilesInKb.defaultExpectation == nil { + mmDeleteAllConvertedFilesInKb.defaultExpectation = &RepositoryIMockDeleteAllConvertedFilesInKbExpectation{mock: mmDeleteAllConvertedFilesInKb.mock} } - mmDeleteAllConvertedFilesinKb.defaultExpectation.results = &RepositoryIMockDeleteAllConvertedFilesinKbResults{err} - return mmDeleteAllConvertedFilesinKb.mock + mmDeleteAllConvertedFilesInKb.defaultExpectation.results = &RepositoryIMockDeleteAllConvertedFilesInKbResults{err} + return mmDeleteAllConvertedFilesInKb.mock } -// Set uses given function f to mock the RepositoryI.DeleteAllConvertedFilesinKb method -func (mmDeleteAllConvertedFilesinKb *mRepositoryIMockDeleteAllConvertedFilesinKb) Set(f func(ctx context.Context, kbUID uuid.UUID) (err error)) *RepositoryIMock { - if mmDeleteAllConvertedFilesinKb.defaultExpectation != nil { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("Default expectation is already set for the RepositoryI.DeleteAllConvertedFilesinKb method") +// Set uses given function f to mock the RepositoryI.DeleteAllConvertedFilesInKb method +func (mmDeleteAllConvertedFilesInKb *mRepositoryIMockDeleteAllConvertedFilesInKb) Set(f func(ctx context.Context, kbUID uuid.UUID) (err error)) *RepositoryIMock { + if mmDeleteAllConvertedFilesInKb.defaultExpectation != nil { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("Default expectation is already set for the RepositoryI.DeleteAllConvertedFilesInKb method") } - if len(mmDeleteAllConvertedFilesinKb.expectations) > 0 { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("Some expectations are already set for the RepositoryI.DeleteAllConvertedFilesinKb method") + if len(mmDeleteAllConvertedFilesInKb.expectations) > 0 { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("Some expectations are already set for the RepositoryI.DeleteAllConvertedFilesInKb method") } - mmDeleteAllConvertedFilesinKb.mock.funcDeleteAllConvertedFilesinKb = f - return mmDeleteAllConvertedFilesinKb.mock + mmDeleteAllConvertedFilesInKb.mock.funcDeleteAllConvertedFilesInKb = f + return mmDeleteAllConvertedFilesInKb.mock } -// When sets expectation for the RepositoryI.DeleteAllConvertedFilesinKb which will trigger the result defined by the following +// When sets expectation for the RepositoryI.DeleteAllConvertedFilesInKb which will trigger the result defined by the following // Then helper -func (mmDeleteAllConvertedFilesinKb *mRepositoryIMockDeleteAllConvertedFilesinKb) When(ctx context.Context, kbUID uuid.UUID) *RepositoryIMockDeleteAllConvertedFilesinKbExpectation { - if mmDeleteAllConvertedFilesinKb.mock.funcDeleteAllConvertedFilesinKb != nil { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesinKb mock is already set by Set") +func (mmDeleteAllConvertedFilesInKb *mRepositoryIMockDeleteAllConvertedFilesInKb) When(ctx context.Context, kbUID uuid.UUID) *RepositoryIMockDeleteAllConvertedFilesInKbExpectation { + if mmDeleteAllConvertedFilesInKb.mock.funcDeleteAllConvertedFilesInKb != nil { + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("RepositoryIMock.DeleteAllConvertedFilesInKb mock is already set by Set") } - expectation := &RepositoryIMockDeleteAllConvertedFilesinKbExpectation{ - mock: mmDeleteAllConvertedFilesinKb.mock, - params: &RepositoryIMockDeleteAllConvertedFilesinKbParams{ctx, kbUID}, + expectation := &RepositoryIMockDeleteAllConvertedFilesInKbExpectation{ + mock: mmDeleteAllConvertedFilesInKb.mock, + params: &RepositoryIMockDeleteAllConvertedFilesInKbParams{ctx, kbUID}, } - mmDeleteAllConvertedFilesinKb.expectations = append(mmDeleteAllConvertedFilesinKb.expectations, expectation) + mmDeleteAllConvertedFilesInKb.expectations = append(mmDeleteAllConvertedFilesInKb.expectations, expectation) return expectation } -// Then sets up RepositoryI.DeleteAllConvertedFilesinKb return parameters for the expectation previously defined by the When method -func (e *RepositoryIMockDeleteAllConvertedFilesinKbExpectation) Then(err error) *RepositoryIMock { - e.results = &RepositoryIMockDeleteAllConvertedFilesinKbResults{err} +// Then sets up RepositoryI.DeleteAllConvertedFilesInKb return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockDeleteAllConvertedFilesInKbExpectation) Then(err error) *RepositoryIMock { + e.results = &RepositoryIMockDeleteAllConvertedFilesInKbResults{err} return e.mock } -// Times sets number of times RepositoryI.DeleteAllConvertedFilesinKb should be invoked -func (mmDeleteAllConvertedFilesinKb *mRepositoryIMockDeleteAllConvertedFilesinKb) Times(n uint64) *mRepositoryIMockDeleteAllConvertedFilesinKb { +// Times sets number of times RepositoryI.DeleteAllConvertedFilesInKb should be invoked +func (mmDeleteAllConvertedFilesInKb *mRepositoryIMockDeleteAllConvertedFilesInKb) Times(n uint64) *mRepositoryIMockDeleteAllConvertedFilesInKb { if n == 0 { - mmDeleteAllConvertedFilesinKb.mock.t.Fatalf("Times of RepositoryIMock.DeleteAllConvertedFilesinKb mock can not be zero") + mmDeleteAllConvertedFilesInKb.mock.t.Fatalf("Times of RepositoryIMock.DeleteAllConvertedFilesInKb mock can not be zero") } - mm_atomic.StoreUint64(&mmDeleteAllConvertedFilesinKb.expectedInvocations, n) - return mmDeleteAllConvertedFilesinKb + mm_atomic.StoreUint64(&mmDeleteAllConvertedFilesInKb.expectedInvocations, n) + return mmDeleteAllConvertedFilesInKb } -func (mmDeleteAllConvertedFilesinKb *mRepositoryIMockDeleteAllConvertedFilesinKb) invocationsDone() bool { - if len(mmDeleteAllConvertedFilesinKb.expectations) == 0 && mmDeleteAllConvertedFilesinKb.defaultExpectation == nil && mmDeleteAllConvertedFilesinKb.mock.funcDeleteAllConvertedFilesinKb == nil { +func (mmDeleteAllConvertedFilesInKb *mRepositoryIMockDeleteAllConvertedFilesInKb) invocationsDone() bool { + if len(mmDeleteAllConvertedFilesInKb.expectations) == 0 && mmDeleteAllConvertedFilesInKb.defaultExpectation == nil && mmDeleteAllConvertedFilesInKb.mock.funcDeleteAllConvertedFilesInKb == nil { return true } - totalInvocations := mm_atomic.LoadUint64(&mmDeleteAllConvertedFilesinKb.mock.afterDeleteAllConvertedFilesinKbCounter) - expectedInvocations := mm_atomic.LoadUint64(&mmDeleteAllConvertedFilesinKb.expectedInvocations) + totalInvocations := mm_atomic.LoadUint64(&mmDeleteAllConvertedFilesInKb.mock.afterDeleteAllConvertedFilesInKbCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmDeleteAllConvertedFilesInKb.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } -// DeleteAllConvertedFilesinKb implements repository.RepositoryI -func (mmDeleteAllConvertedFilesinKb *RepositoryIMock) DeleteAllConvertedFilesinKb(ctx context.Context, kbUID uuid.UUID) (err error) { - mm_atomic.AddUint64(&mmDeleteAllConvertedFilesinKb.beforeDeleteAllConvertedFilesinKbCounter, 1) - defer mm_atomic.AddUint64(&mmDeleteAllConvertedFilesinKb.afterDeleteAllConvertedFilesinKbCounter, 1) +// DeleteAllConvertedFilesInKb implements repository.RepositoryI +func (mmDeleteAllConvertedFilesInKb *RepositoryIMock) DeleteAllConvertedFilesInKb(ctx context.Context, kbUID uuid.UUID) (err error) { + mm_atomic.AddUint64(&mmDeleteAllConvertedFilesInKb.beforeDeleteAllConvertedFilesInKbCounter, 1) + defer mm_atomic.AddUint64(&mmDeleteAllConvertedFilesInKb.afterDeleteAllConvertedFilesInKbCounter, 1) - if mmDeleteAllConvertedFilesinKb.inspectFuncDeleteAllConvertedFilesinKb != nil { - mmDeleteAllConvertedFilesinKb.inspectFuncDeleteAllConvertedFilesinKb(ctx, kbUID) + if mmDeleteAllConvertedFilesInKb.inspectFuncDeleteAllConvertedFilesInKb != nil { + mmDeleteAllConvertedFilesInKb.inspectFuncDeleteAllConvertedFilesInKb(ctx, kbUID) } - mm_params := RepositoryIMockDeleteAllConvertedFilesinKbParams{ctx, kbUID} + mm_params := RepositoryIMockDeleteAllConvertedFilesInKbParams{ctx, kbUID} // Record call args - mmDeleteAllConvertedFilesinKb.DeleteAllConvertedFilesinKbMock.mutex.Lock() - mmDeleteAllConvertedFilesinKb.DeleteAllConvertedFilesinKbMock.callArgs = append(mmDeleteAllConvertedFilesinKb.DeleteAllConvertedFilesinKbMock.callArgs, &mm_params) - mmDeleteAllConvertedFilesinKb.DeleteAllConvertedFilesinKbMock.mutex.Unlock() + mmDeleteAllConvertedFilesInKb.DeleteAllConvertedFilesInKbMock.mutex.Lock() + mmDeleteAllConvertedFilesInKb.DeleteAllConvertedFilesInKbMock.callArgs = append(mmDeleteAllConvertedFilesInKb.DeleteAllConvertedFilesInKbMock.callArgs, &mm_params) + mmDeleteAllConvertedFilesInKb.DeleteAllConvertedFilesInKbMock.mutex.Unlock() - for _, e := range mmDeleteAllConvertedFilesinKb.DeleteAllConvertedFilesinKbMock.expectations { + for _, e := range mmDeleteAllConvertedFilesInKb.DeleteAllConvertedFilesInKbMock.expectations { if minimock.Equal(*e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) return e.results.err } } - if mmDeleteAllConvertedFilesinKb.DeleteAllConvertedFilesinKbMock.defaultExpectation != nil { - mm_atomic.AddUint64(&mmDeleteAllConvertedFilesinKb.DeleteAllConvertedFilesinKbMock.defaultExpectation.Counter, 1) - mm_want := mmDeleteAllConvertedFilesinKb.DeleteAllConvertedFilesinKbMock.defaultExpectation.params - mm_want_ptrs := mmDeleteAllConvertedFilesinKb.DeleteAllConvertedFilesinKbMock.defaultExpectation.paramPtrs + if mmDeleteAllConvertedFilesInKb.DeleteAllConvertedFilesInKbMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmDeleteAllConvertedFilesInKb.DeleteAllConvertedFilesInKbMock.defaultExpectation.Counter, 1) + mm_want := mmDeleteAllConvertedFilesInKb.DeleteAllConvertedFilesInKbMock.defaultExpectation.params + mm_want_ptrs := mmDeleteAllConvertedFilesInKb.DeleteAllConvertedFilesInKbMock.defaultExpectation.paramPtrs - mm_got := RepositoryIMockDeleteAllConvertedFilesinKbParams{ctx, kbUID} + mm_got := RepositoryIMockDeleteAllConvertedFilesInKbParams{ctx, kbUID} if mm_want_ptrs != nil { if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { - mmDeleteAllConvertedFilesinKb.t.Errorf("RepositoryIMock.DeleteAllConvertedFilesinKb 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)) + mmDeleteAllConvertedFilesInKb.t.Errorf("RepositoryIMock.DeleteAllConvertedFilesInKb 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.kbUID != nil && !minimock.Equal(*mm_want_ptrs.kbUID, mm_got.kbUID) { - mmDeleteAllConvertedFilesinKb.t.Errorf("RepositoryIMock.DeleteAllConvertedFilesinKb got unexpected parameter kbUID, want: %#v, got: %#v%s\n", *mm_want_ptrs.kbUID, mm_got.kbUID, minimock.Diff(*mm_want_ptrs.kbUID, mm_got.kbUID)) + mmDeleteAllConvertedFilesInKb.t.Errorf("RepositoryIMock.DeleteAllConvertedFilesInKb got unexpected parameter kbUID, want: %#v, got: %#v%s\n", *mm_want_ptrs.kbUID, mm_got.kbUID, minimock.Diff(*mm_want_ptrs.kbUID, mm_got.kbUID)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { - mmDeleteAllConvertedFilesinKb.t.Errorf("RepositoryIMock.DeleteAllConvertedFilesinKb got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + mmDeleteAllConvertedFilesInKb.t.Errorf("RepositoryIMock.DeleteAllConvertedFilesInKb got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } - mm_results := mmDeleteAllConvertedFilesinKb.DeleteAllConvertedFilesinKbMock.defaultExpectation.results + mm_results := mmDeleteAllConvertedFilesInKb.DeleteAllConvertedFilesInKbMock.defaultExpectation.results if mm_results == nil { - mmDeleteAllConvertedFilesinKb.t.Fatal("No results are set for the RepositoryIMock.DeleteAllConvertedFilesinKb") + mmDeleteAllConvertedFilesInKb.t.Fatal("No results are set for the RepositoryIMock.DeleteAllConvertedFilesInKb") } return (*mm_results).err } - if mmDeleteAllConvertedFilesinKb.funcDeleteAllConvertedFilesinKb != nil { - return mmDeleteAllConvertedFilesinKb.funcDeleteAllConvertedFilesinKb(ctx, kbUID) + if mmDeleteAllConvertedFilesInKb.funcDeleteAllConvertedFilesInKb != nil { + return mmDeleteAllConvertedFilesInKb.funcDeleteAllConvertedFilesInKb(ctx, kbUID) } - mmDeleteAllConvertedFilesinKb.t.Fatalf("Unexpected call to RepositoryIMock.DeleteAllConvertedFilesinKb. %v %v", ctx, kbUID) + mmDeleteAllConvertedFilesInKb.t.Fatalf("Unexpected call to RepositoryIMock.DeleteAllConvertedFilesInKb. %v %v", ctx, kbUID) return } -// DeleteAllConvertedFilesinKbAfterCounter returns a count of finished RepositoryIMock.DeleteAllConvertedFilesinKb invocations -func (mmDeleteAllConvertedFilesinKb *RepositoryIMock) DeleteAllConvertedFilesinKbAfterCounter() uint64 { - return mm_atomic.LoadUint64(&mmDeleteAllConvertedFilesinKb.afterDeleteAllConvertedFilesinKbCounter) +// DeleteAllConvertedFilesInKbAfterCounter returns a count of finished RepositoryIMock.DeleteAllConvertedFilesInKb invocations +func (mmDeleteAllConvertedFilesInKb *RepositoryIMock) DeleteAllConvertedFilesInKbAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmDeleteAllConvertedFilesInKb.afterDeleteAllConvertedFilesInKbCounter) } -// DeleteAllConvertedFilesinKbBeforeCounter returns a count of RepositoryIMock.DeleteAllConvertedFilesinKb invocations -func (mmDeleteAllConvertedFilesinKb *RepositoryIMock) DeleteAllConvertedFilesinKbBeforeCounter() uint64 { - return mm_atomic.LoadUint64(&mmDeleteAllConvertedFilesinKb.beforeDeleteAllConvertedFilesinKbCounter) +// DeleteAllConvertedFilesInKbBeforeCounter returns a count of RepositoryIMock.DeleteAllConvertedFilesInKb invocations +func (mmDeleteAllConvertedFilesInKb *RepositoryIMock) DeleteAllConvertedFilesInKbBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmDeleteAllConvertedFilesInKb.beforeDeleteAllConvertedFilesInKbCounter) } -// Calls returns a list of arguments used in each call to RepositoryIMock.DeleteAllConvertedFilesinKb. +// Calls returns a list of arguments used in each call to RepositoryIMock.DeleteAllConvertedFilesInKb. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) -func (mmDeleteAllConvertedFilesinKb *mRepositoryIMockDeleteAllConvertedFilesinKb) Calls() []*RepositoryIMockDeleteAllConvertedFilesinKbParams { - mmDeleteAllConvertedFilesinKb.mutex.RLock() +func (mmDeleteAllConvertedFilesInKb *mRepositoryIMockDeleteAllConvertedFilesInKb) Calls() []*RepositoryIMockDeleteAllConvertedFilesInKbParams { + mmDeleteAllConvertedFilesInKb.mutex.RLock() - argCopy := make([]*RepositoryIMockDeleteAllConvertedFilesinKbParams, len(mmDeleteAllConvertedFilesinKb.callArgs)) - copy(argCopy, mmDeleteAllConvertedFilesinKb.callArgs) + argCopy := make([]*RepositoryIMockDeleteAllConvertedFilesInKbParams, len(mmDeleteAllConvertedFilesInKb.callArgs)) + copy(argCopy, mmDeleteAllConvertedFilesInKb.callArgs) - mmDeleteAllConvertedFilesinKb.mutex.RUnlock() + mmDeleteAllConvertedFilesInKb.mutex.RUnlock() return argCopy } -// MinimockDeleteAllConvertedFilesinKbDone returns true if the count of the DeleteAllConvertedFilesinKb invocations corresponds +// MinimockDeleteAllConvertedFilesInKbDone returns true if the count of the DeleteAllConvertedFilesInKb invocations corresponds // the number of defined expectations -func (m *RepositoryIMock) MinimockDeleteAllConvertedFilesinKbDone() bool { - for _, e := range m.DeleteAllConvertedFilesinKbMock.expectations { +func (m *RepositoryIMock) MinimockDeleteAllConvertedFilesInKbDone() bool { + for _, e := range m.DeleteAllConvertedFilesInKbMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } - return m.DeleteAllConvertedFilesinKbMock.invocationsDone() + return m.DeleteAllConvertedFilesInKbMock.invocationsDone() } -// MinimockDeleteAllConvertedFilesinKbInspect logs each unmet expectation -func (m *RepositoryIMock) MinimockDeleteAllConvertedFilesinKbInspect() { - for _, e := range m.DeleteAllConvertedFilesinKbMock.expectations { +// MinimockDeleteAllConvertedFilesInKbInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockDeleteAllConvertedFilesInKbInspect() { + for _, e := range m.DeleteAllConvertedFilesInKbMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { - m.t.Errorf("Expected call to RepositoryIMock.DeleteAllConvertedFilesinKb with params: %#v", *e.params) + m.t.Errorf("Expected call to RepositoryIMock.DeleteAllConvertedFilesInKb with params: %#v", *e.params) } } - afterDeleteAllConvertedFilesinKbCounter := mm_atomic.LoadUint64(&m.afterDeleteAllConvertedFilesinKbCounter) + afterDeleteAllConvertedFilesInKbCounter := mm_atomic.LoadUint64(&m.afterDeleteAllConvertedFilesInKbCounter) // if default expectation was set then invocations count should be greater than zero - if m.DeleteAllConvertedFilesinKbMock.defaultExpectation != nil && afterDeleteAllConvertedFilesinKbCounter < 1 { - if m.DeleteAllConvertedFilesinKbMock.defaultExpectation.params == nil { - m.t.Error("Expected call to RepositoryIMock.DeleteAllConvertedFilesinKb") + if m.DeleteAllConvertedFilesInKbMock.defaultExpectation != nil && afterDeleteAllConvertedFilesInKbCounter < 1 { + if m.DeleteAllConvertedFilesInKbMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.DeleteAllConvertedFilesInKb") } else { - m.t.Errorf("Expected call to RepositoryIMock.DeleteAllConvertedFilesinKb with params: %#v", *m.DeleteAllConvertedFilesinKbMock.defaultExpectation.params) + m.t.Errorf("Expected call to RepositoryIMock.DeleteAllConvertedFilesInKb with params: %#v", *m.DeleteAllConvertedFilesInKbMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero - if m.funcDeleteAllConvertedFilesinKb != nil && afterDeleteAllConvertedFilesinKbCounter < 1 { - m.t.Error("Expected call to RepositoryIMock.DeleteAllConvertedFilesinKb") + if m.funcDeleteAllConvertedFilesInKb != nil && afterDeleteAllConvertedFilesInKbCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.DeleteAllConvertedFilesInKb") } - if !m.DeleteAllConvertedFilesinKbMock.invocationsDone() && afterDeleteAllConvertedFilesinKbCounter > 0 { - m.t.Errorf("Expected %d calls to RepositoryIMock.DeleteAllConvertedFilesinKb but found %d calls", - mm_atomic.LoadUint64(&m.DeleteAllConvertedFilesinKbMock.expectedInvocations), afterDeleteAllConvertedFilesinKbCounter) + if !m.DeleteAllConvertedFilesInKbMock.invocationsDone() && afterDeleteAllConvertedFilesInKbCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.DeleteAllConvertedFilesInKb but found %d calls", + mm_atomic.LoadUint64(&m.DeleteAllConvertedFilesInKbMock.expectedInvocations), afterDeleteAllConvertedFilesInKbCounter) } } @@ -5765,6 +5775,310 @@ func (m *RepositoryIMock) MinimockDeleteKnowledgeBaseFileInspect() { } } +type mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageExpectation + expectations []*RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageExpectation + + callArgs []*RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageExpectation specifies expectation struct of the RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage +type RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParams + paramPtrs *RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParamPtrs + results *RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageResults + Counter uint64 +} + +// RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParams contains parameters of the RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage +type RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParams struct { + ctx context.Context + fileUID uuid.UUID +} + +// RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParamPtrs contains pointers to parameters of the RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage +type RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParamPtrs struct { + ctx *context.Context + fileUID *uuid.UUID +} + +// RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageResults contains results of the RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage +type RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageResults struct { + err error +} + +// Expect sets up expected params for RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage) Expect(ctx context.Context, fileUID uuid.UUID) *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage { + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.funcDeleteKnowledgeBaseFileAndDecreaseUsage != nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage mock is already set by Set") + } + + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation == nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageExpectation{} + } + + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.paramPtrs != nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage mock is already set by ExpectParams functions") + } + + mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.params = &RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParams{ctx, fileUID} + for _, e := range mmDeleteKnowledgeBaseFileAndDecreaseUsage.expectations { + if minimock.Equal(e.params, mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.params) { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.params) + } + } + + return mmDeleteKnowledgeBaseFileAndDecreaseUsage +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage { + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.funcDeleteKnowledgeBaseFileAndDecreaseUsage != nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage mock is already set by Set") + } + + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation == nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageExpectation{} + } + + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.params != nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage mock is already set by Expect") + } + + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.paramPtrs == nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.paramPtrs = &RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParamPtrs{} + } + mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.paramPtrs.ctx = &ctx + + return mmDeleteKnowledgeBaseFileAndDecreaseUsage +} + +// ExpectFileUIDParam2 sets up expected param fileUID for RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage) ExpectFileUIDParam2(fileUID uuid.UUID) *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage { + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.funcDeleteKnowledgeBaseFileAndDecreaseUsage != nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage mock is already set by Set") + } + + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation == nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageExpectation{} + } + + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.params != nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage mock is already set by Expect") + } + + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.paramPtrs == nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.paramPtrs = &RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParamPtrs{} + } + mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.paramPtrs.fileUID = &fileUID + + return mmDeleteKnowledgeBaseFileAndDecreaseUsage +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage) Inspect(f func(ctx context.Context, fileUID uuid.UUID)) *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage { + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.inspectFuncDeleteKnowledgeBaseFileAndDecreaseUsage != nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage") + } + + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.inspectFuncDeleteKnowledgeBaseFileAndDecreaseUsage = f + + return mmDeleteKnowledgeBaseFileAndDecreaseUsage +} + +// Return sets up results that will be returned by RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage) Return(err error) *RepositoryIMock { + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.funcDeleteKnowledgeBaseFileAndDecreaseUsage != nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage mock is already set by Set") + } + + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation == nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageExpectation{mock: mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock} + } + mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation.results = &RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageResults{err} + return mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock +} + +// Set uses given function f to mock the RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage method +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage) Set(f func(ctx context.Context, fileUID uuid.UUID) (err error)) *RepositoryIMock { + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation != nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("Default expectation is already set for the RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage method") + } + + if len(mmDeleteKnowledgeBaseFileAndDecreaseUsage.expectations) > 0 { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("Some expectations are already set for the RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage method") + } + + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.funcDeleteKnowledgeBaseFileAndDecreaseUsage = f + return mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock +} + +// When sets expectation for the RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage which will trigger the result defined by the following +// Then helper +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage) When(ctx context.Context, fileUID uuid.UUID) *RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageExpectation { + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.funcDeleteKnowledgeBaseFileAndDecreaseUsage != nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage mock is already set by Set") + } + + expectation := &RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageExpectation{ + mock: mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock, + params: &RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParams{ctx, fileUID}, + } + mmDeleteKnowledgeBaseFileAndDecreaseUsage.expectations = append(mmDeleteKnowledgeBaseFileAndDecreaseUsage.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageExpectation) Then(err error) *RepositoryIMock { + e.results = &RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageResults{err} + return e.mock +} + +// Times sets number of times RepositoryI.DeleteKnowledgeBaseFileAndDecreaseUsage should be invoked +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage) Times(n uint64) *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage { + if n == 0 { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.t.Fatalf("Times of RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage mock can not be zero") + } + mm_atomic.StoreUint64(&mmDeleteKnowledgeBaseFileAndDecreaseUsage.expectedInvocations, n) + return mmDeleteKnowledgeBaseFileAndDecreaseUsage +} + +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage) invocationsDone() bool { + if len(mmDeleteKnowledgeBaseFileAndDecreaseUsage.expectations) == 0 && mmDeleteKnowledgeBaseFileAndDecreaseUsage.defaultExpectation == nil && mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.funcDeleteKnowledgeBaseFileAndDecreaseUsage == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmDeleteKnowledgeBaseFileAndDecreaseUsage.mock.afterDeleteKnowledgeBaseFileAndDecreaseUsageCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmDeleteKnowledgeBaseFileAndDecreaseUsage.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// DeleteKnowledgeBaseFileAndDecreaseUsage implements repository.RepositoryI +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *RepositoryIMock) DeleteKnowledgeBaseFileAndDecreaseUsage(ctx context.Context, fileUID uuid.UUID) (err error) { + mm_atomic.AddUint64(&mmDeleteKnowledgeBaseFileAndDecreaseUsage.beforeDeleteKnowledgeBaseFileAndDecreaseUsageCounter, 1) + defer mm_atomic.AddUint64(&mmDeleteKnowledgeBaseFileAndDecreaseUsage.afterDeleteKnowledgeBaseFileAndDecreaseUsageCounter, 1) + + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.inspectFuncDeleteKnowledgeBaseFileAndDecreaseUsage != nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.inspectFuncDeleteKnowledgeBaseFileAndDecreaseUsage(ctx, fileUID) + } + + mm_params := RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParams{ctx, fileUID} + + // Record call args + mmDeleteKnowledgeBaseFileAndDecreaseUsage.DeleteKnowledgeBaseFileAndDecreaseUsageMock.mutex.Lock() + mmDeleteKnowledgeBaseFileAndDecreaseUsage.DeleteKnowledgeBaseFileAndDecreaseUsageMock.callArgs = append(mmDeleteKnowledgeBaseFileAndDecreaseUsage.DeleteKnowledgeBaseFileAndDecreaseUsageMock.callArgs, &mm_params) + mmDeleteKnowledgeBaseFileAndDecreaseUsage.DeleteKnowledgeBaseFileAndDecreaseUsageMock.mutex.Unlock() + + for _, e := range mmDeleteKnowledgeBaseFileAndDecreaseUsage.DeleteKnowledgeBaseFileAndDecreaseUsageMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.err + } + } + + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.DeleteKnowledgeBaseFileAndDecreaseUsageMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmDeleteKnowledgeBaseFileAndDecreaseUsage.DeleteKnowledgeBaseFileAndDecreaseUsageMock.defaultExpectation.Counter, 1) + mm_want := mmDeleteKnowledgeBaseFileAndDecreaseUsage.DeleteKnowledgeBaseFileAndDecreaseUsageMock.defaultExpectation.params + mm_want_ptrs := mmDeleteKnowledgeBaseFileAndDecreaseUsage.DeleteKnowledgeBaseFileAndDecreaseUsageMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParams{ctx, fileUID} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.t.Errorf("RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage 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.fileUID != nil && !minimock.Equal(*mm_want_ptrs.fileUID, mm_got.fileUID) { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.t.Errorf("RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage 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) { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.t.Errorf("RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmDeleteKnowledgeBaseFileAndDecreaseUsage.DeleteKnowledgeBaseFileAndDecreaseUsageMock.defaultExpectation.results + if mm_results == nil { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.t.Fatal("No results are set for the RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage") + } + return (*mm_results).err + } + if mmDeleteKnowledgeBaseFileAndDecreaseUsage.funcDeleteKnowledgeBaseFileAndDecreaseUsage != nil { + return mmDeleteKnowledgeBaseFileAndDecreaseUsage.funcDeleteKnowledgeBaseFileAndDecreaseUsage(ctx, fileUID) + } + mmDeleteKnowledgeBaseFileAndDecreaseUsage.t.Fatalf("Unexpected call to RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage. %v %v", ctx, fileUID) + return +} + +// DeleteKnowledgeBaseFileAndDecreaseUsageAfterCounter returns a count of finished RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage invocations +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *RepositoryIMock) DeleteKnowledgeBaseFileAndDecreaseUsageAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmDeleteKnowledgeBaseFileAndDecreaseUsage.afterDeleteKnowledgeBaseFileAndDecreaseUsageCounter) +} + +// DeleteKnowledgeBaseFileAndDecreaseUsageBeforeCounter returns a count of RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage invocations +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *RepositoryIMock) DeleteKnowledgeBaseFileAndDecreaseUsageBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmDeleteKnowledgeBaseFileAndDecreaseUsage.beforeDeleteKnowledgeBaseFileAndDecreaseUsageCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmDeleteKnowledgeBaseFileAndDecreaseUsage *mRepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsage) Calls() []*RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParams { + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mutex.RLock() + + argCopy := make([]*RepositoryIMockDeleteKnowledgeBaseFileAndDecreaseUsageParams, len(mmDeleteKnowledgeBaseFileAndDecreaseUsage.callArgs)) + copy(argCopy, mmDeleteKnowledgeBaseFileAndDecreaseUsage.callArgs) + + mmDeleteKnowledgeBaseFileAndDecreaseUsage.mutex.RUnlock() + + return argCopy +} + +// MinimockDeleteKnowledgeBaseFileAndDecreaseUsageDone returns true if the count of the DeleteKnowledgeBaseFileAndDecreaseUsage invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockDeleteKnowledgeBaseFileAndDecreaseUsageDone() bool { + for _, e := range m.DeleteKnowledgeBaseFileAndDecreaseUsageMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.DeleteKnowledgeBaseFileAndDecreaseUsageMock.invocationsDone() +} + +// MinimockDeleteKnowledgeBaseFileAndDecreaseUsageInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockDeleteKnowledgeBaseFileAndDecreaseUsageInspect() { + for _, e := range m.DeleteKnowledgeBaseFileAndDecreaseUsageMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage with params: %#v", *e.params) + } + } + + afterDeleteKnowledgeBaseFileAndDecreaseUsageCounter := mm_atomic.LoadUint64(&m.afterDeleteKnowledgeBaseFileAndDecreaseUsageCounter) + // if default expectation was set then invocations count should be greater than zero + if m.DeleteKnowledgeBaseFileAndDecreaseUsageMock.defaultExpectation != nil && afterDeleteKnowledgeBaseFileAndDecreaseUsageCounter < 1 { + if m.DeleteKnowledgeBaseFileAndDecreaseUsageMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage") + } else { + m.t.Errorf("Expected call to RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage with params: %#v", *m.DeleteKnowledgeBaseFileAndDecreaseUsageMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcDeleteKnowledgeBaseFileAndDecreaseUsage != nil && afterDeleteKnowledgeBaseFileAndDecreaseUsageCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage") + } + + if !m.DeleteKnowledgeBaseFileAndDecreaseUsageMock.invocationsDone() && afterDeleteKnowledgeBaseFileAndDecreaseUsageCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.DeleteKnowledgeBaseFileAndDecreaseUsage but found %d calls", + mm_atomic.LoadUint64(&m.DeleteKnowledgeBaseFileAndDecreaseUsageMock.expectedInvocations), afterDeleteKnowledgeBaseFileAndDecreaseUsageCounter) + } +} + type mRepositoryIMockDeleteMessage struct { mock *RepositoryIMock defaultExpectation *RepositoryIMockDeleteMessageExpectation @@ -13913,6 +14227,7 @@ type RepositoryIMockIncreaseKnowledgeBaseUsageExpectation struct { // RepositoryIMockIncreaseKnowledgeBaseUsageParams contains parameters of the RepositoryI.IncreaseKnowledgeBaseUsage type RepositoryIMockIncreaseKnowledgeBaseUsageParams struct { ctx context.Context + tx *gorm.DB kbUID string amount int } @@ -13920,6 +14235,7 @@ type RepositoryIMockIncreaseKnowledgeBaseUsageParams struct { // RepositoryIMockIncreaseKnowledgeBaseUsageParamPtrs contains pointers to parameters of the RepositoryI.IncreaseKnowledgeBaseUsage type RepositoryIMockIncreaseKnowledgeBaseUsageParamPtrs struct { ctx *context.Context + tx **gorm.DB kbUID *string amount *int } @@ -13930,7 +14246,7 @@ type RepositoryIMockIncreaseKnowledgeBaseUsageResults struct { } // Expect sets up expected params for RepositoryI.IncreaseKnowledgeBaseUsage -func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) Expect(ctx context.Context, kbUID string, amount int) *mRepositoryIMockIncreaseKnowledgeBaseUsage { +func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) Expect(ctx context.Context, tx *gorm.DB, kbUID string, amount int) *mRepositoryIMockIncreaseKnowledgeBaseUsage { if mmIncreaseKnowledgeBaseUsage.mock.funcIncreaseKnowledgeBaseUsage != nil { mmIncreaseKnowledgeBaseUsage.mock.t.Fatalf("RepositoryIMock.IncreaseKnowledgeBaseUsage mock is already set by Set") } @@ -13943,7 +14259,7 @@ func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) mmIncreaseKnowledgeBaseUsage.mock.t.Fatalf("RepositoryIMock.IncreaseKnowledgeBaseUsage mock is already set by ExpectParams functions") } - mmIncreaseKnowledgeBaseUsage.defaultExpectation.params = &RepositoryIMockIncreaseKnowledgeBaseUsageParams{ctx, kbUID, amount} + mmIncreaseKnowledgeBaseUsage.defaultExpectation.params = &RepositoryIMockIncreaseKnowledgeBaseUsageParams{ctx, tx, kbUID, amount} for _, e := range mmIncreaseKnowledgeBaseUsage.expectations { if minimock.Equal(e.params, mmIncreaseKnowledgeBaseUsage.defaultExpectation.params) { mmIncreaseKnowledgeBaseUsage.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmIncreaseKnowledgeBaseUsage.defaultExpectation.params) @@ -13975,8 +14291,30 @@ func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) return mmIncreaseKnowledgeBaseUsage } -// ExpectKbUIDParam2 sets up expected param kbUID for RepositoryI.IncreaseKnowledgeBaseUsage -func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) ExpectKbUIDParam2(kbUID string) *mRepositoryIMockIncreaseKnowledgeBaseUsage { +// ExpectTxParam2 sets up expected param tx for RepositoryI.IncreaseKnowledgeBaseUsage +func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) ExpectTxParam2(tx *gorm.DB) *mRepositoryIMockIncreaseKnowledgeBaseUsage { + if mmIncreaseKnowledgeBaseUsage.mock.funcIncreaseKnowledgeBaseUsage != nil { + mmIncreaseKnowledgeBaseUsage.mock.t.Fatalf("RepositoryIMock.IncreaseKnowledgeBaseUsage mock is already set by Set") + } + + if mmIncreaseKnowledgeBaseUsage.defaultExpectation == nil { + mmIncreaseKnowledgeBaseUsage.defaultExpectation = &RepositoryIMockIncreaseKnowledgeBaseUsageExpectation{} + } + + if mmIncreaseKnowledgeBaseUsage.defaultExpectation.params != nil { + mmIncreaseKnowledgeBaseUsage.mock.t.Fatalf("RepositoryIMock.IncreaseKnowledgeBaseUsage mock is already set by Expect") + } + + if mmIncreaseKnowledgeBaseUsage.defaultExpectation.paramPtrs == nil { + mmIncreaseKnowledgeBaseUsage.defaultExpectation.paramPtrs = &RepositoryIMockIncreaseKnowledgeBaseUsageParamPtrs{} + } + mmIncreaseKnowledgeBaseUsage.defaultExpectation.paramPtrs.tx = &tx + + return mmIncreaseKnowledgeBaseUsage +} + +// ExpectKbUIDParam3 sets up expected param kbUID for RepositoryI.IncreaseKnowledgeBaseUsage +func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) ExpectKbUIDParam3(kbUID string) *mRepositoryIMockIncreaseKnowledgeBaseUsage { if mmIncreaseKnowledgeBaseUsage.mock.funcIncreaseKnowledgeBaseUsage != nil { mmIncreaseKnowledgeBaseUsage.mock.t.Fatalf("RepositoryIMock.IncreaseKnowledgeBaseUsage mock is already set by Set") } @@ -13997,8 +14335,8 @@ func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) return mmIncreaseKnowledgeBaseUsage } -// ExpectAmountParam3 sets up expected param amount for RepositoryI.IncreaseKnowledgeBaseUsage -func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) ExpectAmountParam3(amount int) *mRepositoryIMockIncreaseKnowledgeBaseUsage { +// ExpectAmountParam4 sets up expected param amount for RepositoryI.IncreaseKnowledgeBaseUsage +func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) ExpectAmountParam4(amount int) *mRepositoryIMockIncreaseKnowledgeBaseUsage { if mmIncreaseKnowledgeBaseUsage.mock.funcIncreaseKnowledgeBaseUsage != nil { mmIncreaseKnowledgeBaseUsage.mock.t.Fatalf("RepositoryIMock.IncreaseKnowledgeBaseUsage mock is already set by Set") } @@ -14020,7 +14358,7 @@ func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) } // Inspect accepts an inspector function that has same arguments as the RepositoryI.IncreaseKnowledgeBaseUsage -func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) Inspect(f func(ctx context.Context, kbUID string, amount int)) *mRepositoryIMockIncreaseKnowledgeBaseUsage { +func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) Inspect(f func(ctx context.Context, tx *gorm.DB, kbUID string, amount int)) *mRepositoryIMockIncreaseKnowledgeBaseUsage { if mmIncreaseKnowledgeBaseUsage.mock.inspectFuncIncreaseKnowledgeBaseUsage != nil { mmIncreaseKnowledgeBaseUsage.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.IncreaseKnowledgeBaseUsage") } @@ -14044,7 +14382,7 @@ func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) } // Set uses given function f to mock the RepositoryI.IncreaseKnowledgeBaseUsage method -func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) Set(f func(ctx context.Context, kbUID string, amount int) (err error)) *RepositoryIMock { +func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) Set(f func(ctx context.Context, tx *gorm.DB, kbUID string, amount int) (err error)) *RepositoryIMock { if mmIncreaseKnowledgeBaseUsage.defaultExpectation != nil { mmIncreaseKnowledgeBaseUsage.mock.t.Fatalf("Default expectation is already set for the RepositoryI.IncreaseKnowledgeBaseUsage method") } @@ -14059,14 +14397,14 @@ func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) // When sets expectation for the RepositoryI.IncreaseKnowledgeBaseUsage which will trigger the result defined by the following // Then helper -func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) When(ctx context.Context, kbUID string, amount int) *RepositoryIMockIncreaseKnowledgeBaseUsageExpectation { +func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) When(ctx context.Context, tx *gorm.DB, kbUID string, amount int) *RepositoryIMockIncreaseKnowledgeBaseUsageExpectation { if mmIncreaseKnowledgeBaseUsage.mock.funcIncreaseKnowledgeBaseUsage != nil { mmIncreaseKnowledgeBaseUsage.mock.t.Fatalf("RepositoryIMock.IncreaseKnowledgeBaseUsage mock is already set by Set") } expectation := &RepositoryIMockIncreaseKnowledgeBaseUsageExpectation{ mock: mmIncreaseKnowledgeBaseUsage.mock, - params: &RepositoryIMockIncreaseKnowledgeBaseUsageParams{ctx, kbUID, amount}, + params: &RepositoryIMockIncreaseKnowledgeBaseUsageParams{ctx, tx, kbUID, amount}, } mmIncreaseKnowledgeBaseUsage.expectations = append(mmIncreaseKnowledgeBaseUsage.expectations, expectation) return expectation @@ -14099,15 +14437,15 @@ func (mmIncreaseKnowledgeBaseUsage *mRepositoryIMockIncreaseKnowledgeBaseUsage) } // IncreaseKnowledgeBaseUsage implements repository.RepositoryI -func (mmIncreaseKnowledgeBaseUsage *RepositoryIMock) IncreaseKnowledgeBaseUsage(ctx context.Context, kbUID string, amount int) (err error) { +func (mmIncreaseKnowledgeBaseUsage *RepositoryIMock) IncreaseKnowledgeBaseUsage(ctx context.Context, tx *gorm.DB, kbUID string, amount int) (err error) { mm_atomic.AddUint64(&mmIncreaseKnowledgeBaseUsage.beforeIncreaseKnowledgeBaseUsageCounter, 1) defer mm_atomic.AddUint64(&mmIncreaseKnowledgeBaseUsage.afterIncreaseKnowledgeBaseUsageCounter, 1) if mmIncreaseKnowledgeBaseUsage.inspectFuncIncreaseKnowledgeBaseUsage != nil { - mmIncreaseKnowledgeBaseUsage.inspectFuncIncreaseKnowledgeBaseUsage(ctx, kbUID, amount) + mmIncreaseKnowledgeBaseUsage.inspectFuncIncreaseKnowledgeBaseUsage(ctx, tx, kbUID, amount) } - mm_params := RepositoryIMockIncreaseKnowledgeBaseUsageParams{ctx, kbUID, amount} + mm_params := RepositoryIMockIncreaseKnowledgeBaseUsageParams{ctx, tx, kbUID, amount} // Record call args mmIncreaseKnowledgeBaseUsage.IncreaseKnowledgeBaseUsageMock.mutex.Lock() @@ -14126,7 +14464,7 @@ func (mmIncreaseKnowledgeBaseUsage *RepositoryIMock) IncreaseKnowledgeBaseUsage( mm_want := mmIncreaseKnowledgeBaseUsage.IncreaseKnowledgeBaseUsageMock.defaultExpectation.params mm_want_ptrs := mmIncreaseKnowledgeBaseUsage.IncreaseKnowledgeBaseUsageMock.defaultExpectation.paramPtrs - mm_got := RepositoryIMockIncreaseKnowledgeBaseUsageParams{ctx, kbUID, amount} + mm_got := RepositoryIMockIncreaseKnowledgeBaseUsageParams{ctx, tx, kbUID, amount} if mm_want_ptrs != nil { @@ -14134,6 +14472,10 @@ func (mmIncreaseKnowledgeBaseUsage *RepositoryIMock) IncreaseKnowledgeBaseUsage( mmIncreaseKnowledgeBaseUsage.t.Errorf("RepositoryIMock.IncreaseKnowledgeBaseUsage 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.tx != nil && !minimock.Equal(*mm_want_ptrs.tx, mm_got.tx) { + mmIncreaseKnowledgeBaseUsage.t.Errorf("RepositoryIMock.IncreaseKnowledgeBaseUsage got unexpected parameter tx, want: %#v, got: %#v%s\n", *mm_want_ptrs.tx, mm_got.tx, minimock.Diff(*mm_want_ptrs.tx, mm_got.tx)) + } + if mm_want_ptrs.kbUID != nil && !minimock.Equal(*mm_want_ptrs.kbUID, mm_got.kbUID) { mmIncreaseKnowledgeBaseUsage.t.Errorf("RepositoryIMock.IncreaseKnowledgeBaseUsage got unexpected parameter kbUID, want: %#v, got: %#v%s\n", *mm_want_ptrs.kbUID, mm_got.kbUID, minimock.Diff(*mm_want_ptrs.kbUID, mm_got.kbUID)) } @@ -14153,9 +14495,9 @@ func (mmIncreaseKnowledgeBaseUsage *RepositoryIMock) IncreaseKnowledgeBaseUsage( return (*mm_results).err } if mmIncreaseKnowledgeBaseUsage.funcIncreaseKnowledgeBaseUsage != nil { - return mmIncreaseKnowledgeBaseUsage.funcIncreaseKnowledgeBaseUsage(ctx, kbUID, amount) + return mmIncreaseKnowledgeBaseUsage.funcIncreaseKnowledgeBaseUsage(ctx, tx, kbUID, amount) } - mmIncreaseKnowledgeBaseUsage.t.Fatalf("Unexpected call to RepositoryIMock.IncreaseKnowledgeBaseUsage. %v %v %v", ctx, kbUID, amount) + mmIncreaseKnowledgeBaseUsage.t.Fatalf("Unexpected call to RepositoryIMock.IncreaseKnowledgeBaseUsage. %v %v %v %v", ctx, tx, kbUID, amount) return } @@ -20786,7 +21128,7 @@ func (m *RepositoryIMock) MinimockFinish() { m.MinimockCreateMessageInspect() - m.MinimockDeleteAllConvertedFilesinKbInspect() + m.MinimockDeleteAllConvertedFilesInKbInspect() m.MinimockDeleteAllKnowledgeBaseFilesInspect() @@ -20806,6 +21148,8 @@ func (m *RepositoryIMock) MinimockFinish() { m.MinimockDeleteKnowledgeBaseFileInspect() + m.MinimockDeleteKnowledgeBaseFileAndDecreaseUsageInspect() + m.MinimockDeleteMessageInspect() m.MinimockDeleteRepositoryTagInspect() @@ -20930,7 +21274,7 @@ func (m *RepositoryIMock) minimockDone() bool { m.MinimockCreateKnowledgeBaseDone() && m.MinimockCreateKnowledgeBaseFileDone() && m.MinimockCreateMessageDone() && - m.MinimockDeleteAllConvertedFilesinKbDone() && + m.MinimockDeleteAllConvertedFilesInKbDone() && m.MinimockDeleteAllKnowledgeBaseFilesDone() && m.MinimockDeleteAndCreateChunksDone() && m.MinimockDeleteChunksBySourceDone() && @@ -20940,6 +21284,7 @@ func (m *RepositoryIMock) minimockDone() bool { m.MinimockDeleteEmbeddingsByUIDsDone() && m.MinimockDeleteKnowledgeBaseDone() && m.MinimockDeleteKnowledgeBaseFileDone() && + m.MinimockDeleteKnowledgeBaseFileAndDecreaseUsageDone() && m.MinimockDeleteMessageDone() && m.MinimockDeleteRepositoryTagDone() && m.MinimockGetChunksByUIDsDone() && diff --git a/pkg/repository/convertedfile.go b/pkg/repository/convertedfile.go index 6ee3fac..99be5a8 100644 --- a/pkg/repository/convertedfile.go +++ b/pkg/repository/convertedfile.go @@ -14,7 +14,7 @@ type ConvertedFileI interface { ConvertedFileTableName() string CreateConvertedFile(ctx context.Context, cf ConvertedFile, callExternalService func(convertedFileUID uuid.UUID) (map[string]any, error)) (*ConvertedFile, error) DeleteConvertedFile(ctx context.Context, uid uuid.UUID) error - DeleteAllConvertedFilesinKb(ctx context.Context, kbUID uuid.UUID) error + DeleteAllConvertedFilesInKb(ctx context.Context, kbUID uuid.UUID) error HardDeleteConvertedFileByFileUID(ctx context.Context, fileUID uuid.UUID) error GetConvertedFileByFileUID(ctx context.Context, fileUID uuid.UUID) (*ConvertedFile, error) } @@ -139,8 +139,8 @@ func (r *Repository) DeleteConvertedFile(ctx context.Context, uid uuid.UUID) err return nil } -// DeleteAllConvertedFilesinKb deletes all the records in the knowledge base -func (r *Repository) DeleteAllConvertedFilesinKb(ctx context.Context, kbUID uuid.UUID) error { +// DeleteAllConvertedFilesInKb deletes all the records in the knowledge base +func (r *Repository) DeleteAllConvertedFilesInKb(ctx context.Context, kbUID uuid.UUID) error { err := r.db.Transaction(func(tx *gorm.DB) error { // Specify the condition to find the record by its UID where := fmt.Sprintf("%s = ?", ConvertedFileColumn.KbUID) diff --git a/pkg/repository/knowledgebase.go b/pkg/repository/knowledgebase.go index afe8db5..3dacb9b 100644 --- a/pkg/repository/knowledgebase.go +++ b/pkg/repository/knowledgebase.go @@ -20,7 +20,7 @@ type KnowledgeBaseI interface { DeleteKnowledgeBase(ctx context.Context, ownerUID, kbID string) (*KnowledgeBase, error) GetKnowledgeBaseByOwnerAndKbID(ctx context.Context, ownerUID uuid.UUID, kbID string) (*KnowledgeBase, error) GetKnowledgeBaseCountByOwner(ctx context.Context, ownerUID string) (int64, error) - IncreaseKnowledgeBaseUsage(ctx context.Context, kbUID string, amount int) error + IncreaseKnowledgeBaseUsage(ctx context.Context, tx *gorm.DB, kbUID string, amount int) error } type KnowledgeBase struct { @@ -267,11 +267,14 @@ func (r *Repository) GetKnowledgeBaseCountByOwner(ctx context.Context, owner str } // IncreaseKnowledgeBaseUsage increments the usage count of a KnowledgeBase record by a specified amount. -func (r *Repository) IncreaseKnowledgeBaseUsage(ctx context.Context, kbUID string, amount int) error { +func (r *Repository) IncreaseKnowledgeBaseUsage(ctx context.Context, tx *gorm.DB, kbUID string, amount int) error { + if tx == nil { + tx = r.db.WithContext(ctx) + } // Increment the usage count of the KnowledgeBase record by the specified amount where := fmt.Sprintf("%v = ?", KnowledgeBaseColumn.UID) expr := fmt.Sprintf("%v + ?", KnowledgeBaseColumn.Usage) - if err := r.db.WithContext(ctx).Model(&KnowledgeBase{}).Where(where, kbUID).Update(KnowledgeBaseColumn.Usage, gorm.Expr(expr, amount)).Error; err != nil { + if err := tx.WithContext(ctx).Model(&KnowledgeBase{}).Where(where, kbUID).Update(KnowledgeBaseColumn.Usage, gorm.Expr(expr, amount)).Error; err != nil { return err } return nil diff --git a/pkg/repository/knowledgebasefile.go b/pkg/repository/knowledgebasefile.go index e4bce25..7fa1372 100644 --- a/pkg/repository/knowledgebasefile.go +++ b/pkg/repository/knowledgebasefile.go @@ -47,6 +47,8 @@ type KnowledgeBaseFileI interface { GetTruthSourceByFileUID(ctx context.Context, fileUID uuid.UUID) (*SourceMeta, error) // UpdateKbFileExtraMetaData updates the extra meta data of the knowledge base file UpdateKbFileExtraMetaData(ctx context.Context, fileUID uuid.UUID, failureReason, convertingPipe, chunkingPipe, embeddingPipe string, processingTime, convertingTime, chunkingTime, embeddingTime *int64) error + // DeleteKnowledgeBaseFileAndDecreaseUsage deletes the knowledge base file and decreases the knowledge base usage + DeleteKnowledgeBaseFileAndDecreaseUsage(ctx context.Context, fileUID uuid.UUID) error } type KbUID = uuid.UUID @@ -258,8 +260,7 @@ func (r *Repository) ListKnowledgeBaseFiles(ctx context.Context, uid string, own kbfs, err := r.GetKnowledgeBaseFilesByFileUIDs(ctx, []uuid.UUID{tokenUUID}) if err != nil { return nil, 0, "", fmt.Errorf("failed to get catalog files by next page token: %v", err) - } - if len(kbfs) == 0 { + } else if len(kbfs) == 0 { return nil, 0, "", fmt.Errorf("no catalog file found by next page token") } // whereClause @@ -469,7 +470,7 @@ func (r *Repository) GetKnowledgeBaseFilesByFileUIDs( for _, uid := range fileUIDs { stringUIDs = append(stringUIDs, uid.String()) } - where := fmt.Sprintf("%v IN ?", KnowledgeBaseFileColumn.UID) + where := fmt.Sprintf("%v IN ? AND %v IS NULL", KnowledgeBaseFileColumn.UID, KnowledgeBaseFileColumn.DeleteTime) query := r.db.WithContext(ctx) if len(columns) > 0 { query = query.Select(columns) @@ -637,3 +638,29 @@ func (r *Repository) UpdateKbFileExtraMetaData( // Return the result of the transaction (either nil or an error) return err } + +// DeleteKnowledgeBaseFileAndDecreaseUsage delete the knowledge base file and decrease the knowledge base usage +func (r *Repository) DeleteKnowledgeBaseFileAndDecreaseUsage(ctx context.Context, fileUID uuid.UUID) error { + currentTime := time.Now() + return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { + // get the knowledge base file + file, err := r.GetKnowledgeBaseFilesByFileUIDs(ctx, []uuid.UUID{fileUID}, KnowledgeBaseFileColumn.KnowledgeBaseUID, KnowledgeBaseFileColumn.Size) + if err != nil { + return err + } else if len(file) == 0 { + return fmt.Errorf("file not found by file uid: %v", fileUID) + } + whereClause := fmt.Sprintf("%v = ? AND %v is NULL", KnowledgeBaseFileColumn.UID, KnowledgeBaseFileColumn.DeleteTime) + if err := tx.Model(&KnowledgeBaseFile{}). + Where(whereClause, fileUID). + Update(KnowledgeBaseFileColumn.DeleteTime, currentTime).Error; err != nil { + return err + } + // decrease the knowledge base usage + err = r.IncreaseKnowledgeBaseUsage(ctx, tx, file[0].KnowledgeBaseUID.String(), int(-file[0].Size)) + if err != nil { + return err + } + return nil + }) +} diff --git a/pkg/service/pipeline.go b/pkg/service/pipeline.go index 2e20433..849b1d1 100644 --- a/pkg/service/pipeline.go +++ b/pkg/service/pipeline.go @@ -319,11 +319,9 @@ func (s *Service) EmbeddingTextPipe(ctx context.Context, caller uuid.UUID, reque } // wait for all the goroutines to finish - go func() { - wg.Wait() - close(resultsChan) - close(errChan) - }() + wg.Wait() + close(resultsChan) + close(errChan) // collect the results in the order of the input texts orderedResults := make([][][]float32, len(texts)/maxBatchSize+1) for res := range resultsChan { diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 107c1b0..2f337a4 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -21,7 +21,7 @@ func IsAuditEvent(eventName string) bool { func GoRecover(f func(), name string) { defer func() { if r := recover(); r != nil { - fmt.Println("panic occurred at: ", name, "panic: \n", r) + fmt.Println("\x1b[31m", "panic occurred at: \n", name, "\npanic: \n", r, "\x1b[0m") } }() f()