diff --git a/Dockerfile b/Dockerfile index 04be125..403ac2f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,5 @@ COPY --from=docker:dind-rootless --chown=nobody:nogroup /usr/local/bin/docker /u COPY --from=build --chown=nobody:nogroup /src/config ./config COPY --from=build --chown=nobody:nogroup /src/release-please ./release-please COPY --from=build --chown=nobody:nogroup /src/pkg/db/migration ./pkg/db/migration - COPY --from=build --chown=nobody:nogroup /${SERVICE_NAME}-migrate ./ COPY --from=build --chown=nobody:nogroup /${SERVICE_NAME} ./ diff --git a/Makefile b/Makefile index 9b745e5..703f61a 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,25 @@ dev: ## Run dev container --network instill-network \ --name ${SERVICE_NAME} \ instill/${SERVICE_NAME}:dev +.PHONY: run-local +run-local: + @if docker inspect --type container ${SERVICE_NAME} >/dev/null 2>&1; then \ + echo "A container named ${SERVICE_NAME} is already running. \nRestarting..."; \ + make rm; \ + fi + @docker run -d --rm \ + -p ${SERVICE_PORT}:${SERVICE_PORT} \ + --network instill-network \ + --name ${SERVICE_NAME} \ + instill/${SERVICE_NAME}:local \ + /bin/sh -c "\ + ./artifact-backend-migrate && \ + ./artifact-backend \ + " .PHONY: logs logs: ## Tail service container logs with -n 10 - @docker logs ${SERVICE_NAME} --follow --tail=10 + @docker logs ${SERVICE_NAME} --follow .PHONY: stop stop: ## Stop container @@ -36,7 +51,6 @@ rm: ## Remove container .PHONY: top top: ## Display all running service processes @docker top ${SERVICE_NAME} - .PHONY: build build: ## Build dev docker image @docker build \ @@ -45,6 +59,15 @@ build: ## Build dev docker image --build-arg K6_VERSION=${K6_VERSION} \ -f Dockerfile.dev -t instill/${SERVICE_NAME}:dev . +.PHONY: build-local +build-local: ## Build dev docker image + @docker build \ + --no-cache \ + --build-arg SERVICE_NAME=${SERVICE_NAME} \ + --build-arg GOLANG_VERSION=${GOLANG_VERSION} \ + --build-arg K6_VERSION=${K6_VERSION} \ + -f Dockerfile -t instill/${SERVICE_NAME}:local . + .PHONY: go-gen go-gen: ## Generate codes go generate ./... diff --git a/cmd/main/main.go b/cmd/main/main.go index 8819ee2..342db40 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -49,6 +49,11 @@ import ( var propagator propagation.TextMapPropagator +// grpcHandlerFunc handles incoming HTTP requests and routes them to either the gRPC server or the gateway handler. +// It wraps the handler function with h2c.NewHandler to support HTTP/2 requests. +// The function extracts the B3 context from the incoming request headers and sets it in the request context. +// If the request is a gRPC request, it calls the gRPC server's ServeHTTP method. +// Otherwise, it calls the gateway handler's ServeHTTP method. func grpcHandlerFunc(grpcServer *grpc.Server, gwHandler http.Handler) http.Handler { return h2c.NewHandler( http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -179,7 +184,7 @@ func main() { reflection.Register(publicGrpcS) artifactPB.RegisterArtifactPublicServiceServer( publicGrpcS, - handler.NewPublicHandler(ctx), + handler.NewPublicHandler(ctx, service), ) privateGrpcS := grpc.NewServer(grpcServerOpts...) diff --git a/config/config.go b/config/config.go index 531ce6e..4cd0549 100644 --- a/config/config.go +++ b/config/config.go @@ -130,17 +130,27 @@ func Init() error { fileRelativePath := fs.String("file", "config/config.yaml", "configuration file") flag.Parse() - if err := k.Load(file.Provider(*fileRelativePath), parser); err != nil { + if err := k.Load( + file.Provider(*fileRelativePath), + parser, + ); err != nil { log.Fatal(err.Error()) } - if err := k.Load(env.ProviderWithValue("CFG_", ".", func(s string, v string) (string, interface{}) { - key := strings.Replace(strings.ToLower(strings.TrimPrefix(s, "CFG_")), "_", ".", -1) - if strings.Contains(v, ",") { - return key, strings.Split(strings.TrimSpace(v), ",") - } - return key, v - }), nil); err != nil { + if err := k.Load( + env.ProviderWithValue( + "CFG_", + ".", + func(k string, v string) (string, interface{}) { + key := strings.Replace(strings.ToLower(strings.TrimPrefix(k, "CFG_")), "_", ".", -1) + if strings.Contains(v, ",") { + return key, strings.Split(strings.TrimSpace(v), ",") + } + return key, v + }, + ), + nil, + ); err != nil { return err } diff --git a/config/config.yaml b/config/config.yaml index 4d162a1..27bdffd 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -22,7 +22,7 @@ database: host: pg-sql port: 5432 name: artifact - version: 1 + version: 2 timezone: Etc/UTC pool: idleconnections: 5 diff --git a/go.mod b/go.mod index 0b71862..645787e 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( 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.20240408123548-9a2337cdfe04 + github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240527081147-f7cc66e329f9 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 diff --git a/go.sum b/go.sum index cb223b4..62393c8 100644 --- a/go.sum +++ b/go.sum @@ -282,8 +282,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.20240408123548-9a2337cdfe04 h1:/i0RjGbDDAjc9SPYMoemjLfSHNX8S+Rau6Y8orhLiv8= -github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240408123548-9a2337cdfe04/go.mod h1:jhEL0SauySMoPLVvx105DWyThju9sYTbsXIySVCArmM= +github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240527081147-f7cc66e329f9 h1:bjvRlomNglZpKsxd5Fv+YhoRyFNAD56hVVReesaXqdI= +github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240527081147-f7cc66e329f9/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= diff --git a/pkg/constant/constant.go b/pkg/constant/constant.go index da35cc0..5c386db 100644 --- a/pkg/constant/constant.go +++ b/pkg/constant/constant.go @@ -12,3 +12,4 @@ const MaxPayloadSize = 1024 * 1024 * 32 // Constants for resource owner const DefaultUserID string = "admin" +const HeaderUserUIDKey = "Instill-User-Uid" diff --git a/pkg/service/errors.go b/pkg/customerror/error.go similarity index 96% rename from pkg/service/errors.go rename to pkg/customerror/error.go index 7e97ccb..e3a77e7 100644 --- a/pkg/service/errors.go +++ b/pkg/customerror/error.go @@ -1,4 +1,4 @@ -package service +package customerror import "errors" diff --git a/pkg/db/migration/000002_create_knowledge_base_table.down.sql b/pkg/db/migration/000002_create_knowledge_base_table.down.sql new file mode 100644 index 0000000..1e85d2a --- /dev/null +++ b/pkg/db/migration/000002_create_knowledge_base_table.down.sql @@ -0,0 +1 @@ +DROP TABLE knowledge_base; \ No newline at end of file diff --git a/pkg/db/migration/000002_create_knowledge_base_table.up.sql b/pkg/db/migration/000002_create_knowledge_base_table.up.sql new file mode 100644 index 0000000..fa658e3 --- /dev/null +++ b/pkg/db/migration/000002_create_knowledge_base_table.up.sql @@ -0,0 +1,22 @@ +CREATE TABLE knowledge_base ( + id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), + kb_id VARCHAR(255) NOT NULL UNIQUE, + name VARCHAR(255) NOT NULL, + description VARCHAR(1023), + tags VARCHAR(255)[], + owner VARCHAR(255) NOT NULL, + create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + delete_time TIMESTAMP +); + +COMMENT ON TABLE knowledge_base IS 'Table to store knowledge base information'; +COMMENT ON COLUMN knowledge_base.id IS 'Primary key, auto-generated UUID'; +COMMENT ON COLUMN knowledge_base.name IS 'Name of the knowledge base, up to 255 characters'; +COMMENT ON COLUMN knowledge_base.kb_id IS 'Unique identifier for 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.update_time IS 'Timestamp of the last update, stored in UTC'; +COMMENT ON COLUMN knowledge_base.create_time IS 'Timestamp when the entry was created, stored in UTC'; +COMMENT ON COLUMN knowledge_base.owner IS 'Owner of the knowledge base, up to 255 characters'; +COMMENT ON COLUMN knowledge_base.tags IS 'Array of tags associated with the knowledge base'; +COMMENT ON COLUMN knowledge_base.delete_time IS 'Timestamp when the entry was marked as deleted, stored in UTC'; \ No newline at end of file diff --git a/pkg/handler/knowledgebase.go b/pkg/handler/knowledgebase.go new file mode 100644 index 0000000..25a0128 --- /dev/null +++ b/pkg/handler/knowledgebase.go @@ -0,0 +1,31 @@ +package handler + +import ( + "context" + "fmt" + + "google.golang.org/grpc/metadata" + + artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" +) + +func (ph *PublicHandler) CreateKnowledgeBase(ctx context.Context, req *artifactpb.CreateKnowledgeBaseRequest) (*artifactpb.CreateKnowledgeBaseResponse, error) { + fmt.Println("CreateKnowledgeBase") + return nil, nil +} +func (ph *PublicHandler) GetKnowledgeBases(ctx context.Context, req *artifactpb.GetKnowledgeBasesRequest) (*artifactpb.GetKnowledgeBasesResponse, error) { + fmt.Println("GetKnowledgeBases") + return nil, nil +} +func (ph *PublicHandler) UpdateKnowledgeBase(ctx context.Context, req *artifactpb.UpdateKnowledgeBaseRequest) (*artifactpb.UpdateKnowledgeBaseResponse, error) { + fmt.Println("UpdateKnowledgeBase") + return nil, nil +} +func (ph *PublicHandler) DeleteKnowledgeBase(ctx context.Context, req *artifactpb.DeleteKnowledgeBaseRequest) (*artifactpb.DeleteKnowledgeBaseResponse, error) { + // get header + md, _ := metadata.FromIncomingContext(ctx) + fmt.Println(md) + + fmt.Println("DeleteKnowledgeBase") + return nil, nil +} diff --git a/pkg/handler/public.go b/pkg/handler/public.go index b6e5147..f38528b 100644 --- a/pkg/handler/public.go +++ b/pkg/handler/public.go @@ -2,7 +2,9 @@ package handler import ( "context" + "fmt" + artifact "github.com/instill-ai/artifact-backend/pkg/service" artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" healthcheckPB "github.com/instill-ai/protogen-go/common/healthcheck/v1beta" ) @@ -10,15 +12,20 @@ import ( // PublicHandler handles public API type PublicHandler struct { artifactpb.UnimplementedArtifactPublicServiceServer + ctx context.Context + service *artifact.Service } // NewPublicHandler initiates a handler instance -func NewPublicHandler(_ context.Context) artifactpb.ArtifactPublicServiceServer { - return &PublicHandler{} +func NewPublicHandler(ctx context.Context, service *artifact.Service) artifactpb.ArtifactPublicServiceServer { + return &PublicHandler{ + ctx: ctx, + service: service} } // Liveness returns the health of the service. -func (h *PublicHandler) Liveness(_ context.Context, _ *artifactpb.LivenessRequest) (*artifactpb.LivenessResponse, error) { +func (ph *PublicHandler) Liveness(_ context.Context, _ *artifactpb.LivenessRequest) (*artifactpb.LivenessResponse, error) { + fmt.Println("Liveness") return &artifactpb.LivenessResponse{ HealthCheckResponse: &healthcheckPB.HealthCheckResponse{ Status: healthcheckPB.HealthCheckResponse_SERVING_STATUS_SERVING, @@ -27,7 +34,7 @@ func (h *PublicHandler) Liveness(_ context.Context, _ *artifactpb.LivenessReques } // Readiness returns the state of the service. -func (h *PublicHandler) Readiness(_ context.Context, _ *artifactpb.ReadinessRequest) (*artifactpb.ReadinessResponse, error) { +func (ph *PublicHandler) Readiness(_ context.Context, _ *artifactpb.ReadinessRequest) (*artifactpb.ReadinessResponse, error) { return &artifactpb.ReadinessResponse{ HealthCheckResponse: &healthcheckPB.HealthCheckResponse{ Status: healthcheckPB.HealthCheckResponse_SERVING_STATUS_SERVING, diff --git a/pkg/middleware/interceptor.go b/pkg/middleware/interceptor.go index 053e17d..1f10781 100644 --- a/pkg/middleware/interceptor.go +++ b/pkg/middleware/interceptor.go @@ -16,8 +16,8 @@ import ( grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery" "github.com/instill-ai/artifact-backend/pkg/acl" + "github.com/instill-ai/artifact-backend/pkg/customerror" "github.com/instill-ai/artifact-backend/pkg/handler" - "github.com/instill-ai/artifact-backend/pkg/service" "github.com/instill-ai/x/errmsg" ) @@ -89,7 +89,7 @@ func AsGRPCError(err error) error { code = codes.AlreadyExists case errors.Is(err, gorm.ErrRecordNotFound), - errors.Is(err, service.ErrNotFound), + errors.Is(err, customerror.ErrNotFound), errors.Is(err, acl.ErrMembershipNotFound): code = codes.NotFound @@ -98,7 +98,7 @@ func AsGRPCError(err error) error { errors.Is(err, handler.ErrCheckUpdateImmutableFields), errors.Is(err, handler.ErrCheckOutputOnlyFields), errors.Is(err, handler.ErrCheckRequiredFields), - errors.Is(err, service.ErrExceedMaxBatchSize), + errors.Is(err, customerror.ErrExceedMaxBatchSize), errors.Is(err, handler.ErrFieldMask), errors.Is(err, handler.ErrResourceID), errors.Is(err, handler.ErrSematicVersion), @@ -107,16 +107,16 @@ func AsGRPCError(err error) error { code = codes.InvalidArgument case - errors.Is(err, service.ErrNoPermission): + errors.Is(err, customerror.ErrNoPermission): code = codes.PermissionDenied case - errors.Is(err, service.ErrUnauthenticated): + errors.Is(err, customerror.ErrUnauthenticated): code = codes.Unauthenticated case - errors.Is(err, service.ErrRateLimiting): + errors.Is(err, customerror.ErrRateLimiting): code = codes.ResourceExhausted default: diff --git a/pkg/mock/generator.go b/pkg/mock/generator.go index 0c30927..067b00e 100644 --- a/pkg/mock/generator.go +++ b/pkg/mock/generator.go @@ -1,4 +1,4 @@ package mock //go:generate minimock -g -i github.com/instill-ai/artifact-backend/pkg/service.RegistryClient -o ./ -s "_mock.gen.go" -//go:generate minimock -g -i github.com/instill-ai/artifact-backend/pkg/service.Repository -o ./ -s "_mock.gen.go" +//go:generate minimock -g -i github.com/instill-ai/artifact-backend/pkg/repository.RepositoryI -o ./ -s "_mock.gen.go" diff --git a/pkg/mock/registry_client_mock.gen.go b/pkg/mock/registry_client_mock.gen.go index 7219c8e..445fcff 100644 --- a/pkg/mock/registry_client_mock.gen.go +++ b/pkg/mock/registry_client_mock.gen.go @@ -1,4 +1,4 @@ -// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. +// Code generated by http://github.com/gojuno/minimock (v3.3.9). DO NOT EDIT. package mock @@ -46,14 +46,17 @@ type mRegistryClientMockListTags struct { callArgs []*RegistryClientMockListTagsParams mutex sync.RWMutex + + expectedInvocations uint64 } // RegistryClientMockListTagsExpectation specifies expectation struct of the RegistryClient.ListTags type RegistryClientMockListTagsExpectation struct { - mock *RegistryClientMock - params *RegistryClientMockListTagsParams - results *RegistryClientMockListTagsResults - Counter uint64 + mock *RegistryClientMock + params *RegistryClientMockListTagsParams + paramPtrs *RegistryClientMockListTagsParamPtrs + results *RegistryClientMockListTagsResults + Counter uint64 } // RegistryClientMockListTagsParams contains parameters of the RegistryClient.ListTags @@ -62,6 +65,12 @@ type RegistryClientMockListTagsParams struct { repository string } +// RegistryClientMockListTagsParamPtrs contains pointers to parameters of the RegistryClient.ListTags +type RegistryClientMockListTagsParamPtrs struct { + ctx *context.Context + repository *string +} + // RegistryClientMockListTagsResults contains results of the RegistryClient.ListTags type RegistryClientMockListTagsResults struct { tags []string @@ -78,6 +87,10 @@ func (mmListTags *mRegistryClientMockListTags) Expect(ctx context.Context, repos mmListTags.defaultExpectation = &RegistryClientMockListTagsExpectation{} } + if mmListTags.defaultExpectation.paramPtrs != nil { + mmListTags.mock.t.Fatalf("RegistryClientMock.ListTags mock is already set by ExpectParams functions") + } + mmListTags.defaultExpectation.params = &RegistryClientMockListTagsParams{ctx, repository} for _, e := range mmListTags.expectations { if minimock.Equal(e.params, mmListTags.defaultExpectation.params) { @@ -88,6 +101,50 @@ func (mmListTags *mRegistryClientMockListTags) Expect(ctx context.Context, repos return mmListTags } +// ExpectCtxParam1 sets up expected param ctx for RegistryClient.ListTags +func (mmListTags *mRegistryClientMockListTags) ExpectCtxParam1(ctx context.Context) *mRegistryClientMockListTags { + if mmListTags.mock.funcListTags != nil { + mmListTags.mock.t.Fatalf("RegistryClientMock.ListTags mock is already set by Set") + } + + if mmListTags.defaultExpectation == nil { + mmListTags.defaultExpectation = &RegistryClientMockListTagsExpectation{} + } + + if mmListTags.defaultExpectation.params != nil { + mmListTags.mock.t.Fatalf("RegistryClientMock.ListTags mock is already set by Expect") + } + + if mmListTags.defaultExpectation.paramPtrs == nil { + mmListTags.defaultExpectation.paramPtrs = &RegistryClientMockListTagsParamPtrs{} + } + mmListTags.defaultExpectation.paramPtrs.ctx = &ctx + + return mmListTags +} + +// ExpectRepositoryParam2 sets up expected param repository for RegistryClient.ListTags +func (mmListTags *mRegistryClientMockListTags) ExpectRepositoryParam2(repository string) *mRegistryClientMockListTags { + if mmListTags.mock.funcListTags != nil { + mmListTags.mock.t.Fatalf("RegistryClientMock.ListTags mock is already set by Set") + } + + if mmListTags.defaultExpectation == nil { + mmListTags.defaultExpectation = &RegistryClientMockListTagsExpectation{} + } + + if mmListTags.defaultExpectation.params != nil { + mmListTags.mock.t.Fatalf("RegistryClientMock.ListTags mock is already set by Expect") + } + + if mmListTags.defaultExpectation.paramPtrs == nil { + mmListTags.defaultExpectation.paramPtrs = &RegistryClientMockListTagsParamPtrs{} + } + mmListTags.defaultExpectation.paramPtrs.repository = &repository + + return mmListTags +} + // Inspect accepts an inspector function that has same arguments as the RegistryClient.ListTags func (mmListTags *mRegistryClientMockListTags) Inspect(f func(ctx context.Context, repository string)) *mRegistryClientMockListTags { if mmListTags.mock.inspectFuncListTags != nil { @@ -147,6 +204,26 @@ func (e *RegistryClientMockListTagsExpectation) Then(tags []string, err error) * return e.mock } +// Times sets number of times RegistryClient.ListTags should be invoked +func (mmListTags *mRegistryClientMockListTags) Times(n uint64) *mRegistryClientMockListTags { + if n == 0 { + mmListTags.mock.t.Fatalf("Times of RegistryClientMock.ListTags mock can not be zero") + } + mm_atomic.StoreUint64(&mmListTags.expectedInvocations, n) + return mmListTags +} + +func (mmListTags *mRegistryClientMockListTags) invocationsDone() bool { + if len(mmListTags.expectations) == 0 && mmListTags.defaultExpectation == nil && mmListTags.mock.funcListTags == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmListTags.mock.afterListTagsCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmListTags.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + // ListTags implements service.RegistryClient func (mmListTags *RegistryClientMock) ListTags(ctx context.Context, repository string) (tags []string, err error) { mm_atomic.AddUint64(&mmListTags.beforeListTagsCounter, 1) @@ -173,8 +250,21 @@ func (mmListTags *RegistryClientMock) ListTags(ctx context.Context, repository s if mmListTags.ListTagsMock.defaultExpectation != nil { mm_atomic.AddUint64(&mmListTags.ListTagsMock.defaultExpectation.Counter, 1) mm_want := mmListTags.ListTagsMock.defaultExpectation.params + mm_want_ptrs := mmListTags.ListTagsMock.defaultExpectation.paramPtrs + mm_got := RegistryClientMockListTagsParams{ctx, repository} - if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmListTags.t.Errorf("RegistryClientMock.ListTags 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.repository != nil && !minimock.Equal(*mm_want_ptrs.repository, mm_got.repository) { + mmListTags.t.Errorf("RegistryClientMock.ListTags got unexpected parameter repository, want: %#v, got: %#v%s\n", *mm_want_ptrs.repository, mm_got.repository, minimock.Diff(*mm_want_ptrs.repository, mm_got.repository)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { mmListTags.t.Errorf("RegistryClientMock.ListTags got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) } @@ -223,15 +313,7 @@ func (m *RegistryClientMock) MinimockListTagsDone() bool { } } - // if default expectation was set then invocations count should be greater than zero - if m.ListTagsMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterListTagsCounter) < 1 { - return false - } - // if func was set then invocations count should be greater than zero - if m.funcListTags != nil && mm_atomic.LoadUint64(&m.afterListTagsCounter) < 1 { - return false - } - return true + return m.ListTagsMock.invocationsDone() } // MinimockListTagsInspect logs each unmet expectation @@ -242,8 +324,9 @@ func (m *RegistryClientMock) MinimockListTagsInspect() { } } + afterListTagsCounter := mm_atomic.LoadUint64(&m.afterListTagsCounter) // if default expectation was set then invocations count should be greater than zero - if m.ListTagsMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterListTagsCounter) < 1 { + if m.ListTagsMock.defaultExpectation != nil && afterListTagsCounter < 1 { if m.ListTagsMock.defaultExpectation.params == nil { m.t.Error("Expected call to RegistryClientMock.ListTags") } else { @@ -251,9 +334,14 @@ func (m *RegistryClientMock) MinimockListTagsInspect() { } } // if func was set then invocations count should be greater than zero - if m.funcListTags != nil && mm_atomic.LoadUint64(&m.afterListTagsCounter) < 1 { + if m.funcListTags != nil && afterListTagsCounter < 1 { m.t.Error("Expected call to RegistryClientMock.ListTags") } + + if !m.ListTagsMock.invocationsDone() && afterListTagsCounter > 0 { + m.t.Errorf("Expected %d calls to RegistryClientMock.ListTags but found %d calls", + mm_atomic.LoadUint64(&m.ListTagsMock.expectedInvocations), afterListTagsCounter) + } } // MinimockFinish checks that all mocked methods have been called the expected number of times diff --git a/pkg/mock/repository_i_mock.gen.go b/pkg/mock/repository_i_mock.gen.go new file mode 100644 index 0000000..75c47a2 --- /dev/null +++ b/pkg/mock/repository_i_mock.gen.go @@ -0,0 +1,1936 @@ +// Code generated by http://github.com/gojuno/minimock (v3.3.9). DO NOT EDIT. + +package mock + +import ( + "context" + "sync" + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" + mm_repository "github.com/instill-ai/artifact-backend/pkg/repository" + "github.com/instill-ai/artifact-backend/pkg/utils" + artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" +) + +// RepositoryIMock implements repository.RepositoryI +type RepositoryIMock struct { + t minimock.Tester + finishOnce sync.Once + + funcCreateKnowledgeBase func(ctx context.Context, kb mm_repository.KnowledgeBase) (kp1 *mm_repository.KnowledgeBase, err error) + inspectFuncCreateKnowledgeBase func(ctx context.Context, kb mm_repository.KnowledgeBase) + afterCreateKnowledgeBaseCounter uint64 + beforeCreateKnowledgeBaseCounter uint64 + CreateKnowledgeBaseMock mRepositoryIMockCreateKnowledgeBase + + funcDeleteKnowledgeBase func(ctx context.Context, kb mm_repository.KnowledgeBase) (err error) + inspectFuncDeleteKnowledgeBase func(ctx context.Context, kb mm_repository.KnowledgeBase) + afterDeleteKnowledgeBaseCounter uint64 + beforeDeleteKnowledgeBaseCounter uint64 + DeleteKnowledgeBaseMock mRepositoryIMockDeleteKnowledgeBase + + funcGetKnowledgeBase func(ctx context.Context) (ka1 []mm_repository.KnowledgeBase, err error) + inspectFuncGetKnowledgeBase func(ctx context.Context) + afterGetKnowledgeBaseCounter uint64 + beforeGetKnowledgeBaseCounter uint64 + GetKnowledgeBaseMock mRepositoryIMockGetKnowledgeBase + + funcGetRepositoryTag func(ctx context.Context, r1 utils.RepositoryTagName) (rp1 *artifactpb.RepositoryTag, err error) + inspectFuncGetRepositoryTag func(ctx context.Context, r1 utils.RepositoryTagName) + afterGetRepositoryTagCounter uint64 + beforeGetRepositoryTagCounter uint64 + GetRepositoryTagMock mRepositoryIMockGetRepositoryTag + + funcUpdateKnowledgeBase func(ctx context.Context, kb mm_repository.KnowledgeBase) (kp1 *mm_repository.KnowledgeBase, err error) + inspectFuncUpdateKnowledgeBase func(ctx context.Context, kb mm_repository.KnowledgeBase) + afterUpdateKnowledgeBaseCounter uint64 + beforeUpdateKnowledgeBaseCounter uint64 + UpdateKnowledgeBaseMock mRepositoryIMockUpdateKnowledgeBase + + funcUpsertRepositoryTag func(ctx context.Context, rp1 *artifactpb.RepositoryTag) (rp2 *artifactpb.RepositoryTag, err error) + inspectFuncUpsertRepositoryTag func(ctx context.Context, rp1 *artifactpb.RepositoryTag) + afterUpsertRepositoryTagCounter uint64 + beforeUpsertRepositoryTagCounter uint64 + UpsertRepositoryTagMock mRepositoryIMockUpsertRepositoryTag +} + +// NewRepositoryIMock returns a mock for repository.RepositoryI +func NewRepositoryIMock(t minimock.Tester) *RepositoryIMock { + m := &RepositoryIMock{t: t} + + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.CreateKnowledgeBaseMock = mRepositoryIMockCreateKnowledgeBase{mock: m} + m.CreateKnowledgeBaseMock.callArgs = []*RepositoryIMockCreateKnowledgeBaseParams{} + + m.DeleteKnowledgeBaseMock = mRepositoryIMockDeleteKnowledgeBase{mock: m} + m.DeleteKnowledgeBaseMock.callArgs = []*RepositoryIMockDeleteKnowledgeBaseParams{} + + m.GetKnowledgeBaseMock = mRepositoryIMockGetKnowledgeBase{mock: m} + m.GetKnowledgeBaseMock.callArgs = []*RepositoryIMockGetKnowledgeBaseParams{} + + m.GetRepositoryTagMock = mRepositoryIMockGetRepositoryTag{mock: m} + m.GetRepositoryTagMock.callArgs = []*RepositoryIMockGetRepositoryTagParams{} + + m.UpdateKnowledgeBaseMock = mRepositoryIMockUpdateKnowledgeBase{mock: m} + m.UpdateKnowledgeBaseMock.callArgs = []*RepositoryIMockUpdateKnowledgeBaseParams{} + + m.UpsertRepositoryTagMock = mRepositoryIMockUpsertRepositoryTag{mock: m} + m.UpsertRepositoryTagMock.callArgs = []*RepositoryIMockUpsertRepositoryTagParams{} + + t.Cleanup(m.MinimockFinish) + + return m +} + +type mRepositoryIMockCreateKnowledgeBase struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockCreateKnowledgeBaseExpectation + expectations []*RepositoryIMockCreateKnowledgeBaseExpectation + + callArgs []*RepositoryIMockCreateKnowledgeBaseParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockCreateKnowledgeBaseExpectation specifies expectation struct of the RepositoryI.CreateKnowledgeBase +type RepositoryIMockCreateKnowledgeBaseExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockCreateKnowledgeBaseParams + paramPtrs *RepositoryIMockCreateKnowledgeBaseParamPtrs + results *RepositoryIMockCreateKnowledgeBaseResults + Counter uint64 +} + +// RepositoryIMockCreateKnowledgeBaseParams contains parameters of the RepositoryI.CreateKnowledgeBase +type RepositoryIMockCreateKnowledgeBaseParams struct { + ctx context.Context + kb mm_repository.KnowledgeBase +} + +// RepositoryIMockCreateKnowledgeBaseParamPtrs contains pointers to parameters of the RepositoryI.CreateKnowledgeBase +type RepositoryIMockCreateKnowledgeBaseParamPtrs struct { + ctx *context.Context + kb *mm_repository.KnowledgeBase +} + +// RepositoryIMockCreateKnowledgeBaseResults contains results of the RepositoryI.CreateKnowledgeBase +type RepositoryIMockCreateKnowledgeBaseResults struct { + kp1 *mm_repository.KnowledgeBase + err error +} + +// Expect sets up expected params for RepositoryI.CreateKnowledgeBase +func (mmCreateKnowledgeBase *mRepositoryIMockCreateKnowledgeBase) Expect(ctx context.Context, kb mm_repository.KnowledgeBase) *mRepositoryIMockCreateKnowledgeBase { + if mmCreateKnowledgeBase.mock.funcCreateKnowledgeBase != nil { + mmCreateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBase mock is already set by Set") + } + + if mmCreateKnowledgeBase.defaultExpectation == nil { + mmCreateKnowledgeBase.defaultExpectation = &RepositoryIMockCreateKnowledgeBaseExpectation{} + } + + if mmCreateKnowledgeBase.defaultExpectation.paramPtrs != nil { + mmCreateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBase mock is already set by ExpectParams functions") + } + + mmCreateKnowledgeBase.defaultExpectation.params = &RepositoryIMockCreateKnowledgeBaseParams{ctx, kb} + for _, e := range mmCreateKnowledgeBase.expectations { + if minimock.Equal(e.params, mmCreateKnowledgeBase.defaultExpectation.params) { + mmCreateKnowledgeBase.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmCreateKnowledgeBase.defaultExpectation.params) + } + } + + return mmCreateKnowledgeBase +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.CreateKnowledgeBase +func (mmCreateKnowledgeBase *mRepositoryIMockCreateKnowledgeBase) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockCreateKnowledgeBase { + if mmCreateKnowledgeBase.mock.funcCreateKnowledgeBase != nil { + mmCreateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBase mock is already set by Set") + } + + if mmCreateKnowledgeBase.defaultExpectation == nil { + mmCreateKnowledgeBase.defaultExpectation = &RepositoryIMockCreateKnowledgeBaseExpectation{} + } + + if mmCreateKnowledgeBase.defaultExpectation.params != nil { + mmCreateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBase mock is already set by Expect") + } + + if mmCreateKnowledgeBase.defaultExpectation.paramPtrs == nil { + mmCreateKnowledgeBase.defaultExpectation.paramPtrs = &RepositoryIMockCreateKnowledgeBaseParamPtrs{} + } + mmCreateKnowledgeBase.defaultExpectation.paramPtrs.ctx = &ctx + + return mmCreateKnowledgeBase +} + +// ExpectKbParam2 sets up expected param kb for RepositoryI.CreateKnowledgeBase +func (mmCreateKnowledgeBase *mRepositoryIMockCreateKnowledgeBase) ExpectKbParam2(kb mm_repository.KnowledgeBase) *mRepositoryIMockCreateKnowledgeBase { + if mmCreateKnowledgeBase.mock.funcCreateKnowledgeBase != nil { + mmCreateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBase mock is already set by Set") + } + + if mmCreateKnowledgeBase.defaultExpectation == nil { + mmCreateKnowledgeBase.defaultExpectation = &RepositoryIMockCreateKnowledgeBaseExpectation{} + } + + if mmCreateKnowledgeBase.defaultExpectation.params != nil { + mmCreateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBase mock is already set by Expect") + } + + if mmCreateKnowledgeBase.defaultExpectation.paramPtrs == nil { + mmCreateKnowledgeBase.defaultExpectation.paramPtrs = &RepositoryIMockCreateKnowledgeBaseParamPtrs{} + } + mmCreateKnowledgeBase.defaultExpectation.paramPtrs.kb = &kb + + return mmCreateKnowledgeBase +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.CreateKnowledgeBase +func (mmCreateKnowledgeBase *mRepositoryIMockCreateKnowledgeBase) Inspect(f func(ctx context.Context, kb mm_repository.KnowledgeBase)) *mRepositoryIMockCreateKnowledgeBase { + if mmCreateKnowledgeBase.mock.inspectFuncCreateKnowledgeBase != nil { + mmCreateKnowledgeBase.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.CreateKnowledgeBase") + } + + mmCreateKnowledgeBase.mock.inspectFuncCreateKnowledgeBase = f + + return mmCreateKnowledgeBase +} + +// Return sets up results that will be returned by RepositoryI.CreateKnowledgeBase +func (mmCreateKnowledgeBase *mRepositoryIMockCreateKnowledgeBase) Return(kp1 *mm_repository.KnowledgeBase, err error) *RepositoryIMock { + if mmCreateKnowledgeBase.mock.funcCreateKnowledgeBase != nil { + mmCreateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBase mock is already set by Set") + } + + if mmCreateKnowledgeBase.defaultExpectation == nil { + mmCreateKnowledgeBase.defaultExpectation = &RepositoryIMockCreateKnowledgeBaseExpectation{mock: mmCreateKnowledgeBase.mock} + } + mmCreateKnowledgeBase.defaultExpectation.results = &RepositoryIMockCreateKnowledgeBaseResults{kp1, err} + return mmCreateKnowledgeBase.mock +} + +// Set uses given function f to mock the RepositoryI.CreateKnowledgeBase method +func (mmCreateKnowledgeBase *mRepositoryIMockCreateKnowledgeBase) Set(f func(ctx context.Context, kb mm_repository.KnowledgeBase) (kp1 *mm_repository.KnowledgeBase, err error)) *RepositoryIMock { + if mmCreateKnowledgeBase.defaultExpectation != nil { + mmCreateKnowledgeBase.mock.t.Fatalf("Default expectation is already set for the RepositoryI.CreateKnowledgeBase method") + } + + if len(mmCreateKnowledgeBase.expectations) > 0 { + mmCreateKnowledgeBase.mock.t.Fatalf("Some expectations are already set for the RepositoryI.CreateKnowledgeBase method") + } + + mmCreateKnowledgeBase.mock.funcCreateKnowledgeBase = f + return mmCreateKnowledgeBase.mock +} + +// When sets expectation for the RepositoryI.CreateKnowledgeBase which will trigger the result defined by the following +// Then helper +func (mmCreateKnowledgeBase *mRepositoryIMockCreateKnowledgeBase) When(ctx context.Context, kb mm_repository.KnowledgeBase) *RepositoryIMockCreateKnowledgeBaseExpectation { + if mmCreateKnowledgeBase.mock.funcCreateKnowledgeBase != nil { + mmCreateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.CreateKnowledgeBase mock is already set by Set") + } + + expectation := &RepositoryIMockCreateKnowledgeBaseExpectation{ + mock: mmCreateKnowledgeBase.mock, + params: &RepositoryIMockCreateKnowledgeBaseParams{ctx, kb}, + } + mmCreateKnowledgeBase.expectations = append(mmCreateKnowledgeBase.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.CreateKnowledgeBase return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockCreateKnowledgeBaseExpectation) Then(kp1 *mm_repository.KnowledgeBase, err error) *RepositoryIMock { + e.results = &RepositoryIMockCreateKnowledgeBaseResults{kp1, err} + return e.mock +} + +// Times sets number of times RepositoryI.CreateKnowledgeBase should be invoked +func (mmCreateKnowledgeBase *mRepositoryIMockCreateKnowledgeBase) Times(n uint64) *mRepositoryIMockCreateKnowledgeBase { + if n == 0 { + mmCreateKnowledgeBase.mock.t.Fatalf("Times of RepositoryIMock.CreateKnowledgeBase mock can not be zero") + } + mm_atomic.StoreUint64(&mmCreateKnowledgeBase.expectedInvocations, n) + return mmCreateKnowledgeBase +} + +func (mmCreateKnowledgeBase *mRepositoryIMockCreateKnowledgeBase) invocationsDone() bool { + if len(mmCreateKnowledgeBase.expectations) == 0 && mmCreateKnowledgeBase.defaultExpectation == nil && mmCreateKnowledgeBase.mock.funcCreateKnowledgeBase == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmCreateKnowledgeBase.mock.afterCreateKnowledgeBaseCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmCreateKnowledgeBase.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// CreateKnowledgeBase implements repository.RepositoryI +func (mmCreateKnowledgeBase *RepositoryIMock) CreateKnowledgeBase(ctx context.Context, kb mm_repository.KnowledgeBase) (kp1 *mm_repository.KnowledgeBase, err error) { + mm_atomic.AddUint64(&mmCreateKnowledgeBase.beforeCreateKnowledgeBaseCounter, 1) + defer mm_atomic.AddUint64(&mmCreateKnowledgeBase.afterCreateKnowledgeBaseCounter, 1) + + if mmCreateKnowledgeBase.inspectFuncCreateKnowledgeBase != nil { + mmCreateKnowledgeBase.inspectFuncCreateKnowledgeBase(ctx, kb) + } + + mm_params := RepositoryIMockCreateKnowledgeBaseParams{ctx, kb} + + // Record call args + mmCreateKnowledgeBase.CreateKnowledgeBaseMock.mutex.Lock() + mmCreateKnowledgeBase.CreateKnowledgeBaseMock.callArgs = append(mmCreateKnowledgeBase.CreateKnowledgeBaseMock.callArgs, &mm_params) + mmCreateKnowledgeBase.CreateKnowledgeBaseMock.mutex.Unlock() + + for _, e := range mmCreateKnowledgeBase.CreateKnowledgeBaseMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.kp1, e.results.err + } + } + + if mmCreateKnowledgeBase.CreateKnowledgeBaseMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmCreateKnowledgeBase.CreateKnowledgeBaseMock.defaultExpectation.Counter, 1) + mm_want := mmCreateKnowledgeBase.CreateKnowledgeBaseMock.defaultExpectation.params + mm_want_ptrs := mmCreateKnowledgeBase.CreateKnowledgeBaseMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockCreateKnowledgeBaseParams{ctx, kb} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmCreateKnowledgeBase.t.Errorf("RepositoryIMock.CreateKnowledgeBase 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) { + mmCreateKnowledgeBase.t.Errorf("RepositoryIMock.CreateKnowledgeBase 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) { + mmCreateKnowledgeBase.t.Errorf("RepositoryIMock.CreateKnowledgeBase got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmCreateKnowledgeBase.CreateKnowledgeBaseMock.defaultExpectation.results + if mm_results == nil { + mmCreateKnowledgeBase.t.Fatal("No results are set for the RepositoryIMock.CreateKnowledgeBase") + } + return (*mm_results).kp1, (*mm_results).err + } + if mmCreateKnowledgeBase.funcCreateKnowledgeBase != nil { + return mmCreateKnowledgeBase.funcCreateKnowledgeBase(ctx, kb) + } + mmCreateKnowledgeBase.t.Fatalf("Unexpected call to RepositoryIMock.CreateKnowledgeBase. %v %v", ctx, kb) + return +} + +// CreateKnowledgeBaseAfterCounter returns a count of finished RepositoryIMock.CreateKnowledgeBase invocations +func (mmCreateKnowledgeBase *RepositoryIMock) CreateKnowledgeBaseAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmCreateKnowledgeBase.afterCreateKnowledgeBaseCounter) +} + +// CreateKnowledgeBaseBeforeCounter returns a count of RepositoryIMock.CreateKnowledgeBase invocations +func (mmCreateKnowledgeBase *RepositoryIMock) CreateKnowledgeBaseBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmCreateKnowledgeBase.beforeCreateKnowledgeBaseCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.CreateKnowledgeBase. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmCreateKnowledgeBase *mRepositoryIMockCreateKnowledgeBase) Calls() []*RepositoryIMockCreateKnowledgeBaseParams { + mmCreateKnowledgeBase.mutex.RLock() + + argCopy := make([]*RepositoryIMockCreateKnowledgeBaseParams, len(mmCreateKnowledgeBase.callArgs)) + copy(argCopy, mmCreateKnowledgeBase.callArgs) + + mmCreateKnowledgeBase.mutex.RUnlock() + + return argCopy +} + +// MinimockCreateKnowledgeBaseDone returns true if the count of the CreateKnowledgeBase invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockCreateKnowledgeBaseDone() bool { + for _, e := range m.CreateKnowledgeBaseMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.CreateKnowledgeBaseMock.invocationsDone() +} + +// MinimockCreateKnowledgeBaseInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockCreateKnowledgeBaseInspect() { + for _, e := range m.CreateKnowledgeBaseMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.CreateKnowledgeBase with params: %#v", *e.params) + } + } + + afterCreateKnowledgeBaseCounter := mm_atomic.LoadUint64(&m.afterCreateKnowledgeBaseCounter) + // if default expectation was set then invocations count should be greater than zero + if m.CreateKnowledgeBaseMock.defaultExpectation != nil && afterCreateKnowledgeBaseCounter < 1 { + if m.CreateKnowledgeBaseMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.CreateKnowledgeBase") + } else { + m.t.Errorf("Expected call to RepositoryIMock.CreateKnowledgeBase with params: %#v", *m.CreateKnowledgeBaseMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcCreateKnowledgeBase != nil && afterCreateKnowledgeBaseCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.CreateKnowledgeBase") + } + + if !m.CreateKnowledgeBaseMock.invocationsDone() && afterCreateKnowledgeBaseCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.CreateKnowledgeBase but found %d calls", + mm_atomic.LoadUint64(&m.CreateKnowledgeBaseMock.expectedInvocations), afterCreateKnowledgeBaseCounter) + } +} + +type mRepositoryIMockDeleteKnowledgeBase struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockDeleteKnowledgeBaseExpectation + expectations []*RepositoryIMockDeleteKnowledgeBaseExpectation + + callArgs []*RepositoryIMockDeleteKnowledgeBaseParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockDeleteKnowledgeBaseExpectation specifies expectation struct of the RepositoryI.DeleteKnowledgeBase +type RepositoryIMockDeleteKnowledgeBaseExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockDeleteKnowledgeBaseParams + paramPtrs *RepositoryIMockDeleteKnowledgeBaseParamPtrs + results *RepositoryIMockDeleteKnowledgeBaseResults + Counter uint64 +} + +// RepositoryIMockDeleteKnowledgeBaseParams contains parameters of the RepositoryI.DeleteKnowledgeBase +type RepositoryIMockDeleteKnowledgeBaseParams struct { + ctx context.Context + kb mm_repository.KnowledgeBase +} + +// RepositoryIMockDeleteKnowledgeBaseParamPtrs contains pointers to parameters of the RepositoryI.DeleteKnowledgeBase +type RepositoryIMockDeleteKnowledgeBaseParamPtrs struct { + ctx *context.Context + kb *mm_repository.KnowledgeBase +} + +// RepositoryIMockDeleteKnowledgeBaseResults contains results of the RepositoryI.DeleteKnowledgeBase +type RepositoryIMockDeleteKnowledgeBaseResults struct { + err error +} + +// Expect sets up expected params for RepositoryI.DeleteKnowledgeBase +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Expect(ctx context.Context, kb mm_repository.KnowledgeBase) *mRepositoryIMockDeleteKnowledgeBase { + if mmDeleteKnowledgeBase.mock.funcDeleteKnowledgeBase != nil { + mmDeleteKnowledgeBase.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBase mock is already set by Set") + } + + if mmDeleteKnowledgeBase.defaultExpectation == nil { + mmDeleteKnowledgeBase.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseExpectation{} + } + + if mmDeleteKnowledgeBase.defaultExpectation.paramPtrs != nil { + mmDeleteKnowledgeBase.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBase mock is already set by ExpectParams functions") + } + + mmDeleteKnowledgeBase.defaultExpectation.params = &RepositoryIMockDeleteKnowledgeBaseParams{ctx, kb} + 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) + } + } + + return mmDeleteKnowledgeBase +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.DeleteKnowledgeBase +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockDeleteKnowledgeBase { + if mmDeleteKnowledgeBase.mock.funcDeleteKnowledgeBase != nil { + mmDeleteKnowledgeBase.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBase mock is already set by Set") + } + + if mmDeleteKnowledgeBase.defaultExpectation == nil { + mmDeleteKnowledgeBase.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseExpectation{} + } + + if mmDeleteKnowledgeBase.defaultExpectation.params != nil { + mmDeleteKnowledgeBase.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBase mock is already set by Expect") + } + + if mmDeleteKnowledgeBase.defaultExpectation.paramPtrs == nil { + mmDeleteKnowledgeBase.defaultExpectation.paramPtrs = &RepositoryIMockDeleteKnowledgeBaseParamPtrs{} + } + mmDeleteKnowledgeBase.defaultExpectation.paramPtrs.ctx = &ctx + + return mmDeleteKnowledgeBase +} + +// ExpectKbParam2 sets up expected param kb for RepositoryI.DeleteKnowledgeBase +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) ExpectKbParam2(kb mm_repository.KnowledgeBase) *mRepositoryIMockDeleteKnowledgeBase { + if mmDeleteKnowledgeBase.mock.funcDeleteKnowledgeBase != nil { + mmDeleteKnowledgeBase.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBase mock is already set by Set") + } + + if mmDeleteKnowledgeBase.defaultExpectation == nil { + mmDeleteKnowledgeBase.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseExpectation{} + } + + if mmDeleteKnowledgeBase.defaultExpectation.params != nil { + mmDeleteKnowledgeBase.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBase mock is already set by Expect") + } + + if mmDeleteKnowledgeBase.defaultExpectation.paramPtrs == nil { + mmDeleteKnowledgeBase.defaultExpectation.paramPtrs = &RepositoryIMockDeleteKnowledgeBaseParamPtrs{} + } + mmDeleteKnowledgeBase.defaultExpectation.paramPtrs.kb = &kb + + return mmDeleteKnowledgeBase +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.DeleteKnowledgeBase +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Inspect(f func(ctx context.Context, kb mm_repository.KnowledgeBase)) *mRepositoryIMockDeleteKnowledgeBase { + if mmDeleteKnowledgeBase.mock.inspectFuncDeleteKnowledgeBase != nil { + mmDeleteKnowledgeBase.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.DeleteKnowledgeBase") + } + + mmDeleteKnowledgeBase.mock.inspectFuncDeleteKnowledgeBase = f + + return mmDeleteKnowledgeBase +} + +// Return sets up results that will be returned by RepositoryI.DeleteKnowledgeBase +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Return(err error) *RepositoryIMock { + if mmDeleteKnowledgeBase.mock.funcDeleteKnowledgeBase != nil { + mmDeleteKnowledgeBase.mock.t.Fatalf("RepositoryIMock.DeleteKnowledgeBase mock is already set by Set") + } + + if mmDeleteKnowledgeBase.defaultExpectation == nil { + mmDeleteKnowledgeBase.defaultExpectation = &RepositoryIMockDeleteKnowledgeBaseExpectation{mock: mmDeleteKnowledgeBase.mock} + } + mmDeleteKnowledgeBase.defaultExpectation.results = &RepositoryIMockDeleteKnowledgeBaseResults{err} + return mmDeleteKnowledgeBase.mock +} + +// Set uses given function f to mock the RepositoryI.DeleteKnowledgeBase method +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Set(f func(ctx context.Context, kb mm_repository.KnowledgeBase) (err error)) *RepositoryIMock { + if mmDeleteKnowledgeBase.defaultExpectation != nil { + mmDeleteKnowledgeBase.mock.t.Fatalf("Default expectation is already set for the RepositoryI.DeleteKnowledgeBase method") + } + + if len(mmDeleteKnowledgeBase.expectations) > 0 { + mmDeleteKnowledgeBase.mock.t.Fatalf("Some expectations are already set for the RepositoryI.DeleteKnowledgeBase method") + } + + mmDeleteKnowledgeBase.mock.funcDeleteKnowledgeBase = f + return mmDeleteKnowledgeBase.mock +} + +// 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, kb mm_repository.KnowledgeBase) *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, kb}, + } + mmDeleteKnowledgeBase.expectations = append(mmDeleteKnowledgeBase.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.DeleteKnowledgeBase return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockDeleteKnowledgeBaseExpectation) Then(err error) *RepositoryIMock { + e.results = &RepositoryIMockDeleteKnowledgeBaseResults{err} + return e.mock +} + +// Times sets number of times RepositoryI.DeleteKnowledgeBase should be invoked +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Times(n uint64) *mRepositoryIMockDeleteKnowledgeBase { + if n == 0 { + mmDeleteKnowledgeBase.mock.t.Fatalf("Times of RepositoryIMock.DeleteKnowledgeBase mock can not be zero") + } + mm_atomic.StoreUint64(&mmDeleteKnowledgeBase.expectedInvocations, n) + return mmDeleteKnowledgeBase +} + +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) invocationsDone() bool { + if len(mmDeleteKnowledgeBase.expectations) == 0 && mmDeleteKnowledgeBase.defaultExpectation == nil && mmDeleteKnowledgeBase.mock.funcDeleteKnowledgeBase == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmDeleteKnowledgeBase.mock.afterDeleteKnowledgeBaseCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmDeleteKnowledgeBase.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// DeleteKnowledgeBase implements repository.RepositoryI +func (mmDeleteKnowledgeBase *RepositoryIMock) DeleteKnowledgeBase(ctx context.Context, kb mm_repository.KnowledgeBase) (err error) { + mm_atomic.AddUint64(&mmDeleteKnowledgeBase.beforeDeleteKnowledgeBaseCounter, 1) + defer mm_atomic.AddUint64(&mmDeleteKnowledgeBase.afterDeleteKnowledgeBaseCounter, 1) + + if mmDeleteKnowledgeBase.inspectFuncDeleteKnowledgeBase != nil { + mmDeleteKnowledgeBase.inspectFuncDeleteKnowledgeBase(ctx, kb) + } + + mm_params := RepositoryIMockDeleteKnowledgeBaseParams{ctx, kb} + + // Record call args + mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.mutex.Lock() + mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.callArgs = append(mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.callArgs, &mm_params) + mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.mutex.Unlock() + + for _, e := range mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.err + } + } + + if mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.defaultExpectation.Counter, 1) + mm_want := mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.defaultExpectation.params + mm_want_ptrs := mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockDeleteKnowledgeBaseParams{ctx, kb} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmDeleteKnowledgeBase.t.Errorf("RepositoryIMock.DeleteKnowledgeBase 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) { + mmDeleteKnowledgeBase.t.Errorf("RepositoryIMock.DeleteKnowledgeBase 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) { + mmDeleteKnowledgeBase.t.Errorf("RepositoryIMock.DeleteKnowledgeBase got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmDeleteKnowledgeBase.DeleteKnowledgeBaseMock.defaultExpectation.results + if mm_results == nil { + mmDeleteKnowledgeBase.t.Fatal("No results are set for the RepositoryIMock.DeleteKnowledgeBase") + } + return (*mm_results).err + } + if mmDeleteKnowledgeBase.funcDeleteKnowledgeBase != nil { + return mmDeleteKnowledgeBase.funcDeleteKnowledgeBase(ctx, kb) + } + mmDeleteKnowledgeBase.t.Fatalf("Unexpected call to RepositoryIMock.DeleteKnowledgeBase. %v %v", ctx, kb) + return +} + +// DeleteKnowledgeBaseAfterCounter returns a count of finished RepositoryIMock.DeleteKnowledgeBase invocations +func (mmDeleteKnowledgeBase *RepositoryIMock) DeleteKnowledgeBaseAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmDeleteKnowledgeBase.afterDeleteKnowledgeBaseCounter) +} + +// DeleteKnowledgeBaseBeforeCounter returns a count of RepositoryIMock.DeleteKnowledgeBase invocations +func (mmDeleteKnowledgeBase *RepositoryIMock) DeleteKnowledgeBaseBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmDeleteKnowledgeBase.beforeDeleteKnowledgeBaseCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.DeleteKnowledgeBase. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmDeleteKnowledgeBase *mRepositoryIMockDeleteKnowledgeBase) Calls() []*RepositoryIMockDeleteKnowledgeBaseParams { + mmDeleteKnowledgeBase.mutex.RLock() + + argCopy := make([]*RepositoryIMockDeleteKnowledgeBaseParams, len(mmDeleteKnowledgeBase.callArgs)) + copy(argCopy, mmDeleteKnowledgeBase.callArgs) + + mmDeleteKnowledgeBase.mutex.RUnlock() + + return argCopy +} + +// MinimockDeleteKnowledgeBaseDone returns true if the count of the DeleteKnowledgeBase invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockDeleteKnowledgeBaseDone() bool { + for _, e := range m.DeleteKnowledgeBaseMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.DeleteKnowledgeBaseMock.invocationsDone() +} + +// MinimockDeleteKnowledgeBaseInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockDeleteKnowledgeBaseInspect() { + for _, e := range m.DeleteKnowledgeBaseMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.DeleteKnowledgeBase with params: %#v", *e.params) + } + } + + afterDeleteKnowledgeBaseCounter := mm_atomic.LoadUint64(&m.afterDeleteKnowledgeBaseCounter) + // if default expectation was set then invocations count should be greater than zero + if m.DeleteKnowledgeBaseMock.defaultExpectation != nil && afterDeleteKnowledgeBaseCounter < 1 { + if m.DeleteKnowledgeBaseMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.DeleteKnowledgeBase") + } else { + m.t.Errorf("Expected call to RepositoryIMock.DeleteKnowledgeBase with params: %#v", *m.DeleteKnowledgeBaseMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcDeleteKnowledgeBase != nil && afterDeleteKnowledgeBaseCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.DeleteKnowledgeBase") + } + + if !m.DeleteKnowledgeBaseMock.invocationsDone() && afterDeleteKnowledgeBaseCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.DeleteKnowledgeBase but found %d calls", + mm_atomic.LoadUint64(&m.DeleteKnowledgeBaseMock.expectedInvocations), afterDeleteKnowledgeBaseCounter) + } +} + +type mRepositoryIMockGetKnowledgeBase struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockGetKnowledgeBaseExpectation + expectations []*RepositoryIMockGetKnowledgeBaseExpectation + + callArgs []*RepositoryIMockGetKnowledgeBaseParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockGetKnowledgeBaseExpectation specifies expectation struct of the RepositoryI.GetKnowledgeBase +type RepositoryIMockGetKnowledgeBaseExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockGetKnowledgeBaseParams + paramPtrs *RepositoryIMockGetKnowledgeBaseParamPtrs + results *RepositoryIMockGetKnowledgeBaseResults + Counter uint64 +} + +// RepositoryIMockGetKnowledgeBaseParams contains parameters of the RepositoryI.GetKnowledgeBase +type RepositoryIMockGetKnowledgeBaseParams struct { + ctx context.Context +} + +// RepositoryIMockGetKnowledgeBaseParamPtrs contains pointers to parameters of the RepositoryI.GetKnowledgeBase +type RepositoryIMockGetKnowledgeBaseParamPtrs struct { + ctx *context.Context +} + +// RepositoryIMockGetKnowledgeBaseResults contains results of the RepositoryI.GetKnowledgeBase +type RepositoryIMockGetKnowledgeBaseResults struct { + ka1 []mm_repository.KnowledgeBase + err error +} + +// Expect sets up expected params for RepositoryI.GetKnowledgeBase +func (mmGetKnowledgeBase *mRepositoryIMockGetKnowledgeBase) Expect(ctx context.Context) *mRepositoryIMockGetKnowledgeBase { + if mmGetKnowledgeBase.mock.funcGetKnowledgeBase != nil { + mmGetKnowledgeBase.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBase mock is already set by Set") + } + + if mmGetKnowledgeBase.defaultExpectation == nil { + mmGetKnowledgeBase.defaultExpectation = &RepositoryIMockGetKnowledgeBaseExpectation{} + } + + if mmGetKnowledgeBase.defaultExpectation.paramPtrs != nil { + mmGetKnowledgeBase.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBase mock is already set by ExpectParams functions") + } + + mmGetKnowledgeBase.defaultExpectation.params = &RepositoryIMockGetKnowledgeBaseParams{ctx} + for _, e := range mmGetKnowledgeBase.expectations { + if minimock.Equal(e.params, mmGetKnowledgeBase.defaultExpectation.params) { + mmGetKnowledgeBase.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmGetKnowledgeBase.defaultExpectation.params) + } + } + + return mmGetKnowledgeBase +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.GetKnowledgeBase +func (mmGetKnowledgeBase *mRepositoryIMockGetKnowledgeBase) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockGetKnowledgeBase { + if mmGetKnowledgeBase.mock.funcGetKnowledgeBase != nil { + mmGetKnowledgeBase.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBase mock is already set by Set") + } + + if mmGetKnowledgeBase.defaultExpectation == nil { + mmGetKnowledgeBase.defaultExpectation = &RepositoryIMockGetKnowledgeBaseExpectation{} + } + + if mmGetKnowledgeBase.defaultExpectation.params != nil { + mmGetKnowledgeBase.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBase mock is already set by Expect") + } + + if mmGetKnowledgeBase.defaultExpectation.paramPtrs == nil { + mmGetKnowledgeBase.defaultExpectation.paramPtrs = &RepositoryIMockGetKnowledgeBaseParamPtrs{} + } + mmGetKnowledgeBase.defaultExpectation.paramPtrs.ctx = &ctx + + return mmGetKnowledgeBase +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.GetKnowledgeBase +func (mmGetKnowledgeBase *mRepositoryIMockGetKnowledgeBase) Inspect(f func(ctx context.Context)) *mRepositoryIMockGetKnowledgeBase { + if mmGetKnowledgeBase.mock.inspectFuncGetKnowledgeBase != nil { + mmGetKnowledgeBase.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.GetKnowledgeBase") + } + + mmGetKnowledgeBase.mock.inspectFuncGetKnowledgeBase = f + + return mmGetKnowledgeBase +} + +// Return sets up results that will be returned by RepositoryI.GetKnowledgeBase +func (mmGetKnowledgeBase *mRepositoryIMockGetKnowledgeBase) Return(ka1 []mm_repository.KnowledgeBase, err error) *RepositoryIMock { + if mmGetKnowledgeBase.mock.funcGetKnowledgeBase != nil { + mmGetKnowledgeBase.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBase mock is already set by Set") + } + + if mmGetKnowledgeBase.defaultExpectation == nil { + mmGetKnowledgeBase.defaultExpectation = &RepositoryIMockGetKnowledgeBaseExpectation{mock: mmGetKnowledgeBase.mock} + } + mmGetKnowledgeBase.defaultExpectation.results = &RepositoryIMockGetKnowledgeBaseResults{ka1, err} + return mmGetKnowledgeBase.mock +} + +// Set uses given function f to mock the RepositoryI.GetKnowledgeBase method +func (mmGetKnowledgeBase *mRepositoryIMockGetKnowledgeBase) Set(f func(ctx context.Context) (ka1 []mm_repository.KnowledgeBase, err error)) *RepositoryIMock { + if mmGetKnowledgeBase.defaultExpectation != nil { + mmGetKnowledgeBase.mock.t.Fatalf("Default expectation is already set for the RepositoryI.GetKnowledgeBase method") + } + + if len(mmGetKnowledgeBase.expectations) > 0 { + mmGetKnowledgeBase.mock.t.Fatalf("Some expectations are already set for the RepositoryI.GetKnowledgeBase method") + } + + mmGetKnowledgeBase.mock.funcGetKnowledgeBase = f + return mmGetKnowledgeBase.mock +} + +// When sets expectation for the RepositoryI.GetKnowledgeBase which will trigger the result defined by the following +// Then helper +func (mmGetKnowledgeBase *mRepositoryIMockGetKnowledgeBase) When(ctx context.Context) *RepositoryIMockGetKnowledgeBaseExpectation { + if mmGetKnowledgeBase.mock.funcGetKnowledgeBase != nil { + mmGetKnowledgeBase.mock.t.Fatalf("RepositoryIMock.GetKnowledgeBase mock is already set by Set") + } + + expectation := &RepositoryIMockGetKnowledgeBaseExpectation{ + mock: mmGetKnowledgeBase.mock, + params: &RepositoryIMockGetKnowledgeBaseParams{ctx}, + } + mmGetKnowledgeBase.expectations = append(mmGetKnowledgeBase.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.GetKnowledgeBase return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockGetKnowledgeBaseExpectation) Then(ka1 []mm_repository.KnowledgeBase, err error) *RepositoryIMock { + e.results = &RepositoryIMockGetKnowledgeBaseResults{ka1, err} + return e.mock +} + +// Times sets number of times RepositoryI.GetKnowledgeBase should be invoked +func (mmGetKnowledgeBase *mRepositoryIMockGetKnowledgeBase) Times(n uint64) *mRepositoryIMockGetKnowledgeBase { + if n == 0 { + mmGetKnowledgeBase.mock.t.Fatalf("Times of RepositoryIMock.GetKnowledgeBase mock can not be zero") + } + mm_atomic.StoreUint64(&mmGetKnowledgeBase.expectedInvocations, n) + return mmGetKnowledgeBase +} + +func (mmGetKnowledgeBase *mRepositoryIMockGetKnowledgeBase) invocationsDone() bool { + if len(mmGetKnowledgeBase.expectations) == 0 && mmGetKnowledgeBase.defaultExpectation == nil && mmGetKnowledgeBase.mock.funcGetKnowledgeBase == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmGetKnowledgeBase.mock.afterGetKnowledgeBaseCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmGetKnowledgeBase.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// GetKnowledgeBase implements repository.RepositoryI +func (mmGetKnowledgeBase *RepositoryIMock) GetKnowledgeBase(ctx context.Context) (ka1 []mm_repository.KnowledgeBase, err error) { + mm_atomic.AddUint64(&mmGetKnowledgeBase.beforeGetKnowledgeBaseCounter, 1) + defer mm_atomic.AddUint64(&mmGetKnowledgeBase.afterGetKnowledgeBaseCounter, 1) + + if mmGetKnowledgeBase.inspectFuncGetKnowledgeBase != nil { + mmGetKnowledgeBase.inspectFuncGetKnowledgeBase(ctx) + } + + mm_params := RepositoryIMockGetKnowledgeBaseParams{ctx} + + // Record call args + mmGetKnowledgeBase.GetKnowledgeBaseMock.mutex.Lock() + mmGetKnowledgeBase.GetKnowledgeBaseMock.callArgs = append(mmGetKnowledgeBase.GetKnowledgeBaseMock.callArgs, &mm_params) + mmGetKnowledgeBase.GetKnowledgeBaseMock.mutex.Unlock() + + for _, e := range mmGetKnowledgeBase.GetKnowledgeBaseMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.ka1, e.results.err + } + } + + if mmGetKnowledgeBase.GetKnowledgeBaseMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmGetKnowledgeBase.GetKnowledgeBaseMock.defaultExpectation.Counter, 1) + mm_want := mmGetKnowledgeBase.GetKnowledgeBaseMock.defaultExpectation.params + mm_want_ptrs := mmGetKnowledgeBase.GetKnowledgeBaseMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockGetKnowledgeBaseParams{ctx} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmGetKnowledgeBase.t.Errorf("RepositoryIMock.GetKnowledgeBase 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)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmGetKnowledgeBase.t.Errorf("RepositoryIMock.GetKnowledgeBase got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmGetKnowledgeBase.GetKnowledgeBaseMock.defaultExpectation.results + if mm_results == nil { + mmGetKnowledgeBase.t.Fatal("No results are set for the RepositoryIMock.GetKnowledgeBase") + } + return (*mm_results).ka1, (*mm_results).err + } + if mmGetKnowledgeBase.funcGetKnowledgeBase != nil { + return mmGetKnowledgeBase.funcGetKnowledgeBase(ctx) + } + mmGetKnowledgeBase.t.Fatalf("Unexpected call to RepositoryIMock.GetKnowledgeBase. %v", ctx) + return +} + +// GetKnowledgeBaseAfterCounter returns a count of finished RepositoryIMock.GetKnowledgeBase invocations +func (mmGetKnowledgeBase *RepositoryIMock) GetKnowledgeBaseAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetKnowledgeBase.afterGetKnowledgeBaseCounter) +} + +// GetKnowledgeBaseBeforeCounter returns a count of RepositoryIMock.GetKnowledgeBase invocations +func (mmGetKnowledgeBase *RepositoryIMock) GetKnowledgeBaseBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmGetKnowledgeBase.beforeGetKnowledgeBaseCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.GetKnowledgeBase. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmGetKnowledgeBase *mRepositoryIMockGetKnowledgeBase) Calls() []*RepositoryIMockGetKnowledgeBaseParams { + mmGetKnowledgeBase.mutex.RLock() + + argCopy := make([]*RepositoryIMockGetKnowledgeBaseParams, len(mmGetKnowledgeBase.callArgs)) + copy(argCopy, mmGetKnowledgeBase.callArgs) + + mmGetKnowledgeBase.mutex.RUnlock() + + return argCopy +} + +// MinimockGetKnowledgeBaseDone returns true if the count of the GetKnowledgeBase invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockGetKnowledgeBaseDone() bool { + for _, e := range m.GetKnowledgeBaseMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.GetKnowledgeBaseMock.invocationsDone() +} + +// MinimockGetKnowledgeBaseInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockGetKnowledgeBaseInspect() { + for _, e := range m.GetKnowledgeBaseMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.GetKnowledgeBase with params: %#v", *e.params) + } + } + + afterGetKnowledgeBaseCounter := mm_atomic.LoadUint64(&m.afterGetKnowledgeBaseCounter) + // if default expectation was set then invocations count should be greater than zero + if m.GetKnowledgeBaseMock.defaultExpectation != nil && afterGetKnowledgeBaseCounter < 1 { + if m.GetKnowledgeBaseMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.GetKnowledgeBase") + } else { + m.t.Errorf("Expected call to RepositoryIMock.GetKnowledgeBase with params: %#v", *m.GetKnowledgeBaseMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcGetKnowledgeBase != nil && afterGetKnowledgeBaseCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.GetKnowledgeBase") + } + + if !m.GetKnowledgeBaseMock.invocationsDone() && afterGetKnowledgeBaseCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.GetKnowledgeBase but found %d calls", + mm_atomic.LoadUint64(&m.GetKnowledgeBaseMock.expectedInvocations), afterGetKnowledgeBaseCounter) + } +} + +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 *artifactpb.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 *artifactpb.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 *artifactpb.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 *artifactpb.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 *artifactpb.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 mRepositoryIMockUpdateKnowledgeBase struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockUpdateKnowledgeBaseExpectation + expectations []*RepositoryIMockUpdateKnowledgeBaseExpectation + + callArgs []*RepositoryIMockUpdateKnowledgeBaseParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockUpdateKnowledgeBaseExpectation specifies expectation struct of the RepositoryI.UpdateKnowledgeBase +type RepositoryIMockUpdateKnowledgeBaseExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockUpdateKnowledgeBaseParams + paramPtrs *RepositoryIMockUpdateKnowledgeBaseParamPtrs + results *RepositoryIMockUpdateKnowledgeBaseResults + Counter uint64 +} + +// RepositoryIMockUpdateKnowledgeBaseParams contains parameters of the RepositoryI.UpdateKnowledgeBase +type RepositoryIMockUpdateKnowledgeBaseParams struct { + ctx context.Context + kb mm_repository.KnowledgeBase +} + +// RepositoryIMockUpdateKnowledgeBaseParamPtrs contains pointers to parameters of the RepositoryI.UpdateKnowledgeBase +type RepositoryIMockUpdateKnowledgeBaseParamPtrs struct { + ctx *context.Context + kb *mm_repository.KnowledgeBase +} + +// RepositoryIMockUpdateKnowledgeBaseResults contains results of the RepositoryI.UpdateKnowledgeBase +type RepositoryIMockUpdateKnowledgeBaseResults struct { + kp1 *mm_repository.KnowledgeBase + err error +} + +// Expect sets up expected params for RepositoryI.UpdateKnowledgeBase +func (mmUpdateKnowledgeBase *mRepositoryIMockUpdateKnowledgeBase) Expect(ctx context.Context, kb mm_repository.KnowledgeBase) *mRepositoryIMockUpdateKnowledgeBase { + if mmUpdateKnowledgeBase.mock.funcUpdateKnowledgeBase != nil { + mmUpdateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.UpdateKnowledgeBase mock is already set by Set") + } + + if mmUpdateKnowledgeBase.defaultExpectation == nil { + mmUpdateKnowledgeBase.defaultExpectation = &RepositoryIMockUpdateKnowledgeBaseExpectation{} + } + + if mmUpdateKnowledgeBase.defaultExpectation.paramPtrs != nil { + mmUpdateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.UpdateKnowledgeBase mock is already set by ExpectParams functions") + } + + mmUpdateKnowledgeBase.defaultExpectation.params = &RepositoryIMockUpdateKnowledgeBaseParams{ctx, kb} + for _, e := range mmUpdateKnowledgeBase.expectations { + if minimock.Equal(e.params, mmUpdateKnowledgeBase.defaultExpectation.params) { + mmUpdateKnowledgeBase.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUpdateKnowledgeBase.defaultExpectation.params) + } + } + + return mmUpdateKnowledgeBase +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.UpdateKnowledgeBase +func (mmUpdateKnowledgeBase *mRepositoryIMockUpdateKnowledgeBase) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockUpdateKnowledgeBase { + if mmUpdateKnowledgeBase.mock.funcUpdateKnowledgeBase != nil { + mmUpdateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.UpdateKnowledgeBase mock is already set by Set") + } + + if mmUpdateKnowledgeBase.defaultExpectation == nil { + mmUpdateKnowledgeBase.defaultExpectation = &RepositoryIMockUpdateKnowledgeBaseExpectation{} + } + + if mmUpdateKnowledgeBase.defaultExpectation.params != nil { + mmUpdateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.UpdateKnowledgeBase mock is already set by Expect") + } + + if mmUpdateKnowledgeBase.defaultExpectation.paramPtrs == nil { + mmUpdateKnowledgeBase.defaultExpectation.paramPtrs = &RepositoryIMockUpdateKnowledgeBaseParamPtrs{} + } + mmUpdateKnowledgeBase.defaultExpectation.paramPtrs.ctx = &ctx + + return mmUpdateKnowledgeBase +} + +// ExpectKbParam2 sets up expected param kb for RepositoryI.UpdateKnowledgeBase +func (mmUpdateKnowledgeBase *mRepositoryIMockUpdateKnowledgeBase) ExpectKbParam2(kb mm_repository.KnowledgeBase) *mRepositoryIMockUpdateKnowledgeBase { + if mmUpdateKnowledgeBase.mock.funcUpdateKnowledgeBase != nil { + mmUpdateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.UpdateKnowledgeBase mock is already set by Set") + } + + if mmUpdateKnowledgeBase.defaultExpectation == nil { + mmUpdateKnowledgeBase.defaultExpectation = &RepositoryIMockUpdateKnowledgeBaseExpectation{} + } + + if mmUpdateKnowledgeBase.defaultExpectation.params != nil { + mmUpdateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.UpdateKnowledgeBase mock is already set by Expect") + } + + if mmUpdateKnowledgeBase.defaultExpectation.paramPtrs == nil { + mmUpdateKnowledgeBase.defaultExpectation.paramPtrs = &RepositoryIMockUpdateKnowledgeBaseParamPtrs{} + } + mmUpdateKnowledgeBase.defaultExpectation.paramPtrs.kb = &kb + + return mmUpdateKnowledgeBase +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.UpdateKnowledgeBase +func (mmUpdateKnowledgeBase *mRepositoryIMockUpdateKnowledgeBase) Inspect(f func(ctx context.Context, kb mm_repository.KnowledgeBase)) *mRepositoryIMockUpdateKnowledgeBase { + if mmUpdateKnowledgeBase.mock.inspectFuncUpdateKnowledgeBase != nil { + mmUpdateKnowledgeBase.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.UpdateKnowledgeBase") + } + + mmUpdateKnowledgeBase.mock.inspectFuncUpdateKnowledgeBase = f + + return mmUpdateKnowledgeBase +} + +// Return sets up results that will be returned by RepositoryI.UpdateKnowledgeBase +func (mmUpdateKnowledgeBase *mRepositoryIMockUpdateKnowledgeBase) Return(kp1 *mm_repository.KnowledgeBase, err error) *RepositoryIMock { + if mmUpdateKnowledgeBase.mock.funcUpdateKnowledgeBase != nil { + mmUpdateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.UpdateKnowledgeBase mock is already set by Set") + } + + if mmUpdateKnowledgeBase.defaultExpectation == nil { + mmUpdateKnowledgeBase.defaultExpectation = &RepositoryIMockUpdateKnowledgeBaseExpectation{mock: mmUpdateKnowledgeBase.mock} + } + mmUpdateKnowledgeBase.defaultExpectation.results = &RepositoryIMockUpdateKnowledgeBaseResults{kp1, err} + return mmUpdateKnowledgeBase.mock +} + +// Set uses given function f to mock the RepositoryI.UpdateKnowledgeBase method +func (mmUpdateKnowledgeBase *mRepositoryIMockUpdateKnowledgeBase) Set(f func(ctx context.Context, kb mm_repository.KnowledgeBase) (kp1 *mm_repository.KnowledgeBase, err error)) *RepositoryIMock { + if mmUpdateKnowledgeBase.defaultExpectation != nil { + mmUpdateKnowledgeBase.mock.t.Fatalf("Default expectation is already set for the RepositoryI.UpdateKnowledgeBase method") + } + + if len(mmUpdateKnowledgeBase.expectations) > 0 { + mmUpdateKnowledgeBase.mock.t.Fatalf("Some expectations are already set for the RepositoryI.UpdateKnowledgeBase method") + } + + mmUpdateKnowledgeBase.mock.funcUpdateKnowledgeBase = f + return mmUpdateKnowledgeBase.mock +} + +// When sets expectation for the RepositoryI.UpdateKnowledgeBase which will trigger the result defined by the following +// Then helper +func (mmUpdateKnowledgeBase *mRepositoryIMockUpdateKnowledgeBase) When(ctx context.Context, kb mm_repository.KnowledgeBase) *RepositoryIMockUpdateKnowledgeBaseExpectation { + if mmUpdateKnowledgeBase.mock.funcUpdateKnowledgeBase != nil { + mmUpdateKnowledgeBase.mock.t.Fatalf("RepositoryIMock.UpdateKnowledgeBase mock is already set by Set") + } + + expectation := &RepositoryIMockUpdateKnowledgeBaseExpectation{ + mock: mmUpdateKnowledgeBase.mock, + params: &RepositoryIMockUpdateKnowledgeBaseParams{ctx, kb}, + } + mmUpdateKnowledgeBase.expectations = append(mmUpdateKnowledgeBase.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.UpdateKnowledgeBase return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockUpdateKnowledgeBaseExpectation) Then(kp1 *mm_repository.KnowledgeBase, err error) *RepositoryIMock { + e.results = &RepositoryIMockUpdateKnowledgeBaseResults{kp1, err} + return e.mock +} + +// Times sets number of times RepositoryI.UpdateKnowledgeBase should be invoked +func (mmUpdateKnowledgeBase *mRepositoryIMockUpdateKnowledgeBase) Times(n uint64) *mRepositoryIMockUpdateKnowledgeBase { + if n == 0 { + mmUpdateKnowledgeBase.mock.t.Fatalf("Times of RepositoryIMock.UpdateKnowledgeBase mock can not be zero") + } + mm_atomic.StoreUint64(&mmUpdateKnowledgeBase.expectedInvocations, n) + return mmUpdateKnowledgeBase +} + +func (mmUpdateKnowledgeBase *mRepositoryIMockUpdateKnowledgeBase) invocationsDone() bool { + if len(mmUpdateKnowledgeBase.expectations) == 0 && mmUpdateKnowledgeBase.defaultExpectation == nil && mmUpdateKnowledgeBase.mock.funcUpdateKnowledgeBase == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmUpdateKnowledgeBase.mock.afterUpdateKnowledgeBaseCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmUpdateKnowledgeBase.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// UpdateKnowledgeBase implements repository.RepositoryI +func (mmUpdateKnowledgeBase *RepositoryIMock) UpdateKnowledgeBase(ctx context.Context, kb mm_repository.KnowledgeBase) (kp1 *mm_repository.KnowledgeBase, err error) { + mm_atomic.AddUint64(&mmUpdateKnowledgeBase.beforeUpdateKnowledgeBaseCounter, 1) + defer mm_atomic.AddUint64(&mmUpdateKnowledgeBase.afterUpdateKnowledgeBaseCounter, 1) + + if mmUpdateKnowledgeBase.inspectFuncUpdateKnowledgeBase != nil { + mmUpdateKnowledgeBase.inspectFuncUpdateKnowledgeBase(ctx, kb) + } + + mm_params := RepositoryIMockUpdateKnowledgeBaseParams{ctx, kb} + + // Record call args + mmUpdateKnowledgeBase.UpdateKnowledgeBaseMock.mutex.Lock() + mmUpdateKnowledgeBase.UpdateKnowledgeBaseMock.callArgs = append(mmUpdateKnowledgeBase.UpdateKnowledgeBaseMock.callArgs, &mm_params) + mmUpdateKnowledgeBase.UpdateKnowledgeBaseMock.mutex.Unlock() + + for _, e := range mmUpdateKnowledgeBase.UpdateKnowledgeBaseMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.kp1, e.results.err + } + } + + if mmUpdateKnowledgeBase.UpdateKnowledgeBaseMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmUpdateKnowledgeBase.UpdateKnowledgeBaseMock.defaultExpectation.Counter, 1) + mm_want := mmUpdateKnowledgeBase.UpdateKnowledgeBaseMock.defaultExpectation.params + mm_want_ptrs := mmUpdateKnowledgeBase.UpdateKnowledgeBaseMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockUpdateKnowledgeBaseParams{ctx, kb} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmUpdateKnowledgeBase.t.Errorf("RepositoryIMock.UpdateKnowledgeBase 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) { + mmUpdateKnowledgeBase.t.Errorf("RepositoryIMock.UpdateKnowledgeBase 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) { + mmUpdateKnowledgeBase.t.Errorf("RepositoryIMock.UpdateKnowledgeBase got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmUpdateKnowledgeBase.UpdateKnowledgeBaseMock.defaultExpectation.results + if mm_results == nil { + mmUpdateKnowledgeBase.t.Fatal("No results are set for the RepositoryIMock.UpdateKnowledgeBase") + } + return (*mm_results).kp1, (*mm_results).err + } + if mmUpdateKnowledgeBase.funcUpdateKnowledgeBase != nil { + return mmUpdateKnowledgeBase.funcUpdateKnowledgeBase(ctx, kb) + } + mmUpdateKnowledgeBase.t.Fatalf("Unexpected call to RepositoryIMock.UpdateKnowledgeBase. %v %v", ctx, kb) + return +} + +// UpdateKnowledgeBaseAfterCounter returns a count of finished RepositoryIMock.UpdateKnowledgeBase invocations +func (mmUpdateKnowledgeBase *RepositoryIMock) UpdateKnowledgeBaseAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmUpdateKnowledgeBase.afterUpdateKnowledgeBaseCounter) +} + +// UpdateKnowledgeBaseBeforeCounter returns a count of RepositoryIMock.UpdateKnowledgeBase invocations +func (mmUpdateKnowledgeBase *RepositoryIMock) UpdateKnowledgeBaseBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmUpdateKnowledgeBase.beforeUpdateKnowledgeBaseCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.UpdateKnowledgeBase. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmUpdateKnowledgeBase *mRepositoryIMockUpdateKnowledgeBase) Calls() []*RepositoryIMockUpdateKnowledgeBaseParams { + mmUpdateKnowledgeBase.mutex.RLock() + + argCopy := make([]*RepositoryIMockUpdateKnowledgeBaseParams, len(mmUpdateKnowledgeBase.callArgs)) + copy(argCopy, mmUpdateKnowledgeBase.callArgs) + + mmUpdateKnowledgeBase.mutex.RUnlock() + + return argCopy +} + +// MinimockUpdateKnowledgeBaseDone returns true if the count of the UpdateKnowledgeBase invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockUpdateKnowledgeBaseDone() bool { + for _, e := range m.UpdateKnowledgeBaseMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.UpdateKnowledgeBaseMock.invocationsDone() +} + +// MinimockUpdateKnowledgeBaseInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockUpdateKnowledgeBaseInspect() { + for _, e := range m.UpdateKnowledgeBaseMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.UpdateKnowledgeBase with params: %#v", *e.params) + } + } + + afterUpdateKnowledgeBaseCounter := mm_atomic.LoadUint64(&m.afterUpdateKnowledgeBaseCounter) + // if default expectation was set then invocations count should be greater than zero + if m.UpdateKnowledgeBaseMock.defaultExpectation != nil && afterUpdateKnowledgeBaseCounter < 1 { + if m.UpdateKnowledgeBaseMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.UpdateKnowledgeBase") + } else { + m.t.Errorf("Expected call to RepositoryIMock.UpdateKnowledgeBase with params: %#v", *m.UpdateKnowledgeBaseMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcUpdateKnowledgeBase != nil && afterUpdateKnowledgeBaseCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.UpdateKnowledgeBase") + } + + if !m.UpdateKnowledgeBaseMock.invocationsDone() && afterUpdateKnowledgeBaseCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.UpdateKnowledgeBase but found %d calls", + mm_atomic.LoadUint64(&m.UpdateKnowledgeBaseMock.expectedInvocations), afterUpdateKnowledgeBaseCounter) + } +} + +type mRepositoryIMockUpsertRepositoryTag struct { + mock *RepositoryIMock + defaultExpectation *RepositoryIMockUpsertRepositoryTagExpectation + expectations []*RepositoryIMockUpsertRepositoryTagExpectation + + callArgs []*RepositoryIMockUpsertRepositoryTagParams + mutex sync.RWMutex + + expectedInvocations uint64 +} + +// RepositoryIMockUpsertRepositoryTagExpectation specifies expectation struct of the RepositoryI.UpsertRepositoryTag +type RepositoryIMockUpsertRepositoryTagExpectation struct { + mock *RepositoryIMock + params *RepositoryIMockUpsertRepositoryTagParams + paramPtrs *RepositoryIMockUpsertRepositoryTagParamPtrs + results *RepositoryIMockUpsertRepositoryTagResults + Counter uint64 +} + +// RepositoryIMockUpsertRepositoryTagParams contains parameters of the RepositoryI.UpsertRepositoryTag +type RepositoryIMockUpsertRepositoryTagParams struct { + ctx context.Context + rp1 *artifactpb.RepositoryTag +} + +// RepositoryIMockUpsertRepositoryTagParamPtrs contains pointers to parameters of the RepositoryI.UpsertRepositoryTag +type RepositoryIMockUpsertRepositoryTagParamPtrs struct { + ctx *context.Context + rp1 **artifactpb.RepositoryTag +} + +// RepositoryIMockUpsertRepositoryTagResults contains results of the RepositoryI.UpsertRepositoryTag +type RepositoryIMockUpsertRepositoryTagResults struct { + rp2 *artifactpb.RepositoryTag + err error +} + +// Expect sets up expected params for RepositoryI.UpsertRepositoryTag +func (mmUpsertRepositoryTag *mRepositoryIMockUpsertRepositoryTag) Expect(ctx context.Context, rp1 *artifactpb.RepositoryTag) *mRepositoryIMockUpsertRepositoryTag { + if mmUpsertRepositoryTag.mock.funcUpsertRepositoryTag != nil { + mmUpsertRepositoryTag.mock.t.Fatalf("RepositoryIMock.UpsertRepositoryTag mock is already set by Set") + } + + if mmUpsertRepositoryTag.defaultExpectation == nil { + mmUpsertRepositoryTag.defaultExpectation = &RepositoryIMockUpsertRepositoryTagExpectation{} + } + + if mmUpsertRepositoryTag.defaultExpectation.paramPtrs != nil { + mmUpsertRepositoryTag.mock.t.Fatalf("RepositoryIMock.UpsertRepositoryTag mock is already set by ExpectParams functions") + } + + mmUpsertRepositoryTag.defaultExpectation.params = &RepositoryIMockUpsertRepositoryTagParams{ctx, rp1} + for _, e := range mmUpsertRepositoryTag.expectations { + if minimock.Equal(e.params, mmUpsertRepositoryTag.defaultExpectation.params) { + mmUpsertRepositoryTag.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUpsertRepositoryTag.defaultExpectation.params) + } + } + + return mmUpsertRepositoryTag +} + +// ExpectCtxParam1 sets up expected param ctx for RepositoryI.UpsertRepositoryTag +func (mmUpsertRepositoryTag *mRepositoryIMockUpsertRepositoryTag) ExpectCtxParam1(ctx context.Context) *mRepositoryIMockUpsertRepositoryTag { + if mmUpsertRepositoryTag.mock.funcUpsertRepositoryTag != nil { + mmUpsertRepositoryTag.mock.t.Fatalf("RepositoryIMock.UpsertRepositoryTag mock is already set by Set") + } + + if mmUpsertRepositoryTag.defaultExpectation == nil { + mmUpsertRepositoryTag.defaultExpectation = &RepositoryIMockUpsertRepositoryTagExpectation{} + } + + if mmUpsertRepositoryTag.defaultExpectation.params != nil { + mmUpsertRepositoryTag.mock.t.Fatalf("RepositoryIMock.UpsertRepositoryTag mock is already set by Expect") + } + + if mmUpsertRepositoryTag.defaultExpectation.paramPtrs == nil { + mmUpsertRepositoryTag.defaultExpectation.paramPtrs = &RepositoryIMockUpsertRepositoryTagParamPtrs{} + } + mmUpsertRepositoryTag.defaultExpectation.paramPtrs.ctx = &ctx + + return mmUpsertRepositoryTag +} + +// ExpectRp1Param2 sets up expected param rp1 for RepositoryI.UpsertRepositoryTag +func (mmUpsertRepositoryTag *mRepositoryIMockUpsertRepositoryTag) ExpectRp1Param2(rp1 *artifactpb.RepositoryTag) *mRepositoryIMockUpsertRepositoryTag { + if mmUpsertRepositoryTag.mock.funcUpsertRepositoryTag != nil { + mmUpsertRepositoryTag.mock.t.Fatalf("RepositoryIMock.UpsertRepositoryTag mock is already set by Set") + } + + if mmUpsertRepositoryTag.defaultExpectation == nil { + mmUpsertRepositoryTag.defaultExpectation = &RepositoryIMockUpsertRepositoryTagExpectation{} + } + + if mmUpsertRepositoryTag.defaultExpectation.params != nil { + mmUpsertRepositoryTag.mock.t.Fatalf("RepositoryIMock.UpsertRepositoryTag mock is already set by Expect") + } + + if mmUpsertRepositoryTag.defaultExpectation.paramPtrs == nil { + mmUpsertRepositoryTag.defaultExpectation.paramPtrs = &RepositoryIMockUpsertRepositoryTagParamPtrs{} + } + mmUpsertRepositoryTag.defaultExpectation.paramPtrs.rp1 = &rp1 + + return mmUpsertRepositoryTag +} + +// Inspect accepts an inspector function that has same arguments as the RepositoryI.UpsertRepositoryTag +func (mmUpsertRepositoryTag *mRepositoryIMockUpsertRepositoryTag) Inspect(f func(ctx context.Context, rp1 *artifactpb.RepositoryTag)) *mRepositoryIMockUpsertRepositoryTag { + if mmUpsertRepositoryTag.mock.inspectFuncUpsertRepositoryTag != nil { + mmUpsertRepositoryTag.mock.t.Fatalf("Inspect function is already set for RepositoryIMock.UpsertRepositoryTag") + } + + mmUpsertRepositoryTag.mock.inspectFuncUpsertRepositoryTag = f + + return mmUpsertRepositoryTag +} + +// Return sets up results that will be returned by RepositoryI.UpsertRepositoryTag +func (mmUpsertRepositoryTag *mRepositoryIMockUpsertRepositoryTag) Return(rp2 *artifactpb.RepositoryTag, err error) *RepositoryIMock { + if mmUpsertRepositoryTag.mock.funcUpsertRepositoryTag != nil { + mmUpsertRepositoryTag.mock.t.Fatalf("RepositoryIMock.UpsertRepositoryTag mock is already set by Set") + } + + if mmUpsertRepositoryTag.defaultExpectation == nil { + mmUpsertRepositoryTag.defaultExpectation = &RepositoryIMockUpsertRepositoryTagExpectation{mock: mmUpsertRepositoryTag.mock} + } + mmUpsertRepositoryTag.defaultExpectation.results = &RepositoryIMockUpsertRepositoryTagResults{rp2, err} + return mmUpsertRepositoryTag.mock +} + +// Set uses given function f to mock the RepositoryI.UpsertRepositoryTag method +func (mmUpsertRepositoryTag *mRepositoryIMockUpsertRepositoryTag) Set(f func(ctx context.Context, rp1 *artifactpb.RepositoryTag) (rp2 *artifactpb.RepositoryTag, err error)) *RepositoryIMock { + if mmUpsertRepositoryTag.defaultExpectation != nil { + mmUpsertRepositoryTag.mock.t.Fatalf("Default expectation is already set for the RepositoryI.UpsertRepositoryTag method") + } + + if len(mmUpsertRepositoryTag.expectations) > 0 { + mmUpsertRepositoryTag.mock.t.Fatalf("Some expectations are already set for the RepositoryI.UpsertRepositoryTag method") + } + + mmUpsertRepositoryTag.mock.funcUpsertRepositoryTag = f + return mmUpsertRepositoryTag.mock +} + +// When sets expectation for the RepositoryI.UpsertRepositoryTag which will trigger the result defined by the following +// Then helper +func (mmUpsertRepositoryTag *mRepositoryIMockUpsertRepositoryTag) When(ctx context.Context, rp1 *artifactpb.RepositoryTag) *RepositoryIMockUpsertRepositoryTagExpectation { + if mmUpsertRepositoryTag.mock.funcUpsertRepositoryTag != nil { + mmUpsertRepositoryTag.mock.t.Fatalf("RepositoryIMock.UpsertRepositoryTag mock is already set by Set") + } + + expectation := &RepositoryIMockUpsertRepositoryTagExpectation{ + mock: mmUpsertRepositoryTag.mock, + params: &RepositoryIMockUpsertRepositoryTagParams{ctx, rp1}, + } + mmUpsertRepositoryTag.expectations = append(mmUpsertRepositoryTag.expectations, expectation) + return expectation +} + +// Then sets up RepositoryI.UpsertRepositoryTag return parameters for the expectation previously defined by the When method +func (e *RepositoryIMockUpsertRepositoryTagExpectation) Then(rp2 *artifactpb.RepositoryTag, err error) *RepositoryIMock { + e.results = &RepositoryIMockUpsertRepositoryTagResults{rp2, err} + return e.mock +} + +// Times sets number of times RepositoryI.UpsertRepositoryTag should be invoked +func (mmUpsertRepositoryTag *mRepositoryIMockUpsertRepositoryTag) Times(n uint64) *mRepositoryIMockUpsertRepositoryTag { + if n == 0 { + mmUpsertRepositoryTag.mock.t.Fatalf("Times of RepositoryIMock.UpsertRepositoryTag mock can not be zero") + } + mm_atomic.StoreUint64(&mmUpsertRepositoryTag.expectedInvocations, n) + return mmUpsertRepositoryTag +} + +func (mmUpsertRepositoryTag *mRepositoryIMockUpsertRepositoryTag) invocationsDone() bool { + if len(mmUpsertRepositoryTag.expectations) == 0 && mmUpsertRepositoryTag.defaultExpectation == nil && mmUpsertRepositoryTag.mock.funcUpsertRepositoryTag == nil { + return true + } + + totalInvocations := mm_atomic.LoadUint64(&mmUpsertRepositoryTag.mock.afterUpsertRepositoryTagCounter) + expectedInvocations := mm_atomic.LoadUint64(&mmUpsertRepositoryTag.expectedInvocations) + + return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations) +} + +// UpsertRepositoryTag implements repository.RepositoryI +func (mmUpsertRepositoryTag *RepositoryIMock) UpsertRepositoryTag(ctx context.Context, rp1 *artifactpb.RepositoryTag) (rp2 *artifactpb.RepositoryTag, err error) { + mm_atomic.AddUint64(&mmUpsertRepositoryTag.beforeUpsertRepositoryTagCounter, 1) + defer mm_atomic.AddUint64(&mmUpsertRepositoryTag.afterUpsertRepositoryTagCounter, 1) + + if mmUpsertRepositoryTag.inspectFuncUpsertRepositoryTag != nil { + mmUpsertRepositoryTag.inspectFuncUpsertRepositoryTag(ctx, rp1) + } + + mm_params := RepositoryIMockUpsertRepositoryTagParams{ctx, rp1} + + // Record call args + mmUpsertRepositoryTag.UpsertRepositoryTagMock.mutex.Lock() + mmUpsertRepositoryTag.UpsertRepositoryTagMock.callArgs = append(mmUpsertRepositoryTag.UpsertRepositoryTagMock.callArgs, &mm_params) + mmUpsertRepositoryTag.UpsertRepositoryTagMock.mutex.Unlock() + + for _, e := range mmUpsertRepositoryTag.UpsertRepositoryTagMock.expectations { + if minimock.Equal(*e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.rp2, e.results.err + } + } + + if mmUpsertRepositoryTag.UpsertRepositoryTagMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmUpsertRepositoryTag.UpsertRepositoryTagMock.defaultExpectation.Counter, 1) + mm_want := mmUpsertRepositoryTag.UpsertRepositoryTagMock.defaultExpectation.params + mm_want_ptrs := mmUpsertRepositoryTag.UpsertRepositoryTagMock.defaultExpectation.paramPtrs + + mm_got := RepositoryIMockUpsertRepositoryTagParams{ctx, rp1} + + if mm_want_ptrs != nil { + + if mm_want_ptrs.ctx != nil && !minimock.Equal(*mm_want_ptrs.ctx, mm_got.ctx) { + mmUpsertRepositoryTag.t.Errorf("RepositoryIMock.UpsertRepositoryTag 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.rp1 != nil && !minimock.Equal(*mm_want_ptrs.rp1, mm_got.rp1) { + mmUpsertRepositoryTag.t.Errorf("RepositoryIMock.UpsertRepositoryTag got unexpected parameter rp1, want: %#v, got: %#v%s\n", *mm_want_ptrs.rp1, mm_got.rp1, minimock.Diff(*mm_want_ptrs.rp1, mm_got.rp1)) + } + + } else if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmUpsertRepositoryTag.t.Errorf("RepositoryIMock.UpsertRepositoryTag got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmUpsertRepositoryTag.UpsertRepositoryTagMock.defaultExpectation.results + if mm_results == nil { + mmUpsertRepositoryTag.t.Fatal("No results are set for the RepositoryIMock.UpsertRepositoryTag") + } + return (*mm_results).rp2, (*mm_results).err + } + if mmUpsertRepositoryTag.funcUpsertRepositoryTag != nil { + return mmUpsertRepositoryTag.funcUpsertRepositoryTag(ctx, rp1) + } + mmUpsertRepositoryTag.t.Fatalf("Unexpected call to RepositoryIMock.UpsertRepositoryTag. %v %v", ctx, rp1) + return +} + +// UpsertRepositoryTagAfterCounter returns a count of finished RepositoryIMock.UpsertRepositoryTag invocations +func (mmUpsertRepositoryTag *RepositoryIMock) UpsertRepositoryTagAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmUpsertRepositoryTag.afterUpsertRepositoryTagCounter) +} + +// UpsertRepositoryTagBeforeCounter returns a count of RepositoryIMock.UpsertRepositoryTag invocations +func (mmUpsertRepositoryTag *RepositoryIMock) UpsertRepositoryTagBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmUpsertRepositoryTag.beforeUpsertRepositoryTagCounter) +} + +// Calls returns a list of arguments used in each call to RepositoryIMock.UpsertRepositoryTag. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmUpsertRepositoryTag *mRepositoryIMockUpsertRepositoryTag) Calls() []*RepositoryIMockUpsertRepositoryTagParams { + mmUpsertRepositoryTag.mutex.RLock() + + argCopy := make([]*RepositoryIMockUpsertRepositoryTagParams, len(mmUpsertRepositoryTag.callArgs)) + copy(argCopy, mmUpsertRepositoryTag.callArgs) + + mmUpsertRepositoryTag.mutex.RUnlock() + + return argCopy +} + +// MinimockUpsertRepositoryTagDone returns true if the count of the UpsertRepositoryTag invocations corresponds +// the number of defined expectations +func (m *RepositoryIMock) MinimockUpsertRepositoryTagDone() bool { + for _, e := range m.UpsertRepositoryTagMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + return m.UpsertRepositoryTagMock.invocationsDone() +} + +// MinimockUpsertRepositoryTagInspect logs each unmet expectation +func (m *RepositoryIMock) MinimockUpsertRepositoryTagInspect() { + for _, e := range m.UpsertRepositoryTagMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to RepositoryIMock.UpsertRepositoryTag with params: %#v", *e.params) + } + } + + afterUpsertRepositoryTagCounter := mm_atomic.LoadUint64(&m.afterUpsertRepositoryTagCounter) + // if default expectation was set then invocations count should be greater than zero + if m.UpsertRepositoryTagMock.defaultExpectation != nil && afterUpsertRepositoryTagCounter < 1 { + if m.UpsertRepositoryTagMock.defaultExpectation.params == nil { + m.t.Error("Expected call to RepositoryIMock.UpsertRepositoryTag") + } else { + m.t.Errorf("Expected call to RepositoryIMock.UpsertRepositoryTag with params: %#v", *m.UpsertRepositoryTagMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcUpsertRepositoryTag != nil && afterUpsertRepositoryTagCounter < 1 { + m.t.Error("Expected call to RepositoryIMock.UpsertRepositoryTag") + } + + if !m.UpsertRepositoryTagMock.invocationsDone() && afterUpsertRepositoryTagCounter > 0 { + m.t.Errorf("Expected %d calls to RepositoryIMock.UpsertRepositoryTag but found %d calls", + mm_atomic.LoadUint64(&m.UpsertRepositoryTagMock.expectedInvocations), afterUpsertRepositoryTagCounter) + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *RepositoryIMock) MinimockFinish() { + m.finishOnce.Do(func() { + if !m.minimockDone() { + m.MinimockCreateKnowledgeBaseInspect() + + m.MinimockDeleteKnowledgeBaseInspect() + + m.MinimockGetKnowledgeBaseInspect() + + m.MinimockGetRepositoryTagInspect() + + m.MinimockUpdateKnowledgeBaseInspect() + + m.MinimockUpsertRepositoryTagInspect() + m.t.FailNow() + } + }) +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *RepositoryIMock) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *RepositoryIMock) minimockDone() bool { + done := true + return done && + m.MinimockCreateKnowledgeBaseDone() && + m.MinimockDeleteKnowledgeBaseDone() && + m.MinimockGetKnowledgeBaseDone() && + m.MinimockGetRepositoryTagDone() && + m.MinimockUpdateKnowledgeBaseDone() && + m.MinimockUpsertRepositoryTagDone() +} diff --git a/pkg/mock/repository_mock.gen.go b/pkg/mock/repository_mock.gen.go deleted file mode 100644 index 2b7147a..0000000 --- a/pkg/mock/repository_mock.gen.go +++ /dev/null @@ -1,522 +0,0 @@ -// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. - -package mock - -import ( - "context" - "sync" - - "github.com/gojuno/minimock/v3" - - mm_atomic "sync/atomic" - mm_time "time" - - mm_service "github.com/instill-ai/artifact-backend/pkg/service" - pb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" -) - -// RepositoryMock implements service.Repository -type RepositoryMock struct { - t minimock.Tester - finishOnce sync.Once - - funcGetRepositoryTag func(ctx context.Context, r1 mm_service.RepositoryTagName) (rp1 *pb.RepositoryTag, err error) - inspectFuncGetRepositoryTag func(ctx context.Context, r1 mm_service.RepositoryTagName) - afterGetRepositoryTagCounter uint64 - beforeGetRepositoryTagCounter uint64 - GetRepositoryTagMock mRepositoryMockGetRepositoryTag - - funcUpsertRepositoryTag func(ctx context.Context, rp1 *pb.RepositoryTag) (rp2 *pb.RepositoryTag, err error) - inspectFuncUpsertRepositoryTag func(ctx context.Context, rp1 *pb.RepositoryTag) - afterUpsertRepositoryTagCounter uint64 - beforeUpsertRepositoryTagCounter uint64 - UpsertRepositoryTagMock mRepositoryMockUpsertRepositoryTag -} - -// NewRepositoryMock returns a mock for service.Repository -func NewRepositoryMock(t minimock.Tester) *RepositoryMock { - m := &RepositoryMock{t: t} - - if controller, ok := t.(minimock.MockController); ok { - controller.RegisterMocker(m) - } - - m.GetRepositoryTagMock = mRepositoryMockGetRepositoryTag{mock: m} - m.GetRepositoryTagMock.callArgs = []*RepositoryMockGetRepositoryTagParams{} - - m.UpsertRepositoryTagMock = mRepositoryMockUpsertRepositoryTag{mock: m} - m.UpsertRepositoryTagMock.callArgs = []*RepositoryMockUpsertRepositoryTagParams{} - - t.Cleanup(m.MinimockFinish) - - return m -} - -type mRepositoryMockGetRepositoryTag struct { - mock *RepositoryMock - defaultExpectation *RepositoryMockGetRepositoryTagExpectation - expectations []*RepositoryMockGetRepositoryTagExpectation - - callArgs []*RepositoryMockGetRepositoryTagParams - mutex sync.RWMutex -} - -// RepositoryMockGetRepositoryTagExpectation specifies expectation struct of the Repository.GetRepositoryTag -type RepositoryMockGetRepositoryTagExpectation struct { - mock *RepositoryMock - params *RepositoryMockGetRepositoryTagParams - results *RepositoryMockGetRepositoryTagResults - Counter uint64 -} - -// RepositoryMockGetRepositoryTagParams contains parameters of the Repository.GetRepositoryTag -type RepositoryMockGetRepositoryTagParams struct { - ctx context.Context - r1 mm_service.RepositoryTagName -} - -// RepositoryMockGetRepositoryTagResults contains results of the Repository.GetRepositoryTag -type RepositoryMockGetRepositoryTagResults struct { - rp1 *pb.RepositoryTag - err error -} - -// Expect sets up expected params for Repository.GetRepositoryTag -func (mmGetRepositoryTag *mRepositoryMockGetRepositoryTag) Expect(ctx context.Context, r1 mm_service.RepositoryTagName) *mRepositoryMockGetRepositoryTag { - if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { - mmGetRepositoryTag.mock.t.Fatalf("RepositoryMock.GetRepositoryTag mock is already set by Set") - } - - if mmGetRepositoryTag.defaultExpectation == nil { - mmGetRepositoryTag.defaultExpectation = &RepositoryMockGetRepositoryTagExpectation{} - } - - mmGetRepositoryTag.defaultExpectation.params = &RepositoryMockGetRepositoryTagParams{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 -} - -// Inspect accepts an inspector function that has same arguments as the Repository.GetRepositoryTag -func (mmGetRepositoryTag *mRepositoryMockGetRepositoryTag) Inspect(f func(ctx context.Context, r1 mm_service.RepositoryTagName)) *mRepositoryMockGetRepositoryTag { - if mmGetRepositoryTag.mock.inspectFuncGetRepositoryTag != nil { - mmGetRepositoryTag.mock.t.Fatalf("Inspect function is already set for RepositoryMock.GetRepositoryTag") - } - - mmGetRepositoryTag.mock.inspectFuncGetRepositoryTag = f - - return mmGetRepositoryTag -} - -// Return sets up results that will be returned by Repository.GetRepositoryTag -func (mmGetRepositoryTag *mRepositoryMockGetRepositoryTag) Return(rp1 *pb.RepositoryTag, err error) *RepositoryMock { - if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { - mmGetRepositoryTag.mock.t.Fatalf("RepositoryMock.GetRepositoryTag mock is already set by Set") - } - - if mmGetRepositoryTag.defaultExpectation == nil { - mmGetRepositoryTag.defaultExpectation = &RepositoryMockGetRepositoryTagExpectation{mock: mmGetRepositoryTag.mock} - } - mmGetRepositoryTag.defaultExpectation.results = &RepositoryMockGetRepositoryTagResults{rp1, err} - return mmGetRepositoryTag.mock -} - -// Set uses given function f to mock the Repository.GetRepositoryTag method -func (mmGetRepositoryTag *mRepositoryMockGetRepositoryTag) Set(f func(ctx context.Context, r1 mm_service.RepositoryTagName) (rp1 *pb.RepositoryTag, err error)) *RepositoryMock { - if mmGetRepositoryTag.defaultExpectation != nil { - mmGetRepositoryTag.mock.t.Fatalf("Default expectation is already set for the Repository.GetRepositoryTag method") - } - - if len(mmGetRepositoryTag.expectations) > 0 { - mmGetRepositoryTag.mock.t.Fatalf("Some expectations are already set for the Repository.GetRepositoryTag method") - } - - mmGetRepositoryTag.mock.funcGetRepositoryTag = f - return mmGetRepositoryTag.mock -} - -// When sets expectation for the Repository.GetRepositoryTag which will trigger the result defined by the following -// Then helper -func (mmGetRepositoryTag *mRepositoryMockGetRepositoryTag) When(ctx context.Context, r1 mm_service.RepositoryTagName) *RepositoryMockGetRepositoryTagExpectation { - if mmGetRepositoryTag.mock.funcGetRepositoryTag != nil { - mmGetRepositoryTag.mock.t.Fatalf("RepositoryMock.GetRepositoryTag mock is already set by Set") - } - - expectation := &RepositoryMockGetRepositoryTagExpectation{ - mock: mmGetRepositoryTag.mock, - params: &RepositoryMockGetRepositoryTagParams{ctx, r1}, - } - mmGetRepositoryTag.expectations = append(mmGetRepositoryTag.expectations, expectation) - return expectation -} - -// Then sets up Repository.GetRepositoryTag return parameters for the expectation previously defined by the When method -func (e *RepositoryMockGetRepositoryTagExpectation) Then(rp1 *pb.RepositoryTag, err error) *RepositoryMock { - e.results = &RepositoryMockGetRepositoryTagResults{rp1, err} - return e.mock -} - -// GetRepositoryTag implements service.Repository -func (mmGetRepositoryTag *RepositoryMock) GetRepositoryTag(ctx context.Context, r1 mm_service.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 := RepositoryMockGetRepositoryTagParams{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_got := RepositoryMockGetRepositoryTagParams{ctx, r1} - if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { - mmGetRepositoryTag.t.Errorf("RepositoryMock.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 RepositoryMock.GetRepositoryTag") - } - return (*mm_results).rp1, (*mm_results).err - } - if mmGetRepositoryTag.funcGetRepositoryTag != nil { - return mmGetRepositoryTag.funcGetRepositoryTag(ctx, r1) - } - mmGetRepositoryTag.t.Fatalf("Unexpected call to RepositoryMock.GetRepositoryTag. %v %v", ctx, r1) - return -} - -// GetRepositoryTagAfterCounter returns a count of finished RepositoryMock.GetRepositoryTag invocations -func (mmGetRepositoryTag *RepositoryMock) GetRepositoryTagAfterCounter() uint64 { - return mm_atomic.LoadUint64(&mmGetRepositoryTag.afterGetRepositoryTagCounter) -} - -// GetRepositoryTagBeforeCounter returns a count of RepositoryMock.GetRepositoryTag invocations -func (mmGetRepositoryTag *RepositoryMock) GetRepositoryTagBeforeCounter() uint64 { - return mm_atomic.LoadUint64(&mmGetRepositoryTag.beforeGetRepositoryTagCounter) -} - -// Calls returns a list of arguments used in each call to RepositoryMock.GetRepositoryTag. -// The list is in the same order as the calls were made (i.e. recent calls have a higher index) -func (mmGetRepositoryTag *mRepositoryMockGetRepositoryTag) Calls() []*RepositoryMockGetRepositoryTagParams { - mmGetRepositoryTag.mutex.RLock() - - argCopy := make([]*RepositoryMockGetRepositoryTagParams, 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 *RepositoryMock) MinimockGetRepositoryTagDone() bool { - for _, e := range m.GetRepositoryTagMock.expectations { - if mm_atomic.LoadUint64(&e.Counter) < 1 { - return false - } - } - - // if default expectation was set then invocations count should be greater than zero - if m.GetRepositoryTagMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetRepositoryTagCounter) < 1 { - return false - } - // if func was set then invocations count should be greater than zero - if m.funcGetRepositoryTag != nil && mm_atomic.LoadUint64(&m.afterGetRepositoryTagCounter) < 1 { - return false - } - return true -} - -// MinimockGetRepositoryTagInspect logs each unmet expectation -func (m *RepositoryMock) MinimockGetRepositoryTagInspect() { - for _, e := range m.GetRepositoryTagMock.expectations { - if mm_atomic.LoadUint64(&e.Counter) < 1 { - m.t.Errorf("Expected call to RepositoryMock.GetRepositoryTag with params: %#v", *e.params) - } - } - - // if default expectation was set then invocations count should be greater than zero - if m.GetRepositoryTagMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterGetRepositoryTagCounter) < 1 { - if m.GetRepositoryTagMock.defaultExpectation.params == nil { - m.t.Error("Expected call to RepositoryMock.GetRepositoryTag") - } else { - m.t.Errorf("Expected call to RepositoryMock.GetRepositoryTag with params: %#v", *m.GetRepositoryTagMock.defaultExpectation.params) - } - } - // if func was set then invocations count should be greater than zero - if m.funcGetRepositoryTag != nil && mm_atomic.LoadUint64(&m.afterGetRepositoryTagCounter) < 1 { - m.t.Error("Expected call to RepositoryMock.GetRepositoryTag") - } -} - -type mRepositoryMockUpsertRepositoryTag struct { - mock *RepositoryMock - defaultExpectation *RepositoryMockUpsertRepositoryTagExpectation - expectations []*RepositoryMockUpsertRepositoryTagExpectation - - callArgs []*RepositoryMockUpsertRepositoryTagParams - mutex sync.RWMutex -} - -// RepositoryMockUpsertRepositoryTagExpectation specifies expectation struct of the Repository.UpsertRepositoryTag -type RepositoryMockUpsertRepositoryTagExpectation struct { - mock *RepositoryMock - params *RepositoryMockUpsertRepositoryTagParams - results *RepositoryMockUpsertRepositoryTagResults - Counter uint64 -} - -// RepositoryMockUpsertRepositoryTagParams contains parameters of the Repository.UpsertRepositoryTag -type RepositoryMockUpsertRepositoryTagParams struct { - ctx context.Context - rp1 *pb.RepositoryTag -} - -// RepositoryMockUpsertRepositoryTagResults contains results of the Repository.UpsertRepositoryTag -type RepositoryMockUpsertRepositoryTagResults struct { - rp2 *pb.RepositoryTag - err error -} - -// Expect sets up expected params for Repository.UpsertRepositoryTag -func (mmUpsertRepositoryTag *mRepositoryMockUpsertRepositoryTag) Expect(ctx context.Context, rp1 *pb.RepositoryTag) *mRepositoryMockUpsertRepositoryTag { - if mmUpsertRepositoryTag.mock.funcUpsertRepositoryTag != nil { - mmUpsertRepositoryTag.mock.t.Fatalf("RepositoryMock.UpsertRepositoryTag mock is already set by Set") - } - - if mmUpsertRepositoryTag.defaultExpectation == nil { - mmUpsertRepositoryTag.defaultExpectation = &RepositoryMockUpsertRepositoryTagExpectation{} - } - - mmUpsertRepositoryTag.defaultExpectation.params = &RepositoryMockUpsertRepositoryTagParams{ctx, rp1} - for _, e := range mmUpsertRepositoryTag.expectations { - if minimock.Equal(e.params, mmUpsertRepositoryTag.defaultExpectation.params) { - mmUpsertRepositoryTag.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUpsertRepositoryTag.defaultExpectation.params) - } - } - - return mmUpsertRepositoryTag -} - -// Inspect accepts an inspector function that has same arguments as the Repository.UpsertRepositoryTag -func (mmUpsertRepositoryTag *mRepositoryMockUpsertRepositoryTag) Inspect(f func(ctx context.Context, rp1 *pb.RepositoryTag)) *mRepositoryMockUpsertRepositoryTag { - if mmUpsertRepositoryTag.mock.inspectFuncUpsertRepositoryTag != nil { - mmUpsertRepositoryTag.mock.t.Fatalf("Inspect function is already set for RepositoryMock.UpsertRepositoryTag") - } - - mmUpsertRepositoryTag.mock.inspectFuncUpsertRepositoryTag = f - - return mmUpsertRepositoryTag -} - -// Return sets up results that will be returned by Repository.UpsertRepositoryTag -func (mmUpsertRepositoryTag *mRepositoryMockUpsertRepositoryTag) Return(rp2 *pb.RepositoryTag, err error) *RepositoryMock { - if mmUpsertRepositoryTag.mock.funcUpsertRepositoryTag != nil { - mmUpsertRepositoryTag.mock.t.Fatalf("RepositoryMock.UpsertRepositoryTag mock is already set by Set") - } - - if mmUpsertRepositoryTag.defaultExpectation == nil { - mmUpsertRepositoryTag.defaultExpectation = &RepositoryMockUpsertRepositoryTagExpectation{mock: mmUpsertRepositoryTag.mock} - } - mmUpsertRepositoryTag.defaultExpectation.results = &RepositoryMockUpsertRepositoryTagResults{rp2, err} - return mmUpsertRepositoryTag.mock -} - -// Set uses given function f to mock the Repository.UpsertRepositoryTag method -func (mmUpsertRepositoryTag *mRepositoryMockUpsertRepositoryTag) Set(f func(ctx context.Context, rp1 *pb.RepositoryTag) (rp2 *pb.RepositoryTag, err error)) *RepositoryMock { - if mmUpsertRepositoryTag.defaultExpectation != nil { - mmUpsertRepositoryTag.mock.t.Fatalf("Default expectation is already set for the Repository.UpsertRepositoryTag method") - } - - if len(mmUpsertRepositoryTag.expectations) > 0 { - mmUpsertRepositoryTag.mock.t.Fatalf("Some expectations are already set for the Repository.UpsertRepositoryTag method") - } - - mmUpsertRepositoryTag.mock.funcUpsertRepositoryTag = f - return mmUpsertRepositoryTag.mock -} - -// When sets expectation for the Repository.UpsertRepositoryTag which will trigger the result defined by the following -// Then helper -func (mmUpsertRepositoryTag *mRepositoryMockUpsertRepositoryTag) When(ctx context.Context, rp1 *pb.RepositoryTag) *RepositoryMockUpsertRepositoryTagExpectation { - if mmUpsertRepositoryTag.mock.funcUpsertRepositoryTag != nil { - mmUpsertRepositoryTag.mock.t.Fatalf("RepositoryMock.UpsertRepositoryTag mock is already set by Set") - } - - expectation := &RepositoryMockUpsertRepositoryTagExpectation{ - mock: mmUpsertRepositoryTag.mock, - params: &RepositoryMockUpsertRepositoryTagParams{ctx, rp1}, - } - mmUpsertRepositoryTag.expectations = append(mmUpsertRepositoryTag.expectations, expectation) - return expectation -} - -// Then sets up Repository.UpsertRepositoryTag return parameters for the expectation previously defined by the When method -func (e *RepositoryMockUpsertRepositoryTagExpectation) Then(rp2 *pb.RepositoryTag, err error) *RepositoryMock { - e.results = &RepositoryMockUpsertRepositoryTagResults{rp2, err} - return e.mock -} - -// UpsertRepositoryTag implements service.Repository -func (mmUpsertRepositoryTag *RepositoryMock) UpsertRepositoryTag(ctx context.Context, rp1 *pb.RepositoryTag) (rp2 *pb.RepositoryTag, err error) { - mm_atomic.AddUint64(&mmUpsertRepositoryTag.beforeUpsertRepositoryTagCounter, 1) - defer mm_atomic.AddUint64(&mmUpsertRepositoryTag.afterUpsertRepositoryTagCounter, 1) - - if mmUpsertRepositoryTag.inspectFuncUpsertRepositoryTag != nil { - mmUpsertRepositoryTag.inspectFuncUpsertRepositoryTag(ctx, rp1) - } - - mm_params := RepositoryMockUpsertRepositoryTagParams{ctx, rp1} - - // Record call args - mmUpsertRepositoryTag.UpsertRepositoryTagMock.mutex.Lock() - mmUpsertRepositoryTag.UpsertRepositoryTagMock.callArgs = append(mmUpsertRepositoryTag.UpsertRepositoryTagMock.callArgs, &mm_params) - mmUpsertRepositoryTag.UpsertRepositoryTagMock.mutex.Unlock() - - for _, e := range mmUpsertRepositoryTag.UpsertRepositoryTagMock.expectations { - if minimock.Equal(*e.params, mm_params) { - mm_atomic.AddUint64(&e.Counter, 1) - return e.results.rp2, e.results.err - } - } - - if mmUpsertRepositoryTag.UpsertRepositoryTagMock.defaultExpectation != nil { - mm_atomic.AddUint64(&mmUpsertRepositoryTag.UpsertRepositoryTagMock.defaultExpectation.Counter, 1) - mm_want := mmUpsertRepositoryTag.UpsertRepositoryTagMock.defaultExpectation.params - mm_got := RepositoryMockUpsertRepositoryTagParams{ctx, rp1} - if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { - mmUpsertRepositoryTag.t.Errorf("RepositoryMock.UpsertRepositoryTag got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) - } - - mm_results := mmUpsertRepositoryTag.UpsertRepositoryTagMock.defaultExpectation.results - if mm_results == nil { - mmUpsertRepositoryTag.t.Fatal("No results are set for the RepositoryMock.UpsertRepositoryTag") - } - return (*mm_results).rp2, (*mm_results).err - } - if mmUpsertRepositoryTag.funcUpsertRepositoryTag != nil { - return mmUpsertRepositoryTag.funcUpsertRepositoryTag(ctx, rp1) - } - mmUpsertRepositoryTag.t.Fatalf("Unexpected call to RepositoryMock.UpsertRepositoryTag. %v %v", ctx, rp1) - return -} - -// UpsertRepositoryTagAfterCounter returns a count of finished RepositoryMock.UpsertRepositoryTag invocations -func (mmUpsertRepositoryTag *RepositoryMock) UpsertRepositoryTagAfterCounter() uint64 { - return mm_atomic.LoadUint64(&mmUpsertRepositoryTag.afterUpsertRepositoryTagCounter) -} - -// UpsertRepositoryTagBeforeCounter returns a count of RepositoryMock.UpsertRepositoryTag invocations -func (mmUpsertRepositoryTag *RepositoryMock) UpsertRepositoryTagBeforeCounter() uint64 { - return mm_atomic.LoadUint64(&mmUpsertRepositoryTag.beforeUpsertRepositoryTagCounter) -} - -// Calls returns a list of arguments used in each call to RepositoryMock.UpsertRepositoryTag. -// The list is in the same order as the calls were made (i.e. recent calls have a higher index) -func (mmUpsertRepositoryTag *mRepositoryMockUpsertRepositoryTag) Calls() []*RepositoryMockUpsertRepositoryTagParams { - mmUpsertRepositoryTag.mutex.RLock() - - argCopy := make([]*RepositoryMockUpsertRepositoryTagParams, len(mmUpsertRepositoryTag.callArgs)) - copy(argCopy, mmUpsertRepositoryTag.callArgs) - - mmUpsertRepositoryTag.mutex.RUnlock() - - return argCopy -} - -// MinimockUpsertRepositoryTagDone returns true if the count of the UpsertRepositoryTag invocations corresponds -// the number of defined expectations -func (m *RepositoryMock) MinimockUpsertRepositoryTagDone() bool { - for _, e := range m.UpsertRepositoryTagMock.expectations { - if mm_atomic.LoadUint64(&e.Counter) < 1 { - return false - } - } - - // if default expectation was set then invocations count should be greater than zero - if m.UpsertRepositoryTagMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterUpsertRepositoryTagCounter) < 1 { - return false - } - // if func was set then invocations count should be greater than zero - if m.funcUpsertRepositoryTag != nil && mm_atomic.LoadUint64(&m.afterUpsertRepositoryTagCounter) < 1 { - return false - } - return true -} - -// MinimockUpsertRepositoryTagInspect logs each unmet expectation -func (m *RepositoryMock) MinimockUpsertRepositoryTagInspect() { - for _, e := range m.UpsertRepositoryTagMock.expectations { - if mm_atomic.LoadUint64(&e.Counter) < 1 { - m.t.Errorf("Expected call to RepositoryMock.UpsertRepositoryTag with params: %#v", *e.params) - } - } - - // if default expectation was set then invocations count should be greater than zero - if m.UpsertRepositoryTagMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterUpsertRepositoryTagCounter) < 1 { - if m.UpsertRepositoryTagMock.defaultExpectation.params == nil { - m.t.Error("Expected call to RepositoryMock.UpsertRepositoryTag") - } else { - m.t.Errorf("Expected call to RepositoryMock.UpsertRepositoryTag with params: %#v", *m.UpsertRepositoryTagMock.defaultExpectation.params) - } - } - // if func was set then invocations count should be greater than zero - if m.funcUpsertRepositoryTag != nil && mm_atomic.LoadUint64(&m.afterUpsertRepositoryTagCounter) < 1 { - m.t.Error("Expected call to RepositoryMock.UpsertRepositoryTag") - } -} - -// MinimockFinish checks that all mocked methods have been called the expected number of times -func (m *RepositoryMock) MinimockFinish() { - m.finishOnce.Do(func() { - if !m.minimockDone() { - m.MinimockGetRepositoryTagInspect() - - m.MinimockUpsertRepositoryTagInspect() - m.t.FailNow() - } - }) -} - -// MinimockWait waits for all mocked methods to be called the expected number of times -func (m *RepositoryMock) MinimockWait(timeout mm_time.Duration) { - timeoutCh := mm_time.After(timeout) - for { - if m.minimockDone() { - return - } - select { - case <-timeoutCh: - m.MinimockFinish() - return - case <-mm_time.After(10 * mm_time.Millisecond): - } - } -} - -func (m *RepositoryMock) minimockDone() bool { - done := true - return done && - m.MinimockGetRepositoryTagDone() && - m.MinimockUpsertRepositoryTagDone() -} diff --git a/pkg/repository/knowledgebase.go b/pkg/repository/knowledgebase.go new file mode 100644 index 0000000..4671679 --- /dev/null +++ b/pkg/repository/knowledgebase.go @@ -0,0 +1,123 @@ +package repository + +import ( + "context" + "time" + + "gorm.io/gorm" +) + +type KnowledgeBaseI interface { + CreateKnowledgeBase(ctx context.Context, kb KnowledgeBase) (*KnowledgeBase, error) + GetKnowledgeBase(ctx context.Context) ([]KnowledgeBase, error) + UpdateKnowledgeBase(ctx context.Context, kb KnowledgeBase) (*KnowledgeBase, error) + DeleteKnowledgeBase(ctx context.Context, kb KnowledgeBase) error +} + +type KnowledgeBase struct { + ID uint `gorm:"column:id;primaryKey" json:"id"` + KbID string `gorm:"column:kb_id;size:255;not null;unique" 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"` + 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 KnowledgeBaseColumns struct { + ID string + KbID string + Name string + Description string + Tags string + Owner string + CreateTime string + UpdateTime string + DeleteTime string +} + +var KnowledgeBaseColumn = KnowledgeBaseColumns{ + ID: "id", + KbID: "kb_id", + Name: "name", + Description: "description", + Tags: "tags", + Owner: "owner", + CreateTime: "create_time", + UpdateTime: "update_time", + DeleteTime: "delete_time", +} + +type TagsArray []string + +// CreateKnowledgeBase inserts a new KnowledgeBase record into the database. +func (r *Repository) CreateKnowledgeBase(ctx context.Context, kb KnowledgeBase) (*KnowledgeBase, error) { + + if err := r.db.WithContext(ctx).Create(&kb).Error; err != nil { + return nil, err + } + + return &kb, nil +} + +// GetKnowledgeBase fetches all KnowledgeBase records from the database, excluding soft-deleted ones. +func (r *Repository) GetKnowledgeBase(ctx context.Context) ([]KnowledgeBase, error) { + var knowledgeBases []KnowledgeBase + + // Exclude records where DeleteTime is not null + if err := r.db.WithContext(ctx).Where("delete_time IS NULL").Find(&knowledgeBases).Error; err != nil { + return nil, err + } + + return knowledgeBases, nil +} + +// UpdateKnowledgeBase updates a KnowledgeBase record in the database except for CreateTime and DeleteTime. +func (r *Repository) UpdateKnowledgeBase(ctx context.Context, kb KnowledgeBase) (*KnowledgeBase, error) { + // Fetch the existing record to ensure it exists and to get the CreateTime and DeleteTime fields + var existingKB KnowledgeBase + if err := r.db.WithContext(ctx).First(&existingKB, kb.ID).Error; err != nil { + if err == gorm.ErrRecordNotFound { + return nil, err + } + return nil, err + } + + // Update the specific fields of the record + if err := r.db.WithContext(ctx).Model(&existingKB).Updates(map[string]interface{}{ + // "kb_id": kb.KbID, + KnowledgeBaseColumn.Name: kb.Name, + KnowledgeBaseColumn.Description: kb.Description, + KnowledgeBaseColumn.Tags: kb.Tags, + KnowledgeBaseColumn.Owner: kb.Owner, + }).Error; err != nil { + return nil, err + } + return &kb, nil +} + +// DeleteKnowledgeBase sets the DeleteTime to the current time to perform a soft delete. +func (r *Repository) DeleteKnowledgeBase(ctx context.Context, kb KnowledgeBase) error { + // Fetch the existing record to ensure it exists + var existingKB KnowledgeBase + if err := r.db.WithContext(ctx).First(&existingKB, kb.ID).Error; err != nil { + if err == gorm.ErrRecordNotFound { + return err + } + return err + } + + // Set the DeleteTime to the current time + deleteTime := time.Now().UTC() + existingKB.DeleteTime = &deleteTime + + // Save the changes to mark the record as soft deleted + if err := r.db.WithContext(ctx).Save(&existingKB).Error; err != nil { + return err + } + + return nil +} diff --git a/pkg/repository/repository.go b/pkg/repository/repository.go index 69e8d51..13cd765 100644 --- a/pkg/repository/repository.go +++ b/pkg/repository/repository.go @@ -1,83 +1,22 @@ package repository import ( - "context" - "gorm.io/gorm" - "gorm.io/gorm/clause" - - "google.golang.org/protobuf/types/known/timestamppb" - - artifact "github.com/instill-ai/artifact-backend/pkg/service" - artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" ) +type RepositoryI interface { + TagI + KnowledgeBaseI +} + // Repository implements Artifact storage functions in PostgreSQL. type Repository struct { db *gorm.DB } // NewRepository returns an initialized repository. -func NewRepository(db *gorm.DB) *Repository { +func NewRepository(db *gorm.DB) RepositoryI { return &Repository{ db: db, } } - -// GetRepositoryTag fetches the tag information from the repository_tag table. -// The name param is the resource name of the tag, e.g. -// `repositories/admin/hello-world/tags/0.1.1-beta`. -func (r *Repository) GetRepositoryTag(_ context.Context, name artifact.RepositoryTagName) (*artifactpb.RepositoryTag, error) { - repo, tagID, err := name.ExtractRepositoryAndID() - if err != nil { - return nil, err - } - - record := new(repositoryTag) - if result := r.db.Model(record). - Where("name = ?", repositoryTagName(repo, tagID)). - First(record); result.Error != nil { - - if result.Error == gorm.ErrRecordNotFound { - return nil, artifact.ErrNotFound - } - - return nil, result.Error - } - - return &artifactpb.RepositoryTag{ - Name: string(name), - Id: tagID, - Digest: record.Digest, - UpdateTime: timestamppb.New(record.UpdateTime), - }, nil -} - -// UpsertRepositoryTag stores the provided tag information in the database. The -// update timestamp will be generated on insertion. -func (r *Repository) UpsertRepositoryTag(_ context.Context, tag *artifactpb.RepositoryTag) (*artifactpb.RepositoryTag, error) { - repo, tagID, err := artifact.RepositoryTagName(tag.GetName()).ExtractRepositoryAndID() - if err != nil { - return nil, err - } - - record := &repositoryTag{ - Name: repositoryTagName(repo, tagID), - Digest: tag.GetDigest(), - } - - updateOnConflict := clause.OnConflict{ - Columns: []clause.Column{{Name: "name"}}, - DoUpdates: clause.AssignmentColumns([]string{"digest"}), - } - if result := r.db.Clauses(updateOnConflict).Create(record); result.Error != nil { - return nil, result.Error - } - - return &artifactpb.RepositoryTag{ - Name: tag.GetName(), - Id: tag.GetId(), - Digest: record.Digest, - UpdateTime: timestamppb.New(record.UpdateTime), - }, nil -} diff --git a/pkg/repository/tag.go b/pkg/repository/tag.go new file mode 100644 index 0000000..8bad712 --- /dev/null +++ b/pkg/repository/tag.go @@ -0,0 +1,80 @@ +package repository + +import ( + "context" + + customerror "github.com/instill-ai/artifact-backend/pkg/customerror" + "github.com/instill-ai/artifact-backend/pkg/utils" + artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" + "google.golang.org/protobuf/types/known/timestamppb" + "gorm.io/gorm" + "gorm.io/gorm/clause" +) + +// TagI +// +// GetRepositoryTag(context.Context, utils.RepositoryTagName) (*artifactpb.RepositoryTag, error) +// +// UpsertRepositoryTag(context.Context, *artifactpb.RepositoryTag) (*artifactpb.RepositoryTag, error) +type TagI interface { + GetRepositoryTag(context.Context, utils.RepositoryTagName) (*artifactpb.RepositoryTag, error) + UpsertRepositoryTag(context.Context, *artifactpb.RepositoryTag) (*artifactpb.RepositoryTag, error) +} + +// GetRepositoryTag fetches the tag information from the repository_tag table. +// The name param is the resource name of the tag, e.g. +// `repositories/admin/hello-world/tags/0.1.1-beta`. +func (r *Repository) GetRepositoryTag(_ context.Context, name utils.RepositoryTagName) (*artifactpb.RepositoryTag, error) { + repo, tagID, err := name.ExtractRepositoryAndID() + if err != nil { + return nil, err + } + + record := new(repositoryTag) + if result := r.db.Model(record). + Where("name = ?", repositoryTagName(repo, tagID)). + First(record); result.Error != nil { + + if result.Error == gorm.ErrRecordNotFound { + return nil, customerror.ErrNotFound + } + + return nil, result.Error + } + + return &artifactpb.RepositoryTag{ + Name: string(name), + Id: tagID, + Digest: record.Digest, + UpdateTime: timestamppb.New(record.UpdateTime), + }, nil +} + +// UpsertRepositoryTag stores the provided tag information in the database. The +// update timestamp will be generated on insertion. +func (r *Repository) UpsertRepositoryTag(_ context.Context, tag *artifactpb.RepositoryTag) (*artifactpb.RepositoryTag, error) { + repo, tagID, err := utils.RepositoryTagName(tag.GetName()).ExtractRepositoryAndID() + if err != nil { + return nil, err + } + + record := &repositoryTag{ + Name: repositoryTagName(repo, tagID), + Digest: tag.GetDigest(), + } + + updateOnConflict := clause.OnConflict{ + Columns: []clause.Column{{Name: "name"}}, + DoUpdates: clause.AssignmentColumns([]string{"digest"}), + } + if result := r.db.Clauses(updateOnConflict).Create(record); result.Error != nil { + return nil, result.Error + } + + return &artifactpb.RepositoryTag{ + Name: tag.GetName(), + Id: tag.GetId(), + Digest: record.Digest, + UpdateTime: timestamppb.New(record.UpdateTime), + }, nil +} diff --git a/pkg/service/repository.go b/pkg/service/repository.go deleted file mode 100644 index a1dd345..0000000 --- a/pkg/service/repository.go +++ /dev/null @@ -1,13 +0,0 @@ -package service - -import ( - "context" - - pb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" -) - -// Repository implements the storage functions for Artifact. -type Repository interface { - GetRepositoryTag(context.Context, RepositoryTagName) (*pb.RepositoryTag, error) - UpsertRepositoryTag(context.Context, *pb.RepositoryTag) (*pb.RepositoryTag, error) -} diff --git a/pkg/service/service.go b/pkg/service/service.go index 4ab1e3e..e844a5b 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -6,6 +6,9 @@ import ( "fmt" "strings" + "github.com/instill-ai/artifact-backend/pkg/customerror" + "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" ) @@ -16,13 +19,13 @@ const ( // Service implements the Artifact domain use cases. type Service struct { - repository Repository + repository repository.RepositoryI registryClient RegistryClient } // NewService initiates a service instance func NewService( - r Repository, + r repository.RepositoryI, rc RegistryClient, ) *Service { @@ -63,10 +66,10 @@ func (s *Service) ListRepositoryTags(ctx context.Context, req *pb.ListRepository tags := make([]*pb.RepositoryTag, 0, len(paginatedIDs)) for _, id := range paginatedIDs { - name := NewRepositoryTagName(repo, id) + name := utils.NewRepositoryTagName(repo, id) rt, err := s.repository.GetRepositoryTag(ctx, name) if err != nil { - if !errors.Is(err, ErrNotFound) { + if !errors.Is(err, customerror.ErrNotFound) { return nil, fmt.Errorf("failed to fetch tag %s: %w", id, err) } @@ -111,7 +114,7 @@ func pageInRange(page int32) int { // CreateRepositoryTag stores the tag information of a pushed repository // content. func (s *Service) CreateRepositoryTag(ctx context.Context, req *pb.CreateRepositoryTagRequest) (*pb.CreateRepositoryTagResponse, error) { - name := RepositoryTagName(req.GetTag().GetName()) + name := utils.RepositoryTagName(req.GetTag().GetName()) _, id, err := name.ExtractRepositoryAndID() if err != nil || id != req.GetTag().GetId() { return nil, fmt.Errorf("invalid tag name") diff --git a/pkg/service/service_test.go b/pkg/service/service_test.go index d189a3b..3ad7a4b 100644 --- a/pkg/service/service_test.go +++ b/pkg/service/service_test.go @@ -1,4 +1,4 @@ -package service_test +package service import ( "context" @@ -12,9 +12,10 @@ import ( qt "github.com/frankban/quicktest" + "github.com/instill-ai/artifact-backend/pkg/customerror" "github.com/instill-ai/artifact-backend/pkg/mock" - artifact "github.com/instill-ai/artifact-backend/pkg/service" + "github.com/instill-ai/artifact-backend/pkg/utils" artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha" ) @@ -118,7 +119,7 @@ func TestService_ListRepositoryTags(t *testing.T) { name: "ok - not found in repo", registryTags: tagIDs, repoTags: want[:2], - repoErr: fmt.Errorf("repo error: %w", artifact.ErrNotFound), + repoErr: fmt.Errorf("repo error: %w", customerror.ErrNotFound), wantTags: wantWithEmptyOptional[:2], }, { @@ -193,14 +194,14 @@ func TestService_ListRepositoryTags(t *testing.T) { Then(tc.registryTags, tc.registryErr) } - repository := mock.NewRepositoryMock(c) + repository := mock.NewRepositoryIMock(c) for _, repoTag := range tc.repoTags { - name := artifact.RepositoryTagName(repoTag.Name) + name := utils.RepositoryTagName(repoTag.Name) repository.GetRepositoryTagMock.When(minimock.AnyContext, name). Then(repoTag, tc.repoErr) } - s := artifact.NewService(repository, registry) + s := NewService(repository, registry) req := newReq(tc.in) resp, err := s.ListRepositoryTags(ctx, req) if tc.wantErr != "" { @@ -242,7 +243,7 @@ func TestService_CreateRepositoryTag(t *testing.T) { t.Name = "shake/home:1.3.0" req := &artifactpb.CreateRepositoryTagRequest{Tag: t} - s := artifact.NewService(nil, nil) + s := NewService(nil, nil) _, err := s.CreateRepositoryTag(ctx, req) c.Check(err, qt.ErrorMatches, "invalid tag name") }) @@ -252,7 +253,7 @@ func TestService_CreateRepositoryTag(t *testing.T) { t.Id = "latest" req := &artifactpb.CreateRepositoryTagRequest{Tag: t} - s := artifact.NewService(nil, nil) + s := NewService(nil, nil) _, err := s.CreateRepositoryTag(ctx, req) c.Check(err, qt.ErrorMatches, "invalid tag name") }) @@ -262,19 +263,19 @@ func TestService_CreateRepositoryTag(t *testing.T) { clearedTag.UpdateTime = nil c.Run("nok - repo error", func(c *qt.C) { - repository := mock.NewRepositoryMock(c) + repository := mock.NewRepositoryIMock(c) repository.UpsertRepositoryTagMock.When(minimock.AnyContext, clearedTag).Then(nil, fmt.Errorf("foo")) - s := artifact.NewService(repository, nil) + s := NewService(repository, nil) _, err := s.CreateRepositoryTag(ctx, req) c.Check(err, qt.ErrorMatches, "failed to upsert tag .*: foo") }) c.Run("ok", func(c *qt.C) { - repository := mock.NewRepositoryMock(c) + repository := mock.NewRepositoryIMock(c) repository.UpsertRepositoryTagMock.When(minimock.AnyContext, clearedTag).Then(want, nil) - s := artifact.NewService(repository, nil) + s := NewService(repository, nil) resp, err := s.CreateRepositoryTag(ctx, req) c.Check(err, qt.IsNil) c.Check(resp.GetTag(), cmpPB, want) diff --git a/pkg/service/tag.go b/pkg/utils/tag.go similarity index 98% rename from pkg/service/tag.go rename to pkg/utils/tag.go index 5582518..cc47667 100644 --- a/pkg/service/tag.go +++ b/pkg/utils/tag.go @@ -1,4 +1,4 @@ -package service +package utils import ( "fmt" diff --git a/pkg/service/tag_test.go b/pkg/utils/tag_test.go similarity index 74% rename from pkg/service/tag_test.go rename to pkg/utils/tag_test.go index d7cbe2d..51a421f 100644 --- a/pkg/service/tag_test.go +++ b/pkg/utils/tag_test.go @@ -1,12 +1,10 @@ -package service_test +package utils import ( "fmt" "testing" qt "github.com/frankban/quicktest" - - artifact "github.com/instill-ai/artifact-backend/pkg/service" ) func TestRepositoryTagName_ExtractRepositoryAndID(t *testing.T) { @@ -21,7 +19,7 @@ func TestRepositoryTagName_ExtractRepositoryAndID(t *testing.T) { } for _, pair := range validPairs { c.Run(fmt.Sprintf("ok - %s:%s", pair.repo, pair.id), func(c *qt.C) { - name := artifact.NewRepositoryTagName(pair.repo, pair.id) + name := NewRepositoryTagName(pair.repo, pair.id) repo, id, err := name.ExtractRepositoryAndID() c.Check(err, qt.IsNil) c.Check(repo, qt.Equals, pair.repo) @@ -29,7 +27,7 @@ func TestRepositoryTagName_ExtractRepositoryAndID(t *testing.T) { }) } - invalid := []artifact.RepositoryTagName{ + invalid := []RepositoryTagName{ "repositories/connan-wombat/tags/latest", "repository/connan-wombat/mockasin/tags/latest", "connan-wombat/mockasin:latest", @@ -47,7 +45,7 @@ func TestRepositoryTagName_ExtractRepositoryAndID(t *testing.T) { func TestNewRepositoryTagName(t *testing.T) { c := qt.New(t) - got := artifact.NewRepositoryTagName("connan-wombat/mockasin", "latest") - want := artifact.RepositoryTagName("repositories/connan-wombat/mockasin/tags/latest") + got := NewRepositoryTagName("connan-wombat/mockasin", "latest") + want := RepositoryTagName("repositories/connan-wombat/mockasin/tags/latest") c.Check(got, qt.Equals, want) } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 2f90509..5a22565 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -1,11 +1,13 @@ package utils -import "strings" +import ( + "strings" +) const ( - CreateEvent string = "Create" - UpdateEvent string = "Update" - DeleteEvent string = "Delete" + CreateEvent string = "Create" + UpdateEvent string = "Update" + DeleteEvent string = "Delete" ) func IsAuditEvent(eventName string) bool {