diff --git a/Makefile b/Makefile index 703f61a..16712e1 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ run-local: echo "A container named ${SERVICE_NAME} is already running. \nRestarting..."; \ make rm; \ fi - @docker run -d --rm \ + @docker run -d --rm \ -p ${SERVICE_PORT}:${SERVICE_PORT} \ --network instill-network \ --name ${SERVICE_NAME} \ diff --git a/cmd/main/main.go b/cmd/main/main.go index 342db40..c05c454 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -44,6 +44,7 @@ import ( httpclient "github.com/instill-ai/artifact-backend/pkg/client/http" database "github.com/instill-ai/artifact-backend/pkg/db" custom_otel "github.com/instill-ai/artifact-backend/pkg/logger/otel" + minio "github.com/instill-ai/artifact-backend/pkg/minio" artifactPB "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" ) @@ -178,7 +179,11 @@ func main() { repository := repository.NewRepository(db) - service := service.NewService(repository, httpclient.NewRegistryClient(ctx)) + // Initialize Minio client + minioClient, err := minio.NewMinioClientAndInitBucket() + + + service := service.NewService(repository, minioClient, mgmtPrivateServiceClient, httpclient.NewRegistryClient(ctx)) publicGrpcS := grpc.NewServer(grpcServerOpts...) reflection.Register(publicGrpcS) diff --git a/config/config.go b/config/config.go index 4cd0549..7a6502a 100644 --- a/config/config.go +++ b/config/config.go @@ -27,6 +27,7 @@ type AppConfig struct { MgmtBackend MgmtBackendConfig `koanf:"mgmtbackend"` Registry RegistryConfig `koanf:"registry"` OpenFGA OpenFGAConfig `koanf:"openfga"` + Minio MinioConfig `koanf:"minio"` } // OpenFGA config @@ -121,6 +122,15 @@ type RegistryConfig struct { Port int `koanf:"port"` } +// MinioConfig is the minio configuration. +type MinioConfig struct { + Host string `koanf:"host"` + Port string `koanf:"port"` + RootUser string `koanf:"rootuser"` + RootPwd string `koanf:"rootpwd"` + BucketName string `koanf:"bucketname"` +} + // Init - Assign global config to decoded config struct func Init() error { k := koanf.New(".") diff --git a/config/config.yaml b/config/config.yaml index 27bdffd..ca2886f 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -22,7 +22,7 @@ database: host: pg-sql port: 5432 name: artifact - version: 2 + version: 4 timezone: Etc/UTC pool: idleconnections: 5 @@ -59,3 +59,9 @@ registry: openfga: host: openfga port: 8080 +minio: + host: minio + port: 9000 + rootuser: minioadmin + rootpwd: minioadmin + bucketname: instill-ai-knowledge-bases diff --git a/go.mod b/go.mod index 6e55065..fabab91 100644 --- a/go.mod +++ b/go.mod @@ -11,13 +11,15 @@ require ( github.com/gojuno/minimock/v3 v3.3.6 github.com/golang-migrate/migrate/v4 v4.17.0 github.com/google/go-cmp v0.6.0 + github.com/google/uuid v1.6.0 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 github.com/influxdata/influxdb-client-go/v2 v2.12.3 - github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240530063823-abcb1c583452 + github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240612051236-4bd57e13ff0b github.com/instill-ai/usage-client v0.3.0-alpha.0.20240319060111-4a3a39f2fd61 github.com/instill-ai/x v0.3.0-alpha.0.20231219052200-6230a89e386c github.com/knadh/koanf v1.5.0 + github.com/minio/minio-go v6.0.14+incompatible github.com/openfga/go-sdk v0.2.3 github.com/redis/go-redis/v9 v9.5.1 go.opentelemetry.io/contrib/propagators/b3 v1.17.0 @@ -38,7 +40,10 @@ require ( gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11 ) -require github.com/google/uuid v1.6.0 // indirect +require ( + github.com/go-ini/ini v1.67.0 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect +) require ( github.com/catalinc/hashcash v0.0.0-20220723060415-5e3ec3e24f67 // indirect diff --git a/go.sum b/go.sum index 08537eb..8017f27 100644 --- a/go.sum +++ b/go.sum @@ -138,6 +138,8 @@ github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A= +github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= @@ -284,8 +286,8 @@ github.com/influxdata/influxdb-client-go/v2 v2.12.3 h1:28nRlNMRIV4QbtIUvxhWqaxn0 github.com/influxdata/influxdb-client-go/v2 v2.12.3/go.mod h1:IrrLUbCjjfkmRuaCiGQg4m2GbkaeJDcuWoxiWdQEbA0= github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU= github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= -github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240530063823-abcb1c583452 h1:uAkZouMby0pjaH0spCa5nUHMIKGjAxaBXRSVhe35M44= -github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240530063823-abcb1c583452/go.mod h1:2blmpUwiTwxIDnrjIqT6FhR5ewshZZF554wzjXFvKpQ= +github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240612051236-4bd57e13ff0b h1:YsH/M29+hdGLU5GS6Ty/JcLY1RMnEPT2lhfE43JUR5E= +github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240612051236-4bd57e13ff0b/go.mod h1:2blmpUwiTwxIDnrjIqT6FhR5ewshZZF554wzjXFvKpQ= github.com/instill-ai/usage-client v0.3.0-alpha.0.20240319060111-4a3a39f2fd61 h1:smPTvmXDhn/QC7y/TPXyMTqbbRd0gvzmFgWBChwTfhE= github.com/instill-ai/usage-client v0.3.0-alpha.0.20240319060111-4a3a39f2fd61/go.mod h1:/TAHs4ybuylk5icuy+MQtHRc4XUnIyXzeNKxX9qDFhw= github.com/instill-ai/x v0.3.0-alpha.0.20231219052200-6230a89e386c h1:a2RVkpIV2QcrGnSHAou+t/L+vBsaIfFvk5inVg5Uh4s= @@ -407,11 +409,14 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= +github.com/minio/minio-go v6.0.14+incompatible h1:fnV+GD28LeqdN6vT2XdGKW8Qe/IfjJDswNVuni6km9o= +github.com/minio/minio-go v6.0.14+incompatible/go.mod h1:7guKYtitv8dktvNUGrhzmNlA5wrAABTQXCoesZdFQO8= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= diff --git a/pkg/db/migration/000002_create_knowledge_base_table.down.sql b/pkg/db/migration/000002_create_knowledge_base_table.down.sql index 1e85d2a..9d63087 100644 --- a/pkg/db/migration/000002_create_knowledge_base_table.down.sql +++ b/pkg/db/migration/000002_create_knowledge_base_table.down.sql @@ -1 +1,3 @@ -DROP TABLE knowledge_base; \ No newline at end of file +BEGIN; +DROP TABLE knowledge_base; +COMMIT; \ No newline at end of file diff --git a/pkg/db/migration/000003_re_create_knowledge_base_tables.down.sql b/pkg/db/migration/000003_re_create_knowledge_base_tables.down.sql new file mode 100644 index 0000000..892b6e7 --- /dev/null +++ b/pkg/db/migration/000003_re_create_knowledge_base_tables.down.sql @@ -0,0 +1,5 @@ +BEGIN; +-- Drop the table knowledge_base_files +DROP TABLE IF EXISTS knowledge_base; + +COMMIT; \ No newline at end of file diff --git a/pkg/db/migration/000003_re_create_knowledge_base_tables.up.sql b/pkg/db/migration/000003_re_create_knowledge_base_tables.up.sql new file mode 100644 index 0000000..d80eec2 --- /dev/null +++ b/pkg/db/migration/000003_re_create_knowledge_base_tables.up.sql @@ -0,0 +1,33 @@ +BEGIN; +-- Drop the existing table if exists to avoid conflicts +DROP TABLE IF EXISTS knowledge_base; +-- Create the new knowledge_base table +CREATE TABLE knowledge_base ( + uid UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), + id VARCHAR(255) NOT NULL, + name VARCHAR(255) NOT NULL, + description VARCHAR(1023), + tags VARCHAR(255) [], + owner UUID NOT NULL, + create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + delete_time TIMESTAMP +); +-- Add the index +CREATE UNIQUE INDEX idx_unique_owner_name_delete_time ON knowledge_base (owner, name) +WHERE delete_time IS NULL; +CREATE UNIQUE INDEX unique_owner_id_delete_time ON knowledge_base (owner, id) +WHERE delete_time IS NULL; + +-- Comments for the table and columns +COMMENT ON TABLE knowledge_base IS 'Table to store knowledge base information'; +COMMENT ON COLUMN knowledge_base.uid IS 'Primary key, auto-generated UUID'; +COMMENT ON COLUMN knowledge_base.id IS 'Unique identifier from name for the knowledge base, up to 255 characters created from name'; +COMMENT ON COLUMN knowledge_base.name IS 'Name of the knowledge base, up to 255 characters'; +COMMENT ON COLUMN knowledge_base.description IS 'Description of the knowledge base, up to 1023 characters'; +COMMENT ON COLUMN knowledge_base.tags IS 'Array of tags associated with the knowledge base'; +COMMENT ON COLUMN knowledge_base.owner IS 'Owner of the knowledge base. It is a UUID referencing the owner table(uid field).'; +COMMENT ON COLUMN knowledge_base.create_time IS 'Timestamp when the entry was created, stored in UTC'; +COMMENT ON COLUMN knowledge_base.update_time IS 'Timestamp of the last update, stored in UTC'; +COMMENT ON COLUMN knowledge_base.delete_time IS 'Timestamp when the entry was marked as deleted, stored in UTC'; +COMMIT; \ No newline at end of file diff --git a/pkg/db/migration/000004_create_knowledge_base_file_tables.down.sql b/pkg/db/migration/000004_create_knowledge_base_file_tables.down.sql new file mode 100644 index 0000000..a0d4945 --- /dev/null +++ b/pkg/db/migration/000004_create_knowledge_base_file_tables.down.sql @@ -0,0 +1,5 @@ +BEGIN; +-- Drop the table knowledge_base_files +DROP TABLE IF EXISTS knowledge_base_files; + +COMMIT; \ No newline at end of file diff --git a/pkg/db/migration/000004_create_knowledge_base_file_tables.up.sql b/pkg/db/migration/000004_create_knowledge_base_file_tables.up.sql new file mode 100644 index 0000000..561973c --- /dev/null +++ b/pkg/db/migration/000004_create_knowledge_base_file_tables.up.sql @@ -0,0 +1,37 @@ +BEGIN; +-- Create the table knowledge_base_files +CREATE TABLE knowledge_base_file ( + uid UUID PRIMARY KEY DEFAULT gen_random_uuid(), + owner UUID NOT NULL, + kb_uid UUID NOT NULL, + creator_uid UUID NOT NULL, + name VARCHAR(255) NOT NULL, + type VARCHAR(100) NOT NULL, + destination VARCHAR(255) NOT NULL, + process_status VARCHAR(100) NOT NULL, + extra_meta_data JSONB, + content BYTEA, + create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + delete_time TIMESTAMP +); + +-- Add the unique index on (kb_uid, name) +CREATE UNIQUE INDEX idx_unique_kb_uid_name_delete_time ON knowledge_base_file (kb_uid, name) +WHERE delete_time IS NULL; + +-- Comments for the table and columns +COMMENT ON TABLE knowledge_base_file IS 'Table to store knowledge base files with metadata'; +COMMENT ON COLUMN knowledge_base_file.uid IS 'Unique identifier for the file'; +COMMENT ON COLUMN knowledge_base_file.create_time IS 'Timestamp when the record was created'; +COMMENT ON COLUMN knowledge_base_file.update_time IS 'Timestamp when the record was last updated'; +COMMENT ON COLUMN knowledge_base_file.delete_time IS 'Timestamp when the record was deleted (soft delete)'; +COMMENT ON COLUMN knowledge_base_file.owner IS 'Owner of the file, references owner table''s uid field'; +COMMENT ON COLUMN knowledge_base_file.kb_uid IS 'Knowledge base unique identifier, references knowledge base table''s uid field'; +COMMENT ON COLUMN knowledge_base_file.creator_uid IS 'Creator unique identifier, references owner table''s uid field'; +COMMENT ON COLUMN knowledge_base_file.name IS 'Name of the file'; +COMMENT ON COLUMN knowledge_base_file.process_status IS 'Processing status of the file'; +COMMENT ON COLUMN knowledge_base_file.extra_meta_data IS 'Extra metadata in JSON format, e.g., word count, image count'; +COMMENT ON COLUMN knowledge_base_file.content IS 'File content stored as byte array'; + +COMMIT; \ No newline at end of file diff --git a/pkg/handler/knowledgebase.go b/pkg/handler/knowledgebase.go index 74b47d7..439d5fd 100644 --- a/pkg/handler/knowledgebase.go +++ b/pkg/handler/knowledgebase.go @@ -23,7 +23,7 @@ const ErrorDeleteKnowledgeBaseMsg = "failed to delete knowledge base: %w" func (ph *PublicHandler) CreateKnowledgeBase(ctx context.Context, req *artifactpb.CreateKnowledgeBaseRequest) (*artifactpb.CreateKnowledgeBaseResponse, error) { - uid, err := getUserIDFromContext(ctx) + uid, err := getUserUIDFromContext(ctx) if err != nil { err := fmt.Errorf("failed to get user id from header: %v. err: %w", err, customerror.ErrUnauthenticated) return nil, err @@ -38,10 +38,11 @@ func (ph *PublicHandler) CreateKnowledgeBase(ctx context.Context, req *artifactp msg := "name is invalid: %v. err: %w" return nil, fmt.Errorf(msg, req.Name, customerror.ErrInvalidArgument) } - res, err := ph.service.Repository.CreateKnowledgeBase(ctx, + + dbData, err := ph.service.Repository.CreateKnowledgeBase(ctx, repository.KnowledgeBase{ Name: req.Name, - KbID: toIDStyle(req.Name), + ID: toIDStyle(req.Name), Description: req.Description, Tags: req.Tags, Owner: uid, @@ -50,36 +51,43 @@ func (ph *PublicHandler) CreateKnowledgeBase(ctx context.Context, req *artifactp if err != nil { return nil, err } + + // TODO: ACL - set the owner of the knowledge base + // .... + return &artifactpb.CreateKnowledgeBaseResponse{ Body: &artifactpb.KnowledgeBase{ - Name: res.Name, - Id: res.KbID, - Description: res.Description, - Tags: res.Tags, - OwnerName: res.Owner, - CreateTime: res.CreateTime.String(), - UpdateTime: res.UpdateTime.String(), + Name: dbData.Name, + Id: dbData.ID, + Description: dbData.Description, + Tags: dbData.Tags, + OwnerName: dbData.Owner, + CreateTime: dbData.CreateTime.String(), + UpdateTime: dbData.UpdateTime.String(), }, ErrorMsg: "", StatusCode: 0, }, nil } func (ph *PublicHandler) ListKnowledgeBases(ctx context.Context, _ *artifactpb.ListKnowledgeBasesRequest) (*artifactpb.ListKnowledgeBasesResponse, error) { // get user id from context - uid, err := getUserIDFromContext(ctx) + uid, err := getUserUIDFromContext(ctx) if err != nil { return nil, fmt.Errorf(ErrorListKnowledgeBasesMsg, err) } - res, err := ph.service.Repository.ListKnowledgeBases(ctx, uid) + + // TODO: ACL - check user's permission to list knowledge bases + + dbData, err := ph.service.Repository.ListKnowledgeBases(ctx, uid) if err != nil { return nil, fmt.Errorf(ErrorListKnowledgeBasesMsg, err) } - kbs := make([]*artifactpb.KnowledgeBase, len(res)) - for i, kb := range res { + kbs := make([]*artifactpb.KnowledgeBase, len(dbData)) + for i, kb := range dbData { kbs[i] = &artifactpb.KnowledgeBase{ Name: kb.Name, - Id: kb.KbID, + Id: kb.ID, Description: kb.Description, Tags: kb.Tags, CreateTime: kb.CreateTime.String(), @@ -95,7 +103,7 @@ func (ph *PublicHandler) ListKnowledgeBases(ctx context.Context, _ *artifactpb.L }, nil } func (ph *PublicHandler) UpdateKnowledgeBase(ctx context.Context, req *artifactpb.UpdateKnowledgeBaseRequest) (*artifactpb.UpdateKnowledgeBaseResponse, error) { - uid, err := getUserIDFromContext(ctx) + uid, err := getUserUIDFromContext(ctx) if err != nil { return nil, err } @@ -107,13 +115,16 @@ func (ph *PublicHandler) UpdateKnowledgeBase(ctx context.Context, req *artifactp if !nameOk { return nil, fmt.Errorf("name: %s is invalid. err: %w", req.Name, customerror.ErrInvalidArgument) } + + // TODO: ACL - check user's permission to update knowledge base + // check if knowledge base exists - res, err := ph.service.Repository.UpdateKnowledgeBase( + dbData, err := ph.service.Repository.UpdateKnowledgeBase( ctx, uid, repository.KnowledgeBase{ Name: req.Name, - KbID: req.Id, + ID: req.Id, Description: req.Description, Tags: req.Tags, Owner: uid, @@ -125,23 +136,26 @@ func (ph *PublicHandler) UpdateKnowledgeBase(ctx context.Context, req *artifactp // populate response return &artifactpb.UpdateKnowledgeBaseResponse{ Body: &artifactpb.KnowledgeBase{ - Name: res.Name, - Id: res.KbID, - Description: res.Description, - Tags: res.Tags, - CreateTime: res.CreateTime.String(), - UpdateTime: res.UpdateTime.String(), - OwnerName: res.Owner, + Name: dbData.Name, + Id: dbData.ID, + Description: dbData.Description, + Tags: dbData.Tags, + CreateTime: dbData.CreateTime.String(), + UpdateTime: dbData.UpdateTime.String(), + OwnerName: dbData.Owner, }, ErrorMsg: "", StatusCode: 0, }, nil } func (ph *PublicHandler) DeleteKnowledgeBase(ctx context.Context, req *artifactpb.DeleteKnowledgeBaseRequest) (*artifactpb.DeleteKnowledgeBaseResponse, error) { - uid, err := getUserIDFromContext(ctx) + uid, err := getUserUIDFromContext(ctx) if err != nil { return nil, err } + + // TODO: ACL - check user's permission to delete knowledge base + err = ph.service.Repository.DeleteKnowledgeBase(ctx, uid, req.Id) if err != nil { @@ -151,7 +165,7 @@ func (ph *PublicHandler) DeleteKnowledgeBase(ctx context.Context, req *artifactp ErrorMsg: "", StatusCode: 0, }, nil } -func getUserIDFromContext(ctx context.Context) (string, error) { +func getUserUIDFromContext(ctx context.Context) (string, error) { md, _ := metadata.FromIncomingContext(ctx) if v, ok := md[strings.ToLower(constant.HeaderUserUIDKey)]; ok { return v[0], nil diff --git a/pkg/handler/knowledgebasefiles.go b/pkg/handler/knowledgebasefiles.go new file mode 100644 index 0000000..05fa1a2 --- /dev/null +++ b/pkg/handler/knowledgebasefiles.go @@ -0,0 +1,293 @@ +package handler + +import ( + "context" + "fmt" + "strings" + + "github.com/google/uuid" + "github.com/instill-ai/artifact-backend/pkg/customerror" + "github.com/instill-ai/artifact-backend/pkg/logger" // Add this import + "github.com/instill-ai/artifact-backend/pkg/repository" + artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" + mgmtpb "github.com/instill-ai/protogen-go/core/mgmt/v1beta" + "go.uber.org/zap" + "google.golang.org/protobuf/types/known/timestamppb" +) + +func (ph *PublicHandler) UploadKnowledgeBaseFile(ctx context.Context, req *artifactpb.UploadKnowledgeBaseFileRequest) (*artifactpb.UploadKnowledgeBaseFileResponse, error) { + log, _ := logger.GetZapLogger(ctx) + uid, err := getUserUIDFromContext(ctx) + if err != nil { + err := fmt.Errorf("failed to get user id from header: %v. err: %w", err, customerror.ErrUnauthenticated) + return nil, err + } + err = checkUploadKnowledgeBaseFileRequest(req) + if err != nil { + return nil, err + } + + // TODO: ACL - check if the creator can upload file to this knowledge base. ACL. + // ..... + + //get the owner uid from the mgmt service + var ownerUID uuid.UUID + { + filter := "id=" + req.OwnerId + ownerRes, err := ph.service.MgmtPrv.ListUsersAdmin(ctx, &mgmtpb.ListUsersAdminRequest{Filter: &filter}) + if err != nil { + log.Error("failed to get owner uid", zap.Error(err)) + return nil, err + } + if ownerRes == nil || len(ownerRes.Users) == 0 { + return nil, fmt.Errorf("failed to get owner uid. err: %w", customerror.ErrNotFound) + } + ownerUID, err = uuid.Parse(*ownerRes.Users[0].Uid) + if err != nil { + log.Error("failed to parse owner uid", zap.Error(err)) + return nil, err + } + } + + // upload file to minio + var kb *repository.KnowledgeBase + var filePathName string + { + kb, err = ph.service.Repository.GetKnowledgeBaseByOwnerAndID(ctx, ownerUID.String(), req.KbId) + if err != nil { + return nil, fmt.Errorf("failed to get knowledge base by owner and id. err: %w", err) + } + // check if the name has "/" which may cause folder creation in minio + if strings.Contains(req.File.Name, "/") { + return nil, fmt.Errorf("file name cannot contain '/'. err: %w", customerror.ErrInvalidArgument) + } + filePathName = kb.UID.String() + "/" + req.File.Name + err = ph.service.MinIO.UploadBase64File(ctx, filePathName, req.File.Content, fileTypeConvertToMime(req.File.Type)) + if err != nil { + return nil, err + } + } + + // create metadata in db + var res *repository.KnowledgeBaseFile + { + creatorUID, err := uuid.Parse(uid) + if err != nil { + log.Error("failed to parse creator uid", zap.Error(err)) + return nil, err + } + + kbFile := repository.KnowledgeBaseFile{ + Name: req.File.Name, + Type: artifactpb.FileType_name[int32(req.File.Type)], + Owner: ownerUID, + CreatorUID: creatorUID, + KnowledgeBaseUID: kb.UID, + Destination: filePathName, + ProcessStatus: artifactpb.FileProcessStatus_name[int32(artifactpb.FileProcessStatus_FILE_PROCESS_STATUS_NOTSTARTED)], + } + res, err = ph.service.Repository.CreateKnowledgeBaseFile(ctx, kbFile) + if err != nil { + err:= ph.service.MinIO.DeleteFile(ctx, filePathName) + if err != nil { + log.Error("failed to delete file in minio", zap.Error(err)) + } + return nil, err + } + } + + return &artifactpb.UploadKnowledgeBaseFileResponse{ + File: &artifactpb.File{ + FileUid: res.UID.String(), + OwnerUid: res.Owner.String(), + CreatorUid: res.CreatorUID.String(), + KbUid: res.KnowledgeBaseUID.String(), + Name: res.Name, + Type: req.File.Type, + CreateTime: timestamppb.New(*res.CreateTime), + UpdateTime: timestamppb.New(*res.UpdateTime), + ProcessStatus: artifactpb.FileProcessStatus_FILE_PROCESS_STATUS_NOTSTARTED, + }, + }, nil +} + +func checkUploadKnowledgeBaseFileRequest(req *artifactpb.UploadKnowledgeBaseFileRequest) error { + if req.OwnerId == "" { + return fmt.Errorf("owner uid is required. err: %w", ErrCheckRequiredFields) + } else if req.KbId == "" { + return fmt.Errorf("knowledge base uid is required. err: %w", ErrCheckRequiredFields) + } else if req.File == nil { + return fmt.Errorf("file is required. err: %w", ErrCheckRequiredFields) + } else if req.File.Name == "" { + return fmt.Errorf("file name is required. err: %w", ErrCheckRequiredFields) + } else if req.File.Content == "" { + return fmt.Errorf("file content is required. err: %w", ErrCheckRequiredFields) + } else if req.File.Type == 0 { + return fmt.Errorf("file type is required. err: %w", ErrCheckRequiredFields) + } else if !checkValidFileType(req.File.Type) { + return fmt.Errorf("file type is not supported. err: %w", customerror.ErrInvalidArgument) + } + + return nil +} + +// check if type in pdf, markdown or text +func checkValidFileType(t artifactpb.FileType) bool { + if t == artifactpb.FileType_FILE_TYPE_PDF || + t == artifactpb.FileType_FILE_TYPE_MARKDOWN || + t == artifactpb.FileType_FILE_TYPE_TEXT { + return true + } + return false +} + +func (ph *PublicHandler) ListKnowledgeBaseFiles(ctx context.Context, req *artifactpb.ListKnowledgeBaseFilesRequest) (*artifactpb.ListKnowledgeBaseFilesResponse, error) { + + log, _ := logger.GetZapLogger(ctx) + fmt.Println("ListKnowledgeBaseFiles>>>", req) + uid, err := getUserUIDFromContext(ctx) + if err != nil { + log.Error("failed to get user id from header", zap.Error(err)) + err := fmt.Errorf("failed to get user id from header: %v. err: %w", err, customerror.ErrUnauthenticated) + return nil, err + } + + // TODO: ACL - check if the creator can list files in this knowledge base. ACL using uid to check the certain namespace resource. + // acl, err := ph.service.ACL.CheckPermission(ctx, uid, "knowledgeBase", req.KbId, "read") + + // get the owner uid from the mgmt service + var ownerUID string + { + filter := "id=" + req.OwnerId + ownerRes, err := ph.service.MgmtPrv.ListUsersAdmin(ctx, &mgmtpb.ListUsersAdminRequest{Filter: &filter}) + if err != nil { + log.Error("failed to get owner uid", zap.Error(err)) + return nil, err + } + if ownerRes == nil || len(ownerRes.Users) == 0 { + return nil, fmt.Errorf("failed to get owner uid. err: %w", customerror.ErrNotFound) + } + ownerUID = *ownerRes.Users[0].Uid + + } + + // get the kb uid from the knowledge base table + var kbUID string + { + kb, err := ph.service.Repository.GetKnowledgeBaseByOwnerAndID(ctx, ownerUID, req.KbId) + if err != nil { + log.Error("failed to get knowledge base by owner and id", zap.Error(err)) + return nil, err + } + kbUID = kb.UID.String() + } + // fetch the knowledge base files + var files []*artifactpb.File + var totalSize int + var nextPageToken string + { + if req.Filter == nil { + req.Filter = &artifactpb.ListKnowledgeBaseFilesFilter{ + FileUids: []string{}, + } + } + kbFiles, size, nextToken, err := ph.service.Repository.ListKnowledgeBaseFiles(ctx, uid, ownerUID, kbUID, req.PageSize, req.PageToken, req.Filter.FileUids) + if err != nil { + log.Error("failed to list knowledge base files", zap.Error(err)) + return nil, err + } + totalSize = size + nextPageToken = nextToken + for _, kbFile := range kbFiles { + files = append(files, &artifactpb.File{ + FileUid: kbFile.UID.String(), + OwnerUid: kbFile.Owner.String(), + CreatorUid: kbFile.CreatorUID.String(), + KbUid: kbFile.KnowledgeBaseUID.String(), + Name: kbFile.Name, + Type: artifactpb.FileType(artifactpb.FileType_value[kbFile.Type]), + CreateTime: timestamppb.New(*kbFile.CreateTime), + UpdateTime: timestamppb.New(*kbFile.UpdateTime), + ProcessStatus: artifactpb.FileProcessStatus(artifactpb.FileProcessStatus_value[kbFile.ProcessStatus]), + }) + } + } + + return &artifactpb.ListKnowledgeBaseFilesResponse{ + Files: files, + TotalSize: int32(totalSize), + NextPageToken: nextPageToken, + Filter: req.Filter, + }, nil +} + +func (ph *PublicHandler) DeleteKnowledgeBaseFile( + ctx context.Context, + req *artifactpb.DeleteKnowledgeBaseFileRequest) ( + *artifactpb.DeleteKnowledgeBaseFileResponse, error) { + + // uid, err := getUserIDFromContext(ctx) + // if err != nil { + // err := fmt.Errorf("failed to get user id from header: %v. err: %w", err, customerror.ErrUnauthenticated) + // return nil, err + // } + + // TODO: ACL - check if the uid can delete file. ACL. + + err := ph.service.Repository.DeleteKnowledgeBaseFile(ctx, req.FileUid) + if err != nil { + return nil, err + } + return &artifactpb.DeleteKnowledgeBaseFileResponse{ + FileUid: req.FileUid, + }, nil + +} + +func (ph *PublicHandler) ProcessKnowledgeBaseFiles(ctx context.Context, req *artifactpb.ProcessKnowledgeBaseFilesRequest) (*artifactpb.ProcessKnowledgeBaseFilesResponse, error) { + // uid, err := getUserIDFromContext(ctx) + // if err != nil { + // err := fmt.Errorf("failed to get user id from header: %v. err: %w", err, customerror.ErrUnauthenticated) + // return nil, err + // } + + // TODO: ACL - check if the uid can process file. ACL. + // .... + + files, err := ph.service.Repository.ProcessKnowledgeBaseFiles(ctx, req.FileUids) + if err != nil { + return nil, err + } + + // populate the files into response + var resFiles []*artifactpb.File + for _, file := range files { + resFiles = append(resFiles, &artifactpb.File{ + FileUid: file.UID.String(), + OwnerUid: file.Owner.String(), + CreatorUid: file.CreatorUID.String(), + KbUid: file.KnowledgeBaseUID.String(), + Name: file.Name, + Type: artifactpb.FileType(artifactpb.FileType_value[file.Type]), + CreateTime: timestamppb.New(*file.CreateTime), + UpdateTime: timestamppb.New(*file.UpdateTime), + ProcessStatus: artifactpb.FileProcessStatus(artifactpb.FileProcessStatus_value[file.ProcessStatus]), + }) + } + return &artifactpb.ProcessKnowledgeBaseFilesResponse{ + Files: resFiles, + }, nil +} + +func fileTypeConvertToMime(t artifactpb.FileType) string { + switch t { + case artifactpb.FileType_FILE_TYPE_PDF: + return "application/pdf" + case artifactpb.FileType_FILE_TYPE_MARKDOWN: + return "text/markdown" + case artifactpb.FileType_FILE_TYPE_TEXT: + return "text/plain" + default: + return "application/octet-stream" + } +} \ No newline at end of file diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 6d4c300..3242bf4 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -95,7 +95,10 @@ func GetZapLogger(ctx context.Context) (*zap.Logger, error) { } return nil - })) + }), + zap.AddCaller(), + zap.AddStacktrace(zapcore.ErrorLevel), + ) return logger, err } diff --git a/pkg/minio/minio.go b/pkg/minio/minio.go new file mode 100644 index 0000000..48499a1 --- /dev/null +++ b/pkg/minio/minio.go @@ -0,0 +1,93 @@ +package minio + +import ( + "context" + "encoding/base64" + "strings" + + "github.com/instill-ai/artifact-backend/config" + log "github.com/instill-ai/artifact-backend/pkg/logger" + + "github.com/minio/minio-go" + "go.uber.org/zap" +) + +type MinioI interface { + GetClient() *minio.Client + // uploadFile + UploadBase64File(ctx context.Context, filePathName string, base64Content string, fileMimeType string) (err error) + // deleteFile + DeleteFile(ctx context.Context, filePathName string) (err error) +} + +type Minio struct { + client *minio.Client + bucket string +} + +func NewMinioClientAndInitBucket() (*Minio, error) { + cfg := config.Config.Minio + log, err := log.GetZapLogger(context.Background()) + if err != nil { + return nil, err + } + client, err := minio.New(cfg.Host+":"+cfg.Port, cfg.RootUser, cfg.RootUser, false) + if err != nil { + return nil, err + } + err = client.MakeBucket(cfg.BucketName, "us-east-1") + if err != nil { + // Check if the bucket already exists + exists, errBucketExists := client.BucketExists(cfg.BucketName) + if errBucketExists == nil && exists { + log.Info("Bucket already exists", zap.String("bucket", cfg.BucketName), zap.Error(err)) + } else { + log.Fatal(err.Error(), zap.Error(err)) + } + } else { + log.Info("Successfully created bucket", zap.String("bucket", cfg.BucketName)) + } + return &Minio{client: client, bucket: cfg.BucketName}, nil +} + +func (m *Minio) GetClient() *minio.Client { + return m.client +} + +func (m *Minio) UploadBase64File(ctx context.Context, filePathName string, base64Content string, fileMimeType string) (err error) { + log, err := log.GetZapLogger(ctx) + if err != nil { + return err + } + // Decode the base64 content + decodedContent, err := base64.StdEncoding.DecodeString(base64Content) + if err != nil { + return err + } + // Convert the decoded content to an io.Reader + contentReader := strings.NewReader(string(decodedContent)) + // Upload the content to MinIO + size := int64(len(decodedContent)) + // Create the file path with folder structure + _, err = m.client.PutObjectWithContext(ctx, m.bucket, filePathName, contentReader, size, minio.PutObjectOptions{ContentType: fileMimeType}) + if err != nil { + log.Error("Failed to upload file to MinIO", zap.Error(err)) + return err + } + return nil +} + +// delete the file from minio +func (m *Minio) DeleteFile(ctx context.Context, filePathName string) (err error) { + log, err := log.GetZapLogger(ctx) + if err != nil { + return err + } + // Delete the file from MinIO + err = m.client.RemoveObject(m.bucket, filePathName) + if err != nil { + log.Error("Failed to delete file from MinIO", zap.Error(err)) + return err + } + return nil +} diff --git a/pkg/mock/repository_i_mock.gen.go b/pkg/mock/repository_i_mock.gen.go index de88e1b..0e14b85 100644 --- a/pkg/mock/repository_i_mock.gen.go +++ b/pkg/mock/repository_i_mock.gen.go @@ -25,24 +25,54 @@ type RepositoryIMock struct { beforeCreateKnowledgeBaseCounter uint64 CreateKnowledgeBaseMock mRepositoryIMockCreateKnowledgeBase - funcDeleteKnowledgeBase func(ctx context.Context, uid string, kb_id string) (err error) - inspectFuncDeleteKnowledgeBase func(ctx context.Context, uid string, kb_id string) + funcCreateKnowledgeBaseFile func(ctx context.Context, kb mm_repository.KnowledgeBaseFile) (kp1 *mm_repository.KnowledgeBaseFile, err error) + inspectFuncCreateKnowledgeBaseFile func(ctx context.Context, kb mm_repository.KnowledgeBaseFile) + afterCreateKnowledgeBaseFileCounter uint64 + beforeCreateKnowledgeBaseFileCounter uint64 + CreateKnowledgeBaseFileMock mRepositoryIMockCreateKnowledgeBaseFile + + funcDeleteKnowledgeBase func(ctx context.Context, uid string, kbID string) (err error) + inspectFuncDeleteKnowledgeBase func(ctx context.Context, uid string, kbID string) afterDeleteKnowledgeBaseCounter uint64 beforeDeleteKnowledgeBaseCounter uint64 DeleteKnowledgeBaseMock mRepositoryIMockDeleteKnowledgeBase + funcDeleteKnowledgeBaseFile func(ctx context.Context, file_uid string) (err error) + inspectFuncDeleteKnowledgeBaseFile func(ctx context.Context, file_uid string) + afterDeleteKnowledgeBaseFileCounter uint64 + beforeDeleteKnowledgeBaseFileCounter uint64 + DeleteKnowledgeBaseFileMock mRepositoryIMockDeleteKnowledgeBaseFile + + funcGetKnowledgeBaseByOwnerAndID func(ctx context.Context, owner string, kbID string) (kp1 *mm_repository.KnowledgeBase, err error) + inspectFuncGetKnowledgeBaseByOwnerAndID func(ctx context.Context, owner string, kbID string) + afterGetKnowledgeBaseByOwnerAndIDCounter uint64 + beforeGetKnowledgeBaseByOwnerAndIDCounter uint64 + GetKnowledgeBaseByOwnerAndIDMock mRepositoryIMockGetKnowledgeBaseByOwnerAndID + funcGetRepositoryTag func(ctx context.Context, r1 utils.RepositoryTagName) (rp1 *pb.RepositoryTag, err error) inspectFuncGetRepositoryTag func(ctx context.Context, r1 utils.RepositoryTagName) afterGetRepositoryTagCounter uint64 beforeGetRepositoryTagCounter uint64 GetRepositoryTagMock mRepositoryIMockGetRepositoryTag + funcListKnowledgeBaseFiles func(ctx context.Context, uid string, owner_uid string, kb_uid string, page_size int32, next_page_token string, files_uid []string) (ka1 []mm_repository.KnowledgeBaseFile, i1 int, s1 string, err error) + inspectFuncListKnowledgeBaseFiles func(ctx context.Context, uid string, owner_uid string, kb_uid string, page_size int32, next_page_token string, files_uid []string) + afterListKnowledgeBaseFilesCounter uint64 + beforeListKnowledgeBaseFilesCounter uint64 + ListKnowledgeBaseFilesMock mRepositoryIMockListKnowledgeBaseFiles + funcListKnowledgeBases func(ctx context.Context, uid string) (ka1 []mm_repository.KnowledgeBase, err error) inspectFuncListKnowledgeBases func(ctx context.Context, uid string) afterListKnowledgeBasesCounter uint64 beforeListKnowledgeBasesCounter uint64 ListKnowledgeBasesMock mRepositoryIMockListKnowledgeBases + funcProcessKnowledgeBaseFiles func(ctx context.Context, file_uids []string) (ka1 []mm_repository.KnowledgeBaseFile, err error) + inspectFuncProcessKnowledgeBaseFiles func(ctx context.Context, file_uids []string) + afterProcessKnowledgeBaseFilesCounter uint64 + beforeProcessKnowledgeBaseFilesCounter uint64 + ProcessKnowledgeBaseFilesMock mRepositoryIMockProcessKnowledgeBaseFiles + funcUpdateKnowledgeBase func(ctx context.Context, uid string, kb mm_repository.KnowledgeBase) (kp1 *mm_repository.KnowledgeBase, err error) inspectFuncUpdateKnowledgeBase func(ctx context.Context, uid string, kb mm_repository.KnowledgeBase) afterUpdateKnowledgeBaseCounter uint64 @@ -67,15 +97,30 @@ func NewRepositoryIMock(t minimock.Tester) *RepositoryIMock { m.CreateKnowledgeBaseMock = mRepositoryIMockCreateKnowledgeBase{mock: m} m.CreateKnowledgeBaseMock.callArgs = []*RepositoryIMockCreateKnowledgeBaseParams{} + m.CreateKnowledgeBaseFileMock = mRepositoryIMockCreateKnowledgeBaseFile{mock: m} + m.CreateKnowledgeBaseFileMock.callArgs = []*RepositoryIMockCreateKnowledgeBaseFileParams{} + m.DeleteKnowledgeBaseMock = mRepositoryIMockDeleteKnowledgeBase{mock: m} m.DeleteKnowledgeBaseMock.callArgs = []*RepositoryIMockDeleteKnowledgeBaseParams{} + m.DeleteKnowledgeBaseFileMock = mRepositoryIMockDeleteKnowledgeBaseFile{mock: m} + m.DeleteKnowledgeBaseFileMock.callArgs = []*RepositoryIMockDeleteKnowledgeBaseFileParams{} + + m.GetKnowledgeBaseByOwnerAndIDMock = mRepositoryIMockGetKnowledgeBaseByOwnerAndID{mock: m} + m.GetKnowledgeBaseByOwnerAndIDMock.callArgs = []*RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams{} + m.GetRepositoryTagMock = mRepositoryIMockGetRepositoryTag{mock: m} m.GetRepositoryTagMock.callArgs = []*RepositoryIMockGetRepositoryTagParams{} + m.ListKnowledgeBaseFilesMock = mRepositoryIMockListKnowledgeBaseFiles{mock: m} + m.ListKnowledgeBaseFilesMock.callArgs = []*RepositoryIMockListKnowledgeBaseFilesParams{} + m.ListKnowledgeBasesMock = mRepositoryIMockListKnowledgeBases{mock: m} m.ListKnowledgeBasesMock.callArgs = []*RepositoryIMockListKnowledgeBasesParams{} + m.ProcessKnowledgeBaseFilesMock = mRepositoryIMockProcessKnowledgeBaseFiles{mock: m} + m.ProcessKnowledgeBaseFilesMock.callArgs = []*RepositoryIMockProcessKnowledgeBaseFilesParams{} + m.UpdateKnowledgeBaseMock = mRepositoryIMockUpdateKnowledgeBase{mock: m} m.UpdateKnowledgeBaseMock.callArgs = []*RepositoryIMockUpdateKnowledgeBaseParams{} @@ -392,6 +437,311 @@ func (m *RepositoryIMock) MinimockCreateKnowledgeBaseInspect() { } } +type mRepositoryIMockCreateKnowledgeBaseFile struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockCreateKnowledgeBaseFileExpectation + expectations []*RepositoryIMockCreateKnowledgeBaseFileExpectation + + callArgs []*RepositoryIMockCreateKnowledgeBaseFileParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockCreateKnowledgeBaseFileExpectation specifies expectation struct of the RepositoryI.CreateKnowledgeBaseFile +type RepositoryIMockCreateKnowledgeBaseFileExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockCreateKnowledgeBaseFileParams + paramPtrs *RepositoryIMockCreateKnowledgeBaseFileParamPtrs + results *RepositoryIMockCreateKnowledgeBaseFileResults + Counter uint64 +} + +// RepositoryIMockCreateKnowledgeBaseFileParams contains parameters of the RepositoryI.CreateKnowledgeBaseFile +type RepositoryIMockCreateKnowledgeBaseFileParams struct { + ctx context.Context + kb mm_repository.KnowledgeBaseFile +} + +// RepositoryIMockCreateKnowledgeBaseFileParamPtrs contains pointers to parameters of the RepositoryI.CreateKnowledgeBaseFile +type RepositoryIMockCreateKnowledgeBaseFileParamPtrs struct { + ctx *context.Context + kb *mm_repository.KnowledgeBaseFile +} + +// RepositoryIMockCreateKnowledgeBaseFileResults contains results of the RepositoryI.CreateKnowledgeBaseFile +type RepositoryIMockCreateKnowledgeBaseFileResults struct { + kp1 *mm_repository.KnowledgeBaseFile + err error +} + +// Expect sets up expected params for RepositoryI.CreateKnowledgeBaseFile +func (mmCreateKnowledgeBaseFile *mRepositoryIMockCreateKnowledgeBaseFile) Expect(ctx context.Context, kb mm_repository.KnowledgeBaseFile) *mRepositoryIMockCreateKnowledgeBaseFile { + if mmCreateKnowledgeBaseFile.mock.funcCreateKnowledgeBaseFile != nil { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBaseFile mock is already set by Set") + } + + if mmCreateKnowledgeBaseFile.defaultExpectation == nil { + mmCreateKnowledgeBaseFile.defaultExpectation = &RepositoryIMockCreateKnowledgeBaseFileExpectation{} + } + + if mmCreateKnowledgeBaseFile.defaultExpectation.paramPtrs != nil { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBaseFile mock is already set by ExpectParams functions") + } + + mmCreateKnowledgeBaseFile.defaultExpectation.params = &RepositoryIMockCreateKnowledgeBaseFileParams{ctx, kb} + for _, e := range mmCreateKnowledgeBaseFile.expectations { + if minimock.Equal(e.params, mmCreateKnowledgeBaseFile.defaultExpectation.params) { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmCreateKnowledgeBaseFile.defaultExpectation.params) + } + } + + return mmCreateKnowledgeBaseFile +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.CreateKnowledgeBaseFile +func (mmCreateKnowledgeBaseFile *mRepositoryIMockCreateKnowledgeBaseFile) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockCreateKnowledgeBaseFile { + if mmCreateKnowledgeBaseFile.mock.funcCreateKnowledgeBaseFile != nil { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBaseFile mock is already set by Set") + } + + if mmCreateKnowledgeBaseFile.defaultExpectation == nil { + mmCreateKnowledgeBaseFile.defaultExpectation = &RepositoryIMockCreateKnowledgeBaseFileExpectation{} + } + + if mmCreateKnowledgeBaseFile.defaultExpectation.params != nil { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBaseFile mock is already set by Expect") + } + + if mmCreateKnowledgeBaseFile.defaultExpectation.paramPtrs == nil { + mmCreateKnowledgeBaseFile.defaultExpectation.paramPtrs = &RepositoryIMockCreateKnowledgeBaseFileParamPtrs{} + } + mmCreateKnowledgeBaseFile.defaultExpectation.paramPtrs.ctx = &ctx + + return mmCreateKnowledgeBaseFile +} + +// ExpectKbParam2 sets up expected param kb for RepositoryI.CreateKnowledgeBaseFile +func (mmCreateKnowledgeBaseFile *mRepositoryIMockCreateKnowledgeBaseFile) ExpectKbParam2(kb mm_repository.KnowledgeBaseFile) *mRepositoryIMockCreateKnowledgeBaseFile { + if mmCreateKnowledgeBaseFile.mock.funcCreateKnowledgeBaseFile != nil { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBaseFile mock is already set by Set") + } + + if mmCreateKnowledgeBaseFile.defaultExpectation == nil { + mmCreateKnowledgeBaseFile.defaultExpectation = &RepositoryIMockCreateKnowledgeBaseFileExpectation{} + } + + if mmCreateKnowledgeBaseFile.defaultExpectation.params != nil { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBaseFile mock is already set by Expect") + } + + if mmCreateKnowledgeBaseFile.defaultExpectation.paramPtrs == nil { + mmCreateKnowledgeBaseFile.defaultExpectation.paramPtrs = &RepositoryIMockCreateKnowledgeBaseFileParamPtrs{} + } + mmCreateKnowledgeBaseFile.defaultExpectation.paramPtrs.kb = &kb + + return mmCreateKnowledgeBaseFile +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.CreateKnowledgeBaseFile +func (mmCreateKnowledgeBaseFile *mRepositoryIMockCreateKnowledgeBaseFile) Inspect(f func(ctx context.Context, kb mm_repository.KnowledgeBaseFile)) *mRepositoryIMockCreateKnowledgeBaseFile { + if mmCreateKnowledgeBaseFile.mock.inspectFuncCreateKnowledgeBaseFile != nil { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.CreateKnowledgeBaseFile") + } + + mmCreateKnowledgeBaseFile.mock.inspectFuncCreateKnowledgeBaseFile = f + + return mmCreateKnowledgeBaseFile +} + +// Return sets up results that will be returned by RepositoryI.CreateKnowledgeBaseFile +func (mmCreateKnowledgeBaseFile *mRepositoryIMockCreateKnowledgeBaseFile) Return(kp1 *mm_repository.KnowledgeBaseFile, err error) *RepositoryIMock { + if mmCreateKnowledgeBaseFile.mock.funcCreateKnowledgeBaseFile != nil { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBaseFile mock is already set by Set") + } + + if mmCreateKnowledgeBaseFile.defaultExpectation == nil { + mmCreateKnowledgeBaseFile.defaultExpectation = &RepositoryIMockCreateKnowledgeBaseFileExpectation{mock: mmCreateKnowledgeBaseFile.mock} + } + mmCreateKnowledgeBaseFile.defaultExpectation.results = &RepositoryIMockCreateKnowledgeBaseFileResults{kp1, err} + return mmCreateKnowledgeBaseFile.mock +} + +// Set uses given function f to mock the RepositoryI.CreateKnowledgeBaseFile method +func (mmCreateKnowledgeBaseFile *mRepositoryIMockCreateKnowledgeBaseFile) Set(f func(ctx context.Context, kb mm_repository.KnowledgeBaseFile) (kp1 *mm_repository.KnowledgeBaseFile, err error)) *RepositoryIMock { + if mmCreateKnowledgeBaseFile.defaultExpectation != nil { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("Default expectation is already set for the RepositoryI.CreateKnowledgeBaseFile method") + } + + if len(mmCreateKnowledgeBaseFile.expectations) > 0 { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("Some expectations are already set for the RepositoryI.CreateKnowledgeBaseFile method") + } + + mmCreateKnowledgeBaseFile.mock.funcCreateKnowledgeBaseFile = f + return mmCreateKnowledgeBaseFile.mock +} + +// When sets expectation for the RepositoryI.CreateKnowledgeBaseFile which will trigger the result defined by the following +// Then helper +func (mmCreateKnowledgeBaseFile *mRepositoryIMockCreateKnowledgeBaseFile) When(ctx context.Context, kb mm_repository.KnowledgeBaseFile) *RepositoryIMockCreateKnowledgeBaseFileExpectation { + if mmCreateKnowledgeBaseFile.mock.funcCreateKnowledgeBaseFile != nil { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBaseFile mock is already set by Set") + } + + expectation := &RepositoryIMockCreateKnowledgeBaseFileExpectation{ + mock: mmCreateKnowledgeBaseFile.mock, + params: &RepositoryIMockCreateKnowledgeBaseFileParams{ctx, kb}, + } + mmCreateKnowledgeBaseFile.expectations = append(mmCreateKnowledgeBaseFile.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.CreateKnowledgeBaseFile return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockCreateKnowledgeBaseFileExpectation) Then(kp1 *mm_repository.KnowledgeBaseFile, err error) *RepositoryIMock { + e.results = &RepositoryIMockCreateKnowledgeBaseFileResults{kp1, err} + return e.mock +} + +// Times sets number of times RepositoryI.CreateKnowledgeBaseFile should be invoked +func (mmCreateKnowledgeBaseFile *mRepositoryIMockCreateKnowledgeBaseFile) Times(n uint64) *mRepositoryIMockCreateKnowledgeBaseFile { + if n == 0 { + mmCreateKnowledgeBaseFile.mock.t.Fatalf("Times of RepositoryIMock.CreateKnowledgeBaseFile mock can not be zero") + } + mm_atomic.StoreUint64(&mmCreateKnowledgeBaseFile.expectedInvocations, n) + return mmCreateKnowledgeBaseFile +} + +func (mmCreateKnowledgeBaseFile *mRepositoryIMockCreateKnowledgeBaseFile) invocationsDone() bool { + if len(mmCreateKnowledgeBaseFile.expectations) == 0 && mmCreateKnowledgeBaseFile.defaultExpectation == nil && mmCreateKnowledgeBaseFile.mock.funcCreateKnowledgeBaseFile == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmCreateKnowledgeBaseFile.mock.afterCreateKnowledgeBaseFileCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmCreateKnowledgeBaseFile.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// CreateKnowledgeBaseFile implements repository.RepositoryI +func (mmCreateKnowledgeBaseFile *RepositoryIMock) CreateKnowledgeBaseFile(ctx context.Context, kb mm_repository.KnowledgeBaseFile) (kp1 *mm_repository.KnowledgeBaseFile, err error) { + mm_atomic.AddUint64(&mmCreateKnowledgeBaseFile.beforeCreateKnowledgeBaseFileCounter, 1) + defer mm_atomic.AddUint64(&mmCreateKnowledgeBaseFile.afterCreateKnowledgeBaseFileCounter, 1) + + if mmCreateKnowledgeBaseFile.inspectFuncCreateKnowledgeBaseFile != nil { + mmCreateKnowledgeBaseFile.inspectFuncCreateKnowledgeBaseFile(ctx, kb) + } + + mm_params := RepositoryIMockCreateKnowledgeBaseFileParams{ctx, kb} + + // Record call args + mmCreateKnowledgeBaseFile.CreateKnowledgeBaseFileMock.mutex.Lock() + mmCreateKnowledgeBaseFile.CreateKnowledgeBaseFileMock.callArgs = append(mmCreateKnowledgeBaseFile.CreateKnowledgeBaseFileMock.callArgs, &mm_params) + mmCreateKnowledgeBaseFile.CreateKnowledgeBaseFileMock.mutex.Unlock() + + for _, e := range mmCreateKnowledgeBaseFile.CreateKnowledgeBaseFileMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.kp1, e.results.err + } + } + + if mmCreateKnowledgeBaseFile.CreateKnowledgeBaseFileMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmCreateKnowledgeBaseFile.CreateKnowledgeBaseFileMock.defaultExpectation.Counter, 1) + mm_want := mmCreateKnowledgeBaseFile.CreateKnowledgeBaseFileMock.defaultExpectation.params + mm_want_ptrs := mmCreateKnowledgeBaseFile.CreateKnowledgeBaseFileMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockCreateKnowledgeBaseFileParams{ctx, kb} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmCreateKnowledgeBaseFile.t.Errorf("RepositoryIMock.CreateKnowledgeBaseFile 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.kb != nil && !minimock.Equal(*mm_want_ptrs.kb, mm_got.kb) { + mmCreateKnowledgeBaseFile.t.Errorf("RepositoryIMock.CreateKnowledgeBaseFile got unexpected parameter kb, want: %#v, got: %#v%s\n", *mm_want_ptrs.kb, mm_got.kb, minimock.Diff(*mm_want_ptrs.kb, mm_got.kb)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmCreateKnowledgeBaseFile.t.Errorf("RepositoryIMock.CreateKnowledgeBaseFile got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmCreateKnowledgeBaseFile.CreateKnowledgeBaseFileMock.defaultExpectation.results + if mm_results == nil { + mmCreateKnowledgeBaseFile.t.Fatal("No results are set for the RepositoryIMock.CreateKnowledgeBaseFile") + } + return (*mm_results).kp1, (*mm_results).err + } + if mmCreateKnowledgeBaseFile.funcCreateKnowledgeBaseFile != nil { + return mmCreateKnowledgeBaseFile.funcCreateKnowledgeBaseFile(ctx, kb) + } + mmCreateKnowledgeBaseFile.t.Fatalf("Unexpected call to RepositoryIMock.CreateKnowledgeBaseFile. %v %v", ctx, kb) + return +} + +// CreateKnowledgeBaseFileAfterCounter returns a count of finished RepositoryIMock.CreateKnowledgeBaseFile invocations +func (mmCreateKnowledgeBaseFile *RepositoryIMock) CreateKnowledgeBaseFileAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmCreateKnowledgeBaseFile.afterCreateKnowledgeBaseFileCounter) +} + +// CreateKnowledgeBaseFileBeforeCounter returns a count of RepositoryIMock.CreateKnowledgeBaseFile invocations +func (mmCreateKnowledgeBaseFile *RepositoryIMock) CreateKnowledgeBaseFileBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmCreateKnowledgeBaseFile.beforeCreateKnowledgeBaseFileCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.CreateKnowledgeBaseFile. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmCreateKnowledgeBaseFile *mRepositoryIMockCreateKnowledgeBaseFile) Calls() []*RepositoryIMockCreateKnowledgeBaseFileParams { + mmCreateKnowledgeBaseFile.mutex.RLock() + + argCopy := make([]*RepositoryIMockCreateKnowledgeBaseFileParams, len(mmCreateKnowledgeBaseFile.callArgs)) + copy(argCopy, mmCreateKnowledgeBaseFile.callArgs) + + mmCreateKnowledgeBaseFile.mutex.RUnlock() + + return argCopy +} + +// MinimockCreateKnowledgeBaseFileDone returns true if the count of the CreateKnowledgeBaseFile invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockCreateKnowledgeBaseFileDone() bool { + for _, e := range m.CreateKnowledgeBaseFileMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.CreateKnowledgeBaseFileMock.invocationsDone() +} + +// MinimockCreateKnowledgeBaseFileInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockCreateKnowledgeBaseFileInspect() { + for _, e := range m.CreateKnowledgeBaseFileMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.CreateKnowledgeBaseFile with params: %#v", *e.params) + } + } + + afterCreateKnowledgeBaseFileCounter := mm_atomic.LoadUint64(&m.afterCreateKnowledgeBaseFileCounter) + // if default expectation was set then invocations count should be greater than zero + if m.CreateKnowledgeBaseFileMock.defaultExpectation != nil && afterCreateKnowledgeBaseFileCounter < 1 { + if m.CreateKnowledgeBaseFileMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.CreateKnowledgeBaseFile") + } else { + m.t.Errorf("Expected call to RepositoryIMock.CreateKnowledgeBaseFile with params: %#v", *m.CreateKnowledgeBaseFileMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcCreateKnowledgeBaseFile != nil && afterCreateKnowledgeBaseFileCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.CreateKnowledgeBaseFile") + } + + if !m.CreateKnowledgeBaseFileMock.invocationsDone() && afterCreateKnowledgeBaseFileCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.CreateKnowledgeBaseFile but found %d calls", + mm_atomic.LoadUint64(&m.CreateKnowledgeBaseFileMock.expectedInvocations), afterCreateKnowledgeBaseFileCounter) + } +} + type mRepositoryIMockDeleteKnowledgeBase struct { mock *RepositoryIMock defaultExpectation *RepositoryIMockDeleteKnowledgeBaseExpectation @@ -414,16 +764,16 @@ type RepositoryIMockDeleteKnowledgeBaseExpectation struct { // RepositoryIMockDeleteKnowledgeBaseParams contains parameters of the RepositoryI.DeleteKnowledgeBase type RepositoryIMockDeleteKnowledgeBaseParams struct { - ctx context.Context - uid string - kb_id string + ctx context.Context + uid string + kbID string } // RepositoryIMockDeleteKnowledgeBaseParamPtrs contains pointers to parameters of the RepositoryI.DeleteKnowledgeBase type RepositoryIMockDeleteKnowledgeBaseParamPtrs struct { - ctx *context.Context - uid *string - kb_id *string + ctx *context.Context + uid *string + kbID *string } // RepositoryIMockDeleteKnowledgeBaseResults contains results of the RepositoryI.DeleteKnowledgeBase @@ -432,7 +782,7 @@ type RepositoryIMockDeleteKnowledgeBaseResults struct { } // Expect sets up expected params for RepositoryI.DeleteKnowledgeBase -func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Expect(ctx context.Context, uid string, kb_id string) *mRepositoryIMockDeleteKnowledgeBase { +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Expect(ctx context.Context, uid string, kbID string) *mRepositoryIMockDeleteKnowledgeBase { if mmDeleteKnowledgeBase.mock.funcDeleteKnowledgeBase != nil { mmDeleteKnowledgeBase.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBase mock is already set by Set") } @@ -445,7 +795,7 @@ func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Expect(ctx con mmDeleteKnowledgeBase.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBase mock is already set by ExpectParams functions") } - mmDeleteKnowledgeBase.defaultExpectation.params = &RepositoryIMockDeleteKnowledgeBaseParams{ctx, uid, kb_id} + mmDeleteKnowledgeBase.defaultExpectation.params = &RepositoryIMockDeleteKnowledgeBaseParams{ctx, uid, kbID} for _, e := range mmDeleteKnowledgeBase.expectations { if minimock.Equal(e.params, mmDeleteKnowledgeBase.defaultExpectation.params) { mmDeleteKnowledgeBase.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteKnowledgeBase.defaultExpectation.params) @@ -499,8 +849,8 @@ func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) ExpectUidParam return mmDeleteKnowledgeBase } -// ExpectKb_idParam3 sets up expected param kb_id for RepositoryI.DeleteKnowledgeBase -func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) ExpectKb_idParam3(kb_id string) *mRepositoryIMockDeleteKnowledgeBase { +// ExpectKbIDParam3 sets up expected param kbID for RepositoryI.DeleteKnowledgeBase +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) ExpectKbIDParam3(kbID string) *mRepositoryIMockDeleteKnowledgeBase { if mmDeleteKnowledgeBase.mock.funcDeleteKnowledgeBase != nil { mmDeleteKnowledgeBase.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBase mock is already set by Set") } @@ -516,13 +866,13 @@ func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) ExpectKb_idPar if mmDeleteKnowledgeBase.defaultExpectation.paramPtrs == nil { mmDeleteKnowledgeBase.defaultExpectation.paramPtrs = &RepositoryIMockDeleteKnowledgeBaseParamPtrs{} } - mmDeleteKnowledgeBase.defaultExpectation.paramPtrs.kb_id = &kb_id + mmDeleteKnowledgeBase.defaultExpectation.paramPtrs.kbID = &kbID return mmDeleteKnowledgeBase } // Inspect accepts an inspector function that has same arguments as the RepositoryI.DeleteKnowledgeBase -func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Inspect(f func(ctx context.Context, uid string, kb_id string)) *mRepositoryIMockDeleteKnowledgeBase { +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Inspect(f func(ctx context.Context, uid string, kbID string)) *mRepositoryIMockDeleteKnowledgeBase { if mmDeleteKnowledgeBase.mock.inspectFuncDeleteKnowledgeBase != nil { mmDeleteKnowledgeBase.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.DeleteKnowledgeBase") } @@ -546,7 +896,7 @@ func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Return(err err } // Set uses given function f to mock the RepositoryI.DeleteKnowledgeBase method -func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Set(f func(ctx context.Context, uid string, kb_id string) (err error)) *RepositoryIMock { +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Set(f func(ctx context.Context, uid string, kbID string) (err error)) *RepositoryIMock { if mmDeleteKnowledgeBase.defaultExpectation != nil { mmDeleteKnowledgeBase.mock.t.Fatalf("Default expectation is already set for the RepositoryI.DeleteKnowledgeBase method") } @@ -561,14 +911,14 @@ func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Set(f func(ctx // When sets expectation for the RepositoryI.DeleteKnowledgeBase which will trigger the result defined by the following // Then helper -func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) When(ctx context.Context, uid string, kb_id string) *RepositoryIMockDeleteKnowledgeBaseExpectation { +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) When(ctx context.Context, uid string, kbID string) *RepositoryIMockDeleteKnowledgeBaseExpectation { if mmDeleteKnowledgeBase.mock.funcDeleteKnowledgeBase != nil { mmDeleteKnowledgeBase.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBase mock is already set by Set") } expectation := &RepositoryIMockDeleteKnowledgeBaseExpectation{ mock: mmDeleteKnowledgeBase.mock, - params: &RepositoryIMockDeleteKnowledgeBaseParams{ctx, uid, kb_id}, + params: &RepositoryIMockDeleteKnowledgeBaseParams{ctx, uid, kbID}, } mmDeleteKnowledgeBase.expectations = append(mmDeleteKnowledgeBase.expectations, expectation) return expectation @@ -601,15 +951,15 @@ func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) invocationsDon } // DeleteKnowledgeBase implements repository.RepositoryI -func (mmDeleteKnowledgeBase *RepositoryIMock) DeleteKnowledgeBase(ctx context.Context, uid string, kb_id string) (err error) { +func (mmDeleteKnowledgeBase *RepositoryIMock) DeleteKnowledgeBase(ctx context.Context, uid string, kbID string) (err error) { mm_atomic.AddUint64(&mmDeleteKnowledgeBase.beforeDeleteKnowledgeBaseCounter, 1) defer mm_atomic.AddUint64(&mmDeleteKnowledgeBase.afterDeleteKnowledgeBaseCounter, 1) if mmDeleteKnowledgeBase.inspectFuncDeleteKnowledgeBase != nil { - mmDeleteKnowledgeBase.inspectFuncDeleteKnowledgeBase(ctx, uid, kb_id) + mmDeleteKnowledgeBase.inspectFuncDeleteKnowledgeBase(ctx, uid, kbID) } - mm_params := RepositoryIMockDeleteKnowledgeBaseParams{ctx, uid, kb_id} + mm_params := RepositoryIMockDeleteKnowledgeBaseParams{ctx, uid, kbID} // Record call args mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.mutex.Lock() @@ -628,7 +978,7 @@ func (mmDeleteKnowledgeBase *RepositoryIMock) DeleteKnowledgeBase(ctx context.Co mm_want := mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.defaultExpectation.params mm_want_ptrs := mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.defaultExpectation.paramPtrs - mm_got := RepositoryIMockDeleteKnowledgeBaseParams{ctx, uid, kb_id} + mm_got := RepositoryIMockDeleteKnowledgeBaseParams{ctx, uid, kbID} if mm_want_ptrs != nil { @@ -640,8 +990,8 @@ func (mmDeleteKnowledgeBase *RepositoryIMock) DeleteKnowledgeBase(ctx context.Co mmDeleteKnowledgeBase.t.Errorf("RepositoryIMock.DeleteKnowledgeBase got unexpected parameter uid, want: %#v, got: %#v%s\n", *mm_want_ptrs.uid, mm_got.uid, minimock.Diff(*mm_want_ptrs.uid, mm_got.uid)) } - if mm_want_ptrs.kb_id != nil && !minimock.Equal(*mm_want_ptrs.kb_id, mm_got.kb_id) { - mmDeleteKnowledgeBase.t.Errorf("RepositoryIMock.DeleteKnowledgeBase got unexpected parameter kb_id, want: %#v, got: %#v%s\n", *mm_want_ptrs.kb_id, mm_got.kb_id, minimock.Diff(*mm_want_ptrs.kb_id, mm_got.kb_id)) + if mm_want_ptrs.kbID != nil && !minimock.Equal(*mm_want_ptrs.kbID, mm_got.kbID) { + mmDeleteKnowledgeBase.t.Errorf("RepositoryIMock.DeleteKnowledgeBase got unexpected parameter kbID, want: %#v, got: %#v%s\n", *mm_want_ptrs.kbID, mm_got.kbID, minimock.Diff(*mm_want_ptrs.kbID, mm_got.kbID)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { @@ -655,9 +1005,9 @@ func (mmDeleteKnowledgeBase *RepositoryIMock) DeleteKnowledgeBase(ctx context.Co return (*mm_results).err } if mmDeleteKnowledgeBase.funcDeleteKnowledgeBase != nil { - return mmDeleteKnowledgeBase.funcDeleteKnowledgeBase(ctx, uid, kb_id) + return mmDeleteKnowledgeBase.funcDeleteKnowledgeBase(ctx, uid, kbID) } - mmDeleteKnowledgeBase.t.Fatalf("Unexpected call to RepositoryIMock.DeleteKnowledgeBase. %v %v %v", ctx, uid, kb_id) + mmDeleteKnowledgeBase.t.Fatalf("Unexpected call to RepositoryIMock.DeleteKnowledgeBase. %v %v %v", ctx, uid, kbID) return } @@ -724,308 +1074,1392 @@ func (m *RepositoryIMock) MinimockDeleteKnowledgeBaseInspect() { } } -type mRepositoryIMockGetRepositoryTag struct { +type mRepositoryIMockDeleteKnowledgeBaseFile struct { mock *RepositoryIMock - defaultExpectation *RepositoryIMockGetRepositoryTagExpectation - expectations []*RepositoryIMockGetRepositoryTagExpectation + defaultExpectation *RepositoryIMockDeleteKnowledgeBaseFileExpectation + expectations []*RepositoryIMockDeleteKnowledgeBaseFileExpectation - callArgs []*RepositoryIMockGetRepositoryTagParams + callArgs []*RepositoryIMockDeleteKnowledgeBaseFileParams mutex sync.RWMutex expectedInvocations uint64 } -// RepositoryIMockGetRepositoryTagExpectation specifies expectation struct of the RepositoryI.GetRepositoryTag -type RepositoryIMockGetRepositoryTagExpectation struct { +// RepositoryIMockDeleteKnowledgeBaseFileExpectation specifies expectation struct of the RepositoryI.DeleteKnowledgeBaseFile +type RepositoryIMockDeleteKnowledgeBaseFileExpectation struct { mock *RepositoryIMock - params *RepositoryIMockGetRepositoryTagParams - paramPtrs *RepositoryIMockGetRepositoryTagParamPtrs - results *RepositoryIMockGetRepositoryTagResults + params *RepositoryIMockDeleteKnowledgeBaseFileParams + paramPtrs *RepositoryIMockDeleteKnowledgeBaseFileParamPtrs + results *RepositoryIMockDeleteKnowledgeBaseFileResults Counter uint64 } -// RepositoryIMockGetRepositoryTagParams contains parameters of the RepositoryI.GetRepositoryTag -type RepositoryIMockGetRepositoryTagParams struct { - ctx context.Context - r1 utils.RepositoryTagName +// RepositoryIMockDeleteKnowledgeBaseFileParams contains parameters of the RepositoryI.DeleteKnowledgeBaseFile +type RepositoryIMockDeleteKnowledgeBaseFileParams struct { + ctx context.Context + file_uid string } -// RepositoryIMockGetRepositoryTagParamPtrs contains pointers to parameters of the RepositoryI.GetRepositoryTag -type RepositoryIMockGetRepositoryTagParamPtrs struct { - ctx *context.Context - r1 *utils.RepositoryTagName +// RepositoryIMockDeleteKnowledgeBaseFileParamPtrs contains pointers to parameters of the RepositoryI.DeleteKnowledgeBaseFile +type RepositoryIMockDeleteKnowledgeBaseFileParamPtrs struct { + ctx *context.Context + file_uid *string } -// RepositoryIMockGetRepositoryTagResults contains results of the RepositoryI.GetRepositoryTag -type RepositoryIMockGetRepositoryTagResults struct { - rp1 *pb.RepositoryTag +// RepositoryIMockDeleteKnowledgeBaseFileResults contains results of the RepositoryI.DeleteKnowledgeBaseFile +type RepositoryIMockDeleteKnowledgeBaseFileResults struct { err error } -// Expect sets up expected params for RepositoryI.GetRepositoryTag -func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Expect(ctx context.Context, r1 utils.RepositoryTagName) *mRepositoryIMockGetRepositoryTag { - if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { - mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Set") +// Expect sets up expected params for RepositoryI.DeleteKnowledgeBaseFile +func (mmDeleteKnowledgeBaseFile *mRepositoryIMockDeleteKnowledgeBaseFile) Expect(ctx context.Context, file_uid string) *mRepositoryIMockDeleteKnowledgeBaseFile { + if mmDeleteKnowledgeBaseFile.mock.funcDeleteKnowledgeBaseFile != nil { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFile mock is already set by Set") } - if mmGetRepositoryTag.defaultExpectation == nil { - mmGetRepositoryTag.defaultExpectation = &RepositoryIMockGetRepositoryTagExpectation{} + if mmDeleteKnowledgeBaseFile.defaultExpectation == nil { + mmDeleteKnowledgeBaseFile.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseFileExpectation{} } - if mmGetRepositoryTag.defaultExpectation.paramPtrs != nil { - mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by ExpectParams functions") + if mmDeleteKnowledgeBaseFile.defaultExpectation.paramPtrs != nil { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFile mock is already set by ExpectParams functions") } - mmGetRepositoryTag.defaultExpectation.params = &RepositoryIMockGetRepositoryTagParams{ctx, r1} - for _, e := range mmGetRepositoryTag.expectations { - if minimock.Equal(e.params, mmGetRepositoryTag.defaultExpectation.params) { - mmGetRepositoryTag.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetRepositoryTag.defaultExpectation.params) + mmDeleteKnowledgeBaseFile.defaultExpectation.params = &RepositoryIMockDeleteKnowledgeBaseFileParams{ctx, file_uid} + for _, e := range mmDeleteKnowledgeBaseFile.expectations { + if minimock.Equal(e.params, mmDeleteKnowledgeBaseFile.defaultExpectation.params) { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmDeleteKnowledgeBaseFile.defaultExpectation.params) } } - return mmGetRepositoryTag + return mmDeleteKnowledgeBaseFile } -// ExpectCtxParam1 sets up expected param ctx for RepositoryI.GetRepositoryTag -func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockGetRepositoryTag { - if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { - mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Set") +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.DeleteKnowledgeBaseFile +func (mmDeleteKnowledgeBaseFile *mRepositoryIMockDeleteKnowledgeBaseFile) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockDeleteKnowledgeBaseFile { + if mmDeleteKnowledgeBaseFile.mock.funcDeleteKnowledgeBaseFile != nil { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFile mock is already set by Set") } - if mmGetRepositoryTag.defaultExpectation == nil { - mmGetRepositoryTag.defaultExpectation = &RepositoryIMockGetRepositoryTagExpectation{} + if mmDeleteKnowledgeBaseFile.defaultExpectation == nil { + mmDeleteKnowledgeBaseFile.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseFileExpectation{} } - if mmGetRepositoryTag.defaultExpectation.params != nil { - mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Expect") + if mmDeleteKnowledgeBaseFile.defaultExpectation.params != nil { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFile mock is already set by Expect") } - if mmGetRepositoryTag.defaultExpectation.paramPtrs == nil { - mmGetRepositoryTag.defaultExpectation.paramPtrs = &RepositoryIMockGetRepositoryTagParamPtrs{} + if mmDeleteKnowledgeBaseFile.defaultExpectation.paramPtrs == nil { + mmDeleteKnowledgeBaseFile.defaultExpectation.paramPtrs = &RepositoryIMockDeleteKnowledgeBaseFileParamPtrs{} } - mmGetRepositoryTag.defaultExpectation.paramPtrs.ctx = &ctx + mmDeleteKnowledgeBaseFile.defaultExpectation.paramPtrs.ctx = &ctx - return mmGetRepositoryTag + return mmDeleteKnowledgeBaseFile } -// ExpectR1Param2 sets up expected param r1 for RepositoryI.GetRepositoryTag -func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) ExpectR1Param2(r1 utils.RepositoryTagName) *mRepositoryIMockGetRepositoryTag { - if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { - mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Set") +// ExpectFile_uidParam2 sets up expected param file_uid for RepositoryI.DeleteKnowledgeBaseFile +func (mmDeleteKnowledgeBaseFile *mRepositoryIMockDeleteKnowledgeBaseFile) ExpectFile_uidParam2(file_uid string) *mRepositoryIMockDeleteKnowledgeBaseFile { + if mmDeleteKnowledgeBaseFile.mock.funcDeleteKnowledgeBaseFile != nil { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFile mock is already set by Set") } - if mmGetRepositoryTag.defaultExpectation == nil { - mmGetRepositoryTag.defaultExpectation = &RepositoryIMockGetRepositoryTagExpectation{} + if mmDeleteKnowledgeBaseFile.defaultExpectation == nil { + mmDeleteKnowledgeBaseFile.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseFileExpectation{} } - if mmGetRepositoryTag.defaultExpectation.params != nil { - mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Expect") + if mmDeleteKnowledgeBaseFile.defaultExpectation.params != nil { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFile mock is already set by Expect") } - if mmGetRepositoryTag.defaultExpectation.paramPtrs == nil { - mmGetRepositoryTag.defaultExpectation.paramPtrs = &RepositoryIMockGetRepositoryTagParamPtrs{} + if mmDeleteKnowledgeBaseFile.defaultExpectation.paramPtrs == nil { + mmDeleteKnowledgeBaseFile.defaultExpectation.paramPtrs = &RepositoryIMockDeleteKnowledgeBaseFileParamPtrs{} } - mmGetRepositoryTag.defaultExpectation.paramPtrs.r1 = &r1 + mmDeleteKnowledgeBaseFile.defaultExpectation.paramPtrs.file_uid = &file_uid - return mmGetRepositoryTag + return mmDeleteKnowledgeBaseFile } -// Inspect accepts an inspector function that has same arguments as the RepositoryI.GetRepositoryTag -func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Inspect(f func(ctx context.Context, r1 utils.RepositoryTagName)) *mRepositoryIMockGetRepositoryTag { - if mmGetRepositoryTag.mock.inspectFuncGetRepositoryTag != nil { - mmGetRepositoryTag.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.GetRepositoryTag") +// Inspect accepts an inspector function that has same arguments as the RepositoryI.DeleteKnowledgeBaseFile +func (mmDeleteKnowledgeBaseFile *mRepositoryIMockDeleteKnowledgeBaseFile) Inspect(f func(ctx context.Context, file_uid string)) *mRepositoryIMockDeleteKnowledgeBaseFile { + if mmDeleteKnowledgeBaseFile.mock.inspectFuncDeleteKnowledgeBaseFile != nil { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.DeleteKnowledgeBaseFile") } - mmGetRepositoryTag.mock.inspectFuncGetRepositoryTag = f + mmDeleteKnowledgeBaseFile.mock.inspectFuncDeleteKnowledgeBaseFile = f - return mmGetRepositoryTag + return mmDeleteKnowledgeBaseFile } -// Return sets up results that will be returned by RepositoryI.GetRepositoryTag -func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Return(rp1 *pb.RepositoryTag, err error) *RepositoryIMock { - if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { - mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Set") +// Return sets up results that will be returned by RepositoryI.DeleteKnowledgeBaseFile +func (mmDeleteKnowledgeBaseFile *mRepositoryIMockDeleteKnowledgeBaseFile) Return(err error) *RepositoryIMock { + if mmDeleteKnowledgeBaseFile.mock.funcDeleteKnowledgeBaseFile != nil { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFile mock is already set by Set") + } + + if mmDeleteKnowledgeBaseFile.defaultExpectation == nil { + mmDeleteKnowledgeBaseFile.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseFileExpectation{mock: mmDeleteKnowledgeBaseFile.mock} + } + mmDeleteKnowledgeBaseFile.defaultExpectation.results = &RepositoryIMockDeleteKnowledgeBaseFileResults{err} + return mmDeleteKnowledgeBaseFile.mock +} + +// Set uses given function f to mock the RepositoryI.DeleteKnowledgeBaseFile method +func (mmDeleteKnowledgeBaseFile *mRepositoryIMockDeleteKnowledgeBaseFile) Set(f func(ctx context.Context, file_uid string) (err error)) *RepositoryIMock { + if mmDeleteKnowledgeBaseFile.defaultExpectation != nil { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("Default expectation is already set for the RepositoryI.DeleteKnowledgeBaseFile method") + } + + if len(mmDeleteKnowledgeBaseFile.expectations) > 0 { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("Some expectations are already set for the RepositoryI.DeleteKnowledgeBaseFile method") + } + + mmDeleteKnowledgeBaseFile.mock.funcDeleteKnowledgeBaseFile = f + return mmDeleteKnowledgeBaseFile.mock +} + +// When sets expectation for the RepositoryI.DeleteKnowledgeBaseFile which will trigger the result defined by the following +// Then helper +func (mmDeleteKnowledgeBaseFile *mRepositoryIMockDeleteKnowledgeBaseFile) When(ctx context.Context, file_uid string) *RepositoryIMockDeleteKnowledgeBaseFileExpectation { + if mmDeleteKnowledgeBaseFile.mock.funcDeleteKnowledgeBaseFile != nil { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBaseFile mock is already set by Set") + } + + expectation := &RepositoryIMockDeleteKnowledgeBaseFileExpectation{ + mock: mmDeleteKnowledgeBaseFile.mock, + params: &RepositoryIMockDeleteKnowledgeBaseFileParams{ctx, file_uid}, + } + mmDeleteKnowledgeBaseFile.expectations = append(mmDeleteKnowledgeBaseFile.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.DeleteKnowledgeBaseFile return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockDeleteKnowledgeBaseFileExpectation) Then(err error) *RepositoryIMock { + e.results = &RepositoryIMockDeleteKnowledgeBaseFileResults{err} + return e.mock +} + +// Times sets number of times RepositoryI.DeleteKnowledgeBaseFile should be invoked +func (mmDeleteKnowledgeBaseFile *mRepositoryIMockDeleteKnowledgeBaseFile) Times(n uint64) *mRepositoryIMockDeleteKnowledgeBaseFile { + if n == 0 { + mmDeleteKnowledgeBaseFile.mock.t.Fatalf("Times of RepositoryIMock.DeleteKnowledgeBaseFile mock can not be zero") + } + mm_atomic.StoreUint64(&mmDeleteKnowledgeBaseFile.expectedInvocations, n) + return mmDeleteKnowledgeBaseFile +} + +func (mmDeleteKnowledgeBaseFile *mRepositoryIMockDeleteKnowledgeBaseFile) invocationsDone() bool { + if len(mmDeleteKnowledgeBaseFile.expectations) == 0 && mmDeleteKnowledgeBaseFile.defaultExpectation == nil && mmDeleteKnowledgeBaseFile.mock.funcDeleteKnowledgeBaseFile == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmDeleteKnowledgeBaseFile.mock.afterDeleteKnowledgeBaseFileCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmDeleteKnowledgeBaseFile.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// DeleteKnowledgeBaseFile implements repository.RepositoryI +func (mmDeleteKnowledgeBaseFile *RepositoryIMock) DeleteKnowledgeBaseFile(ctx context.Context, file_uid string) (err error) { + mm_atomic.AddUint64(&mmDeleteKnowledgeBaseFile.beforeDeleteKnowledgeBaseFileCounter, 1) + defer mm_atomic.AddUint64(&mmDeleteKnowledgeBaseFile.afterDeleteKnowledgeBaseFileCounter, 1) + + if mmDeleteKnowledgeBaseFile.inspectFuncDeleteKnowledgeBaseFile != nil { + mmDeleteKnowledgeBaseFile.inspectFuncDeleteKnowledgeBaseFile(ctx, file_uid) + } + + mm_params := RepositoryIMockDeleteKnowledgeBaseFileParams{ctx, file_uid} + + // Record call args + mmDeleteKnowledgeBaseFile.DeleteKnowledgeBaseFileMock.mutex.Lock() + mmDeleteKnowledgeBaseFile.DeleteKnowledgeBaseFileMock.callArgs = append(mmDeleteKnowledgeBaseFile.DeleteKnowledgeBaseFileMock.callArgs, &mm_params) + mmDeleteKnowledgeBaseFile.DeleteKnowledgeBaseFileMock.mutex.Unlock() + + for _, e := range mmDeleteKnowledgeBaseFile.DeleteKnowledgeBaseFileMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.err + } + } + + if mmDeleteKnowledgeBaseFile.DeleteKnowledgeBaseFileMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmDeleteKnowledgeBaseFile.DeleteKnowledgeBaseFileMock.defaultExpectation.Counter, 1) + mm_want := mmDeleteKnowledgeBaseFile.DeleteKnowledgeBaseFileMock.defaultExpectation.params + mm_want_ptrs := mmDeleteKnowledgeBaseFile.DeleteKnowledgeBaseFileMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockDeleteKnowledgeBaseFileParams{ctx, file_uid} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmDeleteKnowledgeBaseFile.t.Errorf("RepositoryIMock.DeleteKnowledgeBaseFile 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.file_uid != nil && !minimock.Equal(*mm_want_ptrs.file_uid, mm_got.file_uid) { + mmDeleteKnowledgeBaseFile.t.Errorf("RepositoryIMock.DeleteKnowledgeBaseFile got unexpected parameter file_uid, want: %#v, got: %#v%s\n", *mm_want_ptrs.file_uid, mm_got.file_uid, minimock.Diff(*mm_want_ptrs.file_uid, mm_got.file_uid)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmDeleteKnowledgeBaseFile.t.Errorf("RepositoryIMock.DeleteKnowledgeBaseFile got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmDeleteKnowledgeBaseFile.DeleteKnowledgeBaseFileMock.defaultExpectation.results + if mm_results == nil { + mmDeleteKnowledgeBaseFile.t.Fatal("No results are set for the RepositoryIMock.DeleteKnowledgeBaseFile") + } + return (*mm_results).err + } + if mmDeleteKnowledgeBaseFile.funcDeleteKnowledgeBaseFile != nil { + return mmDeleteKnowledgeBaseFile.funcDeleteKnowledgeBaseFile(ctx, file_uid) + } + mmDeleteKnowledgeBaseFile.t.Fatalf("Unexpected call to RepositoryIMock.DeleteKnowledgeBaseFile. %v %v", ctx, file_uid) + return +} + +// DeleteKnowledgeBaseFileAfterCounter returns a count of finished RepositoryIMock.DeleteKnowledgeBaseFile invocations +func (mmDeleteKnowledgeBaseFile *RepositoryIMock) DeleteKnowledgeBaseFileAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmDeleteKnowledgeBaseFile.afterDeleteKnowledgeBaseFileCounter) +} + +// DeleteKnowledgeBaseFileBeforeCounter returns a count of RepositoryIMock.DeleteKnowledgeBaseFile invocations +func (mmDeleteKnowledgeBaseFile *RepositoryIMock) DeleteKnowledgeBaseFileBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmDeleteKnowledgeBaseFile.beforeDeleteKnowledgeBaseFileCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.DeleteKnowledgeBaseFile. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmDeleteKnowledgeBaseFile *mRepositoryIMockDeleteKnowledgeBaseFile) Calls() []*RepositoryIMockDeleteKnowledgeBaseFileParams { + mmDeleteKnowledgeBaseFile.mutex.RLock() + + argCopy := make([]*RepositoryIMockDeleteKnowledgeBaseFileParams, len(mmDeleteKnowledgeBaseFile.callArgs)) + copy(argCopy, mmDeleteKnowledgeBaseFile.callArgs) + + mmDeleteKnowledgeBaseFile.mutex.RUnlock() + + return argCopy +} + +// MinimockDeleteKnowledgeBaseFileDone returns true if the count of the DeleteKnowledgeBaseFile invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockDeleteKnowledgeBaseFileDone() bool { + for _, e := range m.DeleteKnowledgeBaseFileMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.DeleteKnowledgeBaseFileMock.invocationsDone() +} + +// MinimockDeleteKnowledgeBaseFileInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockDeleteKnowledgeBaseFileInspect() { + for _, e := range m.DeleteKnowledgeBaseFileMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.DeleteKnowledgeBaseFile with params: %#v", *e.params) + } + } + + afterDeleteKnowledgeBaseFileCounter := mm_atomic.LoadUint64(&m.afterDeleteKnowledgeBaseFileCounter) + // if default expectation was set then invocations count should be greater than zero + if m.DeleteKnowledgeBaseFileMock.defaultExpectation != nil && afterDeleteKnowledgeBaseFileCounter < 1 { + if m.DeleteKnowledgeBaseFileMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.DeleteKnowledgeBaseFile") + } else { + m.t.Errorf("Expected call to RepositoryIMock.DeleteKnowledgeBaseFile with params: %#v", *m.DeleteKnowledgeBaseFileMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcDeleteKnowledgeBaseFile != nil && afterDeleteKnowledgeBaseFileCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.DeleteKnowledgeBaseFile") + } + + if !m.DeleteKnowledgeBaseFileMock.invocationsDone() && afterDeleteKnowledgeBaseFileCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.DeleteKnowledgeBaseFile but found %d calls", + mm_atomic.LoadUint64(&m.DeleteKnowledgeBaseFileMock.expectedInvocations), afterDeleteKnowledgeBaseFileCounter) + } +} + +type mRepositoryIMockGetKnowledgeBaseByOwnerAndID struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation + expectations []*RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation + + callArgs []*RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation specifies expectation struct of the RepositoryI.GetKnowledgeBaseByOwnerAndID +type RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams + paramPtrs *RepositoryIMockGetKnowledgeBaseByOwnerAndIDParamPtrs + results *RepositoryIMockGetKnowledgeBaseByOwnerAndIDResults + Counter uint64 +} + +// RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams contains parameters of the RepositoryI.GetKnowledgeBaseByOwnerAndID +type RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams struct { + ctx context.Context + owner string + kbID string +} + +// RepositoryIMockGetKnowledgeBaseByOwnerAndIDParamPtrs contains pointers to parameters of the RepositoryI.GetKnowledgeBaseByOwnerAndID +type RepositoryIMockGetKnowledgeBaseByOwnerAndIDParamPtrs struct { + ctx *context.Context + owner *string + kbID *string +} + +// RepositoryIMockGetKnowledgeBaseByOwnerAndIDResults contains results of the RepositoryI.GetKnowledgeBaseByOwnerAndID +type RepositoryIMockGetKnowledgeBaseByOwnerAndIDResults struct { + kp1 *mm_repository.KnowledgeBase + err error +} + +// Expect sets up expected params for RepositoryI.GetKnowledgeBaseByOwnerAndID +func (mmGetKnowledgeBaseByOwnerAndID *mRepositoryIMockGetKnowledgeBaseByOwnerAndID) Expect(ctx context.Context, owner string, kbID string) *mRepositoryIMockGetKnowledgeBaseByOwnerAndID { + if mmGetKnowledgeBaseByOwnerAndID.mock.funcGetKnowledgeBaseByOwnerAndID != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID mock is already set by Set") + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation == nil { + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation = &RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation{} + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.paramPtrs != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID mock is already set by ExpectParams functions") + } + + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.params = &RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams{ctx, owner, kbID} + for _, e := range mmGetKnowledgeBaseByOwnerAndID.expectations { + if minimock.Equal(e.params, mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.params) { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.params) + } + } + + return mmGetKnowledgeBaseByOwnerAndID +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.GetKnowledgeBaseByOwnerAndID +func (mmGetKnowledgeBaseByOwnerAndID *mRepositoryIMockGetKnowledgeBaseByOwnerAndID) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockGetKnowledgeBaseByOwnerAndID { + if mmGetKnowledgeBaseByOwnerAndID.mock.funcGetKnowledgeBaseByOwnerAndID != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID mock is already set by Set") + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation == nil { + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation = &RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation{} + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.params != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID mock is already set by Expect") + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.paramPtrs == nil { + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.paramPtrs = &RepositoryIMockGetKnowledgeBaseByOwnerAndIDParamPtrs{} + } + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.paramPtrs.ctx = &ctx + + return mmGetKnowledgeBaseByOwnerAndID +} + +// ExpectOwnerParam2 sets up expected param owner for RepositoryI.GetKnowledgeBaseByOwnerAndID +func (mmGetKnowledgeBaseByOwnerAndID *mRepositoryIMockGetKnowledgeBaseByOwnerAndID) ExpectOwnerParam2(owner string) *mRepositoryIMockGetKnowledgeBaseByOwnerAndID { + if mmGetKnowledgeBaseByOwnerAndID.mock.funcGetKnowledgeBaseByOwnerAndID != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID mock is already set by Set") + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation == nil { + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation = &RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation{} + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.params != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID mock is already set by Expect") + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.paramPtrs == nil { + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.paramPtrs = &RepositoryIMockGetKnowledgeBaseByOwnerAndIDParamPtrs{} + } + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.paramPtrs.owner = &owner + + return mmGetKnowledgeBaseByOwnerAndID +} + +// ExpectKbIDParam3 sets up expected param kbID for RepositoryI.GetKnowledgeBaseByOwnerAndID +func (mmGetKnowledgeBaseByOwnerAndID *mRepositoryIMockGetKnowledgeBaseByOwnerAndID) ExpectKbIDParam3(kbID string) *mRepositoryIMockGetKnowledgeBaseByOwnerAndID { + if mmGetKnowledgeBaseByOwnerAndID.mock.funcGetKnowledgeBaseByOwnerAndID != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID mock is already set by Set") + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation == nil { + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation = &RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation{} + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.params != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID mock is already set by Expect") + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.paramPtrs == nil { + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.paramPtrs = &RepositoryIMockGetKnowledgeBaseByOwnerAndIDParamPtrs{} + } + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.paramPtrs.kbID = &kbID + + return mmGetKnowledgeBaseByOwnerAndID +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.GetKnowledgeBaseByOwnerAndID +func (mmGetKnowledgeBaseByOwnerAndID *mRepositoryIMockGetKnowledgeBaseByOwnerAndID) Inspect(f func(ctx context.Context, owner string, kbID string)) *mRepositoryIMockGetKnowledgeBaseByOwnerAndID { + if mmGetKnowledgeBaseByOwnerAndID.mock.inspectFuncGetKnowledgeBaseByOwnerAndID != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.GetKnowledgeBaseByOwnerAndID") + } + + mmGetKnowledgeBaseByOwnerAndID.mock.inspectFuncGetKnowledgeBaseByOwnerAndID = f + + return mmGetKnowledgeBaseByOwnerAndID +} + +// Return sets up results that will be returned by RepositoryI.GetKnowledgeBaseByOwnerAndID +func (mmGetKnowledgeBaseByOwnerAndID *mRepositoryIMockGetKnowledgeBaseByOwnerAndID) Return(kp1 *mm_repository.KnowledgeBase, err error) *RepositoryIMock { + if mmGetKnowledgeBaseByOwnerAndID.mock.funcGetKnowledgeBaseByOwnerAndID != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID mock is already set by Set") + } + + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation == nil { + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation = &RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation{mock: mmGetKnowledgeBaseByOwnerAndID.mock} + } + mmGetKnowledgeBaseByOwnerAndID.defaultExpectation.results = &RepositoryIMockGetKnowledgeBaseByOwnerAndIDResults{kp1, err} + return mmGetKnowledgeBaseByOwnerAndID.mock +} + +// Set uses given function f to mock the RepositoryI.GetKnowledgeBaseByOwnerAndID method +func (mmGetKnowledgeBaseByOwnerAndID *mRepositoryIMockGetKnowledgeBaseByOwnerAndID) Set(f func(ctx context.Context, owner string, kbID string) (kp1 *mm_repository.KnowledgeBase, err error)) *RepositoryIMock { + if mmGetKnowledgeBaseByOwnerAndID.defaultExpectation != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("Default expectation is already set for the RepositoryI.GetKnowledgeBaseByOwnerAndID method") + } + + if len(mmGetKnowledgeBaseByOwnerAndID.expectations) > 0 { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("Some expectations are already set for the RepositoryI.GetKnowledgeBaseByOwnerAndID method") + } + + mmGetKnowledgeBaseByOwnerAndID.mock.funcGetKnowledgeBaseByOwnerAndID = f + return mmGetKnowledgeBaseByOwnerAndID.mock +} + +// When sets expectation for the RepositoryI.GetKnowledgeBaseByOwnerAndID which will trigger the result defined by the following +// Then helper +func (mmGetKnowledgeBaseByOwnerAndID *mRepositoryIMockGetKnowledgeBaseByOwnerAndID) When(ctx context.Context, owner string, kbID string) *RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation { + if mmGetKnowledgeBaseByOwnerAndID.mock.funcGetKnowledgeBaseByOwnerAndID != nil { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID mock is already set by Set") + } + + expectation := &RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation{ + mock: mmGetKnowledgeBaseByOwnerAndID.mock, + params: &RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams{ctx, owner, kbID}, + } + mmGetKnowledgeBaseByOwnerAndID.expectations = append(mmGetKnowledgeBaseByOwnerAndID.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.GetKnowledgeBaseByOwnerAndID return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockGetKnowledgeBaseByOwnerAndIDExpectation) Then(kp1 *mm_repository.KnowledgeBase, err error) *RepositoryIMock { + e.results = &RepositoryIMockGetKnowledgeBaseByOwnerAndIDResults{kp1, err} + return e.mock +} + +// Times sets number of times RepositoryI.GetKnowledgeBaseByOwnerAndID should be invoked +func (mmGetKnowledgeBaseByOwnerAndID *mRepositoryIMockGetKnowledgeBaseByOwnerAndID) Times(n uint64) *mRepositoryIMockGetKnowledgeBaseByOwnerAndID { + if n == 0 { + mmGetKnowledgeBaseByOwnerAndID.mock.t.Fatalf("Times of RepositoryIMock.GetKnowledgeBaseByOwnerAndID mock can not be zero") + } + mm_atomic.StoreUint64(&mmGetKnowledgeBaseByOwnerAndID.expectedInvocations, n) + return mmGetKnowledgeBaseByOwnerAndID +} + +func (mmGetKnowledgeBaseByOwnerAndID *mRepositoryIMockGetKnowledgeBaseByOwnerAndID) invocationsDone() bool { + if len(mmGetKnowledgeBaseByOwnerAndID.expectations) == 0 && mmGetKnowledgeBaseByOwnerAndID.defaultExpectation == nil && mmGetKnowledgeBaseByOwnerAndID.mock.funcGetKnowledgeBaseByOwnerAndID == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmGetKnowledgeBaseByOwnerAndID.mock.afterGetKnowledgeBaseByOwnerAndIDCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmGetKnowledgeBaseByOwnerAndID.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// GetKnowledgeBaseByOwnerAndID implements repository.RepositoryI +func (mmGetKnowledgeBaseByOwnerAndID *RepositoryIMock) GetKnowledgeBaseByOwnerAndID(ctx context.Context, owner string, kbID string) (kp1 *mm_repository.KnowledgeBase, err error) { + mm_atomic.AddUint64(&mmGetKnowledgeBaseByOwnerAndID.beforeGetKnowledgeBaseByOwnerAndIDCounter, 1) + defer mm_atomic.AddUint64(&mmGetKnowledgeBaseByOwnerAndID.afterGetKnowledgeBaseByOwnerAndIDCounter, 1) + + if mmGetKnowledgeBaseByOwnerAndID.inspectFuncGetKnowledgeBaseByOwnerAndID != nil { + mmGetKnowledgeBaseByOwnerAndID.inspectFuncGetKnowledgeBaseByOwnerAndID(ctx, owner, kbID) + } + + mm_params := RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams{ctx, owner, kbID} + + // Record call args + mmGetKnowledgeBaseByOwnerAndID.GetKnowledgeBaseByOwnerAndIDMock.mutex.Lock() + mmGetKnowledgeBaseByOwnerAndID.GetKnowledgeBaseByOwnerAndIDMock.callArgs = append(mmGetKnowledgeBaseByOwnerAndID.GetKnowledgeBaseByOwnerAndIDMock.callArgs, &mm_params) + mmGetKnowledgeBaseByOwnerAndID.GetKnowledgeBaseByOwnerAndIDMock.mutex.Unlock() + + for _, e := range mmGetKnowledgeBaseByOwnerAndID.GetKnowledgeBaseByOwnerAndIDMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.kp1, e.results.err + } + } + + if mmGetKnowledgeBaseByOwnerAndID.GetKnowledgeBaseByOwnerAndIDMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmGetKnowledgeBaseByOwnerAndID.GetKnowledgeBaseByOwnerAndIDMock.defaultExpectation.Counter, 1) + mm_want := mmGetKnowledgeBaseByOwnerAndID.GetKnowledgeBaseByOwnerAndIDMock.defaultExpectation.params + mm_want_ptrs := mmGetKnowledgeBaseByOwnerAndID.GetKnowledgeBaseByOwnerAndIDMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams{ctx, owner, kbID} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmGetKnowledgeBaseByOwnerAndID.t.Errorf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID 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.owner != nil && !minimock.Equal(*mm_want_ptrs.owner, mm_got.owner) { + mmGetKnowledgeBaseByOwnerAndID.t.Errorf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID got unexpected parameter owner, want: %#v, got: %#v%s\n", *mm_want_ptrs.owner, mm_got.owner, minimock.Diff(*mm_want_ptrs.owner, mm_got.owner)) + } + + if mm_want_ptrs.kbID != nil && !minimock.Equal(*mm_want_ptrs.kbID, mm_got.kbID) { + mmGetKnowledgeBaseByOwnerAndID.t.Errorf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID got unexpected parameter kbID, want: %#v, got: %#v%s\n", *mm_want_ptrs.kbID, mm_got.kbID, minimock.Diff(*mm_want_ptrs.kbID, mm_got.kbID)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmGetKnowledgeBaseByOwnerAndID.t.Errorf("RepositoryIMock.GetKnowledgeBaseByOwnerAndID got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmGetKnowledgeBaseByOwnerAndID.GetKnowledgeBaseByOwnerAndIDMock.defaultExpectation.results + if mm_results == nil { + mmGetKnowledgeBaseByOwnerAndID.t.Fatal("No results are set for the RepositoryIMock.GetKnowledgeBaseByOwnerAndID") + } + return (*mm_results).kp1, (*mm_results).err + } + if mmGetKnowledgeBaseByOwnerAndID.funcGetKnowledgeBaseByOwnerAndID != nil { + return mmGetKnowledgeBaseByOwnerAndID.funcGetKnowledgeBaseByOwnerAndID(ctx, owner, kbID) + } + mmGetKnowledgeBaseByOwnerAndID.t.Fatalf("Unexpected call to RepositoryIMock.GetKnowledgeBaseByOwnerAndID. %v %v %v", ctx, owner, kbID) + return +} + +// GetKnowledgeBaseByOwnerAndIDAfterCounter returns a count of finished RepositoryIMock.GetKnowledgeBaseByOwnerAndID invocations +func (mmGetKnowledgeBaseByOwnerAndID *RepositoryIMock) GetKnowledgeBaseByOwnerAndIDAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetKnowledgeBaseByOwnerAndID.afterGetKnowledgeBaseByOwnerAndIDCounter) +} + +// GetKnowledgeBaseByOwnerAndIDBeforeCounter returns a count of RepositoryIMock.GetKnowledgeBaseByOwnerAndID invocations +func (mmGetKnowledgeBaseByOwnerAndID *RepositoryIMock) GetKnowledgeBaseByOwnerAndIDBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetKnowledgeBaseByOwnerAndID.beforeGetKnowledgeBaseByOwnerAndIDCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.GetKnowledgeBaseByOwnerAndID. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmGetKnowledgeBaseByOwnerAndID *mRepositoryIMockGetKnowledgeBaseByOwnerAndID) Calls() []*RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams { + mmGetKnowledgeBaseByOwnerAndID.mutex.RLock() + + argCopy := make([]*RepositoryIMockGetKnowledgeBaseByOwnerAndIDParams, len(mmGetKnowledgeBaseByOwnerAndID.callArgs)) + copy(argCopy, mmGetKnowledgeBaseByOwnerAndID.callArgs) + + mmGetKnowledgeBaseByOwnerAndID.mutex.RUnlock() + + return argCopy +} + +// MinimockGetKnowledgeBaseByOwnerAndIDDone returns true if the count of the GetKnowledgeBaseByOwnerAndID invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockGetKnowledgeBaseByOwnerAndIDDone() bool { + for _, e := range m.GetKnowledgeBaseByOwnerAndIDMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.GetKnowledgeBaseByOwnerAndIDMock.invocationsDone() +} + +// MinimockGetKnowledgeBaseByOwnerAndIDInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockGetKnowledgeBaseByOwnerAndIDInspect() { + for _, e := range m.GetKnowledgeBaseByOwnerAndIDMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.GetKnowledgeBaseByOwnerAndID with params: %#v", *e.params) + } + } + + afterGetKnowledgeBaseByOwnerAndIDCounter := mm_atomic.LoadUint64(&m.afterGetKnowledgeBaseByOwnerAndIDCounter) + // if default expectation was set then invocations count should be greater than zero + if m.GetKnowledgeBaseByOwnerAndIDMock.defaultExpectation != nil && afterGetKnowledgeBaseByOwnerAndIDCounter < 1 { + if m.GetKnowledgeBaseByOwnerAndIDMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.GetKnowledgeBaseByOwnerAndID") + } else { + m.t.Errorf("Expected call to RepositoryIMock.GetKnowledgeBaseByOwnerAndID with params: %#v", *m.GetKnowledgeBaseByOwnerAndIDMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcGetKnowledgeBaseByOwnerAndID != nil && afterGetKnowledgeBaseByOwnerAndIDCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.GetKnowledgeBaseByOwnerAndID") + } + + if !m.GetKnowledgeBaseByOwnerAndIDMock.invocationsDone() && afterGetKnowledgeBaseByOwnerAndIDCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.GetKnowledgeBaseByOwnerAndID but found %d calls", + mm_atomic.LoadUint64(&m.GetKnowledgeBaseByOwnerAndIDMock.expectedInvocations), afterGetKnowledgeBaseByOwnerAndIDCounter) + } +} + +type mRepositoryIMockGetRepositoryTag struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockGetRepositoryTagExpectation + expectations []*RepositoryIMockGetRepositoryTagExpectation + + callArgs []*RepositoryIMockGetRepositoryTagParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockGetRepositoryTagExpectation specifies expectation struct of the RepositoryI.GetRepositoryTag +type RepositoryIMockGetRepositoryTagExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockGetRepositoryTagParams + paramPtrs *RepositoryIMockGetRepositoryTagParamPtrs + results *RepositoryIMockGetRepositoryTagResults + Counter uint64 +} + +// RepositoryIMockGetRepositoryTagParams contains parameters of the RepositoryI.GetRepositoryTag +type RepositoryIMockGetRepositoryTagParams struct { + ctx context.Context + r1 utils.RepositoryTagName +} + +// RepositoryIMockGetRepositoryTagParamPtrs contains pointers to parameters of the RepositoryI.GetRepositoryTag +type RepositoryIMockGetRepositoryTagParamPtrs struct { + ctx *context.Context + r1 *utils.RepositoryTagName +} + +// RepositoryIMockGetRepositoryTagResults contains results of the RepositoryI.GetRepositoryTag +type RepositoryIMockGetRepositoryTagResults struct { + rp1 *pb.RepositoryTag + err error +} + +// Expect sets up expected params for RepositoryI.GetRepositoryTag +func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Expect(ctx context.Context, r1 utils.RepositoryTagName) *mRepositoryIMockGetRepositoryTag { + if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { + mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Set") + } + + if mmGetRepositoryTag.defaultExpectation == nil { + mmGetRepositoryTag.defaultExpectation = &RepositoryIMockGetRepositoryTagExpectation{} + } + + if mmGetRepositoryTag.defaultExpectation.paramPtrs != nil { + mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by ExpectParams functions") + } + + mmGetRepositoryTag.defaultExpectation.params = &RepositoryIMockGetRepositoryTagParams{ctx, r1} + for _, e := range mmGetRepositoryTag.expectations { + if minimock.Equal(e.params, mmGetRepositoryTag.defaultExpectation.params) { + mmGetRepositoryTag.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetRepositoryTag.defaultExpectation.params) + } + } + + return mmGetRepositoryTag +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.GetRepositoryTag +func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockGetRepositoryTag { + if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { + mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Set") + } + + if mmGetRepositoryTag.defaultExpectation == nil { + mmGetRepositoryTag.defaultExpectation = &RepositoryIMockGetRepositoryTagExpectation{} + } + + if mmGetRepositoryTag.defaultExpectation.params != nil { + mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Expect") + } + + if mmGetRepositoryTag.defaultExpectation.paramPtrs == nil { + mmGetRepositoryTag.defaultExpectation.paramPtrs = &RepositoryIMockGetRepositoryTagParamPtrs{} + } + mmGetRepositoryTag.defaultExpectation.paramPtrs.ctx = &ctx + + return mmGetRepositoryTag +} + +// ExpectR1Param2 sets up expected param r1 for RepositoryI.GetRepositoryTag +func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) ExpectR1Param2(r1 utils.RepositoryTagName) *mRepositoryIMockGetRepositoryTag { + if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { + mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Set") + } + + if mmGetRepositoryTag.defaultExpectation == nil { + mmGetRepositoryTag.defaultExpectation = &RepositoryIMockGetRepositoryTagExpectation{} + } + + if mmGetRepositoryTag.defaultExpectation.params != nil { + mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Expect") + } + + if mmGetRepositoryTag.defaultExpectation.paramPtrs == nil { + mmGetRepositoryTag.defaultExpectation.paramPtrs = &RepositoryIMockGetRepositoryTagParamPtrs{} + } + mmGetRepositoryTag.defaultExpectation.paramPtrs.r1 = &r1 + + return mmGetRepositoryTag +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.GetRepositoryTag +func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Inspect(f func(ctx context.Context, r1 utils.RepositoryTagName)) *mRepositoryIMockGetRepositoryTag { + if mmGetRepositoryTag.mock.inspectFuncGetRepositoryTag != nil { + mmGetRepositoryTag.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.GetRepositoryTag") + } + + mmGetRepositoryTag.mock.inspectFuncGetRepositoryTag = f + + return mmGetRepositoryTag +} + +// Return sets up results that will be returned by RepositoryI.GetRepositoryTag +func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Return(rp1 *pb.RepositoryTag, err error) *RepositoryIMock { + if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { + mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Set") + } + + if mmGetRepositoryTag.defaultExpectation == nil { + mmGetRepositoryTag.defaultExpectation = &RepositoryIMockGetRepositoryTagExpectation{mock: mmGetRepositoryTag.mock} + } + mmGetRepositoryTag.defaultExpectation.results = &RepositoryIMockGetRepositoryTagResults{rp1, err} + return mmGetRepositoryTag.mock +} + +// Set uses given function f to mock the RepositoryI.GetRepositoryTag method +func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Set(f func(ctx context.Context, r1 utils.RepositoryTagName) (rp1 *pb.RepositoryTag, err error)) *RepositoryIMock { + if mmGetRepositoryTag.defaultExpectation != nil { + mmGetRepositoryTag.mock.t.Fatalf("Default expectation is already set for the RepositoryI.GetRepositoryTag method") + } + + if len(mmGetRepositoryTag.expectations) > 0 { + mmGetRepositoryTag.mock.t.Fatalf("Some expectations are already set for the RepositoryI.GetRepositoryTag method") + } + + mmGetRepositoryTag.mock.funcGetRepositoryTag = f + return mmGetRepositoryTag.mock +} + +// When sets expectation for the RepositoryI.GetRepositoryTag which will trigger the result defined by the following +// Then helper +func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) When(ctx context.Context, r1 utils.RepositoryTagName) *RepositoryIMockGetRepositoryTagExpectation { + if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { + mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Set") + } + + expectation := &RepositoryIMockGetRepositoryTagExpectation{ + mock: mmGetRepositoryTag.mock, + params: &RepositoryIMockGetRepositoryTagParams{ctx, r1}, + } + mmGetRepositoryTag.expectations = append(mmGetRepositoryTag.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.GetRepositoryTag return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockGetRepositoryTagExpectation) Then(rp1 *pb.RepositoryTag, err error) *RepositoryIMock { + e.results = &RepositoryIMockGetRepositoryTagResults{rp1, err} + return e.mock +} + +// Times sets number of times RepositoryI.GetRepositoryTag should be invoked +func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Times(n uint64) *mRepositoryIMockGetRepositoryTag { + if n == 0 { + mmGetRepositoryTag.mock.t.Fatalf("Times of RepositoryIMock.GetRepositoryTag mock can not be zero") + } + mm_atomic.StoreUint64(&mmGetRepositoryTag.expectedInvocations, n) + return mmGetRepositoryTag +} + +func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) invocationsDone() bool { + if len(mmGetRepositoryTag.expectations) == 0 && mmGetRepositoryTag.defaultExpectation == nil && mmGetRepositoryTag.mock.funcGetRepositoryTag == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmGetRepositoryTag.mock.afterGetRepositoryTagCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmGetRepositoryTag.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// GetRepositoryTag implements repository.RepositoryI +func (mmGetRepositoryTag *RepositoryIMock) GetRepositoryTag(ctx context.Context, r1 utils.RepositoryTagName) (rp1 *pb.RepositoryTag, err error) { + mm_atomic.AddUint64(&mmGetRepositoryTag.beforeGetRepositoryTagCounter, 1) + defer mm_atomic.AddUint64(&mmGetRepositoryTag.afterGetRepositoryTagCounter, 1) + + if mmGetRepositoryTag.inspectFuncGetRepositoryTag != nil { + mmGetRepositoryTag.inspectFuncGetRepositoryTag(ctx, r1) + } + + mm_params := RepositoryIMockGetRepositoryTagParams{ctx, r1} + + // Record call args + mmGetRepositoryTag.GetRepositoryTagMock.mutex.Lock() + mmGetRepositoryTag.GetRepositoryTagMock.callArgs = append(mmGetRepositoryTag.GetRepositoryTagMock.callArgs, &mm_params) + mmGetRepositoryTag.GetRepositoryTagMock.mutex.Unlock() + + for _, e := range mmGetRepositoryTag.GetRepositoryTagMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.rp1, e.results.err + } + } + + if mmGetRepositoryTag.GetRepositoryTagMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmGetRepositoryTag.GetRepositoryTagMock.defaultExpectation.Counter, 1) + mm_want := mmGetRepositoryTag.GetRepositoryTagMock.defaultExpectation.params + mm_want_ptrs := mmGetRepositoryTag.GetRepositoryTagMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockGetRepositoryTagParams{ctx, r1} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmGetRepositoryTag.t.Errorf("RepositoryIMock.GetRepositoryTag 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.r1 != nil && !minimock.Equal(*mm_want_ptrs.r1, mm_got.r1) { + mmGetRepositoryTag.t.Errorf("RepositoryIMock.GetRepositoryTag got unexpected parameter r1, want: %#v, got: %#v%s\n", *mm_want_ptrs.r1, mm_got.r1, minimock.Diff(*mm_want_ptrs.r1, mm_got.r1)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmGetRepositoryTag.t.Errorf("RepositoryIMock.GetRepositoryTag got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmGetRepositoryTag.GetRepositoryTagMock.defaultExpectation.results + if mm_results == nil { + mmGetRepositoryTag.t.Fatal("No results are set for the RepositoryIMock.GetRepositoryTag") + } + return (*mm_results).rp1, (*mm_results).err + } + if mmGetRepositoryTag.funcGetRepositoryTag != nil { + return mmGetRepositoryTag.funcGetRepositoryTag(ctx, r1) + } + mmGetRepositoryTag.t.Fatalf("Unexpected call to RepositoryIMock.GetRepositoryTag. %v %v", ctx, r1) + return +} + +// GetRepositoryTagAfterCounter returns a count of finished RepositoryIMock.GetRepositoryTag invocations +func (mmGetRepositoryTag *RepositoryIMock) GetRepositoryTagAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetRepositoryTag.afterGetRepositoryTagCounter) +} + +// GetRepositoryTagBeforeCounter returns a count of RepositoryIMock.GetRepositoryTag invocations +func (mmGetRepositoryTag *RepositoryIMock) GetRepositoryTagBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetRepositoryTag.beforeGetRepositoryTagCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.GetRepositoryTag. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Calls() []*RepositoryIMockGetRepositoryTagParams { + mmGetRepositoryTag.mutex.RLock() + + argCopy := make([]*RepositoryIMockGetRepositoryTagParams, len(mmGetRepositoryTag.callArgs)) + copy(argCopy, mmGetRepositoryTag.callArgs) + + mmGetRepositoryTag.mutex.RUnlock() + + return argCopy +} + +// MinimockGetRepositoryTagDone returns true if the count of the GetRepositoryTag invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockGetRepositoryTagDone() bool { + for _, e := range m.GetRepositoryTagMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.GetRepositoryTagMock.invocationsDone() +} + +// MinimockGetRepositoryTagInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockGetRepositoryTagInspect() { + for _, e := range m.GetRepositoryTagMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.GetRepositoryTag with params: %#v", *e.params) + } + } + + afterGetRepositoryTagCounter := mm_atomic.LoadUint64(&m.afterGetRepositoryTagCounter) + // if default expectation was set then invocations count should be greater than zero + if m.GetRepositoryTagMock.defaultExpectation != nil && afterGetRepositoryTagCounter < 1 { + if m.GetRepositoryTagMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.GetRepositoryTag") + } else { + m.t.Errorf("Expected call to RepositoryIMock.GetRepositoryTag with params: %#v", *m.GetRepositoryTagMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcGetRepositoryTag != nil && afterGetRepositoryTagCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.GetRepositoryTag") + } + + if !m.GetRepositoryTagMock.invocationsDone() && afterGetRepositoryTagCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.GetRepositoryTag but found %d calls", + mm_atomic.LoadUint64(&m.GetRepositoryTagMock.expectedInvocations), afterGetRepositoryTagCounter) + } +} + +type mRepositoryIMockListKnowledgeBaseFiles struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockListKnowledgeBaseFilesExpectation + expectations []*RepositoryIMockListKnowledgeBaseFilesExpectation + + callArgs []*RepositoryIMockListKnowledgeBaseFilesParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockListKnowledgeBaseFilesExpectation specifies expectation struct of the RepositoryI.ListKnowledgeBaseFiles +type RepositoryIMockListKnowledgeBaseFilesExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockListKnowledgeBaseFilesParams + paramPtrs *RepositoryIMockListKnowledgeBaseFilesParamPtrs + results *RepositoryIMockListKnowledgeBaseFilesResults + Counter uint64 +} + +// RepositoryIMockListKnowledgeBaseFilesParams contains parameters of the RepositoryI.ListKnowledgeBaseFiles +type RepositoryIMockListKnowledgeBaseFilesParams struct { + ctx context.Context + uid string + owner_uid string + kb_uid string + page_size int32 + next_page_token string + files_uid []string +} + +// RepositoryIMockListKnowledgeBaseFilesParamPtrs contains pointers to parameters of the RepositoryI.ListKnowledgeBaseFiles +type RepositoryIMockListKnowledgeBaseFilesParamPtrs struct { + ctx *context.Context + uid *string + owner_uid *string + kb_uid *string + page_size *int32 + next_page_token *string + files_uid *[]string +} + +// RepositoryIMockListKnowledgeBaseFilesResults contains results of the RepositoryI.ListKnowledgeBaseFiles +type RepositoryIMockListKnowledgeBaseFilesResults struct { + ka1 []mm_repository.KnowledgeBaseFile + i1 int + s1 string + err error +} + +// Expect sets up expected params for RepositoryI.ListKnowledgeBaseFiles +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) Expect(ctx context.Context, uid string, owner_uid string, kb_uid string, page_size int32, next_page_token string, files_uid []string) *mRepositoryIMockListKnowledgeBaseFiles { + if mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Set") + } + + if mmListKnowledgeBaseFiles.defaultExpectation == nil { + mmListKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockListKnowledgeBaseFilesExpectation{} + } + + if mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by ExpectParams functions") + } + + mmListKnowledgeBaseFiles.defaultExpectation.params = &RepositoryIMockListKnowledgeBaseFilesParams{ctx, uid, owner_uid, kb_uid, page_size, next_page_token, files_uid} + for _, e := range mmListKnowledgeBaseFiles.expectations { + if minimock.Equal(e.params, mmListKnowledgeBaseFiles.defaultExpectation.params) { + mmListKnowledgeBaseFiles.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmListKnowledgeBaseFiles.defaultExpectation.params) + } + } + + return mmListKnowledgeBaseFiles +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.ListKnowledgeBaseFiles +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockListKnowledgeBaseFiles { + if mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Set") + } + + if mmListKnowledgeBaseFiles.defaultExpectation == nil { + mmListKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockListKnowledgeBaseFilesExpectation{} + } + + if mmListKnowledgeBaseFiles.defaultExpectation.params != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Expect") + } + + if mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs == nil { + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs = &RepositoryIMockListKnowledgeBaseFilesParamPtrs{} + } + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs.ctx = &ctx + + return mmListKnowledgeBaseFiles +} + +// ExpectUidParam2 sets up expected param uid for RepositoryI.ListKnowledgeBaseFiles +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) ExpectUidParam2(uid string) *mRepositoryIMockListKnowledgeBaseFiles { + if mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Set") + } + + if mmListKnowledgeBaseFiles.defaultExpectation == nil { + mmListKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockListKnowledgeBaseFilesExpectation{} + } + + if mmListKnowledgeBaseFiles.defaultExpectation.params != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Expect") + } + + if mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs == nil { + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs = &RepositoryIMockListKnowledgeBaseFilesParamPtrs{} + } + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs.uid = &uid + + return mmListKnowledgeBaseFiles +} + +// ExpectOwner_uidParam3 sets up expected param owner_uid for RepositoryI.ListKnowledgeBaseFiles +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) ExpectOwner_uidParam3(owner_uid string) *mRepositoryIMockListKnowledgeBaseFiles { + if mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Set") + } + + if mmListKnowledgeBaseFiles.defaultExpectation == nil { + mmListKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockListKnowledgeBaseFilesExpectation{} + } + + if mmListKnowledgeBaseFiles.defaultExpectation.params != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Expect") + } + + if mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs == nil { + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs = &RepositoryIMockListKnowledgeBaseFilesParamPtrs{} + } + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs.owner_uid = &owner_uid + + return mmListKnowledgeBaseFiles +} + +// ExpectKb_uidParam4 sets up expected param kb_uid for RepositoryI.ListKnowledgeBaseFiles +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) ExpectKb_uidParam4(kb_uid string) *mRepositoryIMockListKnowledgeBaseFiles { + if mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Set") + } + + if mmListKnowledgeBaseFiles.defaultExpectation == nil { + mmListKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockListKnowledgeBaseFilesExpectation{} + } + + if mmListKnowledgeBaseFiles.defaultExpectation.params != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Expect") + } + + if mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs == nil { + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs = &RepositoryIMockListKnowledgeBaseFilesParamPtrs{} + } + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs.kb_uid = &kb_uid + + return mmListKnowledgeBaseFiles +} + +// ExpectPage_sizeParam5 sets up expected param page_size for RepositoryI.ListKnowledgeBaseFiles +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) ExpectPage_sizeParam5(page_size int32) *mRepositoryIMockListKnowledgeBaseFiles { + if mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Set") + } + + if mmListKnowledgeBaseFiles.defaultExpectation == nil { + mmListKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockListKnowledgeBaseFilesExpectation{} + } + + if mmListKnowledgeBaseFiles.defaultExpectation.params != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Expect") + } + + if mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs == nil { + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs = &RepositoryIMockListKnowledgeBaseFilesParamPtrs{} + } + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs.page_size = &page_size + + return mmListKnowledgeBaseFiles +} + +// ExpectNext_page_tokenParam6 sets up expected param next_page_token for RepositoryI.ListKnowledgeBaseFiles +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) ExpectNext_page_tokenParam6(next_page_token string) *mRepositoryIMockListKnowledgeBaseFiles { + if mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Set") + } + + if mmListKnowledgeBaseFiles.defaultExpectation == nil { + mmListKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockListKnowledgeBaseFilesExpectation{} + } + + if mmListKnowledgeBaseFiles.defaultExpectation.params != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Expect") + } + + if mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs == nil { + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs = &RepositoryIMockListKnowledgeBaseFilesParamPtrs{} + } + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs.next_page_token = &next_page_token + + return mmListKnowledgeBaseFiles +} + +// ExpectFiles_uidParam7 sets up expected param files_uid for RepositoryI.ListKnowledgeBaseFiles +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) ExpectFiles_uidParam7(files_uid []string) *mRepositoryIMockListKnowledgeBaseFiles { + if mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Set") + } + + if mmListKnowledgeBaseFiles.defaultExpectation == nil { + mmListKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockListKnowledgeBaseFilesExpectation{} + } + + if mmListKnowledgeBaseFiles.defaultExpectation.params != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Expect") + } + + if mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs == nil { + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs = &RepositoryIMockListKnowledgeBaseFilesParamPtrs{} + } + mmListKnowledgeBaseFiles.defaultExpectation.paramPtrs.files_uid = &files_uid + + return mmListKnowledgeBaseFiles +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.ListKnowledgeBaseFiles +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) Inspect(f func(ctx context.Context, uid string, owner_uid string, kb_uid string, page_size int32, next_page_token string, files_uid []string)) *mRepositoryIMockListKnowledgeBaseFiles { + if mmListKnowledgeBaseFiles.mock.inspectFuncListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.ListKnowledgeBaseFiles") + } + + mmListKnowledgeBaseFiles.mock.inspectFuncListKnowledgeBaseFiles = f + + return mmListKnowledgeBaseFiles +} + +// Return sets up results that will be returned by RepositoryI.ListKnowledgeBaseFiles +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) Return(ka1 []mm_repository.KnowledgeBaseFile, i1 int, s1 string, err error) *RepositoryIMock { + if mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Set") } - if mmGetRepositoryTag.defaultExpectation == nil { - mmGetRepositoryTag.defaultExpectation = &RepositoryIMockGetRepositoryTagExpectation{mock: mmGetRepositoryTag.mock} + if mmListKnowledgeBaseFiles.defaultExpectation == nil { + mmListKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockListKnowledgeBaseFilesExpectation{mock: mmListKnowledgeBaseFiles.mock} } - mmGetRepositoryTag.defaultExpectation.results = &RepositoryIMockGetRepositoryTagResults{rp1, err} - return mmGetRepositoryTag.mock + mmListKnowledgeBaseFiles.defaultExpectation.results = &RepositoryIMockListKnowledgeBaseFilesResults{ka1, i1, s1, err} + return mmListKnowledgeBaseFiles.mock } -// Set uses given function f to mock the RepositoryI.GetRepositoryTag method -func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Set(f func(ctx context.Context, r1 utils.RepositoryTagName) (rp1 *pb.RepositoryTag, err error)) *RepositoryIMock { - if mmGetRepositoryTag.defaultExpectation != nil { - mmGetRepositoryTag.mock.t.Fatalf("Default expectation is already set for the RepositoryI.GetRepositoryTag method") +// Set uses given function f to mock the RepositoryI.ListKnowledgeBaseFiles method +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) Set(f func(ctx context.Context, uid string, owner_uid string, kb_uid string, page_size int32, next_page_token string, files_uid []string) (ka1 []mm_repository.KnowledgeBaseFile, i1 int, s1 string, err error)) *RepositoryIMock { + if mmListKnowledgeBaseFiles.defaultExpectation != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("Default expectation is already set for the RepositoryI.ListKnowledgeBaseFiles method") } - if len(mmGetRepositoryTag.expectations) > 0 { - mmGetRepositoryTag.mock.t.Fatalf("Some expectations are already set for the RepositoryI.GetRepositoryTag method") + if len(mmListKnowledgeBaseFiles.expectations) > 0 { + mmListKnowledgeBaseFiles.mock.t.Fatalf("Some expectations are already set for the RepositoryI.ListKnowledgeBaseFiles method") } - mmGetRepositoryTag.mock.funcGetRepositoryTag = f - return mmGetRepositoryTag.mock + mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles = f + return mmListKnowledgeBaseFiles.mock } -// When sets expectation for the RepositoryI.GetRepositoryTag which will trigger the result defined by the following +// When sets expectation for the RepositoryI.ListKnowledgeBaseFiles which will trigger the result defined by the following // Then helper -func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) When(ctx context.Context, r1 utils.RepositoryTagName) *RepositoryIMockGetRepositoryTagExpectation { - if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { - mmGetRepositoryTag.mock.t.Fatalf("RepositoryIMock.GetRepositoryTag mock is already set by Set") +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) When(ctx context.Context, uid string, owner_uid string, kb_uid string, page_size int32, next_page_token string, files_uid []string) *RepositoryIMockListKnowledgeBaseFilesExpectation { + if mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ListKnowledgeBaseFiles mock is already set by Set") } - expectation := &RepositoryIMockGetRepositoryTagExpectation{ - mock: mmGetRepositoryTag.mock, - params: &RepositoryIMockGetRepositoryTagParams{ctx, r1}, + expectation := &RepositoryIMockListKnowledgeBaseFilesExpectation{ + mock: mmListKnowledgeBaseFiles.mock, + params: &RepositoryIMockListKnowledgeBaseFilesParams{ctx, uid, owner_uid, kb_uid, page_size, next_page_token, files_uid}, } - mmGetRepositoryTag.expectations = append(mmGetRepositoryTag.expectations, expectation) + mmListKnowledgeBaseFiles.expectations = append(mmListKnowledgeBaseFiles.expectations, expectation) return expectation } -// Then sets up RepositoryI.GetRepositoryTag return parameters for the expectation previously defined by the When method -func (e *RepositoryIMockGetRepositoryTagExpectation) Then(rp1 *pb.RepositoryTag, err error) *RepositoryIMock { - e.results = &RepositoryIMockGetRepositoryTagResults{rp1, err} +// Then sets up RepositoryI.ListKnowledgeBaseFiles return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockListKnowledgeBaseFilesExpectation) Then(ka1 []mm_repository.KnowledgeBaseFile, i1 int, s1 string, err error) *RepositoryIMock { + e.results = &RepositoryIMockListKnowledgeBaseFilesResults{ka1, i1, s1, err} return e.mock } -// Times sets number of times RepositoryI.GetRepositoryTag should be invoked -func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Times(n uint64) *mRepositoryIMockGetRepositoryTag { +// Times sets number of times RepositoryI.ListKnowledgeBaseFiles should be invoked +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) Times(n uint64) *mRepositoryIMockListKnowledgeBaseFiles { if n == 0 { - mmGetRepositoryTag.mock.t.Fatalf("Times of RepositoryIMock.GetRepositoryTag mock can not be zero") + mmListKnowledgeBaseFiles.mock.t.Fatalf("Times of RepositoryIMock.ListKnowledgeBaseFiles mock can not be zero") } - mm_atomic.StoreUint64(&mmGetRepositoryTag.expectedInvocations, n) - return mmGetRepositoryTag + mm_atomic.StoreUint64(&mmListKnowledgeBaseFiles.expectedInvocations, n) + return mmListKnowledgeBaseFiles } -func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) invocationsDone() bool { - if len(mmGetRepositoryTag.expectations) == 0 && mmGetRepositoryTag.defaultExpectation == nil && mmGetRepositoryTag.mock.funcGetRepositoryTag == nil { +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) invocationsDone() bool { + if len(mmListKnowledgeBaseFiles.expectations) == 0 && mmListKnowledgeBaseFiles.defaultExpectation == nil && mmListKnowledgeBaseFiles.mock.funcListKnowledgeBaseFiles == nil { return true } - totalInvocations := mm_atomic.LoadUint64(&mmGetRepositoryTag.mock.afterGetRepositoryTagCounter) - expectedInvocations := mm_atomic.LoadUint64(&mmGetRepositoryTag.expectedInvocations) + totalInvocations := mm_atomic.LoadUint64(&mmListKnowledgeBaseFiles.mock.afterListKnowledgeBaseFilesCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmListKnowledgeBaseFiles.expectedInvocations) return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) } -// GetRepositoryTag implements repository.RepositoryI -func (mmGetRepositoryTag *RepositoryIMock) GetRepositoryTag(ctx context.Context, r1 utils.RepositoryTagName) (rp1 *pb.RepositoryTag, err error) { - mm_atomic.AddUint64(&mmGetRepositoryTag.beforeGetRepositoryTagCounter, 1) - defer mm_atomic.AddUint64(&mmGetRepositoryTag.afterGetRepositoryTagCounter, 1) +// ListKnowledgeBaseFiles implements repository.RepositoryI +func (mmListKnowledgeBaseFiles *RepositoryIMock) ListKnowledgeBaseFiles(ctx context.Context, uid string, owner_uid string, kb_uid string, page_size int32, next_page_token string, files_uid []string) (ka1 []mm_repository.KnowledgeBaseFile, i1 int, s1 string, err error) { + mm_atomic.AddUint64(&mmListKnowledgeBaseFiles.beforeListKnowledgeBaseFilesCounter, 1) + defer mm_atomic.AddUint64(&mmListKnowledgeBaseFiles.afterListKnowledgeBaseFilesCounter, 1) - if mmGetRepositoryTag.inspectFuncGetRepositoryTag != nil { - mmGetRepositoryTag.inspectFuncGetRepositoryTag(ctx, r1) + if mmListKnowledgeBaseFiles.inspectFuncListKnowledgeBaseFiles != nil { + mmListKnowledgeBaseFiles.inspectFuncListKnowledgeBaseFiles(ctx, uid, owner_uid, kb_uid, page_size, next_page_token, files_uid) } - mm_params := RepositoryIMockGetRepositoryTagParams{ctx, r1} + mm_params := RepositoryIMockListKnowledgeBaseFilesParams{ctx, uid, owner_uid, kb_uid, page_size, next_page_token, files_uid} // Record call args - mmGetRepositoryTag.GetRepositoryTagMock.mutex.Lock() - mmGetRepositoryTag.GetRepositoryTagMock.callArgs = append(mmGetRepositoryTag.GetRepositoryTagMock.callArgs, &mm_params) - mmGetRepositoryTag.GetRepositoryTagMock.mutex.Unlock() + mmListKnowledgeBaseFiles.ListKnowledgeBaseFilesMock.mutex.Lock() + mmListKnowledgeBaseFiles.ListKnowledgeBaseFilesMock.callArgs = append(mmListKnowledgeBaseFiles.ListKnowledgeBaseFilesMock.callArgs, &mm_params) + mmListKnowledgeBaseFiles.ListKnowledgeBaseFilesMock.mutex.Unlock() - for _, e := range mmGetRepositoryTag.GetRepositoryTagMock.expectations { + for _, e := range mmListKnowledgeBaseFiles.ListKnowledgeBaseFilesMock.expectations { if minimock.Equal(*e.params, mm_params) { mm_atomic.AddUint64(&e.Counter, 1) - return e.results.rp1, e.results.err + return e.results.ka1, e.results.i1, e.results.s1, e.results.err } } - if mmGetRepositoryTag.GetRepositoryTagMock.defaultExpectation != nil { - mm_atomic.AddUint64(&mmGetRepositoryTag.GetRepositoryTagMock.defaultExpectation.Counter, 1) - mm_want := mmGetRepositoryTag.GetRepositoryTagMock.defaultExpectation.params - mm_want_ptrs := mmGetRepositoryTag.GetRepositoryTagMock.defaultExpectation.paramPtrs + if mmListKnowledgeBaseFiles.ListKnowledgeBaseFilesMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmListKnowledgeBaseFiles.ListKnowledgeBaseFilesMock.defaultExpectation.Counter, 1) + mm_want := mmListKnowledgeBaseFiles.ListKnowledgeBaseFilesMock.defaultExpectation.params + mm_want_ptrs := mmListKnowledgeBaseFiles.ListKnowledgeBaseFilesMock.defaultExpectation.paramPtrs - mm_got := RepositoryIMockGetRepositoryTagParams{ctx, r1} + mm_got := RepositoryIMockListKnowledgeBaseFilesParams{ctx, uid, owner_uid, kb_uid, page_size, next_page_token, files_uid} if mm_want_ptrs != nil { if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { - mmGetRepositoryTag.t.Errorf("RepositoryIMock.GetRepositoryTag 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)) + mmListKnowledgeBaseFiles.t.Errorf("RepositoryIMock.ListKnowledgeBaseFiles 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.r1 != nil && !minimock.Equal(*mm_want_ptrs.r1, mm_got.r1) { - mmGetRepositoryTag.t.Errorf("RepositoryIMock.GetRepositoryTag got unexpected parameter r1, want: %#v, got: %#v%s\n", *mm_want_ptrs.r1, mm_got.r1, minimock.Diff(*mm_want_ptrs.r1, mm_got.r1)) + if mm_want_ptrs.uid != nil && !minimock.Equal(*mm_want_ptrs.uid, mm_got.uid) { + mmListKnowledgeBaseFiles.t.Errorf("RepositoryIMock.ListKnowledgeBaseFiles got unexpected parameter uid, want: %#v, got: %#v%s\n", *mm_want_ptrs.uid, mm_got.uid, minimock.Diff(*mm_want_ptrs.uid, mm_got.uid)) + } + + if mm_want_ptrs.owner_uid != nil && !minimock.Equal(*mm_want_ptrs.owner_uid, mm_got.owner_uid) { + mmListKnowledgeBaseFiles.t.Errorf("RepositoryIMock.ListKnowledgeBaseFiles got unexpected parameter owner_uid, want: %#v, got: %#v%s\n", *mm_want_ptrs.owner_uid, mm_got.owner_uid, minimock.Diff(*mm_want_ptrs.owner_uid, mm_got.owner_uid)) + } + + if mm_want_ptrs.kb_uid != nil && !minimock.Equal(*mm_want_ptrs.kb_uid, mm_got.kb_uid) { + mmListKnowledgeBaseFiles.t.Errorf("RepositoryIMock.ListKnowledgeBaseFiles got unexpected parameter kb_uid, want: %#v, got: %#v%s\n", *mm_want_ptrs.kb_uid, mm_got.kb_uid, minimock.Diff(*mm_want_ptrs.kb_uid, mm_got.kb_uid)) + } + + if mm_want_ptrs.page_size != nil && !minimock.Equal(*mm_want_ptrs.page_size, mm_got.page_size) { + mmListKnowledgeBaseFiles.t.Errorf("RepositoryIMock.ListKnowledgeBaseFiles got unexpected parameter page_size, want: %#v, got: %#v%s\n", *mm_want_ptrs.page_size, mm_got.page_size, minimock.Diff(*mm_want_ptrs.page_size, mm_got.page_size)) + } + + if mm_want_ptrs.next_page_token != nil && !minimock.Equal(*mm_want_ptrs.next_page_token, mm_got.next_page_token) { + mmListKnowledgeBaseFiles.t.Errorf("RepositoryIMock.ListKnowledgeBaseFiles got unexpected parameter next_page_token, want: %#v, got: %#v%s\n", *mm_want_ptrs.next_page_token, mm_got.next_page_token, minimock.Diff(*mm_want_ptrs.next_page_token, mm_got.next_page_token)) + } + + if mm_want_ptrs.files_uid != nil && !minimock.Equal(*mm_want_ptrs.files_uid, mm_got.files_uid) { + mmListKnowledgeBaseFiles.t.Errorf("RepositoryIMock.ListKnowledgeBaseFiles got unexpected parameter files_uid, want: %#v, got: %#v%s\n", *mm_want_ptrs.files_uid, mm_got.files_uid, minimock.Diff(*mm_want_ptrs.files_uid, mm_got.files_uid)) } } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { - mmGetRepositoryTag.t.Errorf("RepositoryIMock.GetRepositoryTag got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + mmListKnowledgeBaseFiles.t.Errorf("RepositoryIMock.ListKnowledgeBaseFiles got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } - mm_results := mmGetRepositoryTag.GetRepositoryTagMock.defaultExpectation.results + mm_results := mmListKnowledgeBaseFiles.ListKnowledgeBaseFilesMock.defaultExpectation.results if mm_results == nil { - mmGetRepositoryTag.t.Fatal("No results are set for the RepositoryIMock.GetRepositoryTag") + mmListKnowledgeBaseFiles.t.Fatal("No results are set for the RepositoryIMock.ListKnowledgeBaseFiles") } - return (*mm_results).rp1, (*mm_results).err + return (*mm_results).ka1, (*mm_results).i1, (*mm_results).s1, (*mm_results).err } - if mmGetRepositoryTag.funcGetRepositoryTag != nil { - return mmGetRepositoryTag.funcGetRepositoryTag(ctx, r1) + if mmListKnowledgeBaseFiles.funcListKnowledgeBaseFiles != nil { + return mmListKnowledgeBaseFiles.funcListKnowledgeBaseFiles(ctx, uid, owner_uid, kb_uid, page_size, next_page_token, files_uid) } - mmGetRepositoryTag.t.Fatalf("Unexpected call to RepositoryIMock.GetRepositoryTag. %v %v", ctx, r1) + mmListKnowledgeBaseFiles.t.Fatalf("Unexpected call to RepositoryIMock.ListKnowledgeBaseFiles. %v %v %v %v %v %v %v", ctx, uid, owner_uid, kb_uid, page_size, next_page_token, files_uid) return } -// GetRepositoryTagAfterCounter returns a count of finished RepositoryIMock.GetRepositoryTag invocations -func (mmGetRepositoryTag *RepositoryIMock) GetRepositoryTagAfterCounter() uint64 { - return mm_atomic.LoadUint64(&mmGetRepositoryTag.afterGetRepositoryTagCounter) +// ListKnowledgeBaseFilesAfterCounter returns a count of finished RepositoryIMock.ListKnowledgeBaseFiles invocations +func (mmListKnowledgeBaseFiles *RepositoryIMock) ListKnowledgeBaseFilesAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmListKnowledgeBaseFiles.afterListKnowledgeBaseFilesCounter) } -// GetRepositoryTagBeforeCounter returns a count of RepositoryIMock.GetRepositoryTag invocations -func (mmGetRepositoryTag *RepositoryIMock) GetRepositoryTagBeforeCounter() uint64 { - return mm_atomic.LoadUint64(&mmGetRepositoryTag.beforeGetRepositoryTagCounter) +// ListKnowledgeBaseFilesBeforeCounter returns a count of RepositoryIMock.ListKnowledgeBaseFiles invocations +func (mmListKnowledgeBaseFiles *RepositoryIMock) ListKnowledgeBaseFilesBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmListKnowledgeBaseFiles.beforeListKnowledgeBaseFilesCounter) } -// Calls returns a list of arguments used in each call to RepositoryIMock.GetRepositoryTag. +// Calls returns a list of arguments used in each call to RepositoryIMock.ListKnowledgeBaseFiles. // The list is in the same order as the calls were made (i.e. recent calls have a higher index) -func (mmGetRepositoryTag *mRepositoryIMockGetRepositoryTag) Calls() []*RepositoryIMockGetRepositoryTagParams { - mmGetRepositoryTag.mutex.RLock() +func (mmListKnowledgeBaseFiles *mRepositoryIMockListKnowledgeBaseFiles) Calls() []*RepositoryIMockListKnowledgeBaseFilesParams { + mmListKnowledgeBaseFiles.mutex.RLock() - argCopy := make([]*RepositoryIMockGetRepositoryTagParams, len(mmGetRepositoryTag.callArgs)) - copy(argCopy, mmGetRepositoryTag.callArgs) + argCopy := make([]*RepositoryIMockListKnowledgeBaseFilesParams, len(mmListKnowledgeBaseFiles.callArgs)) + copy(argCopy, mmListKnowledgeBaseFiles.callArgs) - mmGetRepositoryTag.mutex.RUnlock() + mmListKnowledgeBaseFiles.mutex.RUnlock() return argCopy } -// MinimockGetRepositoryTagDone returns true if the count of the GetRepositoryTag invocations corresponds +// MinimockListKnowledgeBaseFilesDone returns true if the count of the ListKnowledgeBaseFiles invocations corresponds // the number of defined expectations -func (m *RepositoryIMock) MinimockGetRepositoryTagDone() bool { - for _, e := range m.GetRepositoryTagMock.expectations { +func (m *RepositoryIMock) MinimockListKnowledgeBaseFilesDone() bool { + for _, e := range m.ListKnowledgeBaseFilesMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { return false } } - return m.GetRepositoryTagMock.invocationsDone() + return m.ListKnowledgeBaseFilesMock.invocationsDone() } -// MinimockGetRepositoryTagInspect logs each unmet expectation -func (m *RepositoryIMock) MinimockGetRepositoryTagInspect() { - for _, e := range m.GetRepositoryTagMock.expectations { +// MinimockListKnowledgeBaseFilesInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockListKnowledgeBaseFilesInspect() { + for _, e := range m.ListKnowledgeBaseFilesMock.expectations { if mm_atomic.LoadUint64(&e.Counter) < 1 { - m.t.Errorf("Expected call to RepositoryIMock.GetRepositoryTag with params: %#v", *e.params) + m.t.Errorf("Expected call to RepositoryIMock.ListKnowledgeBaseFiles with params: %#v", *e.params) } } - afterGetRepositoryTagCounter := mm_atomic.LoadUint64(&m.afterGetRepositoryTagCounter) + afterListKnowledgeBaseFilesCounter := mm_atomic.LoadUint64(&m.afterListKnowledgeBaseFilesCounter) // if default expectation was set then invocations count should be greater than zero - if m.GetRepositoryTagMock.defaultExpectation != nil && afterGetRepositoryTagCounter < 1 { - if m.GetRepositoryTagMock.defaultExpectation.params == nil { - m.t.Error("Expected call to RepositoryIMock.GetRepositoryTag") + if m.ListKnowledgeBaseFilesMock.defaultExpectation != nil && afterListKnowledgeBaseFilesCounter < 1 { + if m.ListKnowledgeBaseFilesMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.ListKnowledgeBaseFiles") } else { - m.t.Errorf("Expected call to RepositoryIMock.GetRepositoryTag with params: %#v", *m.GetRepositoryTagMock.defaultExpectation.params) + m.t.Errorf("Expected call to RepositoryIMock.ListKnowledgeBaseFiles with params: %#v", *m.ListKnowledgeBaseFilesMock.defaultExpectation.params) } } // if func was set then invocations count should be greater than zero - if m.funcGetRepositoryTag != nil && afterGetRepositoryTagCounter < 1 { - m.t.Error("Expected call to RepositoryIMock.GetRepositoryTag") + if m.funcListKnowledgeBaseFiles != nil && afterListKnowledgeBaseFilesCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.ListKnowledgeBaseFiles") } - if !m.GetRepositoryTagMock.invocationsDone() && afterGetRepositoryTagCounter > 0 { - m.t.Errorf("Expected %d calls to RepositoryIMock.GetRepositoryTag but found %d calls", - mm_atomic.LoadUint64(&m.GetRepositoryTagMock.expectedInvocations), afterGetRepositoryTagCounter) + if !m.ListKnowledgeBaseFilesMock.invocationsDone() && afterListKnowledgeBaseFilesCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.ListKnowledgeBaseFiles but found %d calls", + mm_atomic.LoadUint64(&m.ListKnowledgeBaseFilesMock.expectedInvocations), afterListKnowledgeBaseFilesCounter) } } @@ -1334,6 +2768,311 @@ func (m *RepositoryIMock) MinimockListKnowledgeBasesInspect() { } } +type mRepositoryIMockProcessKnowledgeBaseFiles struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockProcessKnowledgeBaseFilesExpectation + expectations []*RepositoryIMockProcessKnowledgeBaseFilesExpectation + + callArgs []*RepositoryIMockProcessKnowledgeBaseFilesParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockProcessKnowledgeBaseFilesExpectation specifies expectation struct of the RepositoryI.ProcessKnowledgeBaseFiles +type RepositoryIMockProcessKnowledgeBaseFilesExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockProcessKnowledgeBaseFilesParams + paramPtrs *RepositoryIMockProcessKnowledgeBaseFilesParamPtrs + results *RepositoryIMockProcessKnowledgeBaseFilesResults + Counter uint64 +} + +// RepositoryIMockProcessKnowledgeBaseFilesParams contains parameters of the RepositoryI.ProcessKnowledgeBaseFiles +type RepositoryIMockProcessKnowledgeBaseFilesParams struct { + ctx context.Context + file_uids []string +} + +// RepositoryIMockProcessKnowledgeBaseFilesParamPtrs contains pointers to parameters of the RepositoryI.ProcessKnowledgeBaseFiles +type RepositoryIMockProcessKnowledgeBaseFilesParamPtrs struct { + ctx *context.Context + file_uids *[]string +} + +// RepositoryIMockProcessKnowledgeBaseFilesResults contains results of the RepositoryI.ProcessKnowledgeBaseFiles +type RepositoryIMockProcessKnowledgeBaseFilesResults struct { + ka1 []mm_repository.KnowledgeBaseFile + err error +} + +// Expect sets up expected params for RepositoryI.ProcessKnowledgeBaseFiles +func (mmProcessKnowledgeBaseFiles *mRepositoryIMockProcessKnowledgeBaseFiles) Expect(ctx context.Context, file_uids []string) *mRepositoryIMockProcessKnowledgeBaseFiles { + if mmProcessKnowledgeBaseFiles.mock.funcProcessKnowledgeBaseFiles != nil { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ProcessKnowledgeBaseFiles mock is already set by Set") + } + + if mmProcessKnowledgeBaseFiles.defaultExpectation == nil { + mmProcessKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockProcessKnowledgeBaseFilesExpectation{} + } + + if mmProcessKnowledgeBaseFiles.defaultExpectation.paramPtrs != nil { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ProcessKnowledgeBaseFiles mock is already set by ExpectParams functions") + } + + mmProcessKnowledgeBaseFiles.defaultExpectation.params = &RepositoryIMockProcessKnowledgeBaseFilesParams{ctx, file_uids} + for _, e := range mmProcessKnowledgeBaseFiles.expectations { + if minimock.Equal(e.params, mmProcessKnowledgeBaseFiles.defaultExpectation.params) { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmProcessKnowledgeBaseFiles.defaultExpectation.params) + } + } + + return mmProcessKnowledgeBaseFiles +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.ProcessKnowledgeBaseFiles +func (mmProcessKnowledgeBaseFiles *mRepositoryIMockProcessKnowledgeBaseFiles) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockProcessKnowledgeBaseFiles { + if mmProcessKnowledgeBaseFiles.mock.funcProcessKnowledgeBaseFiles != nil { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ProcessKnowledgeBaseFiles mock is already set by Set") + } + + if mmProcessKnowledgeBaseFiles.defaultExpectation == nil { + mmProcessKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockProcessKnowledgeBaseFilesExpectation{} + } + + if mmProcessKnowledgeBaseFiles.defaultExpectation.params != nil { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ProcessKnowledgeBaseFiles mock is already set by Expect") + } + + if mmProcessKnowledgeBaseFiles.defaultExpectation.paramPtrs == nil { + mmProcessKnowledgeBaseFiles.defaultExpectation.paramPtrs = &RepositoryIMockProcessKnowledgeBaseFilesParamPtrs{} + } + mmProcessKnowledgeBaseFiles.defaultExpectation.paramPtrs.ctx = &ctx + + return mmProcessKnowledgeBaseFiles +} + +// ExpectFile_uidsParam2 sets up expected param file_uids for RepositoryI.ProcessKnowledgeBaseFiles +func (mmProcessKnowledgeBaseFiles *mRepositoryIMockProcessKnowledgeBaseFiles) ExpectFile_uidsParam2(file_uids []string) *mRepositoryIMockProcessKnowledgeBaseFiles { + if mmProcessKnowledgeBaseFiles.mock.funcProcessKnowledgeBaseFiles != nil { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ProcessKnowledgeBaseFiles mock is already set by Set") + } + + if mmProcessKnowledgeBaseFiles.defaultExpectation == nil { + mmProcessKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockProcessKnowledgeBaseFilesExpectation{} + } + + if mmProcessKnowledgeBaseFiles.defaultExpectation.params != nil { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ProcessKnowledgeBaseFiles mock is already set by Expect") + } + + if mmProcessKnowledgeBaseFiles.defaultExpectation.paramPtrs == nil { + mmProcessKnowledgeBaseFiles.defaultExpectation.paramPtrs = &RepositoryIMockProcessKnowledgeBaseFilesParamPtrs{} + } + mmProcessKnowledgeBaseFiles.defaultExpectation.paramPtrs.file_uids = &file_uids + + return mmProcessKnowledgeBaseFiles +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.ProcessKnowledgeBaseFiles +func (mmProcessKnowledgeBaseFiles *mRepositoryIMockProcessKnowledgeBaseFiles) Inspect(f func(ctx context.Context, file_uids []string)) *mRepositoryIMockProcessKnowledgeBaseFiles { + if mmProcessKnowledgeBaseFiles.mock.inspectFuncProcessKnowledgeBaseFiles != nil { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.ProcessKnowledgeBaseFiles") + } + + mmProcessKnowledgeBaseFiles.mock.inspectFuncProcessKnowledgeBaseFiles = f + + return mmProcessKnowledgeBaseFiles +} + +// Return sets up results that will be returned by RepositoryI.ProcessKnowledgeBaseFiles +func (mmProcessKnowledgeBaseFiles *mRepositoryIMockProcessKnowledgeBaseFiles) Return(ka1 []mm_repository.KnowledgeBaseFile, err error) *RepositoryIMock { + if mmProcessKnowledgeBaseFiles.mock.funcProcessKnowledgeBaseFiles != nil { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ProcessKnowledgeBaseFiles mock is already set by Set") + } + + if mmProcessKnowledgeBaseFiles.defaultExpectation == nil { + mmProcessKnowledgeBaseFiles.defaultExpectation = &RepositoryIMockProcessKnowledgeBaseFilesExpectation{mock: mmProcessKnowledgeBaseFiles.mock} + } + mmProcessKnowledgeBaseFiles.defaultExpectation.results = &RepositoryIMockProcessKnowledgeBaseFilesResults{ka1, err} + return mmProcessKnowledgeBaseFiles.mock +} + +// Set uses given function f to mock the RepositoryI.ProcessKnowledgeBaseFiles method +func (mmProcessKnowledgeBaseFiles *mRepositoryIMockProcessKnowledgeBaseFiles) Set(f func(ctx context.Context, file_uids []string) (ka1 []mm_repository.KnowledgeBaseFile, err error)) *RepositoryIMock { + if mmProcessKnowledgeBaseFiles.defaultExpectation != nil { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("Default expectation is already set for the RepositoryI.ProcessKnowledgeBaseFiles method") + } + + if len(mmProcessKnowledgeBaseFiles.expectations) > 0 { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("Some expectations are already set for the RepositoryI.ProcessKnowledgeBaseFiles method") + } + + mmProcessKnowledgeBaseFiles.mock.funcProcessKnowledgeBaseFiles = f + return mmProcessKnowledgeBaseFiles.mock +} + +// When sets expectation for the RepositoryI.ProcessKnowledgeBaseFiles which will trigger the result defined by the following +// Then helper +func (mmProcessKnowledgeBaseFiles *mRepositoryIMockProcessKnowledgeBaseFiles) When(ctx context.Context, file_uids []string) *RepositoryIMockProcessKnowledgeBaseFilesExpectation { + if mmProcessKnowledgeBaseFiles.mock.funcProcessKnowledgeBaseFiles != nil { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("RepositoryIMock.ProcessKnowledgeBaseFiles mock is already set by Set") + } + + expectation := &RepositoryIMockProcessKnowledgeBaseFilesExpectation{ + mock: mmProcessKnowledgeBaseFiles.mock, + params: &RepositoryIMockProcessKnowledgeBaseFilesParams{ctx, file_uids}, + } + mmProcessKnowledgeBaseFiles.expectations = append(mmProcessKnowledgeBaseFiles.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.ProcessKnowledgeBaseFiles return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockProcessKnowledgeBaseFilesExpectation) Then(ka1 []mm_repository.KnowledgeBaseFile, err error) *RepositoryIMock { + e.results = &RepositoryIMockProcessKnowledgeBaseFilesResults{ka1, err} + return e.mock +} + +// Times sets number of times RepositoryI.ProcessKnowledgeBaseFiles should be invoked +func (mmProcessKnowledgeBaseFiles *mRepositoryIMockProcessKnowledgeBaseFiles) Times(n uint64) *mRepositoryIMockProcessKnowledgeBaseFiles { + if n == 0 { + mmProcessKnowledgeBaseFiles.mock.t.Fatalf("Times of RepositoryIMock.ProcessKnowledgeBaseFiles mock can not be zero") + } + mm_atomic.StoreUint64(&mmProcessKnowledgeBaseFiles.expectedInvocations, n) + return mmProcessKnowledgeBaseFiles +} + +func (mmProcessKnowledgeBaseFiles *mRepositoryIMockProcessKnowledgeBaseFiles) invocationsDone() bool { + if len(mmProcessKnowledgeBaseFiles.expectations) == 0 && mmProcessKnowledgeBaseFiles.defaultExpectation == nil && mmProcessKnowledgeBaseFiles.mock.funcProcessKnowledgeBaseFiles == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmProcessKnowledgeBaseFiles.mock.afterProcessKnowledgeBaseFilesCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmProcessKnowledgeBaseFiles.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// ProcessKnowledgeBaseFiles implements repository.RepositoryI +func (mmProcessKnowledgeBaseFiles *RepositoryIMock) ProcessKnowledgeBaseFiles(ctx context.Context, file_uids []string) (ka1 []mm_repository.KnowledgeBaseFile, err error) { + mm_atomic.AddUint64(&mmProcessKnowledgeBaseFiles.beforeProcessKnowledgeBaseFilesCounter, 1) + defer mm_atomic.AddUint64(&mmProcessKnowledgeBaseFiles.afterProcessKnowledgeBaseFilesCounter, 1) + + if mmProcessKnowledgeBaseFiles.inspectFuncProcessKnowledgeBaseFiles != nil { + mmProcessKnowledgeBaseFiles.inspectFuncProcessKnowledgeBaseFiles(ctx, file_uids) + } + + mm_params := RepositoryIMockProcessKnowledgeBaseFilesParams{ctx, file_uids} + + // Record call args + mmProcessKnowledgeBaseFiles.ProcessKnowledgeBaseFilesMock.mutex.Lock() + mmProcessKnowledgeBaseFiles.ProcessKnowledgeBaseFilesMock.callArgs = append(mmProcessKnowledgeBaseFiles.ProcessKnowledgeBaseFilesMock.callArgs, &mm_params) + mmProcessKnowledgeBaseFiles.ProcessKnowledgeBaseFilesMock.mutex.Unlock() + + for _, e := range mmProcessKnowledgeBaseFiles.ProcessKnowledgeBaseFilesMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.ka1, e.results.err + } + } + + if mmProcessKnowledgeBaseFiles.ProcessKnowledgeBaseFilesMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmProcessKnowledgeBaseFiles.ProcessKnowledgeBaseFilesMock.defaultExpectation.Counter, 1) + mm_want := mmProcessKnowledgeBaseFiles.ProcessKnowledgeBaseFilesMock.defaultExpectation.params + mm_want_ptrs := mmProcessKnowledgeBaseFiles.ProcessKnowledgeBaseFilesMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockProcessKnowledgeBaseFilesParams{ctx, file_uids} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmProcessKnowledgeBaseFiles.t.Errorf("RepositoryIMock.ProcessKnowledgeBaseFiles 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.file_uids != nil && !minimock.Equal(*mm_want_ptrs.file_uids, mm_got.file_uids) { + mmProcessKnowledgeBaseFiles.t.Errorf("RepositoryIMock.ProcessKnowledgeBaseFiles got unexpected parameter file_uids, want: %#v, got: %#v%s\n", *mm_want_ptrs.file_uids, mm_got.file_uids, minimock.Diff(*mm_want_ptrs.file_uids, mm_got.file_uids)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmProcessKnowledgeBaseFiles.t.Errorf("RepositoryIMock.ProcessKnowledgeBaseFiles got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmProcessKnowledgeBaseFiles.ProcessKnowledgeBaseFilesMock.defaultExpectation.results + if mm_results == nil { + mmProcessKnowledgeBaseFiles.t.Fatal("No results are set for the RepositoryIMock.ProcessKnowledgeBaseFiles") + } + return (*mm_results).ka1, (*mm_results).err + } + if mmProcessKnowledgeBaseFiles.funcProcessKnowledgeBaseFiles != nil { + return mmProcessKnowledgeBaseFiles.funcProcessKnowledgeBaseFiles(ctx, file_uids) + } + mmProcessKnowledgeBaseFiles.t.Fatalf("Unexpected call to RepositoryIMock.ProcessKnowledgeBaseFiles. %v %v", ctx, file_uids) + return +} + +// ProcessKnowledgeBaseFilesAfterCounter returns a count of finished RepositoryIMock.ProcessKnowledgeBaseFiles invocations +func (mmProcessKnowledgeBaseFiles *RepositoryIMock) ProcessKnowledgeBaseFilesAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmProcessKnowledgeBaseFiles.afterProcessKnowledgeBaseFilesCounter) +} + +// ProcessKnowledgeBaseFilesBeforeCounter returns a count of RepositoryIMock.ProcessKnowledgeBaseFiles invocations +func (mmProcessKnowledgeBaseFiles *RepositoryIMock) ProcessKnowledgeBaseFilesBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmProcessKnowledgeBaseFiles.beforeProcessKnowledgeBaseFilesCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.ProcessKnowledgeBaseFiles. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmProcessKnowledgeBaseFiles *mRepositoryIMockProcessKnowledgeBaseFiles) Calls() []*RepositoryIMockProcessKnowledgeBaseFilesParams { + mmProcessKnowledgeBaseFiles.mutex.RLock() + + argCopy := make([]*RepositoryIMockProcessKnowledgeBaseFilesParams, len(mmProcessKnowledgeBaseFiles.callArgs)) + copy(argCopy, mmProcessKnowledgeBaseFiles.callArgs) + + mmProcessKnowledgeBaseFiles.mutex.RUnlock() + + return argCopy +} + +// MinimockProcessKnowledgeBaseFilesDone returns true if the count of the ProcessKnowledgeBaseFiles invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockProcessKnowledgeBaseFilesDone() bool { + for _, e := range m.ProcessKnowledgeBaseFilesMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.ProcessKnowledgeBaseFilesMock.invocationsDone() +} + +// MinimockProcessKnowledgeBaseFilesInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockProcessKnowledgeBaseFilesInspect() { + for _, e := range m.ProcessKnowledgeBaseFilesMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.ProcessKnowledgeBaseFiles with params: %#v", *e.params) + } + } + + afterProcessKnowledgeBaseFilesCounter := mm_atomic.LoadUint64(&m.afterProcessKnowledgeBaseFilesCounter) + // if default expectation was set then invocations count should be greater than zero + if m.ProcessKnowledgeBaseFilesMock.defaultExpectation != nil && afterProcessKnowledgeBaseFilesCounter < 1 { + if m.ProcessKnowledgeBaseFilesMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.ProcessKnowledgeBaseFiles") + } else { + m.t.Errorf("Expected call to RepositoryIMock.ProcessKnowledgeBaseFiles with params: %#v", *m.ProcessKnowledgeBaseFilesMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcProcessKnowledgeBaseFiles != nil && afterProcessKnowledgeBaseFilesCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.ProcessKnowledgeBaseFiles") + } + + if !m.ProcessKnowledgeBaseFilesMock.invocationsDone() && afterProcessKnowledgeBaseFilesCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.ProcessKnowledgeBaseFiles but found %d calls", + mm_atomic.LoadUint64(&m.ProcessKnowledgeBaseFilesMock.expectedInvocations), afterProcessKnowledgeBaseFilesCounter) + } +} + type mRepositoryIMockUpdateKnowledgeBase struct { mock *RepositoryIMock defaultExpectation *RepositoryIMockUpdateKnowledgeBaseExpectation @@ -1978,12 +3717,22 @@ func (m *RepositoryIMock) MinimockFinish() { if !m.minimockDone() { m.MinimockCreateKnowledgeBaseInspect() + m.MinimockCreateKnowledgeBaseFileInspect() + m.MinimockDeleteKnowledgeBaseInspect() + m.MinimockDeleteKnowledgeBaseFileInspect() + + m.MinimockGetKnowledgeBaseByOwnerAndIDInspect() + m.MinimockGetRepositoryTagInspect() + m.MinimockListKnowledgeBaseFilesInspect() + m.MinimockListKnowledgeBasesInspect() + m.MinimockProcessKnowledgeBaseFilesInspect() + m.MinimockUpdateKnowledgeBaseInspect() m.MinimockUpsertRepositoryTagInspect() @@ -2012,9 +3761,14 @@ func (m *RepositoryIMock) minimockDone() bool { done := true return done && m.MinimockCreateKnowledgeBaseDone() && + m.MinimockCreateKnowledgeBaseFileDone() && m.MinimockDeleteKnowledgeBaseDone() && + m.MinimockDeleteKnowledgeBaseFileDone() && + m.MinimockGetKnowledgeBaseByOwnerAndIDDone() && m.MinimockGetRepositoryTagDone() && + m.MinimockListKnowledgeBaseFilesDone() && m.MinimockListKnowledgeBasesDone() && + m.MinimockProcessKnowledgeBaseFilesDone() && m.MinimockUpdateKnowledgeBaseDone() && m.MinimockUpsertRepositoryTagDone() } diff --git a/pkg/repository/knowledgebase.go b/pkg/repository/knowledgebase.go index 1548c27..91d4124 100644 --- a/pkg/repository/knowledgebase.go +++ b/pkg/repository/knowledgebase.go @@ -18,15 +18,16 @@ type KnowledgeBaseI interface { ListKnowledgeBases(ctx context.Context, uid string) ([]KnowledgeBase, error) UpdateKnowledgeBase(ctx context.Context, uid string, kb KnowledgeBase) (*KnowledgeBase, error) DeleteKnowledgeBase(ctx context.Context, uid, kbID string) error + GetKnowledgeBaseByOwnerAndID(ctx context.Context, owner string, kbID string) (*KnowledgeBase, error) } type KnowledgeBase struct { - ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primaryKey" json:"id"` - KbID string `gorm:"column:kb_id;size:255;not null;unique" json:"kb_id"` + UID uuid.UUID `gorm:"column:uid;type:uuid;default:uuid_generate_v4();primaryKey" json:"uid"` + ID string `gorm:"column:id;size:255;not null" json:"kb_id"` Name string `gorm:"column:name;size:255;not null" json:"name"` Description string `gorm:"column:description;size:1023" json:"description"` Tags TagsArray `gorm:"column:tags;type:VARCHAR(255)[]" json:"tags"` - Owner string `gorm:"column:owner;size:255;not null" json:"owner"` + Owner string `gorm:"column:owner;type:uuid;not null" json:"owner"` CreateTime *time.Time `gorm:"column:create_time;not null;default:CURRENT_TIMESTAMP" json:"create_time"` UpdateTime *time.Time `gorm:"column:update_time;not null;autoUpdateTime" json:"update_time"` // Use autoUpdateTime DeleteTime *time.Time `gorm:"column:delete_time" json:"delete_time"` @@ -34,8 +35,8 @@ type KnowledgeBase struct { // table columns map type KnowledgeBaseColumns struct { + UID string ID string - KbID string Name string Description string Tags string @@ -46,8 +47,8 @@ type KnowledgeBaseColumns struct { } var KnowledgeBaseColumn = KnowledgeBaseColumns{ + UID: "uid", ID: "id", - KbID: "kb_id", Name: "name", Description: "description", Tags: "tags", @@ -99,19 +100,16 @@ func formatPostgresArray(tags []string) string { // CreateKnowledgeBase inserts a new KnowledgeBase record into the database. func (r *Repository) CreateKnowledgeBase(ctx context.Context, kb KnowledgeBase) (*KnowledgeBase, error) { - // check if the kb_id is unique, if yes try to add suffix to make it unique - for try := 0; try < 5; try++ { - // Check if the kb_id already exists - var existingKB KnowledgeBase - if err := r.db.WithContext(ctx).Where(KnowledgeBaseColumn.KbID+" = ?", kb.KbID).First(&existingKB).Error; err != nil { - if err != gorm.ErrRecordNotFound { - return nil, err - } - } else { - // kb_id already exists, generate a new one - kb.KbID = fmt.Sprintf("%s_%s", kb.KbID, uuid.New().String()[0:5]) // Add suffix to make it unique - continue + // check if the kb_id is unique + var existingKB KnowledgeBase + // check if the knowledge base exists and not delete + whereClause := fmt.Sprintf("%v = ? AND %v IS NULL", KnowledgeBaseColumn.ID, KnowledgeBaseColumn.DeleteTime) + if err := r.db.WithContext(ctx).Where(whereClause, kb.ID).First(&existingKB).Error; err != nil { + if err != gorm.ErrRecordNotFound { + return nil, err } + } else { + return nil, fmt.Errorf("knowledge base ID already exists. err: %w", customerror.ErrInvalidArgument) } // check if the name is unique in the owner's knowledge bases @@ -126,7 +124,7 @@ func (r *Repository) CreateKnowledgeBase(ctx context.Context, kb KnowledgeBase) // Create a new KnowledgeBase record if err := r.db.WithContext(ctx).Create(&kb).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - return nil, fmt.Errorf("knowledge base ID not found: %v, err:%w", kb.KbID, gorm.ErrRecordNotFound) + return nil, fmt.Errorf("knowledge base ID not found: %v, err:%w", kb.ID, gorm.ErrRecordNotFound) } return nil, err } @@ -152,11 +150,11 @@ func (r *Repository) UpdateKnowledgeBase(ctx context.Context, uid string, kb Kno var existingKB KnowledgeBase // Find the KnowledgeBase record by ID - conds := fmt.Sprintf("%s = ?", KnowledgeBaseColumn.KbID) + conds := fmt.Sprintf("%s = ?", KnowledgeBaseColumn.ID) // Find the KnowledgeBase record by ID - if err := r.db.WithContext(ctx).Where(conds, kb.KbID).First(&existingKB).Error; err != nil { + if err := r.db.WithContext(ctx).Where(conds, kb.ID).First(&existingKB).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - return nil, fmt.Errorf("knowledge base ID not found: %v", kb.KbID) + return nil, fmt.Errorf("knowledge base ID not found: %v", kb.ID) } return nil, err } @@ -178,9 +176,9 @@ func (r *Repository) UpdateKnowledgeBase(ctx context.Context, uid string, kb Kno } // Fetch the updated record var updatedKB KnowledgeBase - if err := r.db.WithContext(ctx).Where(conds, kb.KbID).First(&updatedKB).Error; err != nil { + if err := r.db.WithContext(ctx).Where(conds, kb.ID).First(&updatedKB).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - return nil, fmt.Errorf("knowledge base ID not found: %v. err: %w", kb.KbID, gorm.ErrRecordNotFound) + return nil, fmt.Errorf("knowledge base name id not found: %v. err: %w", kb.ID, gorm.ErrRecordNotFound) } return nil, err } @@ -193,7 +191,7 @@ func (r *Repository) UpdateKnowledgeBase(ctx context.Context, uid string, kb Kno func (r *Repository) DeleteKnowledgeBase(ctx context.Context, uid string, kbID string) error { // Fetch the existing record to ensure it exists var existingKB KnowledgeBase - conds := fmt.Sprintf("%v = ? AND %v IS NULL", KnowledgeBaseColumn.KbID, KnowledgeBaseColumn.DeleteTime) + conds := fmt.Sprintf("%v = ? AND %v IS NULL", KnowledgeBaseColumn.ID, KnowledgeBaseColumn.DeleteTime) if err := r.db.WithContext(ctx).First(&existingKB, conds, kbID).Error; err != nil { if err == gorm.ErrRecordNotFound { return fmt.Errorf("knowledge base ID not found: %v. err: %w", kbID, gorm.ErrRecordNotFound) @@ -213,7 +211,7 @@ func (r *Repository) DeleteKnowledgeBase(ctx context.Context, uid string, kbID s // Save the changes to mark the record as soft deleted if err := r.db.WithContext(ctx).Save(&existingKB).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - return fmt.Errorf("knowledge base ID not found: %v. err: %w", existingKB.KbID, gorm.ErrRecordNotFound) + return fmt.Errorf("knowledge base ID not found: %v. err: %w", existingKB.ID, gorm.ErrRecordNotFound) } return err } @@ -223,7 +221,7 @@ func (r *Repository) DeleteKnowledgeBase(ctx context.Context, uid string, kbID s func (r *Repository) checkIfNameUnique(ctx context.Context, owner string, name string) (bool, error) { var existingKB KnowledgeBase - whereString := fmt.Sprintf("%v = ? AND %v = ?", KnowledgeBaseColumn.Owner, KnowledgeBaseColumn.Name) + whereString := fmt.Sprintf("%v = ? AND %v = ? AND %s is NULL", KnowledgeBaseColumn.Owner, KnowledgeBaseColumn.Name, KnowledgeBaseColumn.DeleteTime) if err := r.db.WithContext(ctx).Where(whereString, owner, name).First(&existingKB).Error; err != nil { if err != gorm.ErrRecordNotFound { return false, err @@ -233,3 +231,27 @@ func (r *Repository) checkIfNameUnique(ctx context.Context, owner string, name s } return false, nil } + +// check if knowledge base exists by kb_uid +func (r *Repository) checkIfKnowledgeBaseExists(ctx context.Context, kbUID string) (bool, error) { + var existingKB KnowledgeBase + whereString := fmt.Sprintf("%v = ? AND %s is NULL", KnowledgeBaseColumn.UID, KnowledgeBaseColumn.DeleteTime) + if err := r.db.WithContext(ctx).Where(whereString, kbUID).First(&existingKB).Error; err != nil { + if err != gorm.ErrRecordNotFound { + return false, err + } + } else { + return true, nil + } + return false, nil +} + +// get the knowledge base by (owner, kb_id) +func (r *Repository) GetKnowledgeBaseByOwnerAndID(ctx context.Context, owner string, kbID string) (*KnowledgeBase, error) { + var existingKB KnowledgeBase + whereString := fmt.Sprintf("%v = ? AND %v = ? AND %v is NULL", KnowledgeBaseColumn.Owner, KnowledgeBaseColumn.ID, KnowledgeBaseColumn.DeleteTime) + if err := r.db.WithContext(ctx).Where(whereString, owner, kbID).First(&existingKB).Error; err != nil { + return nil, err + } + return &existingKB, nil +} diff --git a/pkg/repository/knowledgebasefile.go b/pkg/repository/knowledgebasefile.go new file mode 100644 index 0000000..28b01a7 --- /dev/null +++ b/pkg/repository/knowledgebasefile.go @@ -0,0 +1,175 @@ +package repository + +import ( + "context" + "fmt" + "time" + + "github.com/google/uuid" + artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" + "gorm.io/gorm" +) + +type KnowledgeBaseFileI interface { + CreateKnowledgeBaseFile(ctx context.Context, kb KnowledgeBaseFile) (*KnowledgeBaseFile, error) + ListKnowledgeBaseFiles(ctx context.Context, uid string, ownerUID string, kbUID string, pageSize int32, nextPageToken string, filesUID []string) ([]KnowledgeBaseFile, int, string, error) + DeleteKnowledgeBaseFile(ctx context.Context, fileUID string) error + ProcessKnowledgeBaseFiles(ctx context.Context, fileUids []string) ([]KnowledgeBaseFile, error) +} + +type KnowledgeBaseFile struct { + UID uuid.UUID `gorm:"column:uid;type:uuid;default:gen_random_uuid();primaryKey" json:"uid"` + Owner uuid.UUID `gorm:"column:owner;type:uuid;not null" json:"owner"` + KnowledgeBaseUID uuid.UUID `gorm:"column:kb_uid;type:uuid;not null" json:"kb_uid"` + CreatorUID uuid.UUID `gorm:"column:creator_uid;type:uuid;not null" json:"creator_uid"` + Name string `gorm:"column:name;size:255;not null" json:"name"` + Type string `gorm:"column:type;not null" json:"type"` + Destination string `gorm:"column:destination;size:255;not null" json:"destination"` + ProcessStatus string `gorm:"column:process_status;size:100;not null" json:"process_status"` + ExtraMetaData string `gorm:"column:extra_meta_data;type:jsonb" json:"extra_meta_data"` + // Content not used yet + Content []byte `gorm:"column:content;type:bytea" json:"content"` + CreateTime *time.Time `gorm:"column:create_time;not null;default:CURRENT_TIMESTAMP" json:"create_time"` + UpdateTime *time.Time `gorm:"column:update_time;not null;autoUpdateTime" json:"update_time"` // Use autoUpdateTime + DeleteTime *time.Time `gorm:"column:delete_time" json:"delete_time"` +} + +// table columns map +type KnowledgeBaseFileColumns struct { + UID string + Owner string + KnowledgeBaseUID string + CreatorUID string + Name string + Type string + Destination string + ProcessStatus string + CreateTime string + ExtraMetaData string + UpdateTime string + DeleteTime string +} + +var KnowledgeBaseFileColumn = KnowledgeBaseFileColumns{ + UID: "uid", + Owner: "owner", + KnowledgeBaseUID: "kb_uid", + CreatorUID: "creator_uid", + Name: "name", + Type: "type", + Destination: "destination", + ProcessStatus: "process_status", + ExtraMetaData: "extra_meta_data", + CreateTime: "create_time", + UpdateTime: "update_time", + DeleteTime: "delete_time", +} + +func (r *Repository) CreateKnowledgeBaseFile(ctx context.Context, kb KnowledgeBaseFile) (*KnowledgeBaseFile, error) { + // check if the file already exists in the same knowledge base and not delete + var existingFile KnowledgeBaseFile + whereClause := fmt.Sprintf("%s = ? AND %s = ? AND %v is NULL", KnowledgeBaseFileColumn.KnowledgeBaseUID, KnowledgeBaseFileColumn.Name, KnowledgeBaseFileColumn.DeleteTime) + if err := r.db.Where(whereClause, kb.KnowledgeBaseUID, kb.Name).First(&existingFile).Error; err != nil { + if err != gorm.ErrRecordNotFound { + return nil, err + } + } else { + return nil, fmt.Errorf("file already exists in the knowledge base. file: {%v}", kb.Name) + } + + exist, err := r.checkIfKnowledgeBaseExists(ctx, kb.KnowledgeBaseUID.String()) + if err != nil { + return nil, err + } + if !exist { + return nil, fmt.Errorf("knowledge base does not exist. kb.uid:{%v}", kb.KnowledgeBaseUID.String()) + } + + kb.ExtraMetaData = "{}" + if err := r.db.WithContext(ctx).Create(&kb).Error; err != nil { + return nil, err + } + return &kb, nil +} + +func (r *Repository) ListKnowledgeBaseFiles(ctx context.Context, uid string, ownerUID string, kbUID string, pageSize int32, nextPageToken string, fileUIDs []string) ([]KnowledgeBaseFile, int, string, error) { + var kbs []KnowledgeBaseFile + var totalCount int64 + + // Initial query with owner and knowledge base uid and delete time is null + whereClause := fmt.Sprintf("%v = ? AND %v = ? AND %v is NULL", KnowledgeBaseFileColumn.Owner, KnowledgeBaseFileColumn.KnowledgeBaseUID, KnowledgeBaseFileColumn.DeleteTime) + query := r.db.Model(&KnowledgeBaseFile{}).Where(whereClause, ownerUID, kbUID) + + // Apply file UID filter if provided + if len(fileUIDs) > 0 { + whereClause := fmt.Sprintf("%v IN ?", KnowledgeBaseFileColumn.UID) + query = query.Where(whereClause, fileUIDs) + } + + // Count the total number of matching records + if err := query.Count(&totalCount).Error; err != nil { + return nil, 0, "", err + } + + // Apply pagination. page size's default value is 10 and cap to 100. + if pageSize > 100 { + pageSize = 100 + } else if pageSize <= 0 { + pageSize = 10 + } + + query = query.Limit(int(pageSize)) + + if nextPageToken != "" { + // Assuming next_page_token is the `create_time` timestamp of the last record from the previous page + if parsedTime, err := time.Parse(time.RFC3339, nextPageToken); err == nil { + whereClause := fmt.Sprintf("%v > ?", KnowledgeBaseFileColumn.CreateTime) + query = query.Where(whereClause, parsedTime) + } else { + return nil, 0, "", fmt.Errorf("invalid next_page_token format(RFC3339): %v", err) + } + } + + // Fetch the records + if err := query.Find(&kbs).Error; err != nil { + return nil, 0, "", err + } + + // Determine the next page token + newNextPageToken := "" + if len(kbs) > 0 { + newNextPageToken = kbs[len(kbs)-1].CreateTime.Format(time.RFC3339) + } + return kbs, int(totalCount), newNextPageToken, nil +} + +// delete the file which is to set the delete time +func (r *Repository) DeleteKnowledgeBaseFile(ctx context.Context, fileUID string) error { + currentTime := time.Now() + whereClause := fmt.Sprintf("%v = ? AND %v is NULL", KnowledgeBaseFileColumn.UID, KnowledgeBaseFileColumn.DeleteTime) + if err := r.db.WithContext(ctx).Model(&KnowledgeBaseFile{}). + Where(whereClause, fileUID). + Update(KnowledgeBaseFileColumn.DeleteTime, currentTime).Error; err != nil { + return err + } + return nil +} + +// ProcessKnowledgeBaseFiles updates the process status of the files +func (r *Repository) ProcessKnowledgeBaseFiles(ctx context.Context, fileUIDs []string) ([]KnowledgeBaseFile, error) { + // Update the process status of the files + waitingStatus := artifactpb.FileProcessStatus_name[int32(artifactpb.FileProcessStatus_FILE_PROCESS_STATUS_WAITING)] + if err := r.db.WithContext(ctx).Model(&KnowledgeBaseFile{}). + Where(KnowledgeBaseFileColumn.UID+" IN ?", fileUIDs). + Update(KnowledgeBaseFileColumn.ProcessStatus, waitingStatus).Error; err != nil { + return nil, err + } + + // Retrieve the updated records + var files []KnowledgeBaseFile + if err := r.db.WithContext(ctx).Where(KnowledgeBaseFileColumn.UID+" IN ?", fileUIDs).Find(&files).Error; err != nil { + return nil, err + } + + return files, nil +} diff --git a/pkg/repository/repository.go b/pkg/repository/repository.go index 13cd765..f875892 100644 --- a/pkg/repository/repository.go +++ b/pkg/repository/repository.go @@ -7,6 +7,7 @@ import ( type RepositoryI interface { TagI KnowledgeBaseI + KnowledgeBaseFileI } // Repository implements Artifact storage functions in PostgreSQL. diff --git a/pkg/service/service.go b/pkg/service/service.go index 514775c..fc5ebf1 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -7,9 +7,11 @@ import ( "strings" "github.com/instill-ai/artifact-backend/pkg/customerror" + "github.com/instill-ai/artifact-backend/pkg/minio" "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" + mgmtPB "github.com/instill-ai/protogen-go/core/mgmt/v1beta" ) const ( @@ -20,17 +22,23 @@ const ( // Service implements the Artifact domain use cases. type Service struct { Repository repository.RepositoryI + MinIO minio.MinioI + MgmtPrv mgmtPB.MgmtPrivateServiceClient registryClient RegistryClient } // NewService initiates a service instance func NewService( r repository.RepositoryI, + mc minio.MinioI, + mgmtPrv mgmtPB.MgmtPrivateServiceClient, rc RegistryClient, ) *Service { return &Service{ Repository: r, + MinIO: mc, + MgmtPrv: mgmtPrv, registryClient: rc, } } diff --git a/pkg/service/service_test.go b/pkg/service/service_test.go index 3ad7a4b..3dd3cc8 100644 --- a/pkg/service/service_test.go +++ b/pkg/service/service_test.go @@ -201,7 +201,7 @@ func TestService_ListRepositoryTags(t *testing.T) { Then(repoTag, tc.repoErr) } - s := NewService(repository, registry) + s := NewService(repository, nil, nil, registry) req := newReq(tc.in) resp, err := s.ListRepositoryTags(ctx, req) if tc.wantErr != "" { @@ -243,7 +243,7 @@ func TestService_CreateRepositoryTag(t *testing.T) { t.Name = "shake/home:1.3.0" req := &artifactpb.CreateRepositoryTagRequest{Tag: t} - s := NewService(nil, nil) + s := NewService(nil, nil, nil, nil) _, err := s.CreateRepositoryTag(ctx, req) c.Check(err, qt.ErrorMatches, "invalid tag name") }) @@ -253,7 +253,7 @@ func TestService_CreateRepositoryTag(t *testing.T) { t.Id = "latest" req := &artifactpb.CreateRepositoryTagRequest{Tag: t} - s := NewService(nil, nil) + s := NewService(nil, nil, nil, nil) _, err := s.CreateRepositoryTag(ctx, req) c.Check(err, qt.ErrorMatches, "invalid tag name") }) @@ -266,7 +266,7 @@ func TestService_CreateRepositoryTag(t *testing.T) { repository := mock.NewRepositoryIMock(c) repository.UpsertRepositoryTagMock.When(minimock.AnyContext, clearedTag).Then(nil, fmt.Errorf("foo")) - s := NewService(repository, nil) + s := NewService(repository, nil, nil, nil) _, err := s.CreateRepositoryTag(ctx, req) c.Check(err, qt.ErrorMatches, "failed to upsert tag .*: foo") }) @@ -275,7 +275,7 @@ func TestService_CreateRepositoryTag(t *testing.T) { repository := mock.NewRepositoryIMock(c) repository.UpsertRepositoryTagMock.When(minimock.AnyContext, clearedTag).Then(want, nil) - s := NewService(repository, nil) + s := NewService(repository, nil, nil, nil) resp, err := s.CreateRepositoryTag(ctx, req) c.Check(err, qt.IsNil) c.Check(resp.GetTag(), cmpPB, want)