From 96e630f1a2dbc744dcca3d6834ebed51965bb658 Mon Sep 17 00:00:00 2001 From: yiling Date: Thu, 5 Dec 2024 16:29:45 +0800 Subject: [PATCH 1/2] refactor and add some component tests --- .gitlab-ci.yml | 140 +- .golangci.yaml | 16 +- .mockery.yaml | 74 +- .../accounting/mock_AccountingClient.go | 93 + .../builder/deploy/mock_Deployer.go | 890 ++++++++ .../builder/git/gitserver/mock_GitServer.go | 2 +- .../git/membership/mock_GitMemerShip.go | 2 +- .../git/mirrorserver/mock_MirrorServer.go | 247 ++ .../builder/inference/mock_Client.go | 150 ++ .../builder/rpc/mock_ModerationSvcClient.go | 209 ++ .../builder/rpc/mock_UserSvcClient.go | 2 +- .../builder/sensitive/mock_Green2022Client.go | 2 +- .../builder/sensitive/mock_GreenClient.go | 2 +- .../sensitive/mock_SensitiveChecker.go | 158 ++ .../store/database/mock_AccessTokenStore.go | 613 +++++ .../database/mock_AccountMeteringStore.go | 2 +- .../store/database/mock_ClusterInfoStore.go | 304 +++ .../builder/store/database/mock_CodeStore.go | 633 ++++++ .../store/database/mock_CollectionStore.go | 827 +++++++ .../store/database/mock_DatasetStore.go | 2 +- .../store/database/mock_DeployTaskStore.go | 1183 ++++++++++ .../store/database/mock_DiscussionStore.go | 582 +++++ .../builder/store/database/mock_EventStore.go | 131 ++ .../builder/store/database/mock_FileStore.go | 144 ++ .../mock_GitServerAccessTokenStore.go | 213 ++ .../store/database/mock_LLMConfigStore.go | 2 +- .../store/database/mock_LfsLockStore.go | 323 +++ .../store/database/mock_LfsMetaObjectStore.go | 369 +++ .../store/database/mock_MemberStore.go | 2 +- .../store/database/mock_MirrorSourceStore.go | 366 +++ .../store/database/mock_MirrorStore.go | 2 +- .../builder/store/database/mock_ModelStore.go | 2 +- .../store/database/mock_MultiSyncStore.go | 271 +++ .../store/database/mock_NamespaceStore.go | 10 +- .../builder/store/database/mock_OrgStore.go | 2 +- .../database/mock_PromptConversationStore.go | 2 +- .../store/database/mock_PromptPrefixStore.go | 2 +- .../store/database/mock_PromptStore.go | 2 +- .../builder/store/database/mock_RecomStore.go | 309 +++ .../store/database/mock_RepoFileCheckStore.go | 131 ++ .../store/database/mock_RepoFileStore.go | 324 +++ .../store/database/mock_RepoRelationsStore.go | 265 +++ .../builder/store/database/mock_RepoStore.go | 2 +- .../mock_RepositoriesRuntimeFrameworkStore.go | 481 ++++ .../store/database/mock_ResourceModelStore.go | 156 ++ .../mock_RuntimeArchitecturesStore.go | 430 ++++ .../database/mock_RuntimeFrameworksStore.go | 603 +++++ .../store/database/mock_SSHKeyStore.go | 557 +++++ .../store/database/mock_SelectOption.go | 69 + .../store/database/mock_SpaceResourceStore.go | 2 +- .../store/database/mock_SpaceSdkStore.go | 319 +++ .../builder/store/database/mock_SpaceStore.go | 692 ++++++ .../database/mock_SyncClientSettingStore.go | 256 +++ .../store/database/mock_SyncVersionStore.go | 252 ++ .../builder/store/database/mock_TagStore.go | 2 +- .../store/database/mock_TelemetryStore.go | 84 + .../store/database/mock_UserLikesStore.go | 2 +- .../builder/store/database/mock_UserStore.go | 2 +- .../builder/store/s3/mock_Client.go | 335 +++ .../common/types/mock_SensitiveRequestV2.go | 82 + .../component/mock_AccountingComponent.go | 96 + .../component/mock_RepoComponent.go | 165 +- .../mock_RuntimeArchitectureComponent.go | 516 +++++ .../component/mock_SpaceComponent.go | 1029 +++++++++ .../component/mock_TagComponent.go | 309 +++ .../mirror/queue/mock_PriorityQueue.go | 195 ++ .../csghub-server/mq/mock_MessageQueue.go | 618 +++++ .../user/component/mock_MemberComponent.go | 2 +- api/router/api.go | 4 +- builder/accounting/client.go | 21 +- builder/deploy/scheduler/builder_runner.go | 6 +- builder/deploy/scheduler/deploy_runner.go | 10 +- builder/git/membership/gitea/member.go | 2 +- builder/inference/llm_infer.go | 1 + builder/multisync/client.go | 5 + builder/rpc/http_client.go | 2 + builder/store/database/common.go | 2 +- builder/store/database/lfs.go | 2 +- .../store/database/runtime_architecture.go | 2 +- builder/store/s3/minio.go | 25 +- builder/store/s3/minio_test.go | 2 +- cmd/csghub-server/cmd/cron/gen_telemetry.go | 1 + .../cmd/git/generate_lfs_meta_objects.go | 4 +- common/tests/stores.go | 156 +- common/types/user.go | 2 +- component/accounting.go | 16 +- component/accounting_test.go | 29 + component/code.go | 4 +- component/collection.go | 2 +- component/dataset.go | 8 +- component/git_http.go | 12 +- component/internal.go | 2 +- component/mirror.go | 8 +- component/model.go | 208 +- component/model_test.go | 699 +++++- component/prompt.go | 4 +- component/prompt_test.go | 344 +-- component/repo.go | 351 +-- component/repo_test.go | 2025 +++++++++++++++++ component/runtime_architecture.go | 16 +- component/space.go | 119 +- component/space_test.go | 519 +++++ component/tagparser/tag_processor.go | 2 +- component/tagparser/tag_processor_test.go | 2 +- component/user.go | 144 +- component/user_test.go | 481 ++++ component/wire.go | 107 + component/wire_gen.go | 330 +++ component/wireset.go | 278 +++ go.mod | 1 + go.sum | 18 + mirror/lfssyncer/minio.go | 6 +- mirror/prioriy_queue.go | 2 +- mirror/queue/queue.go | 25 +- mirror/reposyncer/local_woker.go | 2 +- servicerunner/handler/k8s.go | 4 +- user/component/member.go | 6 +- user/component/user.go | 4 +- 118 files changed, 21403 insertions(+), 883 deletions(-) create mode 100644 _mocks/opencsg.com/csghub-server/builder/accounting/mock_AccountingClient.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/deploy/mock_Deployer.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/git/mirrorserver/mock_MirrorServer.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/inference/mock_Client.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/rpc/mock_ModerationSvcClient.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/sensitive/mock_SensitiveChecker.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_AccessTokenStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_ClusterInfoStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_CodeStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_CollectionStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_DeployTaskStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_DiscussionStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_EventStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_FileStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_GitServerAccessTokenStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_LfsLockStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_LfsMetaObjectStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorSourceStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_MultiSyncStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_RecomStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoFileCheckStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoFileStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoRelationsStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_RepositoriesRuntimeFrameworkStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_ResourceModelStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_RuntimeArchitecturesStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_RuntimeFrameworksStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_SSHKeyStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_SelectOption.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceSdkStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_SyncClientSettingStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_SyncVersionStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/database/mock_TelemetryStore.go create mode 100644 _mocks/opencsg.com/csghub-server/builder/store/s3/mock_Client.go create mode 100644 _mocks/opencsg.com/csghub-server/common/types/mock_SensitiveRequestV2.go create mode 100644 _mocks/opencsg.com/csghub-server/component/mock_AccountingComponent.go create mode 100644 _mocks/opencsg.com/csghub-server/component/mock_RuntimeArchitectureComponent.go create mode 100644 _mocks/opencsg.com/csghub-server/component/mock_SpaceComponent.go create mode 100644 _mocks/opencsg.com/csghub-server/component/mock_TagComponent.go create mode 100644 _mocks/opencsg.com/csghub-server/mirror/queue/mock_PriorityQueue.go create mode 100644 _mocks/opencsg.com/csghub-server/mq/mock_MessageQueue.go create mode 100644 component/accounting_test.go create mode 100644 component/repo_test.go create mode 100644 component/space_test.go create mode 100644 component/user_test.go create mode 100644 component/wire.go create mode 100644 component/wire_gen.go create mode 100644 component/wireset.go diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 15ef455a..8c0f39f4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,60 +1,134 @@ -default: - image: docker:latest - stages: + - lint - test - build - deploy variables: - IMAGE_NAME: "csghub-server" - IMAGE_TAG: "latest" SAST_IMAGE_SUFFIX: '-fips' - DOCKER_HOST: tcp://docker:2375 + DOCKER_HOST: "tcp://docker:2375" DOCKER_TLS_CERTDIR: "" + GOLANGCI_LINT_CACHE: ${CI_PROJECT_DIR}/.golangci-lint + GOMODCACHE: ${CI_PROJECT_DIR}/.cache/go-mod + GOCACHE: ${CI_PROJECT_DIR}/.cache/go-build + TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX: opencsg-registry.cn-beijing.cr.aliyuncs.com/opencsg_public + TESTCONTAINERS_RYUK_DISABLED: true + +cache: + paths: + - .golangci-lint/ + - .cache/ include: - template: Jobs/Secret-Detection.gitlab-ci.yml +.before_script: &pre + image: docker:27.3 + stage: build + services: + - name: docker:27.3-dind + command: [ "--feature=containerd-snapshotter", "--experimental" ] + variables: + BUILDX_NO_DEFAULT_ATTESTATIONS: 1 + before_script: + - echo "$CI_REGISTRY_PASSWORD" | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin + - docker run --privileged --rm opencsg-registry.cn-beijing.cr.aliyuncs.com/opencsg_public/tonistiigi/binfmt --install all + +lint: + image: opencsg-registry.cn-beijing.cr.aliyuncs.com/opencsg_public/golangci/golangci-lint:v1.62.0 + stage: lint + interruptible: true + needs: [] + script: + - go env -w GO111MODULE=on + - go env -w GOPROXY=https://goproxy.cn,direct + - golangci-lint run --timeout=10m + test: stage: test - image: golang:1.21.0 + interruptible: true + image: $CI_REGISTRY_IMAGE/docker-golang:1.21.0 + needs: [] + services: + - name: docker:27.3-dind script: - go env -w GO111MODULE=on - go env -w GOPROXY=https://goproxy.cn,direct - - go build -o starhub ./cmd/csghub-server - except: - - main + - go test -coverprofile=coverage.out ./... + - go tool cover -html=coverage.out -o coverage.html + artifacts: + paths: + - coverage.out + - coverage.html + expire_in: 1 week -build_server_image:commit: - image: docker:24.0.6 +build:stg:amd64: + image: docker:27.3 stage: build services: - - docker:24.0.6-dind - variables: - IMAGE_TAG: "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" - LATEST_IMAGE_TAG: "$CI_REGISTRY_IMAGE:latest" + - docker:27.3-dind + script: + - echo "$CI_REGISTRY_PASSWORD" | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin + - docker build -t ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} -t ${CI_REGISTRY_IMAGE}:latest -f docker/Dockerfile . + - docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} + - docker push ${CI_REGISTRY_IMAGE}:latest + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_BRANCH == $CI_COMMIT_REF_NAME # when commit to main branch + + +.build:stg:arm64: + <<: *pre script: - - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - - docker build -t $IMAGE_TAG -f docker/Dockerfile . - - docker tag $IMAGE_TAG $LATEST_IMAGE_TAG - - docker push $IMAGE_TAG - - docker push $LATEST_IMAGE_TAG + - | + docker buildx build --platform linux/arm64 \ + -t ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} \ + -t ${CI_REGISTRY_IMAGE}:latest \ + -f docker/Dockerfile \ + --push . rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_BRANCH == $CI_COMMIT_REF_NAME # when commit to main branch - -build_server_image:tag: - image: docker:24.0.6 + +build:prod:amd64: + image: docker:27.3 stage: build services: - - docker:24.0.6-dind - only: - refs: - - tags - variables: - IMAGE_TAG: "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" + - docker:27.3-dind + script: + - echo "$CI_REGISTRY_PASSWORD" | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin + - docker build -t ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG} -t ${CI_REGISTRY_IMAGE}:latest -f docker/Dockerfile . + - docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG} + - docker push ${CI_REGISTRY_IMAGE}:latest + rules: + - if: $CI_COMMIT_TAG + +.build:prod:arm64: + <<: *pre + script: + - | + docker buildx build --platform linux/arm64 \ + -t ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG} \ + -t ${CI_REGISTRY_IMAGE}:latest \ + -f docker/Dockerfile \ + --push . + rules: + - if: $CI_COMMIT_TAG + +# trigger starhub-deploy project(only works for x86_64 arch) +trigger_deploy_stg: + stage: deploy + needs: ['build:stg:amd64'] + image: alpine:3.14 + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_BRANCH == $CI_COMMIT_REF_NAME script: - - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - - docker build -t $IMAGE_TAG -f docker/Dockerfile . - - docker push $IMAGE_TAG + - |- + sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories + apk add --no-cache curl + curl --fail-with-body \ + --request POST \ + --form "token=${STARHUB_DEPLOY_TRIGGER_TOKEN}" \ + --form ref=main \ + --form "variables[starhub_tag]=${CI_COMMIT_SHORT_SHA}" \ + --form "variables[ENV_NAME]=stg" \ + https://git-devops.opencsg.com/api/v4/projects/58/trigger/pipeline diff --git a/.golangci.yaml b/.golangci.yaml index a3f379d3..f2da1ff9 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,9 +1,19 @@ +linters: + disable-all: true + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - unused + + - misspell + - bodyclose + linters-settings: staticcheck: checks: ["all", "-SA1029"] - whitespace: - multi-if: true - multi-func: true govet: disable: - composites diff --git a/.mockery.yaml b/.mockery.yaml index d44e4206..9c3ab5e0 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -1,53 +1,43 @@ with-expecter: true dir: "_mocks/{{.PackagePath}}" +# new from v2.49.0, for more detail please refer to: +# https://github.com/vektra/mockery/commit/13fc60740a1eab3fc705fcc131a4b9a6eacfd0fe#diff-4bc8f03915f15ecf2cb9965592fcf933bb06986003613b5633a8dea7962c31a9R40 +resolve-type-alias: false packages: opencsg.com/csghub-server/component: config: interfaces: RepoComponent: + TagComponent: + AccountingComponent: + SpaceComponent: + RuntimeArchitectureComponent: opencsg.com/csghub-server/user/component: config: interfaces: MemberComponent: opencsg.com/csghub-server/builder/store/database: config: - interfaces: - UserStore: - NamespaceStore: - LicenseStore: - MirrorStore: - RepoStore: - OrgStore: - MemberStore: - ModelStore: - SpaceResourceStore: - TagStore: - DatasetStore: - PromptConversationStore: - PromptPrefixStore: - LLMConfigStore: - PromptStore: - UserLikesStore: - AccountStatementStore: - AccountOrderStore: - AccountPriceStore: - AccountBillStore: - AccountEventStore: - AccountMeteringStore: - AccountPresentStore: + all: True opencsg.com/csghub-server/builder/rpc: config: interfaces: UserSvcClient: + ModerationSvcClient: opencsg.com/csghub-server/builder/sensitive: config: interfaces: GreenClient: Green2022Client: + SensitiveChecker: opencsg.com/csghub-server/builder/git/gitserver: config: interfaces: GitServer: + opencsg.com/csghub-server/builder/git/mirrorserver: + config: + interfaces: + MirrorServer: opencsg.com/csghub-server/builder/git/membership: config: interfaces: @@ -60,3 +50,39 @@ packages: config: interfaces: Cache: + opencsg.com/csghub-server/common/types: + config: + interfaces: + SensitiveRequestV2: + opencsg.com/csghub-server/mq: + config: + interfaces: + MessageQueue: + opencsg.com/csghub-server/builder/store/s3: + config: + interfaces: + Client: + opencsg.com/csghub-server/mirror/queue: + config: + interfaces: + PriorityQueue: + opencsg.com/csghub-server/builder/deploy: + config: + interfaces: + Deployer: + opencsg.com/csghub-server/builder/inference: + config: + interfaces: + Client: + opencsg.com/csghub-server/accounting/component: + config: + interfaces: + AccountingUserComponent: + AccountingStatementComponent: + AccountingBillComponent: + AccountingPresentComponent: + opencsg.com/csghub-server/builder/accounting: + config: + interfaces: + AccountingClient: + diff --git a/_mocks/opencsg.com/csghub-server/builder/accounting/mock_AccountingClient.go b/_mocks/opencsg.com/csghub-server/builder/accounting/mock_AccountingClient.go new file mode 100644 index 00000000..5c2f70c1 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/accounting/mock_AccountingClient.go @@ -0,0 +1,93 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package accounting + +import ( + mock "github.com/stretchr/testify/mock" + types "opencsg.com/csghub-server/common/types" +) + +// MockAccountingClient is an autogenerated mock type for the AccountingClient type +type MockAccountingClient struct { + mock.Mock +} + +type MockAccountingClient_Expecter struct { + mock *mock.Mock +} + +func (_m *MockAccountingClient) EXPECT() *MockAccountingClient_Expecter { + return &MockAccountingClient_Expecter{mock: &_m.Mock} +} + +// ListMeteringsByUserIDAndTime provides a mock function with given fields: req +func (_m *MockAccountingClient) ListMeteringsByUserIDAndTime(req types.ACCT_STATEMENTS_REQ) (any, error) { + ret := _m.Called(req) + + if len(ret) == 0 { + panic("no return value specified for ListMeteringsByUserIDAndTime") + } + + var r0 any + var r1 error + if rf, ok := ret.Get(0).(func(types.ACCT_STATEMENTS_REQ) (any, error)); ok { + return rf(req) + } + if rf, ok := ret.Get(0).(func(types.ACCT_STATEMENTS_REQ) any); ok { + r0 = rf(req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(any) + } + } + + if rf, ok := ret.Get(1).(func(types.ACCT_STATEMENTS_REQ) error); ok { + r1 = rf(req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockAccountingClient_ListMeteringsByUserIDAndTime_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListMeteringsByUserIDAndTime' +type MockAccountingClient_ListMeteringsByUserIDAndTime_Call struct { + *mock.Call +} + +// ListMeteringsByUserIDAndTime is a helper method to define mock.On call +// - req types.ACCT_STATEMENTS_REQ +func (_e *MockAccountingClient_Expecter) ListMeteringsByUserIDAndTime(req interface{}) *MockAccountingClient_ListMeteringsByUserIDAndTime_Call { + return &MockAccountingClient_ListMeteringsByUserIDAndTime_Call{Call: _e.mock.On("ListMeteringsByUserIDAndTime", req)} +} + +func (_c *MockAccountingClient_ListMeteringsByUserIDAndTime_Call) Run(run func(req types.ACCT_STATEMENTS_REQ)) *MockAccountingClient_ListMeteringsByUserIDAndTime_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(types.ACCT_STATEMENTS_REQ)) + }) + return _c +} + +func (_c *MockAccountingClient_ListMeteringsByUserIDAndTime_Call) Return(_a0 any, _a1 error) *MockAccountingClient_ListMeteringsByUserIDAndTime_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockAccountingClient_ListMeteringsByUserIDAndTime_Call) RunAndReturn(run func(types.ACCT_STATEMENTS_REQ) (any, error)) *MockAccountingClient_ListMeteringsByUserIDAndTime_Call { + _c.Call.Return(run) + return _c +} + +// NewMockAccountingClient creates a new instance of MockAccountingClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockAccountingClient(t interface { + mock.TestingT + Cleanup(func()) +}) *MockAccountingClient { + mock := &MockAccountingClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/deploy/mock_Deployer.go b/_mocks/opencsg.com/csghub-server/builder/deploy/mock_Deployer.go new file mode 100644 index 00000000..2f067af4 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/deploy/mock_Deployer.go @@ -0,0 +1,890 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package deploy + +import ( + context "context" + + deploy "opencsg.com/csghub-server/builder/deploy" + database "opencsg.com/csghub-server/builder/store/database" + + mock "github.com/stretchr/testify/mock" + + types "opencsg.com/csghub-server/common/types" +) + +// MockDeployer is an autogenerated mock type for the Deployer type +type MockDeployer struct { + mock.Mock +} + +type MockDeployer_Expecter struct { + mock *mock.Mock +} + +func (_m *MockDeployer) EXPECT() *MockDeployer_Expecter { + return &MockDeployer_Expecter{mock: &_m.Mock} +} + +// CheckResourceAvailable provides a mock function with given fields: ctx, clusterId, hardWare +func (_m *MockDeployer) CheckResourceAvailable(ctx context.Context, clusterId string, hardWare *types.HardWare) (bool, error) { + ret := _m.Called(ctx, clusterId, hardWare) + + if len(ret) == 0 { + panic("no return value specified for CheckResourceAvailable") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, *types.HardWare) (bool, error)); ok { + return rf(ctx, clusterId, hardWare) + } + if rf, ok := ret.Get(0).(func(context.Context, string, *types.HardWare) bool); ok { + r0 = rf(ctx, clusterId, hardWare) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, *types.HardWare) error); ok { + r1 = rf(ctx, clusterId, hardWare) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployer_CheckResourceAvailable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckResourceAvailable' +type MockDeployer_CheckResourceAvailable_Call struct { + *mock.Call +} + +// CheckResourceAvailable is a helper method to define mock.On call +// - ctx context.Context +// - clusterId string +// - hardWare *types.HardWare +func (_e *MockDeployer_Expecter) CheckResourceAvailable(ctx interface{}, clusterId interface{}, hardWare interface{}) *MockDeployer_CheckResourceAvailable_Call { + return &MockDeployer_CheckResourceAvailable_Call{Call: _e.mock.On("CheckResourceAvailable", ctx, clusterId, hardWare)} +} + +func (_c *MockDeployer_CheckResourceAvailable_Call) Run(run func(ctx context.Context, clusterId string, hardWare *types.HardWare)) *MockDeployer_CheckResourceAvailable_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(*types.HardWare)) + }) + return _c +} + +func (_c *MockDeployer_CheckResourceAvailable_Call) Return(_a0 bool, _a1 error) *MockDeployer_CheckResourceAvailable_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployer_CheckResourceAvailable_Call) RunAndReturn(run func(context.Context, string, *types.HardWare) (bool, error)) *MockDeployer_CheckResourceAvailable_Call { + _c.Call.Return(run) + return _c +} + +// Deploy provides a mock function with given fields: ctx, dr +func (_m *MockDeployer) Deploy(ctx context.Context, dr types.DeployRepo) (int64, error) { + ret := _m.Called(ctx, dr) + + if len(ret) == 0 { + panic("no return value specified for Deploy") + } + + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) (int64, error)); ok { + return rf(ctx, dr) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) int64); ok { + r0 = rf(ctx, dr) + } else { + r0 = ret.Get(0).(int64) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployRepo) error); ok { + r1 = rf(ctx, dr) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployer_Deploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Deploy' +type MockDeployer_Deploy_Call struct { + *mock.Call +} + +// Deploy is a helper method to define mock.On call +// - ctx context.Context +// - dr types.DeployRepo +func (_e *MockDeployer_Expecter) Deploy(ctx interface{}, dr interface{}) *MockDeployer_Deploy_Call { + return &MockDeployer_Deploy_Call{Call: _e.mock.On("Deploy", ctx, dr)} +} + +func (_c *MockDeployer_Deploy_Call) Run(run func(ctx context.Context, dr types.DeployRepo)) *MockDeployer_Deploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployRepo)) + }) + return _c +} + +func (_c *MockDeployer_Deploy_Call) Return(deployID int64, err error) *MockDeployer_Deploy_Call { + _c.Call.Return(deployID, err) + return _c +} + +func (_c *MockDeployer_Deploy_Call) RunAndReturn(run func(context.Context, types.DeployRepo) (int64, error)) *MockDeployer_Deploy_Call { + _c.Call.Return(run) + return _c +} + +// Exist provides a mock function with given fields: ctx, dr +func (_m *MockDeployer) Exist(ctx context.Context, dr types.DeployRepo) (bool, error) { + ret := _m.Called(ctx, dr) + + if len(ret) == 0 { + panic("no return value specified for Exist") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) (bool, error)); ok { + return rf(ctx, dr) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) bool); ok { + r0 = rf(ctx, dr) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployRepo) error); ok { + r1 = rf(ctx, dr) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployer_Exist_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Exist' +type MockDeployer_Exist_Call struct { + *mock.Call +} + +// Exist is a helper method to define mock.On call +// - ctx context.Context +// - dr types.DeployRepo +func (_e *MockDeployer_Expecter) Exist(ctx interface{}, dr interface{}) *MockDeployer_Exist_Call { + return &MockDeployer_Exist_Call{Call: _e.mock.On("Exist", ctx, dr)} +} + +func (_c *MockDeployer_Exist_Call) Run(run func(ctx context.Context, dr types.DeployRepo)) *MockDeployer_Exist_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployRepo)) + }) + return _c +} + +func (_c *MockDeployer_Exist_Call) Return(_a0 bool, _a1 error) *MockDeployer_Exist_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployer_Exist_Call) RunAndReturn(run func(context.Context, types.DeployRepo) (bool, error)) *MockDeployer_Exist_Call { + _c.Call.Return(run) + return _c +} + +// GetClusterById provides a mock function with given fields: ctx, clusterId +func (_m *MockDeployer) GetClusterById(ctx context.Context, clusterId string) (*types.ClusterRes, error) { + ret := _m.Called(ctx, clusterId) + + if len(ret) == 0 { + panic("no return value specified for GetClusterById") + } + + var r0 *types.ClusterRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*types.ClusterRes, error)); ok { + return rf(ctx, clusterId) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *types.ClusterRes); ok { + r0 = rf(ctx, clusterId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.ClusterRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, clusterId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployer_GetClusterById_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetClusterById' +type MockDeployer_GetClusterById_Call struct { + *mock.Call +} + +// GetClusterById is a helper method to define mock.On call +// - ctx context.Context +// - clusterId string +func (_e *MockDeployer_Expecter) GetClusterById(ctx interface{}, clusterId interface{}) *MockDeployer_GetClusterById_Call { + return &MockDeployer_GetClusterById_Call{Call: _e.mock.On("GetClusterById", ctx, clusterId)} +} + +func (_c *MockDeployer_GetClusterById_Call) Run(run func(ctx context.Context, clusterId string)) *MockDeployer_GetClusterById_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockDeployer_GetClusterById_Call) Return(_a0 *types.ClusterRes, _a1 error) *MockDeployer_GetClusterById_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployer_GetClusterById_Call) RunAndReturn(run func(context.Context, string) (*types.ClusterRes, error)) *MockDeployer_GetClusterById_Call { + _c.Call.Return(run) + return _c +} + +// GetReplica provides a mock function with given fields: ctx, dr +func (_m *MockDeployer) GetReplica(ctx context.Context, dr types.DeployRepo) (int, int, []types.Instance, error) { + ret := _m.Called(ctx, dr) + + if len(ret) == 0 { + panic("no return value specified for GetReplica") + } + + var r0 int + var r1 int + var r2 []types.Instance + var r3 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) (int, int, []types.Instance, error)); ok { + return rf(ctx, dr) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) int); ok { + r0 = rf(ctx, dr) + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployRepo) int); ok { + r1 = rf(ctx, dr) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, types.DeployRepo) []types.Instance); ok { + r2 = rf(ctx, dr) + } else { + if ret.Get(2) != nil { + r2 = ret.Get(2).([]types.Instance) + } + } + + if rf, ok := ret.Get(3).(func(context.Context, types.DeployRepo) error); ok { + r3 = rf(ctx, dr) + } else { + r3 = ret.Error(3) + } + + return r0, r1, r2, r3 +} + +// MockDeployer_GetReplica_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetReplica' +type MockDeployer_GetReplica_Call struct { + *mock.Call +} + +// GetReplica is a helper method to define mock.On call +// - ctx context.Context +// - dr types.DeployRepo +func (_e *MockDeployer_Expecter) GetReplica(ctx interface{}, dr interface{}) *MockDeployer_GetReplica_Call { + return &MockDeployer_GetReplica_Call{Call: _e.mock.On("GetReplica", ctx, dr)} +} + +func (_c *MockDeployer_GetReplica_Call) Run(run func(ctx context.Context, dr types.DeployRepo)) *MockDeployer_GetReplica_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployRepo)) + }) + return _c +} + +func (_c *MockDeployer_GetReplica_Call) Return(_a0 int, _a1 int, _a2 []types.Instance, _a3 error) *MockDeployer_GetReplica_Call { + _c.Call.Return(_a0, _a1, _a2, _a3) + return _c +} + +func (_c *MockDeployer_GetReplica_Call) RunAndReturn(run func(context.Context, types.DeployRepo) (int, int, []types.Instance, error)) *MockDeployer_GetReplica_Call { + _c.Call.Return(run) + return _c +} + +// InstanceLogs provides a mock function with given fields: ctx, dr +func (_m *MockDeployer) InstanceLogs(ctx context.Context, dr types.DeployRepo) (*deploy.MultiLogReader, error) { + ret := _m.Called(ctx, dr) + + if len(ret) == 0 { + panic("no return value specified for InstanceLogs") + } + + var r0 *deploy.MultiLogReader + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) (*deploy.MultiLogReader, error)); ok { + return rf(ctx, dr) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) *deploy.MultiLogReader); ok { + r0 = rf(ctx, dr) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*deploy.MultiLogReader) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployRepo) error); ok { + r1 = rf(ctx, dr) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployer_InstanceLogs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'InstanceLogs' +type MockDeployer_InstanceLogs_Call struct { + *mock.Call +} + +// InstanceLogs is a helper method to define mock.On call +// - ctx context.Context +// - dr types.DeployRepo +func (_e *MockDeployer_Expecter) InstanceLogs(ctx interface{}, dr interface{}) *MockDeployer_InstanceLogs_Call { + return &MockDeployer_InstanceLogs_Call{Call: _e.mock.On("InstanceLogs", ctx, dr)} +} + +func (_c *MockDeployer_InstanceLogs_Call) Run(run func(ctx context.Context, dr types.DeployRepo)) *MockDeployer_InstanceLogs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployRepo)) + }) + return _c +} + +func (_c *MockDeployer_InstanceLogs_Call) Return(_a0 *deploy.MultiLogReader, _a1 error) *MockDeployer_InstanceLogs_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployer_InstanceLogs_Call) RunAndReturn(run func(context.Context, types.DeployRepo) (*deploy.MultiLogReader, error)) *MockDeployer_InstanceLogs_Call { + _c.Call.Return(run) + return _c +} + +// ListCluster provides a mock function with given fields: ctx +func (_m *MockDeployer) ListCluster(ctx context.Context) ([]types.ClusterRes, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ListCluster") + } + + var r0 []types.ClusterRes + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]types.ClusterRes, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []types.ClusterRes); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.ClusterRes) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployer_ListCluster_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListCluster' +type MockDeployer_ListCluster_Call struct { + *mock.Call +} + +// ListCluster is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockDeployer_Expecter) ListCluster(ctx interface{}) *MockDeployer_ListCluster_Call { + return &MockDeployer_ListCluster_Call{Call: _e.mock.On("ListCluster", ctx)} +} + +func (_c *MockDeployer_ListCluster_Call) Run(run func(ctx context.Context)) *MockDeployer_ListCluster_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockDeployer_ListCluster_Call) Return(_a0 []types.ClusterRes, _a1 error) *MockDeployer_ListCluster_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployer_ListCluster_Call) RunAndReturn(run func(context.Context) ([]types.ClusterRes, error)) *MockDeployer_ListCluster_Call { + _c.Call.Return(run) + return _c +} + +// Logs provides a mock function with given fields: ctx, dr +func (_m *MockDeployer) Logs(ctx context.Context, dr types.DeployRepo) (*deploy.MultiLogReader, error) { + ret := _m.Called(ctx, dr) + + if len(ret) == 0 { + panic("no return value specified for Logs") + } + + var r0 *deploy.MultiLogReader + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) (*deploy.MultiLogReader, error)); ok { + return rf(ctx, dr) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) *deploy.MultiLogReader); ok { + r0 = rf(ctx, dr) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*deploy.MultiLogReader) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployRepo) error); ok { + r1 = rf(ctx, dr) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployer_Logs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Logs' +type MockDeployer_Logs_Call struct { + *mock.Call +} + +// Logs is a helper method to define mock.On call +// - ctx context.Context +// - dr types.DeployRepo +func (_e *MockDeployer_Expecter) Logs(ctx interface{}, dr interface{}) *MockDeployer_Logs_Call { + return &MockDeployer_Logs_Call{Call: _e.mock.On("Logs", ctx, dr)} +} + +func (_c *MockDeployer_Logs_Call) Run(run func(ctx context.Context, dr types.DeployRepo)) *MockDeployer_Logs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployRepo)) + }) + return _c +} + +func (_c *MockDeployer_Logs_Call) Return(_a0 *deploy.MultiLogReader, _a1 error) *MockDeployer_Logs_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployer_Logs_Call) RunAndReturn(run func(context.Context, types.DeployRepo) (*deploy.MultiLogReader, error)) *MockDeployer_Logs_Call { + _c.Call.Return(run) + return _c +} + +// Purge provides a mock function with given fields: ctx, dr +func (_m *MockDeployer) Purge(ctx context.Context, dr types.DeployRepo) error { + ret := _m.Called(ctx, dr) + + if len(ret) == 0 { + panic("no return value specified for Purge") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) error); ok { + r0 = rf(ctx, dr) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployer_Purge_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Purge' +type MockDeployer_Purge_Call struct { + *mock.Call +} + +// Purge is a helper method to define mock.On call +// - ctx context.Context +// - dr types.DeployRepo +func (_e *MockDeployer_Expecter) Purge(ctx interface{}, dr interface{}) *MockDeployer_Purge_Call { + return &MockDeployer_Purge_Call{Call: _e.mock.On("Purge", ctx, dr)} +} + +func (_c *MockDeployer_Purge_Call) Run(run func(ctx context.Context, dr types.DeployRepo)) *MockDeployer_Purge_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployRepo)) + }) + return _c +} + +func (_c *MockDeployer_Purge_Call) Return(err error) *MockDeployer_Purge_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockDeployer_Purge_Call) RunAndReturn(run func(context.Context, types.DeployRepo) error) *MockDeployer_Purge_Call { + _c.Call.Return(run) + return _c +} + +// StartDeploy provides a mock function with given fields: ctx, _a1 +func (_m *MockDeployer) StartDeploy(ctx context.Context, _a1 *database.Deploy) error { + ret := _m.Called(ctx, _a1) + + if len(ret) == 0 { + panic("no return value specified for StartDeploy") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Deploy) error); ok { + r0 = rf(ctx, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployer_StartDeploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'StartDeploy' +type MockDeployer_StartDeploy_Call struct { + *mock.Call +} + +// StartDeploy is a helper method to define mock.On call +// - ctx context.Context +// - _a1 *database.Deploy +func (_e *MockDeployer_Expecter) StartDeploy(ctx interface{}, _a1 interface{}) *MockDeployer_StartDeploy_Call { + return &MockDeployer_StartDeploy_Call{Call: _e.mock.On("StartDeploy", ctx, _a1)} +} + +func (_c *MockDeployer_StartDeploy_Call) Run(run func(ctx context.Context, _a1 *database.Deploy)) *MockDeployer_StartDeploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Deploy)) + }) + return _c +} + +func (_c *MockDeployer_StartDeploy_Call) Return(_a0 error) *MockDeployer_StartDeploy_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDeployer_StartDeploy_Call) RunAndReturn(run func(context.Context, *database.Deploy) error) *MockDeployer_StartDeploy_Call { + _c.Call.Return(run) + return _c +} + +// Status provides a mock function with given fields: ctx, dr, needDetails +func (_m *MockDeployer) Status(ctx context.Context, dr types.DeployRepo, needDetails bool) (string, int, []types.Instance, error) { + ret := _m.Called(ctx, dr, needDetails) + + if len(ret) == 0 { + panic("no return value specified for Status") + } + + var r0 string + var r1 int + var r2 []types.Instance + var r3 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo, bool) (string, int, []types.Instance, error)); ok { + return rf(ctx, dr, needDetails) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo, bool) string); ok { + r0 = rf(ctx, dr, needDetails) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployRepo, bool) int); ok { + r1 = rf(ctx, dr, needDetails) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, types.DeployRepo, bool) []types.Instance); ok { + r2 = rf(ctx, dr, needDetails) + } else { + if ret.Get(2) != nil { + r2 = ret.Get(2).([]types.Instance) + } + } + + if rf, ok := ret.Get(3).(func(context.Context, types.DeployRepo, bool) error); ok { + r3 = rf(ctx, dr, needDetails) + } else { + r3 = ret.Error(3) + } + + return r0, r1, r2, r3 +} + +// MockDeployer_Status_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Status' +type MockDeployer_Status_Call struct { + *mock.Call +} + +// Status is a helper method to define mock.On call +// - ctx context.Context +// - dr types.DeployRepo +// - needDetails bool +func (_e *MockDeployer_Expecter) Status(ctx interface{}, dr interface{}, needDetails interface{}) *MockDeployer_Status_Call { + return &MockDeployer_Status_Call{Call: _e.mock.On("Status", ctx, dr, needDetails)} +} + +func (_c *MockDeployer_Status_Call) Run(run func(ctx context.Context, dr types.DeployRepo, needDetails bool)) *MockDeployer_Status_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployRepo), args[2].(bool)) + }) + return _c +} + +func (_c *MockDeployer_Status_Call) Return(srvName string, status int, instances []types.Instance, err error) *MockDeployer_Status_Call { + _c.Call.Return(srvName, status, instances, err) + return _c +} + +func (_c *MockDeployer_Status_Call) RunAndReturn(run func(context.Context, types.DeployRepo, bool) (string, int, []types.Instance, error)) *MockDeployer_Status_Call { + _c.Call.Return(run) + return _c +} + +// Stop provides a mock function with given fields: ctx, dr +func (_m *MockDeployer) Stop(ctx context.Context, dr types.DeployRepo) error { + ret := _m.Called(ctx, dr) + + if len(ret) == 0 { + panic("no return value specified for Stop") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) error); ok { + r0 = rf(ctx, dr) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployer_Stop_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Stop' +type MockDeployer_Stop_Call struct { + *mock.Call +} + +// Stop is a helper method to define mock.On call +// - ctx context.Context +// - dr types.DeployRepo +func (_e *MockDeployer_Expecter) Stop(ctx interface{}, dr interface{}) *MockDeployer_Stop_Call { + return &MockDeployer_Stop_Call{Call: _e.mock.On("Stop", ctx, dr)} +} + +func (_c *MockDeployer_Stop_Call) Run(run func(ctx context.Context, dr types.DeployRepo)) *MockDeployer_Stop_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployRepo)) + }) + return _c +} + +func (_c *MockDeployer_Stop_Call) Return(err error) *MockDeployer_Stop_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockDeployer_Stop_Call) RunAndReturn(run func(context.Context, types.DeployRepo) error) *MockDeployer_Stop_Call { + _c.Call.Return(run) + return _c +} + +// UpdateCluster provides a mock function with given fields: ctx, data +func (_m *MockDeployer) UpdateCluster(ctx context.Context, data types.ClusterRequest) (*types.UpdateClusterResponse, error) { + ret := _m.Called(ctx, data) + + if len(ret) == 0 { + panic("no return value specified for UpdateCluster") + } + + var r0 *types.UpdateClusterResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.ClusterRequest) (*types.UpdateClusterResponse, error)); ok { + return rf(ctx, data) + } + if rf, ok := ret.Get(0).(func(context.Context, types.ClusterRequest) *types.UpdateClusterResponse); ok { + r0 = rf(ctx, data) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.UpdateClusterResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.ClusterRequest) error); ok { + r1 = rf(ctx, data) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployer_UpdateCluster_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateCluster' +type MockDeployer_UpdateCluster_Call struct { + *mock.Call +} + +// UpdateCluster is a helper method to define mock.On call +// - ctx context.Context +// - data types.ClusterRequest +func (_e *MockDeployer_Expecter) UpdateCluster(ctx interface{}, data interface{}) *MockDeployer_UpdateCluster_Call { + return &MockDeployer_UpdateCluster_Call{Call: _e.mock.On("UpdateCluster", ctx, data)} +} + +func (_c *MockDeployer_UpdateCluster_Call) Run(run func(ctx context.Context, data types.ClusterRequest)) *MockDeployer_UpdateCluster_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.ClusterRequest)) + }) + return _c +} + +func (_c *MockDeployer_UpdateCluster_Call) Return(_a0 *types.UpdateClusterResponse, _a1 error) *MockDeployer_UpdateCluster_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployer_UpdateCluster_Call) RunAndReturn(run func(context.Context, types.ClusterRequest) (*types.UpdateClusterResponse, error)) *MockDeployer_UpdateCluster_Call { + _c.Call.Return(run) + return _c +} + +// UpdateDeploy provides a mock function with given fields: ctx, dur, _a2 +func (_m *MockDeployer) UpdateDeploy(ctx context.Context, dur *types.DeployUpdateReq, _a2 *database.Deploy) error { + ret := _m.Called(ctx, dur, _a2) + + if len(ret) == 0 { + panic("no return value specified for UpdateDeploy") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *types.DeployUpdateReq, *database.Deploy) error); ok { + r0 = rf(ctx, dur, _a2) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployer_UpdateDeploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateDeploy' +type MockDeployer_UpdateDeploy_Call struct { + *mock.Call +} + +// UpdateDeploy is a helper method to define mock.On call +// - ctx context.Context +// - dur *types.DeployUpdateReq +// - _a2 *database.Deploy +func (_e *MockDeployer_Expecter) UpdateDeploy(ctx interface{}, dur interface{}, _a2 interface{}) *MockDeployer_UpdateDeploy_Call { + return &MockDeployer_UpdateDeploy_Call{Call: _e.mock.On("UpdateDeploy", ctx, dur, _a2)} +} + +func (_c *MockDeployer_UpdateDeploy_Call) Run(run func(ctx context.Context, dur *types.DeployUpdateReq, _a2 *database.Deploy)) *MockDeployer_UpdateDeploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.DeployUpdateReq), args[2].(*database.Deploy)) + }) + return _c +} + +func (_c *MockDeployer_UpdateDeploy_Call) Return(_a0 error) *MockDeployer_UpdateDeploy_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDeployer_UpdateDeploy_Call) RunAndReturn(run func(context.Context, *types.DeployUpdateReq, *database.Deploy) error) *MockDeployer_UpdateDeploy_Call { + _c.Call.Return(run) + return _c +} + +// Wakeup provides a mock function with given fields: ctx, dr +func (_m *MockDeployer) Wakeup(ctx context.Context, dr types.DeployRepo) error { + ret := _m.Called(ctx, dr) + + if len(ret) == 0 { + panic("no return value specified for Wakeup") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployRepo) error); ok { + r0 = rf(ctx, dr) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployer_Wakeup_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Wakeup' +type MockDeployer_Wakeup_Call struct { + *mock.Call +} + +// Wakeup is a helper method to define mock.On call +// - ctx context.Context +// - dr types.DeployRepo +func (_e *MockDeployer_Expecter) Wakeup(ctx interface{}, dr interface{}) *MockDeployer_Wakeup_Call { + return &MockDeployer_Wakeup_Call{Call: _e.mock.On("Wakeup", ctx, dr)} +} + +func (_c *MockDeployer_Wakeup_Call) Run(run func(ctx context.Context, dr types.DeployRepo)) *MockDeployer_Wakeup_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployRepo)) + }) + return _c +} + +func (_c *MockDeployer_Wakeup_Call) Return(err error) *MockDeployer_Wakeup_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockDeployer_Wakeup_Call) RunAndReturn(run func(context.Context, types.DeployRepo) error) *MockDeployer_Wakeup_Call { + _c.Call.Return(run) + return _c +} + +// NewMockDeployer creates a new instance of MockDeployer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockDeployer(t interface { + mock.TestingT + Cleanup(func()) +}) *MockDeployer { + mock := &MockDeployer{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/git/gitserver/mock_GitServer.go b/_mocks/opencsg.com/csghub-server/builder/git/gitserver/mock_GitServer.go index 31b4ba06..41dbe1f3 100644 --- a/_mocks/opencsg.com/csghub-server/builder/git/gitserver/mock_GitServer.go +++ b/_mocks/opencsg.com/csghub-server/builder/git/gitserver/mock_GitServer.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package gitserver diff --git a/_mocks/opencsg.com/csghub-server/builder/git/membership/mock_GitMemerShip.go b/_mocks/opencsg.com/csghub-server/builder/git/membership/mock_GitMemerShip.go index 00c051a1..c600efa4 100644 --- a/_mocks/opencsg.com/csghub-server/builder/git/membership/mock_GitMemerShip.go +++ b/_mocks/opencsg.com/csghub-server/builder/git/membership/mock_GitMemerShip.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package membership diff --git a/_mocks/opencsg.com/csghub-server/builder/git/mirrorserver/mock_MirrorServer.go b/_mocks/opencsg.com/csghub-server/builder/git/mirrorserver/mock_MirrorServer.go new file mode 100644 index 00000000..8dab0948 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/git/mirrorserver/mock_MirrorServer.go @@ -0,0 +1,247 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package mirrorserver + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + mirrorserver "opencsg.com/csghub-server/builder/git/mirrorserver" +) + +// MockMirrorServer is an autogenerated mock type for the MirrorServer type +type MockMirrorServer struct { + mock.Mock +} + +type MockMirrorServer_Expecter struct { + mock *mock.Mock +} + +func (_m *MockMirrorServer) EXPECT() *MockMirrorServer_Expecter { + return &MockMirrorServer_Expecter{mock: &_m.Mock} +} + +// CreateMirrorRepo provides a mock function with given fields: ctx, req +func (_m *MockMirrorServer) CreateMirrorRepo(ctx context.Context, req mirrorserver.CreateMirrorRepoReq) (int64, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for CreateMirrorRepo") + } + + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, mirrorserver.CreateMirrorRepoReq) (int64, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, mirrorserver.CreateMirrorRepoReq) int64); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Get(0).(int64) + } + + if rf, ok := ret.Get(1).(func(context.Context, mirrorserver.CreateMirrorRepoReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorServer_CreateMirrorRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateMirrorRepo' +type MockMirrorServer_CreateMirrorRepo_Call struct { + *mock.Call +} + +// CreateMirrorRepo is a helper method to define mock.On call +// - ctx context.Context +// - req mirrorserver.CreateMirrorRepoReq +func (_e *MockMirrorServer_Expecter) CreateMirrorRepo(ctx interface{}, req interface{}) *MockMirrorServer_CreateMirrorRepo_Call { + return &MockMirrorServer_CreateMirrorRepo_Call{Call: _e.mock.On("CreateMirrorRepo", ctx, req)} +} + +func (_c *MockMirrorServer_CreateMirrorRepo_Call) Run(run func(ctx context.Context, req mirrorserver.CreateMirrorRepoReq)) *MockMirrorServer_CreateMirrorRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(mirrorserver.CreateMirrorRepoReq)) + }) + return _c +} + +func (_c *MockMirrorServer_CreateMirrorRepo_Call) Return(_a0 int64, _a1 error) *MockMirrorServer_CreateMirrorRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorServer_CreateMirrorRepo_Call) RunAndReturn(run func(context.Context, mirrorserver.CreateMirrorRepoReq) (int64, error)) *MockMirrorServer_CreateMirrorRepo_Call { + _c.Call.Return(run) + return _c +} + +// CreatePushMirror provides a mock function with given fields: ctx, req +func (_m *MockMirrorServer) CreatePushMirror(ctx context.Context, req mirrorserver.CreatePushMirrorReq) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for CreatePushMirror") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, mirrorserver.CreatePushMirrorReq) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMirrorServer_CreatePushMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreatePushMirror' +type MockMirrorServer_CreatePushMirror_Call struct { + *mock.Call +} + +// CreatePushMirror is a helper method to define mock.On call +// - ctx context.Context +// - req mirrorserver.CreatePushMirrorReq +func (_e *MockMirrorServer_Expecter) CreatePushMirror(ctx interface{}, req interface{}) *MockMirrorServer_CreatePushMirror_Call { + return &MockMirrorServer_CreatePushMirror_Call{Call: _e.mock.On("CreatePushMirror", ctx, req)} +} + +func (_c *MockMirrorServer_CreatePushMirror_Call) Run(run func(ctx context.Context, req mirrorserver.CreatePushMirrorReq)) *MockMirrorServer_CreatePushMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(mirrorserver.CreatePushMirrorReq)) + }) + return _c +} + +func (_c *MockMirrorServer_CreatePushMirror_Call) Return(_a0 error) *MockMirrorServer_CreatePushMirror_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMirrorServer_CreatePushMirror_Call) RunAndReturn(run func(context.Context, mirrorserver.CreatePushMirrorReq) error) *MockMirrorServer_CreatePushMirror_Call { + _c.Call.Return(run) + return _c +} + +// GetMirrorTaskInfo provides a mock function with given fields: ctx, taskId +func (_m *MockMirrorServer) GetMirrorTaskInfo(ctx context.Context, taskId int64) (*mirrorserver.MirrorTaskInfo, error) { + ret := _m.Called(ctx, taskId) + + if len(ret) == 0 { + panic("no return value specified for GetMirrorTaskInfo") + } + + var r0 *mirrorserver.MirrorTaskInfo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*mirrorserver.MirrorTaskInfo, error)); ok { + return rf(ctx, taskId) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *mirrorserver.MirrorTaskInfo); ok { + r0 = rf(ctx, taskId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*mirrorserver.MirrorTaskInfo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, taskId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorServer_GetMirrorTaskInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetMirrorTaskInfo' +type MockMirrorServer_GetMirrorTaskInfo_Call struct { + *mock.Call +} + +// GetMirrorTaskInfo is a helper method to define mock.On call +// - ctx context.Context +// - taskId int64 +func (_e *MockMirrorServer_Expecter) GetMirrorTaskInfo(ctx interface{}, taskId interface{}) *MockMirrorServer_GetMirrorTaskInfo_Call { + return &MockMirrorServer_GetMirrorTaskInfo_Call{Call: _e.mock.On("GetMirrorTaskInfo", ctx, taskId)} +} + +func (_c *MockMirrorServer_GetMirrorTaskInfo_Call) Run(run func(ctx context.Context, taskId int64)) *MockMirrorServer_GetMirrorTaskInfo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockMirrorServer_GetMirrorTaskInfo_Call) Return(_a0 *mirrorserver.MirrorTaskInfo, _a1 error) *MockMirrorServer_GetMirrorTaskInfo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorServer_GetMirrorTaskInfo_Call) RunAndReturn(run func(context.Context, int64) (*mirrorserver.MirrorTaskInfo, error)) *MockMirrorServer_GetMirrorTaskInfo_Call { + _c.Call.Return(run) + return _c +} + +// MirrorSync provides a mock function with given fields: ctx, req +func (_m *MockMirrorServer) MirrorSync(ctx context.Context, req mirrorserver.MirrorSyncReq) error { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for MirrorSync") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, mirrorserver.MirrorSyncReq) error); ok { + r0 = rf(ctx, req) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMirrorServer_MirrorSync_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MirrorSync' +type MockMirrorServer_MirrorSync_Call struct { + *mock.Call +} + +// MirrorSync is a helper method to define mock.On call +// - ctx context.Context +// - req mirrorserver.MirrorSyncReq +func (_e *MockMirrorServer_Expecter) MirrorSync(ctx interface{}, req interface{}) *MockMirrorServer_MirrorSync_Call { + return &MockMirrorServer_MirrorSync_Call{Call: _e.mock.On("MirrorSync", ctx, req)} +} + +func (_c *MockMirrorServer_MirrorSync_Call) Run(run func(ctx context.Context, req mirrorserver.MirrorSyncReq)) *MockMirrorServer_MirrorSync_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(mirrorserver.MirrorSyncReq)) + }) + return _c +} + +func (_c *MockMirrorServer_MirrorSync_Call) Return(_a0 error) *MockMirrorServer_MirrorSync_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMirrorServer_MirrorSync_Call) RunAndReturn(run func(context.Context, mirrorserver.MirrorSyncReq) error) *MockMirrorServer_MirrorSync_Call { + _c.Call.Return(run) + return _c +} + +// NewMockMirrorServer creates a new instance of MockMirrorServer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockMirrorServer(t interface { + mock.TestingT + Cleanup(func()) +}) *MockMirrorServer { + mock := &MockMirrorServer{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/inference/mock_Client.go b/_mocks/opencsg.com/csghub-server/builder/inference/mock_Client.go new file mode 100644 index 00000000..14db257f --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/inference/mock_Client.go @@ -0,0 +1,150 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package inference + +import ( + mock "github.com/stretchr/testify/mock" + inference "opencsg.com/csghub-server/builder/inference" +) + +// MockClient is an autogenerated mock type for the Client type +type MockClient struct { + mock.Mock +} + +type MockClient_Expecter struct { + mock *mock.Mock +} + +func (_m *MockClient) EXPECT() *MockClient_Expecter { + return &MockClient_Expecter{mock: &_m.Mock} +} + +// GetModelInfo provides a mock function with given fields: id +func (_m *MockClient) GetModelInfo(id inference.ModelID) (inference.ModelInfo, error) { + ret := _m.Called(id) + + if len(ret) == 0 { + panic("no return value specified for GetModelInfo") + } + + var r0 inference.ModelInfo + var r1 error + if rf, ok := ret.Get(0).(func(inference.ModelID) (inference.ModelInfo, error)); ok { + return rf(id) + } + if rf, ok := ret.Get(0).(func(inference.ModelID) inference.ModelInfo); ok { + r0 = rf(id) + } else { + r0 = ret.Get(0).(inference.ModelInfo) + } + + if rf, ok := ret.Get(1).(func(inference.ModelID) error); ok { + r1 = rf(id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockClient_GetModelInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetModelInfo' +type MockClient_GetModelInfo_Call struct { + *mock.Call +} + +// GetModelInfo is a helper method to define mock.On call +// - id inference.ModelID +func (_e *MockClient_Expecter) GetModelInfo(id interface{}) *MockClient_GetModelInfo_Call { + return &MockClient_GetModelInfo_Call{Call: _e.mock.On("GetModelInfo", id)} +} + +func (_c *MockClient_GetModelInfo_Call) Run(run func(id inference.ModelID)) *MockClient_GetModelInfo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(inference.ModelID)) + }) + return _c +} + +func (_c *MockClient_GetModelInfo_Call) Return(_a0 inference.ModelInfo, _a1 error) *MockClient_GetModelInfo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockClient_GetModelInfo_Call) RunAndReturn(run func(inference.ModelID) (inference.ModelInfo, error)) *MockClient_GetModelInfo_Call { + _c.Call.Return(run) + return _c +} + +// Predict provides a mock function with given fields: id, req +func (_m *MockClient) Predict(id inference.ModelID, req *inference.PredictRequest) (*inference.PredictResponse, error) { + ret := _m.Called(id, req) + + if len(ret) == 0 { + panic("no return value specified for Predict") + } + + var r0 *inference.PredictResponse + var r1 error + if rf, ok := ret.Get(0).(func(inference.ModelID, *inference.PredictRequest) (*inference.PredictResponse, error)); ok { + return rf(id, req) + } + if rf, ok := ret.Get(0).(func(inference.ModelID, *inference.PredictRequest) *inference.PredictResponse); ok { + r0 = rf(id, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*inference.PredictResponse) + } + } + + if rf, ok := ret.Get(1).(func(inference.ModelID, *inference.PredictRequest) error); ok { + r1 = rf(id, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockClient_Predict_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Predict' +type MockClient_Predict_Call struct { + *mock.Call +} + +// Predict is a helper method to define mock.On call +// - id inference.ModelID +// - req *inference.PredictRequest +func (_e *MockClient_Expecter) Predict(id interface{}, req interface{}) *MockClient_Predict_Call { + return &MockClient_Predict_Call{Call: _e.mock.On("Predict", id, req)} +} + +func (_c *MockClient_Predict_Call) Run(run func(id inference.ModelID, req *inference.PredictRequest)) *MockClient_Predict_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(inference.ModelID), args[1].(*inference.PredictRequest)) + }) + return _c +} + +func (_c *MockClient_Predict_Call) Return(_a0 *inference.PredictResponse, _a1 error) *MockClient_Predict_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockClient_Predict_Call) RunAndReturn(run func(inference.ModelID, *inference.PredictRequest) (*inference.PredictResponse, error)) *MockClient_Predict_Call { + _c.Call.Return(run) + return _c +} + +// NewMockClient creates a new instance of MockClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockClient(t interface { + mock.TestingT + Cleanup(func()) +}) *MockClient { + mock := &MockClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/rpc/mock_ModerationSvcClient.go b/_mocks/opencsg.com/csghub-server/builder/rpc/mock_ModerationSvcClient.go new file mode 100644 index 00000000..d49f87cd --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/rpc/mock_ModerationSvcClient.go @@ -0,0 +1,209 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package rpc + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + rpc "opencsg.com/csghub-server/builder/rpc" + + types "opencsg.com/csghub-server/common/types" +) + +// MockModerationSvcClient is an autogenerated mock type for the ModerationSvcClient type +type MockModerationSvcClient struct { + mock.Mock +} + +type MockModerationSvcClient_Expecter struct { + mock *mock.Mock +} + +func (_m *MockModerationSvcClient) EXPECT() *MockModerationSvcClient_Expecter { + return &MockModerationSvcClient_Expecter{mock: &_m.Mock} +} + +// PassImageCheck provides a mock function with given fields: ctx, scenario, ossBucketName, ossObjectName +func (_m *MockModerationSvcClient) PassImageCheck(ctx context.Context, scenario string, ossBucketName string, ossObjectName string) (*rpc.CheckResult, error) { + ret := _m.Called(ctx, scenario, ossBucketName, ossObjectName) + + if len(ret) == 0 { + panic("no return value specified for PassImageCheck") + } + + var r0 *rpc.CheckResult + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) (*rpc.CheckResult, error)); ok { + return rf(ctx, scenario, ossBucketName, ossObjectName) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *rpc.CheckResult); ok { + r0 = rf(ctx, scenario, ossBucketName, ossObjectName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*rpc.CheckResult) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { + r1 = rf(ctx, scenario, ossBucketName, ossObjectName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModerationSvcClient_PassImageCheck_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PassImageCheck' +type MockModerationSvcClient_PassImageCheck_Call struct { + *mock.Call +} + +// PassImageCheck is a helper method to define mock.On call +// - ctx context.Context +// - scenario string +// - ossBucketName string +// - ossObjectName string +func (_e *MockModerationSvcClient_Expecter) PassImageCheck(ctx interface{}, scenario interface{}, ossBucketName interface{}, ossObjectName interface{}) *MockModerationSvcClient_PassImageCheck_Call { + return &MockModerationSvcClient_PassImageCheck_Call{Call: _e.mock.On("PassImageCheck", ctx, scenario, ossBucketName, ossObjectName)} +} + +func (_c *MockModerationSvcClient_PassImageCheck_Call) Run(run func(ctx context.Context, scenario string, ossBucketName string, ossObjectName string)) *MockModerationSvcClient_PassImageCheck_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockModerationSvcClient_PassImageCheck_Call) Return(_a0 *rpc.CheckResult, _a1 error) *MockModerationSvcClient_PassImageCheck_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModerationSvcClient_PassImageCheck_Call) RunAndReturn(run func(context.Context, string, string, string) (*rpc.CheckResult, error)) *MockModerationSvcClient_PassImageCheck_Call { + _c.Call.Return(run) + return _c +} + +// PassTextCheck provides a mock function with given fields: ctx, scenario, text +func (_m *MockModerationSvcClient) PassTextCheck(ctx context.Context, scenario string, text string) (*rpc.CheckResult, error) { + ret := _m.Called(ctx, scenario, text) + + if len(ret) == 0 { + panic("no return value specified for PassTextCheck") + } + + var r0 *rpc.CheckResult + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*rpc.CheckResult, error)); ok { + return rf(ctx, scenario, text) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) *rpc.CheckResult); ok { + r0 = rf(ctx, scenario, text) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*rpc.CheckResult) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, scenario, text) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockModerationSvcClient_PassTextCheck_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PassTextCheck' +type MockModerationSvcClient_PassTextCheck_Call struct { + *mock.Call +} + +// PassTextCheck is a helper method to define mock.On call +// - ctx context.Context +// - scenario string +// - text string +func (_e *MockModerationSvcClient_Expecter) PassTextCheck(ctx interface{}, scenario interface{}, text interface{}) *MockModerationSvcClient_PassTextCheck_Call { + return &MockModerationSvcClient_PassTextCheck_Call{Call: _e.mock.On("PassTextCheck", ctx, scenario, text)} +} + +func (_c *MockModerationSvcClient_PassTextCheck_Call) Run(run func(ctx context.Context, scenario string, text string)) *MockModerationSvcClient_PassTextCheck_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockModerationSvcClient_PassTextCheck_Call) Return(_a0 *rpc.CheckResult, _a1 error) *MockModerationSvcClient_PassTextCheck_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockModerationSvcClient_PassTextCheck_Call) RunAndReturn(run func(context.Context, string, string) (*rpc.CheckResult, error)) *MockModerationSvcClient_PassTextCheck_Call { + _c.Call.Return(run) + return _c +} + +// SubmitRepoCheck provides a mock function with given fields: ctx, repoType, namespace, name +func (_m *MockModerationSvcClient) SubmitRepoCheck(ctx context.Context, repoType types.RepositoryType, namespace string, name string) error { + ret := _m.Called(ctx, repoType, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for SubmitRepoCheck") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) error); ok { + r0 = rf(ctx, repoType, namespace, name) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockModerationSvcClient_SubmitRepoCheck_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SubmitRepoCheck' +type MockModerationSvcClient_SubmitRepoCheck_Call struct { + *mock.Call +} + +// SubmitRepoCheck is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +func (_e *MockModerationSvcClient_Expecter) SubmitRepoCheck(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}) *MockModerationSvcClient_SubmitRepoCheck_Call { + return &MockModerationSvcClient_SubmitRepoCheck_Call{Call: _e.mock.On("SubmitRepoCheck", ctx, repoType, namespace, name)} +} + +func (_c *MockModerationSvcClient_SubmitRepoCheck_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string)) *MockModerationSvcClient_SubmitRepoCheck_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockModerationSvcClient_SubmitRepoCheck_Call) Return(_a0 error) *MockModerationSvcClient_SubmitRepoCheck_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockModerationSvcClient_SubmitRepoCheck_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string) error) *MockModerationSvcClient_SubmitRepoCheck_Call { + _c.Call.Return(run) + return _c +} + +// NewMockModerationSvcClient creates a new instance of MockModerationSvcClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockModerationSvcClient(t interface { + mock.TestingT + Cleanup(func()) +}) *MockModerationSvcClient { + mock := &MockModerationSvcClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/rpc/mock_UserSvcClient.go b/_mocks/opencsg.com/csghub-server/builder/rpc/mock_UserSvcClient.go index 5a7be599..9cfa654d 100644 --- a/_mocks/opencsg.com/csghub-server/builder/rpc/mock_UserSvcClient.go +++ b/_mocks/opencsg.com/csghub-server/builder/rpc/mock_UserSvcClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package rpc diff --git a/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_Green2022Client.go b/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_Green2022Client.go index e9b8f697..d19c434a 100644 --- a/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_Green2022Client.go +++ b/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_Green2022Client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package sensitive diff --git a/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_GreenClient.go b/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_GreenClient.go index 5913e09e..d49dfe9c 100644 --- a/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_GreenClient.go +++ b/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_GreenClient.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package sensitive diff --git a/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_SensitiveChecker.go b/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_SensitiveChecker.go new file mode 100644 index 00000000..f0f7c338 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/sensitive/mock_SensitiveChecker.go @@ -0,0 +1,158 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package sensitive + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + sensitive "opencsg.com/csghub-server/builder/sensitive" +) + +// MockSensitiveChecker is an autogenerated mock type for the SensitiveChecker type +type MockSensitiveChecker struct { + mock.Mock +} + +type MockSensitiveChecker_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSensitiveChecker) EXPECT() *MockSensitiveChecker_Expecter { + return &MockSensitiveChecker_Expecter{mock: &_m.Mock} +} + +// PassImageCheck provides a mock function with given fields: ctx, scenario, ossBucketName, ossObjectName +func (_m *MockSensitiveChecker) PassImageCheck(ctx context.Context, scenario sensitive.Scenario, ossBucketName string, ossObjectName string) (*sensitive.CheckResult, error) { + ret := _m.Called(ctx, scenario, ossBucketName, ossObjectName) + + if len(ret) == 0 { + panic("no return value specified for PassImageCheck") + } + + var r0 *sensitive.CheckResult + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, sensitive.Scenario, string, string) (*sensitive.CheckResult, error)); ok { + return rf(ctx, scenario, ossBucketName, ossObjectName) + } + if rf, ok := ret.Get(0).(func(context.Context, sensitive.Scenario, string, string) *sensitive.CheckResult); ok { + r0 = rf(ctx, scenario, ossBucketName, ossObjectName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*sensitive.CheckResult) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, sensitive.Scenario, string, string) error); ok { + r1 = rf(ctx, scenario, ossBucketName, ossObjectName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSensitiveChecker_PassImageCheck_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PassImageCheck' +type MockSensitiveChecker_PassImageCheck_Call struct { + *mock.Call +} + +// PassImageCheck is a helper method to define mock.On call +// - ctx context.Context +// - scenario sensitive.Scenario +// - ossBucketName string +// - ossObjectName string +func (_e *MockSensitiveChecker_Expecter) PassImageCheck(ctx interface{}, scenario interface{}, ossBucketName interface{}, ossObjectName interface{}) *MockSensitiveChecker_PassImageCheck_Call { + return &MockSensitiveChecker_PassImageCheck_Call{Call: _e.mock.On("PassImageCheck", ctx, scenario, ossBucketName, ossObjectName)} +} + +func (_c *MockSensitiveChecker_PassImageCheck_Call) Run(run func(ctx context.Context, scenario sensitive.Scenario, ossBucketName string, ossObjectName string)) *MockSensitiveChecker_PassImageCheck_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(sensitive.Scenario), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockSensitiveChecker_PassImageCheck_Call) Return(_a0 *sensitive.CheckResult, _a1 error) *MockSensitiveChecker_PassImageCheck_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSensitiveChecker_PassImageCheck_Call) RunAndReturn(run func(context.Context, sensitive.Scenario, string, string) (*sensitive.CheckResult, error)) *MockSensitiveChecker_PassImageCheck_Call { + _c.Call.Return(run) + return _c +} + +// PassTextCheck provides a mock function with given fields: ctx, scenario, text +func (_m *MockSensitiveChecker) PassTextCheck(ctx context.Context, scenario sensitive.Scenario, text string) (*sensitive.CheckResult, error) { + ret := _m.Called(ctx, scenario, text) + + if len(ret) == 0 { + panic("no return value specified for PassTextCheck") + } + + var r0 *sensitive.CheckResult + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, sensitive.Scenario, string) (*sensitive.CheckResult, error)); ok { + return rf(ctx, scenario, text) + } + if rf, ok := ret.Get(0).(func(context.Context, sensitive.Scenario, string) *sensitive.CheckResult); ok { + r0 = rf(ctx, scenario, text) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*sensitive.CheckResult) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, sensitive.Scenario, string) error); ok { + r1 = rf(ctx, scenario, text) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSensitiveChecker_PassTextCheck_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PassTextCheck' +type MockSensitiveChecker_PassTextCheck_Call struct { + *mock.Call +} + +// PassTextCheck is a helper method to define mock.On call +// - ctx context.Context +// - scenario sensitive.Scenario +// - text string +func (_e *MockSensitiveChecker_Expecter) PassTextCheck(ctx interface{}, scenario interface{}, text interface{}) *MockSensitiveChecker_PassTextCheck_Call { + return &MockSensitiveChecker_PassTextCheck_Call{Call: _e.mock.On("PassTextCheck", ctx, scenario, text)} +} + +func (_c *MockSensitiveChecker_PassTextCheck_Call) Run(run func(ctx context.Context, scenario sensitive.Scenario, text string)) *MockSensitiveChecker_PassTextCheck_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(sensitive.Scenario), args[2].(string)) + }) + return _c +} + +func (_c *MockSensitiveChecker_PassTextCheck_Call) Return(_a0 *sensitive.CheckResult, _a1 error) *MockSensitiveChecker_PassTextCheck_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSensitiveChecker_PassTextCheck_Call) RunAndReturn(run func(context.Context, sensitive.Scenario, string) (*sensitive.CheckResult, error)) *MockSensitiveChecker_PassTextCheck_Call { + _c.Call.Return(run) + return _c +} + +// NewMockSensitiveChecker creates a new instance of MockSensitiveChecker. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSensitiveChecker(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSensitiveChecker { + mock := &MockSensitiveChecker{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccessTokenStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccessTokenStore.go new file mode 100644 index 00000000..c5b3939d --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccessTokenStore.go @@ -0,0 +1,613 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" + + time "time" +) + +// MockAccessTokenStore is an autogenerated mock type for the AccessTokenStore type +type MockAccessTokenStore struct { + mock.Mock +} + +type MockAccessTokenStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockAccessTokenStore) EXPECT() *MockAccessTokenStore_Expecter { + return &MockAccessTokenStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, token +func (_m *MockAccessTokenStore) Create(ctx context.Context, token *database.AccessToken) error { + ret := _m.Called(ctx, token) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.AccessToken) error); ok { + r0 = rf(ctx, token) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockAccessTokenStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockAccessTokenStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - token *database.AccessToken +func (_e *MockAccessTokenStore_Expecter) Create(ctx interface{}, token interface{}) *MockAccessTokenStore_Create_Call { + return &MockAccessTokenStore_Create_Call{Call: _e.mock.On("Create", ctx, token)} +} + +func (_c *MockAccessTokenStore_Create_Call) Run(run func(ctx context.Context, token *database.AccessToken)) *MockAccessTokenStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.AccessToken)) + }) + return _c +} + +func (_c *MockAccessTokenStore_Create_Call) Return(err error) *MockAccessTokenStore_Create_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockAccessTokenStore_Create_Call) RunAndReturn(run func(context.Context, *database.AccessToken) error) *MockAccessTokenStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, username, tkName, app +func (_m *MockAccessTokenStore) Delete(ctx context.Context, username string, tkName string, app string) error { + ret := _m.Called(ctx, username, tkName, app) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) error); ok { + r0 = rf(ctx, username, tkName, app) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockAccessTokenStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockAccessTokenStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - tkName string +// - app string +func (_e *MockAccessTokenStore_Expecter) Delete(ctx interface{}, username interface{}, tkName interface{}, app interface{}) *MockAccessTokenStore_Delete_Call { + return &MockAccessTokenStore_Delete_Call{Call: _e.mock.On("Delete", ctx, username, tkName, app)} +} + +func (_c *MockAccessTokenStore_Delete_Call) Run(run func(ctx context.Context, username string, tkName string, app string)) *MockAccessTokenStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockAccessTokenStore_Delete_Call) Return(err error) *MockAccessTokenStore_Delete_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockAccessTokenStore_Delete_Call) RunAndReturn(run func(context.Context, string, string, string) error) *MockAccessTokenStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindByID provides a mock function with given fields: ctx, id +func (_m *MockAccessTokenStore) FindByID(ctx context.Context, id int64) (*database.AccessToken, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for FindByID") + } + + var r0 *database.AccessToken + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.AccessToken, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.AccessToken); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.AccessToken) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockAccessTokenStore_FindByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByID' +type MockAccessTokenStore_FindByID_Call struct { + *mock.Call +} + +// FindByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockAccessTokenStore_Expecter) FindByID(ctx interface{}, id interface{}) *MockAccessTokenStore_FindByID_Call { + return &MockAccessTokenStore_FindByID_Call{Call: _e.mock.On("FindByID", ctx, id)} +} + +func (_c *MockAccessTokenStore_FindByID_Call) Run(run func(ctx context.Context, id int64)) *MockAccessTokenStore_FindByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockAccessTokenStore_FindByID_Call) Return(token *database.AccessToken, err error) *MockAccessTokenStore_FindByID_Call { + _c.Call.Return(token, err) + return _c +} + +func (_c *MockAccessTokenStore_FindByID_Call) RunAndReturn(run func(context.Context, int64) (*database.AccessToken, error)) *MockAccessTokenStore_FindByID_Call { + _c.Call.Return(run) + return _c +} + +// FindByToken provides a mock function with given fields: ctx, tokenValue, app +func (_m *MockAccessTokenStore) FindByToken(ctx context.Context, tokenValue string, app string) (*database.AccessToken, error) { + ret := _m.Called(ctx, tokenValue, app) + + if len(ret) == 0 { + panic("no return value specified for FindByToken") + } + + var r0 *database.AccessToken + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*database.AccessToken, error)); ok { + return rf(ctx, tokenValue, app) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) *database.AccessToken); ok { + r0 = rf(ctx, tokenValue, app) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.AccessToken) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, tokenValue, app) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockAccessTokenStore_FindByToken_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByToken' +type MockAccessTokenStore_FindByToken_Call struct { + *mock.Call +} + +// FindByToken is a helper method to define mock.On call +// - ctx context.Context +// - tokenValue string +// - app string +func (_e *MockAccessTokenStore_Expecter) FindByToken(ctx interface{}, tokenValue interface{}, app interface{}) *MockAccessTokenStore_FindByToken_Call { + return &MockAccessTokenStore_FindByToken_Call{Call: _e.mock.On("FindByToken", ctx, tokenValue, app)} +} + +func (_c *MockAccessTokenStore_FindByToken_Call) Run(run func(ctx context.Context, tokenValue string, app string)) *MockAccessTokenStore_FindByToken_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockAccessTokenStore_FindByToken_Call) Return(_a0 *database.AccessToken, _a1 error) *MockAccessTokenStore_FindByToken_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockAccessTokenStore_FindByToken_Call) RunAndReturn(run func(context.Context, string, string) (*database.AccessToken, error)) *MockAccessTokenStore_FindByToken_Call { + _c.Call.Return(run) + return _c +} + +// FindByTokenName provides a mock function with given fields: ctx, username, tokenName, app +func (_m *MockAccessTokenStore) FindByTokenName(ctx context.Context, username string, tokenName string, app string) (*database.AccessToken, error) { + ret := _m.Called(ctx, username, tokenName, app) + + if len(ret) == 0 { + panic("no return value specified for FindByTokenName") + } + + var r0 *database.AccessToken + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) (*database.AccessToken, error)); ok { + return rf(ctx, username, tokenName, app) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *database.AccessToken); ok { + r0 = rf(ctx, username, tokenName, app) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.AccessToken) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { + r1 = rf(ctx, username, tokenName, app) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockAccessTokenStore_FindByTokenName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByTokenName' +type MockAccessTokenStore_FindByTokenName_Call struct { + *mock.Call +} + +// FindByTokenName is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - tokenName string +// - app string +func (_e *MockAccessTokenStore_Expecter) FindByTokenName(ctx interface{}, username interface{}, tokenName interface{}, app interface{}) *MockAccessTokenStore_FindByTokenName_Call { + return &MockAccessTokenStore_FindByTokenName_Call{Call: _e.mock.On("FindByTokenName", ctx, username, tokenName, app)} +} + +func (_c *MockAccessTokenStore_FindByTokenName_Call) Run(run func(ctx context.Context, username string, tokenName string, app string)) *MockAccessTokenStore_FindByTokenName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockAccessTokenStore_FindByTokenName_Call) Return(_a0 *database.AccessToken, _a1 error) *MockAccessTokenStore_FindByTokenName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockAccessTokenStore_FindByTokenName_Call) RunAndReturn(run func(context.Context, string, string, string) (*database.AccessToken, error)) *MockAccessTokenStore_FindByTokenName_Call { + _c.Call.Return(run) + return _c +} + +// FindByUID provides a mock function with given fields: ctx, uid +func (_m *MockAccessTokenStore) FindByUID(ctx context.Context, uid int64) (*database.AccessToken, error) { + ret := _m.Called(ctx, uid) + + if len(ret) == 0 { + panic("no return value specified for FindByUID") + } + + var r0 *database.AccessToken + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.AccessToken, error)); ok { + return rf(ctx, uid) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.AccessToken); ok { + r0 = rf(ctx, uid) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.AccessToken) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, uid) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockAccessTokenStore_FindByUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByUID' +type MockAccessTokenStore_FindByUID_Call struct { + *mock.Call +} + +// FindByUID is a helper method to define mock.On call +// - ctx context.Context +// - uid int64 +func (_e *MockAccessTokenStore_Expecter) FindByUID(ctx interface{}, uid interface{}) *MockAccessTokenStore_FindByUID_Call { + return &MockAccessTokenStore_FindByUID_Call{Call: _e.mock.On("FindByUID", ctx, uid)} +} + +func (_c *MockAccessTokenStore_FindByUID_Call) Run(run func(ctx context.Context, uid int64)) *MockAccessTokenStore_FindByUID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockAccessTokenStore_FindByUID_Call) Return(token *database.AccessToken, err error) *MockAccessTokenStore_FindByUID_Call { + _c.Call.Return(token, err) + return _c +} + +func (_c *MockAccessTokenStore_FindByUID_Call) RunAndReturn(run func(context.Context, int64) (*database.AccessToken, error)) *MockAccessTokenStore_FindByUID_Call { + _c.Call.Return(run) + return _c +} + +// FindByUser provides a mock function with given fields: ctx, username, app +func (_m *MockAccessTokenStore) FindByUser(ctx context.Context, username string, app string) ([]database.AccessToken, error) { + ret := _m.Called(ctx, username, app) + + if len(ret) == 0 { + panic("no return value specified for FindByUser") + } + + var r0 []database.AccessToken + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) ([]database.AccessToken, error)); ok { + return rf(ctx, username, app) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) []database.AccessToken); ok { + r0 = rf(ctx, username, app) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.AccessToken) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, username, app) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockAccessTokenStore_FindByUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByUser' +type MockAccessTokenStore_FindByUser_Call struct { + *mock.Call +} + +// FindByUser is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - app string +func (_e *MockAccessTokenStore_Expecter) FindByUser(ctx interface{}, username interface{}, app interface{}) *MockAccessTokenStore_FindByUser_Call { + return &MockAccessTokenStore_FindByUser_Call{Call: _e.mock.On("FindByUser", ctx, username, app)} +} + +func (_c *MockAccessTokenStore_FindByUser_Call) Run(run func(ctx context.Context, username string, app string)) *MockAccessTokenStore_FindByUser_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockAccessTokenStore_FindByUser_Call) Return(_a0 []database.AccessToken, _a1 error) *MockAccessTokenStore_FindByUser_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockAccessTokenStore_FindByUser_Call) RunAndReturn(run func(context.Context, string, string) ([]database.AccessToken, error)) *MockAccessTokenStore_FindByUser_Call { + _c.Call.Return(run) + return _c +} + +// GetUserGitToken provides a mock function with given fields: ctx, username +func (_m *MockAccessTokenStore) GetUserGitToken(ctx context.Context, username string) (*database.AccessToken, error) { + ret := _m.Called(ctx, username) + + if len(ret) == 0 { + panic("no return value specified for GetUserGitToken") + } + + var r0 *database.AccessToken + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.AccessToken, error)); ok { + return rf(ctx, username) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.AccessToken); ok { + r0 = rf(ctx, username) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.AccessToken) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockAccessTokenStore_GetUserGitToken_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetUserGitToken' +type MockAccessTokenStore_GetUserGitToken_Call struct { + *mock.Call +} + +// GetUserGitToken is a helper method to define mock.On call +// - ctx context.Context +// - username string +func (_e *MockAccessTokenStore_Expecter) GetUserGitToken(ctx interface{}, username interface{}) *MockAccessTokenStore_GetUserGitToken_Call { + return &MockAccessTokenStore_GetUserGitToken_Call{Call: _e.mock.On("GetUserGitToken", ctx, username)} +} + +func (_c *MockAccessTokenStore_GetUserGitToken_Call) Run(run func(ctx context.Context, username string)) *MockAccessTokenStore_GetUserGitToken_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockAccessTokenStore_GetUserGitToken_Call) Return(_a0 *database.AccessToken, _a1 error) *MockAccessTokenStore_GetUserGitToken_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockAccessTokenStore_GetUserGitToken_Call) RunAndReturn(run func(context.Context, string) (*database.AccessToken, error)) *MockAccessTokenStore_GetUserGitToken_Call { + _c.Call.Return(run) + return _c +} + +// IsExist provides a mock function with given fields: ctx, username, tkName, app +func (_m *MockAccessTokenStore) IsExist(ctx context.Context, username string, tkName string, app string) (bool, error) { + ret := _m.Called(ctx, username, tkName, app) + + if len(ret) == 0 { + panic("no return value specified for IsExist") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) (bool, error)); ok { + return rf(ctx, username, tkName, app) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) bool); ok { + r0 = rf(ctx, username, tkName, app) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { + r1 = rf(ctx, username, tkName, app) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockAccessTokenStore_IsExist_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsExist' +type MockAccessTokenStore_IsExist_Call struct { + *mock.Call +} + +// IsExist is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - tkName string +// - app string +func (_e *MockAccessTokenStore_Expecter) IsExist(ctx interface{}, username interface{}, tkName interface{}, app interface{}) *MockAccessTokenStore_IsExist_Call { + return &MockAccessTokenStore_IsExist_Call{Call: _e.mock.On("IsExist", ctx, username, tkName, app)} +} + +func (_c *MockAccessTokenStore_IsExist_Call) Run(run func(ctx context.Context, username string, tkName string, app string)) *MockAccessTokenStore_IsExist_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockAccessTokenStore_IsExist_Call) Return(exists bool, err error) *MockAccessTokenStore_IsExist_Call { + _c.Call.Return(exists, err) + return _c +} + +func (_c *MockAccessTokenStore_IsExist_Call) RunAndReturn(run func(context.Context, string, string, string) (bool, error)) *MockAccessTokenStore_IsExist_Call { + _c.Call.Return(run) + return _c +} + +// Refresh provides a mock function with given fields: ctx, token, newTokenValue, newExpiredAt +func (_m *MockAccessTokenStore) Refresh(ctx context.Context, token *database.AccessToken, newTokenValue string, newExpiredAt time.Time) (*database.AccessToken, error) { + ret := _m.Called(ctx, token, newTokenValue, newExpiredAt) + + if len(ret) == 0 { + panic("no return value specified for Refresh") + } + + var r0 *database.AccessToken + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *database.AccessToken, string, time.Time) (*database.AccessToken, error)); ok { + return rf(ctx, token, newTokenValue, newExpiredAt) + } + if rf, ok := ret.Get(0).(func(context.Context, *database.AccessToken, string, time.Time) *database.AccessToken); ok { + r0 = rf(ctx, token, newTokenValue, newExpiredAt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.AccessToken) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *database.AccessToken, string, time.Time) error); ok { + r1 = rf(ctx, token, newTokenValue, newExpiredAt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockAccessTokenStore_Refresh_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Refresh' +type MockAccessTokenStore_Refresh_Call struct { + *mock.Call +} + +// Refresh is a helper method to define mock.On call +// - ctx context.Context +// - token *database.AccessToken +// - newTokenValue string +// - newExpiredAt time.Time +func (_e *MockAccessTokenStore_Expecter) Refresh(ctx interface{}, token interface{}, newTokenValue interface{}, newExpiredAt interface{}) *MockAccessTokenStore_Refresh_Call { + return &MockAccessTokenStore_Refresh_Call{Call: _e.mock.On("Refresh", ctx, token, newTokenValue, newExpiredAt)} +} + +func (_c *MockAccessTokenStore_Refresh_Call) Run(run func(ctx context.Context, token *database.AccessToken, newTokenValue string, newExpiredAt time.Time)) *MockAccessTokenStore_Refresh_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.AccessToken), args[2].(string), args[3].(time.Time)) + }) + return _c +} + +func (_c *MockAccessTokenStore_Refresh_Call) Return(_a0 *database.AccessToken, _a1 error) *MockAccessTokenStore_Refresh_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockAccessTokenStore_Refresh_Call) RunAndReturn(run func(context.Context, *database.AccessToken, string, time.Time) (*database.AccessToken, error)) *MockAccessTokenStore_Refresh_Call { + _c.Call.Return(run) + return _c +} + +// NewMockAccessTokenStore creates a new instance of MockAccessTokenStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockAccessTokenStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockAccessTokenStore { + mock := &MockAccessTokenStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountMeteringStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountMeteringStore.go index d5c9a8cd..ad7bb0ec 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountMeteringStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_AccountMeteringStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ClusterInfoStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ClusterInfoStore.go new file mode 100644 index 00000000..86fbeb25 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ClusterInfoStore.go @@ -0,0 +1,304 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockClusterInfoStore is an autogenerated mock type for the ClusterInfoStore type +type MockClusterInfoStore struct { + mock.Mock +} + +type MockClusterInfoStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockClusterInfoStore) EXPECT() *MockClusterInfoStore_Expecter { + return &MockClusterInfoStore_Expecter{mock: &_m.Mock} +} + +// Add provides a mock function with given fields: ctx, clusterConfig, region +func (_m *MockClusterInfoStore) Add(ctx context.Context, clusterConfig string, region string) error { + ret := _m.Called(ctx, clusterConfig, region) + + if len(ret) == 0 { + panic("no return value specified for Add") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { + r0 = rf(ctx, clusterConfig, region) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockClusterInfoStore_Add_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Add' +type MockClusterInfoStore_Add_Call struct { + *mock.Call +} + +// Add is a helper method to define mock.On call +// - ctx context.Context +// - clusterConfig string +// - region string +func (_e *MockClusterInfoStore_Expecter) Add(ctx interface{}, clusterConfig interface{}, region interface{}) *MockClusterInfoStore_Add_Call { + return &MockClusterInfoStore_Add_Call{Call: _e.mock.On("Add", ctx, clusterConfig, region)} +} + +func (_c *MockClusterInfoStore_Add_Call) Run(run func(ctx context.Context, clusterConfig string, region string)) *MockClusterInfoStore_Add_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockClusterInfoStore_Add_Call) Return(_a0 error) *MockClusterInfoStore_Add_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockClusterInfoStore_Add_Call) RunAndReturn(run func(context.Context, string, string) error) *MockClusterInfoStore_Add_Call { + _c.Call.Return(run) + return _c +} + +// ByClusterConfig provides a mock function with given fields: ctx, clusterConfig +func (_m *MockClusterInfoStore) ByClusterConfig(ctx context.Context, clusterConfig string) (database.ClusterInfo, error) { + ret := _m.Called(ctx, clusterConfig) + + if len(ret) == 0 { + panic("no return value specified for ByClusterConfig") + } + + var r0 database.ClusterInfo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (database.ClusterInfo, error)); ok { + return rf(ctx, clusterConfig) + } + if rf, ok := ret.Get(0).(func(context.Context, string) database.ClusterInfo); ok { + r0 = rf(ctx, clusterConfig) + } else { + r0 = ret.Get(0).(database.ClusterInfo) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, clusterConfig) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockClusterInfoStore_ByClusterConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByClusterConfig' +type MockClusterInfoStore_ByClusterConfig_Call struct { + *mock.Call +} + +// ByClusterConfig is a helper method to define mock.On call +// - ctx context.Context +// - clusterConfig string +func (_e *MockClusterInfoStore_Expecter) ByClusterConfig(ctx interface{}, clusterConfig interface{}) *MockClusterInfoStore_ByClusterConfig_Call { + return &MockClusterInfoStore_ByClusterConfig_Call{Call: _e.mock.On("ByClusterConfig", ctx, clusterConfig)} +} + +func (_c *MockClusterInfoStore_ByClusterConfig_Call) Run(run func(ctx context.Context, clusterConfig string)) *MockClusterInfoStore_ByClusterConfig_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockClusterInfoStore_ByClusterConfig_Call) Return(clusterInfo database.ClusterInfo, err error) *MockClusterInfoStore_ByClusterConfig_Call { + _c.Call.Return(clusterInfo, err) + return _c +} + +func (_c *MockClusterInfoStore_ByClusterConfig_Call) RunAndReturn(run func(context.Context, string) (database.ClusterInfo, error)) *MockClusterInfoStore_ByClusterConfig_Call { + _c.Call.Return(run) + return _c +} + +// ByClusterID provides a mock function with given fields: ctx, clusterId +func (_m *MockClusterInfoStore) ByClusterID(ctx context.Context, clusterId string) (database.ClusterInfo, error) { + ret := _m.Called(ctx, clusterId) + + if len(ret) == 0 { + panic("no return value specified for ByClusterID") + } + + var r0 database.ClusterInfo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (database.ClusterInfo, error)); ok { + return rf(ctx, clusterId) + } + if rf, ok := ret.Get(0).(func(context.Context, string) database.ClusterInfo); ok { + r0 = rf(ctx, clusterId) + } else { + r0 = ret.Get(0).(database.ClusterInfo) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, clusterId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockClusterInfoStore_ByClusterID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByClusterID' +type MockClusterInfoStore_ByClusterID_Call struct { + *mock.Call +} + +// ByClusterID is a helper method to define mock.On call +// - ctx context.Context +// - clusterId string +func (_e *MockClusterInfoStore_Expecter) ByClusterID(ctx interface{}, clusterId interface{}) *MockClusterInfoStore_ByClusterID_Call { + return &MockClusterInfoStore_ByClusterID_Call{Call: _e.mock.On("ByClusterID", ctx, clusterId)} +} + +func (_c *MockClusterInfoStore_ByClusterID_Call) Run(run func(ctx context.Context, clusterId string)) *MockClusterInfoStore_ByClusterID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockClusterInfoStore_ByClusterID_Call) Return(clusterInfo database.ClusterInfo, err error) *MockClusterInfoStore_ByClusterID_Call { + _c.Call.Return(clusterInfo, err) + return _c +} + +func (_c *MockClusterInfoStore_ByClusterID_Call) RunAndReturn(run func(context.Context, string) (database.ClusterInfo, error)) *MockClusterInfoStore_ByClusterID_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx +func (_m *MockClusterInfoStore) List(ctx context.Context) ([]database.ClusterInfo, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []database.ClusterInfo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.ClusterInfo, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.ClusterInfo); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.ClusterInfo) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockClusterInfoStore_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type MockClusterInfoStore_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockClusterInfoStore_Expecter) List(ctx interface{}) *MockClusterInfoStore_List_Call { + return &MockClusterInfoStore_List_Call{Call: _e.mock.On("List", ctx)} +} + +func (_c *MockClusterInfoStore_List_Call) Run(run func(ctx context.Context)) *MockClusterInfoStore_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockClusterInfoStore_List_Call) Return(_a0 []database.ClusterInfo, _a1 error) *MockClusterInfoStore_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockClusterInfoStore_List_Call) RunAndReturn(run func(context.Context) ([]database.ClusterInfo, error)) *MockClusterInfoStore_List_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, clusterInfo +func (_m *MockClusterInfoStore) Update(ctx context.Context, clusterInfo database.ClusterInfo) error { + ret := _m.Called(ctx, clusterInfo) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.ClusterInfo) error); ok { + r0 = rf(ctx, clusterInfo) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockClusterInfoStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockClusterInfoStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - clusterInfo database.ClusterInfo +func (_e *MockClusterInfoStore_Expecter) Update(ctx interface{}, clusterInfo interface{}) *MockClusterInfoStore_Update_Call { + return &MockClusterInfoStore_Update_Call{Call: _e.mock.On("Update", ctx, clusterInfo)} +} + +func (_c *MockClusterInfoStore_Update_Call) Run(run func(ctx context.Context, clusterInfo database.ClusterInfo)) *MockClusterInfoStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.ClusterInfo)) + }) + return _c +} + +func (_c *MockClusterInfoStore_Update_Call) Return(_a0 error) *MockClusterInfoStore_Update_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockClusterInfoStore_Update_Call) RunAndReturn(run func(context.Context, database.ClusterInfo) error) *MockClusterInfoStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockClusterInfoStore creates a new instance of MockClusterInfoStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockClusterInfoStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockClusterInfoStore { + mock := &MockClusterInfoStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_CodeStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_CodeStore.go new file mode 100644 index 00000000..928deaba --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_CodeStore.go @@ -0,0 +1,633 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockCodeStore is an autogenerated mock type for the CodeStore type +type MockCodeStore struct { + mock.Mock +} + +type MockCodeStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockCodeStore) EXPECT() *MockCodeStore_Expecter { + return &MockCodeStore_Expecter{mock: &_m.Mock} +} + +// ByOrgPath provides a mock function with given fields: ctx, namespace, per, page, onlyPublic +func (_m *MockCodeStore) ByOrgPath(ctx context.Context, namespace string, per int, page int, onlyPublic bool) ([]database.Code, int, error) { + ret := _m.Called(ctx, namespace, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByOrgPath") + } + + var r0 []database.Code + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Code, int, error)); ok { + return rf(ctx, namespace, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Code); ok { + r0 = rf(ctx, namespace, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Code) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockCodeStore_ByOrgPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByOrgPath' +type MockCodeStore_ByOrgPath_Call struct { + *mock.Call +} + +// ByOrgPath is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockCodeStore_Expecter) ByOrgPath(ctx interface{}, namespace interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockCodeStore_ByOrgPath_Call { + return &MockCodeStore_ByOrgPath_Call{Call: _e.mock.On("ByOrgPath", ctx, namespace, per, page, onlyPublic)} +} + +func (_c *MockCodeStore_ByOrgPath_Call) Run(run func(ctx context.Context, namespace string, per int, page int, onlyPublic bool)) *MockCodeStore_ByOrgPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockCodeStore_ByOrgPath_Call) Return(codes []database.Code, total int, err error) *MockCodeStore_ByOrgPath_Call { + _c.Call.Return(codes, total, err) + return _c +} + +func (_c *MockCodeStore_ByOrgPath_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Code, int, error)) *MockCodeStore_ByOrgPath_Call { + _c.Call.Return(run) + return _c +} + +// ByRepoID provides a mock function with given fields: ctx, repoID +func (_m *MockCodeStore) ByRepoID(ctx context.Context, repoID int64) (*database.Code, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for ByRepoID") + } + + var r0 *database.Code + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Code, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Code); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Code) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockCodeStore_ByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByRepoID' +type MockCodeStore_ByRepoID_Call struct { + *mock.Call +} + +// ByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockCodeStore_Expecter) ByRepoID(ctx interface{}, repoID interface{}) *MockCodeStore_ByRepoID_Call { + return &MockCodeStore_ByRepoID_Call{Call: _e.mock.On("ByRepoID", ctx, repoID)} +} + +func (_c *MockCodeStore_ByRepoID_Call) Run(run func(ctx context.Context, repoID int64)) *MockCodeStore_ByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockCodeStore_ByRepoID_Call) Return(_a0 *database.Code, _a1 error) *MockCodeStore_ByRepoID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockCodeStore_ByRepoID_Call) RunAndReturn(run func(context.Context, int64) (*database.Code, error)) *MockCodeStore_ByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// ByRepoIDs provides a mock function with given fields: ctx, repoIDs +func (_m *MockCodeStore) ByRepoIDs(ctx context.Context, repoIDs []int64) ([]database.Code, error) { + ret := _m.Called(ctx, repoIDs) + + if len(ret) == 0 { + panic("no return value specified for ByRepoIDs") + } + + var r0 []database.Code + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []int64) ([]database.Code, error)); ok { + return rf(ctx, repoIDs) + } + if rf, ok := ret.Get(0).(func(context.Context, []int64) []database.Code); ok { + r0 = rf(ctx, repoIDs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Code) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []int64) error); ok { + r1 = rf(ctx, repoIDs) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockCodeStore_ByRepoIDs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByRepoIDs' +type MockCodeStore_ByRepoIDs_Call struct { + *mock.Call +} + +// ByRepoIDs is a helper method to define mock.On call +// - ctx context.Context +// - repoIDs []int64 +func (_e *MockCodeStore_Expecter) ByRepoIDs(ctx interface{}, repoIDs interface{}) *MockCodeStore_ByRepoIDs_Call { + return &MockCodeStore_ByRepoIDs_Call{Call: _e.mock.On("ByRepoIDs", ctx, repoIDs)} +} + +func (_c *MockCodeStore_ByRepoIDs_Call) Run(run func(ctx context.Context, repoIDs []int64)) *MockCodeStore_ByRepoIDs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]int64)) + }) + return _c +} + +func (_c *MockCodeStore_ByRepoIDs_Call) Return(codes []database.Code, err error) *MockCodeStore_ByRepoIDs_Call { + _c.Call.Return(codes, err) + return _c +} + +func (_c *MockCodeStore_ByRepoIDs_Call) RunAndReturn(run func(context.Context, []int64) ([]database.Code, error)) *MockCodeStore_ByRepoIDs_Call { + _c.Call.Return(run) + return _c +} + +// ByUsername provides a mock function with given fields: ctx, username, per, page, onlyPublic +func (_m *MockCodeStore) ByUsername(ctx context.Context, username string, per int, page int, onlyPublic bool) ([]database.Code, int, error) { + ret := _m.Called(ctx, username, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByUsername") + } + + var r0 []database.Code + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Code, int, error)); ok { + return rf(ctx, username, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Code); ok { + r0 = rf(ctx, username, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Code) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, username, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, username, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockCodeStore_ByUsername_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByUsername' +type MockCodeStore_ByUsername_Call struct { + *mock.Call +} + +// ByUsername is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockCodeStore_Expecter) ByUsername(ctx interface{}, username interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockCodeStore_ByUsername_Call { + return &MockCodeStore_ByUsername_Call{Call: _e.mock.On("ByUsername", ctx, username, per, page, onlyPublic)} +} + +func (_c *MockCodeStore_ByUsername_Call) Run(run func(ctx context.Context, username string, per int, page int, onlyPublic bool)) *MockCodeStore_ByUsername_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockCodeStore_ByUsername_Call) Return(codes []database.Code, total int, err error) *MockCodeStore_ByUsername_Call { + _c.Call.Return(codes, total, err) + return _c +} + +func (_c *MockCodeStore_ByUsername_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Code, int, error)) *MockCodeStore_ByUsername_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, input +func (_m *MockCodeStore) Create(ctx context.Context, input database.Code) (*database.Code, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.Code + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Code) (*database.Code, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Code) *database.Code); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Code) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Code) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockCodeStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockCodeStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - input database.Code +func (_e *MockCodeStore_Expecter) Create(ctx interface{}, input interface{}) *MockCodeStore_Create_Call { + return &MockCodeStore_Create_Call{Call: _e.mock.On("Create", ctx, input)} +} + +func (_c *MockCodeStore_Create_Call) Run(run func(ctx context.Context, input database.Code)) *MockCodeStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Code)) + }) + return _c +} + +func (_c *MockCodeStore_Create_Call) Return(_a0 *database.Code, _a1 error) *MockCodeStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockCodeStore_Create_Call) RunAndReturn(run func(context.Context, database.Code) (*database.Code, error)) *MockCodeStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, input +func (_m *MockCodeStore) Delete(ctx context.Context, input database.Code) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.Code) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockCodeStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockCodeStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - input database.Code +func (_e *MockCodeStore_Expecter) Delete(ctx interface{}, input interface{}) *MockCodeStore_Delete_Call { + return &MockCodeStore_Delete_Call{Call: _e.mock.On("Delete", ctx, input)} +} + +func (_c *MockCodeStore_Delete_Call) Run(run func(ctx context.Context, input database.Code)) *MockCodeStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Code)) + }) + return _c +} + +func (_c *MockCodeStore_Delete_Call) Return(_a0 error) *MockCodeStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockCodeStore_Delete_Call) RunAndReturn(run func(context.Context, database.Code) error) *MockCodeStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindByPath provides a mock function with given fields: ctx, namespace, repoPath +func (_m *MockCodeStore) FindByPath(ctx context.Context, namespace string, repoPath string) (*database.Code, error) { + ret := _m.Called(ctx, namespace, repoPath) + + if len(ret) == 0 { + panic("no return value specified for FindByPath") + } + + var r0 *database.Code + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*database.Code, error)); ok { + return rf(ctx, namespace, repoPath) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) *database.Code); ok { + r0 = rf(ctx, namespace, repoPath) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Code) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, namespace, repoPath) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockCodeStore_FindByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByPath' +type MockCodeStore_FindByPath_Call struct { + *mock.Call +} + +// FindByPath is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - repoPath string +func (_e *MockCodeStore_Expecter) FindByPath(ctx interface{}, namespace interface{}, repoPath interface{}) *MockCodeStore_FindByPath_Call { + return &MockCodeStore_FindByPath_Call{Call: _e.mock.On("FindByPath", ctx, namespace, repoPath)} +} + +func (_c *MockCodeStore_FindByPath_Call) Run(run func(ctx context.Context, namespace string, repoPath string)) *MockCodeStore_FindByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockCodeStore_FindByPath_Call) Return(code *database.Code, err error) *MockCodeStore_FindByPath_Call { + _c.Call.Return(code, err) + return _c +} + +func (_c *MockCodeStore_FindByPath_Call) RunAndReturn(run func(context.Context, string, string) (*database.Code, error)) *MockCodeStore_FindByPath_Call { + _c.Call.Return(run) + return _c +} + +// ListByPath provides a mock function with given fields: ctx, paths +func (_m *MockCodeStore) ListByPath(ctx context.Context, paths []string) ([]database.Code, error) { + ret := _m.Called(ctx, paths) + + if len(ret) == 0 { + panic("no return value specified for ListByPath") + } + + var r0 []database.Code + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []string) ([]database.Code, error)); ok { + return rf(ctx, paths) + } + if rf, ok := ret.Get(0).(func(context.Context, []string) []database.Code); ok { + r0 = rf(ctx, paths) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Code) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok { + r1 = rf(ctx, paths) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockCodeStore_ListByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByPath' +type MockCodeStore_ListByPath_Call struct { + *mock.Call +} + +// ListByPath is a helper method to define mock.On call +// - ctx context.Context +// - paths []string +func (_e *MockCodeStore_Expecter) ListByPath(ctx interface{}, paths interface{}) *MockCodeStore_ListByPath_Call { + return &MockCodeStore_ListByPath_Call{Call: _e.mock.On("ListByPath", ctx, paths)} +} + +func (_c *MockCodeStore_ListByPath_Call) Run(run func(ctx context.Context, paths []string)) *MockCodeStore_ListByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]string)) + }) + return _c +} + +func (_c *MockCodeStore_ListByPath_Call) Return(_a0 []database.Code, _a1 error) *MockCodeStore_ListByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockCodeStore_ListByPath_Call) RunAndReturn(run func(context.Context, []string) ([]database.Code, error)) *MockCodeStore_ListByPath_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, input +func (_m *MockCodeStore) Update(ctx context.Context, input database.Code) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.Code) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockCodeStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockCodeStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - input database.Code +func (_e *MockCodeStore_Expecter) Update(ctx interface{}, input interface{}) *MockCodeStore_Update_Call { + return &MockCodeStore_Update_Call{Call: _e.mock.On("Update", ctx, input)} +} + +func (_c *MockCodeStore_Update_Call) Run(run func(ctx context.Context, input database.Code)) *MockCodeStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Code)) + }) + return _c +} + +func (_c *MockCodeStore_Update_Call) Return(err error) *MockCodeStore_Update_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockCodeStore_Update_Call) RunAndReturn(run func(context.Context, database.Code) error) *MockCodeStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// UserLikesCodes provides a mock function with given fields: ctx, userID, per, page +func (_m *MockCodeStore) UserLikesCodes(ctx context.Context, userID int64, per int, page int) ([]database.Code, int, error) { + ret := _m.Called(ctx, userID, per, page) + + if len(ret) == 0 { + panic("no return value specified for UserLikesCodes") + } + + var r0 []database.Code + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) ([]database.Code, int, error)); ok { + return rf(ctx, userID, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) []database.Code); ok { + r0 = rf(ctx, userID, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Code) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int, int) int); ok { + r1 = rf(ctx, userID, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, int64, int, int) error); ok { + r2 = rf(ctx, userID, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockCodeStore_UserLikesCodes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UserLikesCodes' +type MockCodeStore_UserLikesCodes_Call struct { + *mock.Call +} + +// UserLikesCodes is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +// - per int +// - page int +func (_e *MockCodeStore_Expecter) UserLikesCodes(ctx interface{}, userID interface{}, per interface{}, page interface{}) *MockCodeStore_UserLikesCodes_Call { + return &MockCodeStore_UserLikesCodes_Call{Call: _e.mock.On("UserLikesCodes", ctx, userID, per, page)} +} + +func (_c *MockCodeStore_UserLikesCodes_Call) Run(run func(ctx context.Context, userID int64, per int, page int)) *MockCodeStore_UserLikesCodes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockCodeStore_UserLikesCodes_Call) Return(codes []database.Code, total int, err error) *MockCodeStore_UserLikesCodes_Call { + _c.Call.Return(codes, total, err) + return _c +} + +func (_c *MockCodeStore_UserLikesCodes_Call) RunAndReturn(run func(context.Context, int64, int, int) ([]database.Code, int, error)) *MockCodeStore_UserLikesCodes_Call { + _c.Call.Return(run) + return _c +} + +// NewMockCodeStore creates a new instance of MockCodeStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockCodeStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockCodeStore { + mock := &MockCodeStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_CollectionStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_CollectionStore.go new file mode 100644 index 00000000..73d8a93c --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_CollectionStore.go @@ -0,0 +1,827 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" + + types "opencsg.com/csghub-server/common/types" +) + +// MockCollectionStore is an autogenerated mock type for the CollectionStore type +type MockCollectionStore struct { + mock.Mock +} + +type MockCollectionStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockCollectionStore) EXPECT() *MockCollectionStore_Expecter { + return &MockCollectionStore_Expecter{mock: &_m.Mock} +} + +// AddCollectionRepos provides a mock function with given fields: ctx, crs +func (_m *MockCollectionStore) AddCollectionRepos(ctx context.Context, crs []database.CollectionRepository) error { + ret := _m.Called(ctx, crs) + + if len(ret) == 0 { + panic("no return value specified for AddCollectionRepos") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []database.CollectionRepository) error); ok { + r0 = rf(ctx, crs) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockCollectionStore_AddCollectionRepos_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddCollectionRepos' +type MockCollectionStore_AddCollectionRepos_Call struct { + *mock.Call +} + +// AddCollectionRepos is a helper method to define mock.On call +// - ctx context.Context +// - crs []database.CollectionRepository +func (_e *MockCollectionStore_Expecter) AddCollectionRepos(ctx interface{}, crs interface{}) *MockCollectionStore_AddCollectionRepos_Call { + return &MockCollectionStore_AddCollectionRepos_Call{Call: _e.mock.On("AddCollectionRepos", ctx, crs)} +} + +func (_c *MockCollectionStore_AddCollectionRepos_Call) Run(run func(ctx context.Context, crs []database.CollectionRepository)) *MockCollectionStore_AddCollectionRepos_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]database.CollectionRepository)) + }) + return _c +} + +func (_c *MockCollectionStore_AddCollectionRepos_Call) Return(_a0 error) *MockCollectionStore_AddCollectionRepos_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockCollectionStore_AddCollectionRepos_Call) RunAndReturn(run func(context.Context, []database.CollectionRepository) error) *MockCollectionStore_AddCollectionRepos_Call { + _c.Call.Return(run) + return _c +} + +// ByUserLikes provides a mock function with given fields: ctx, userID, per, page +func (_m *MockCollectionStore) ByUserLikes(ctx context.Context, userID int64, per int, page int) ([]database.Collection, int, error) { + ret := _m.Called(ctx, userID, per, page) + + if len(ret) == 0 { + panic("no return value specified for ByUserLikes") + } + + var r0 []database.Collection + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) ([]database.Collection, int, error)); ok { + return rf(ctx, userID, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) []database.Collection); ok { + r0 = rf(ctx, userID, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int, int) int); ok { + r1 = rf(ctx, userID, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, int64, int, int) error); ok { + r2 = rf(ctx, userID, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockCollectionStore_ByUserLikes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByUserLikes' +type MockCollectionStore_ByUserLikes_Call struct { + *mock.Call +} + +// ByUserLikes is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +// - per int +// - page int +func (_e *MockCollectionStore_Expecter) ByUserLikes(ctx interface{}, userID interface{}, per interface{}, page interface{}) *MockCollectionStore_ByUserLikes_Call { + return &MockCollectionStore_ByUserLikes_Call{Call: _e.mock.On("ByUserLikes", ctx, userID, per, page)} +} + +func (_c *MockCollectionStore_ByUserLikes_Call) Run(run func(ctx context.Context, userID int64, per int, page int)) *MockCollectionStore_ByUserLikes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockCollectionStore_ByUserLikes_Call) Return(collections []database.Collection, total int, err error) *MockCollectionStore_ByUserLikes_Call { + _c.Call.Return(collections, total, err) + return _c +} + +func (_c *MockCollectionStore_ByUserLikes_Call) RunAndReturn(run func(context.Context, int64, int, int) ([]database.Collection, int, error)) *MockCollectionStore_ByUserLikes_Call { + _c.Call.Return(run) + return _c +} + +// ByUserOrgs provides a mock function with given fields: ctx, namespace, per, page, onlyPublic +func (_m *MockCollectionStore) ByUserOrgs(ctx context.Context, namespace string, per int, page int, onlyPublic bool) ([]database.Collection, int, error) { + ret := _m.Called(ctx, namespace, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByUserOrgs") + } + + var r0 []database.Collection + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Collection, int, error)); ok { + return rf(ctx, namespace, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Collection); ok { + r0 = rf(ctx, namespace, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockCollectionStore_ByUserOrgs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByUserOrgs' +type MockCollectionStore_ByUserOrgs_Call struct { + *mock.Call +} + +// ByUserOrgs is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockCollectionStore_Expecter) ByUserOrgs(ctx interface{}, namespace interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockCollectionStore_ByUserOrgs_Call { + return &MockCollectionStore_ByUserOrgs_Call{Call: _e.mock.On("ByUserOrgs", ctx, namespace, per, page, onlyPublic)} +} + +func (_c *MockCollectionStore_ByUserOrgs_Call) Run(run func(ctx context.Context, namespace string, per int, page int, onlyPublic bool)) *MockCollectionStore_ByUserOrgs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockCollectionStore_ByUserOrgs_Call) Return(collections []database.Collection, total int, err error) *MockCollectionStore_ByUserOrgs_Call { + _c.Call.Return(collections, total, err) + return _c +} + +func (_c *MockCollectionStore_ByUserOrgs_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Collection, int, error)) *MockCollectionStore_ByUserOrgs_Call { + _c.Call.Return(run) + return _c +} + +// ByUsername provides a mock function with given fields: ctx, username, per, page, onlyPublic +func (_m *MockCollectionStore) ByUsername(ctx context.Context, username string, per int, page int, onlyPublic bool) ([]database.Collection, int, error) { + ret := _m.Called(ctx, username, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByUsername") + } + + var r0 []database.Collection + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Collection, int, error)); ok { + return rf(ctx, username, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Collection); ok { + r0 = rf(ctx, username, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, username, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, username, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockCollectionStore_ByUsername_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByUsername' +type MockCollectionStore_ByUsername_Call struct { + *mock.Call +} + +// ByUsername is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockCollectionStore_Expecter) ByUsername(ctx interface{}, username interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockCollectionStore_ByUsername_Call { + return &MockCollectionStore_ByUsername_Call{Call: _e.mock.On("ByUsername", ctx, username, per, page, onlyPublic)} +} + +func (_c *MockCollectionStore_ByUsername_Call) Run(run func(ctx context.Context, username string, per int, page int, onlyPublic bool)) *MockCollectionStore_ByUsername_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockCollectionStore_ByUsername_Call) Return(collections []database.Collection, total int, err error) *MockCollectionStore_ByUsername_Call { + _c.Call.Return(collections, total, err) + return _c +} + +func (_c *MockCollectionStore_ByUsername_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Collection, int, error)) *MockCollectionStore_ByUsername_Call { + _c.Call.Return(run) + return _c +} + +// CreateCollection provides a mock function with given fields: ctx, collection +func (_m *MockCollectionStore) CreateCollection(ctx context.Context, collection database.Collection) (*database.Collection, error) { + ret := _m.Called(ctx, collection) + + if len(ret) == 0 { + panic("no return value specified for CreateCollection") + } + + var r0 *database.Collection + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Collection) (*database.Collection, error)); ok { + return rf(ctx, collection) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Collection) *database.Collection); ok { + r0 = rf(ctx, collection) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Collection) error); ok { + r1 = rf(ctx, collection) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockCollectionStore_CreateCollection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateCollection' +type MockCollectionStore_CreateCollection_Call struct { + *mock.Call +} + +// CreateCollection is a helper method to define mock.On call +// - ctx context.Context +// - collection database.Collection +func (_e *MockCollectionStore_Expecter) CreateCollection(ctx interface{}, collection interface{}) *MockCollectionStore_CreateCollection_Call { + return &MockCollectionStore_CreateCollection_Call{Call: _e.mock.On("CreateCollection", ctx, collection)} +} + +func (_c *MockCollectionStore_CreateCollection_Call) Run(run func(ctx context.Context, collection database.Collection)) *MockCollectionStore_CreateCollection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Collection)) + }) + return _c +} + +func (_c *MockCollectionStore_CreateCollection_Call) Return(_a0 *database.Collection, _a1 error) *MockCollectionStore_CreateCollection_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockCollectionStore_CreateCollection_Call) RunAndReturn(run func(context.Context, database.Collection) (*database.Collection, error)) *MockCollectionStore_CreateCollection_Call { + _c.Call.Return(run) + return _c +} + +// DeleteCollection provides a mock function with given fields: ctx, id, uid +func (_m *MockCollectionStore) DeleteCollection(ctx context.Context, id int64, uid int64) error { + ret := _m.Called(ctx, id, uid) + + if len(ret) == 0 { + panic("no return value specified for DeleteCollection") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64) error); ok { + r0 = rf(ctx, id, uid) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockCollectionStore_DeleteCollection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteCollection' +type MockCollectionStore_DeleteCollection_Call struct { + *mock.Call +} + +// DeleteCollection is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +// - uid int64 +func (_e *MockCollectionStore_Expecter) DeleteCollection(ctx interface{}, id interface{}, uid interface{}) *MockCollectionStore_DeleteCollection_Call { + return &MockCollectionStore_DeleteCollection_Call{Call: _e.mock.On("DeleteCollection", ctx, id, uid)} +} + +func (_c *MockCollectionStore_DeleteCollection_Call) Run(run func(ctx context.Context, id int64, uid int64)) *MockCollectionStore_DeleteCollection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64)) + }) + return _c +} + +func (_c *MockCollectionStore_DeleteCollection_Call) Return(_a0 error) *MockCollectionStore_DeleteCollection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockCollectionStore_DeleteCollection_Call) RunAndReturn(run func(context.Context, int64, int64) error) *MockCollectionStore_DeleteCollection_Call { + _c.Call.Return(run) + return _c +} + +// FindById provides a mock function with given fields: ctx, id +func (_m *MockCollectionStore) FindById(ctx context.Context, id int64) (database.Collection, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for FindById") + } + + var r0 database.Collection + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (database.Collection, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) database.Collection); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Get(0).(database.Collection) + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockCollectionStore_FindById_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindById' +type MockCollectionStore_FindById_Call struct { + *mock.Call +} + +// FindById is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockCollectionStore_Expecter) FindById(ctx interface{}, id interface{}) *MockCollectionStore_FindById_Call { + return &MockCollectionStore_FindById_Call{Call: _e.mock.On("FindById", ctx, id)} +} + +func (_c *MockCollectionStore_FindById_Call) Run(run func(ctx context.Context, id int64)) *MockCollectionStore_FindById_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockCollectionStore_FindById_Call) Return(collection database.Collection, err error) *MockCollectionStore_FindById_Call { + _c.Call.Return(collection, err) + return _c +} + +func (_c *MockCollectionStore_FindById_Call) RunAndReturn(run func(context.Context, int64) (database.Collection, error)) *MockCollectionStore_FindById_Call { + _c.Call.Return(run) + return _c +} + +// GetCollection provides a mock function with given fields: ctx, id +func (_m *MockCollectionStore) GetCollection(ctx context.Context, id int64) (*database.Collection, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetCollection") + } + + var r0 *database.Collection + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Collection, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Collection); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockCollectionStore_GetCollection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCollection' +type MockCollectionStore_GetCollection_Call struct { + *mock.Call +} + +// GetCollection is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockCollectionStore_Expecter) GetCollection(ctx interface{}, id interface{}) *MockCollectionStore_GetCollection_Call { + return &MockCollectionStore_GetCollection_Call{Call: _e.mock.On("GetCollection", ctx, id)} +} + +func (_c *MockCollectionStore_GetCollection_Call) Run(run func(ctx context.Context, id int64)) *MockCollectionStore_GetCollection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockCollectionStore_GetCollection_Call) Return(_a0 *database.Collection, _a1 error) *MockCollectionStore_GetCollection_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockCollectionStore_GetCollection_Call) RunAndReturn(run func(context.Context, int64) (*database.Collection, error)) *MockCollectionStore_GetCollection_Call { + _c.Call.Return(run) + return _c +} + +// GetCollections provides a mock function with given fields: ctx, filter, per, page, showPrivate +func (_m *MockCollectionStore) GetCollections(ctx context.Context, filter *types.CollectionFilter, per int, page int, showPrivate bool) ([]database.Collection, int, error) { + ret := _m.Called(ctx, filter, per, page, showPrivate) + + if len(ret) == 0 { + panic("no return value specified for GetCollections") + } + + var r0 []database.Collection + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.CollectionFilter, int, int, bool) ([]database.Collection, int, error)); ok { + return rf(ctx, filter, per, page, showPrivate) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.CollectionFilter, int, int, bool) []database.Collection); ok { + r0 = rf(ctx, filter, per, page, showPrivate) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.CollectionFilter, int, int, bool) int); ok { + r1 = rf(ctx, filter, per, page, showPrivate) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.CollectionFilter, int, int, bool) error); ok { + r2 = rf(ctx, filter, per, page, showPrivate) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockCollectionStore_GetCollections_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCollections' +type MockCollectionStore_GetCollections_Call struct { + *mock.Call +} + +// GetCollections is a helper method to define mock.On call +// - ctx context.Context +// - filter *types.CollectionFilter +// - per int +// - page int +// - showPrivate bool +func (_e *MockCollectionStore_Expecter) GetCollections(ctx interface{}, filter interface{}, per interface{}, page interface{}, showPrivate interface{}) *MockCollectionStore_GetCollections_Call { + return &MockCollectionStore_GetCollections_Call{Call: _e.mock.On("GetCollections", ctx, filter, per, page, showPrivate)} +} + +func (_c *MockCollectionStore_GetCollections_Call) Run(run func(ctx context.Context, filter *types.CollectionFilter, per int, page int, showPrivate bool)) *MockCollectionStore_GetCollections_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.CollectionFilter), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockCollectionStore_GetCollections_Call) Return(collections []database.Collection, total int, err error) *MockCollectionStore_GetCollections_Call { + _c.Call.Return(collections, total, err) + return _c +} + +func (_c *MockCollectionStore_GetCollections_Call) RunAndReturn(run func(context.Context, *types.CollectionFilter, int, int, bool) ([]database.Collection, int, error)) *MockCollectionStore_GetCollections_Call { + _c.Call.Return(run) + return _c +} + +// GetCollectionsByIDs provides a mock function with given fields: ctx, collections, ids, total, onlyPublic +func (_m *MockCollectionStore) GetCollectionsByIDs(ctx context.Context, collections []database.Collection, ids []interface{}, total int, onlyPublic bool) ([]database.Collection, int, error) { + ret := _m.Called(ctx, collections, ids, total, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for GetCollectionsByIDs") + } + + var r0 []database.Collection + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, []database.Collection, []interface{}, int, bool) ([]database.Collection, int, error)); ok { + return rf(ctx, collections, ids, total, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, []database.Collection, []interface{}, int, bool) []database.Collection); ok { + r0 = rf(ctx, collections, ids, total, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []database.Collection, []interface{}, int, bool) int); ok { + r1 = rf(ctx, collections, ids, total, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, []database.Collection, []interface{}, int, bool) error); ok { + r2 = rf(ctx, collections, ids, total, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockCollectionStore_GetCollectionsByIDs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCollectionsByIDs' +type MockCollectionStore_GetCollectionsByIDs_Call struct { + *mock.Call +} + +// GetCollectionsByIDs is a helper method to define mock.On call +// - ctx context.Context +// - collections []database.Collection +// - ids []interface{} +// - total int +// - onlyPublic bool +func (_e *MockCollectionStore_Expecter) GetCollectionsByIDs(ctx interface{}, collections interface{}, ids interface{}, total interface{}, onlyPublic interface{}) *MockCollectionStore_GetCollectionsByIDs_Call { + return &MockCollectionStore_GetCollectionsByIDs_Call{Call: _e.mock.On("GetCollectionsByIDs", ctx, collections, ids, total, onlyPublic)} +} + +func (_c *MockCollectionStore_GetCollectionsByIDs_Call) Run(run func(ctx context.Context, collections []database.Collection, ids []interface{}, total int, onlyPublic bool)) *MockCollectionStore_GetCollectionsByIDs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]database.Collection), args[2].([]interface{}), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockCollectionStore_GetCollectionsByIDs_Call) Return(_a0 []database.Collection, _a1 int, _a2 error) *MockCollectionStore_GetCollectionsByIDs_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockCollectionStore_GetCollectionsByIDs_Call) RunAndReturn(run func(context.Context, []database.Collection, []interface{}, int, bool) ([]database.Collection, int, error)) *MockCollectionStore_GetCollectionsByIDs_Call { + _c.Call.Return(run) + return _c +} + +// QueryByTrending provides a mock function with given fields: ctx, filter, per, page +func (_m *MockCollectionStore) QueryByTrending(ctx context.Context, filter *types.CollectionFilter, per int, page int) ([]database.Collection, int, error) { + ret := _m.Called(ctx, filter, per, page) + + if len(ret) == 0 { + panic("no return value specified for QueryByTrending") + } + + var r0 []database.Collection + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.CollectionFilter, int, int) ([]database.Collection, int, error)); ok { + return rf(ctx, filter, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.CollectionFilter, int, int) []database.Collection); ok { + r0 = rf(ctx, filter, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.CollectionFilter, int, int) int); ok { + r1 = rf(ctx, filter, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.CollectionFilter, int, int) error); ok { + r2 = rf(ctx, filter, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockCollectionStore_QueryByTrending_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryByTrending' +type MockCollectionStore_QueryByTrending_Call struct { + *mock.Call +} + +// QueryByTrending is a helper method to define mock.On call +// - ctx context.Context +// - filter *types.CollectionFilter +// - per int +// - page int +func (_e *MockCollectionStore_Expecter) QueryByTrending(ctx interface{}, filter interface{}, per interface{}, page interface{}) *MockCollectionStore_QueryByTrending_Call { + return &MockCollectionStore_QueryByTrending_Call{Call: _e.mock.On("QueryByTrending", ctx, filter, per, page)} +} + +func (_c *MockCollectionStore_QueryByTrending_Call) Run(run func(ctx context.Context, filter *types.CollectionFilter, per int, page int)) *MockCollectionStore_QueryByTrending_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.CollectionFilter), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockCollectionStore_QueryByTrending_Call) Return(collections []database.Collection, total int, err error) *MockCollectionStore_QueryByTrending_Call { + _c.Call.Return(collections, total, err) + return _c +} + +func (_c *MockCollectionStore_QueryByTrending_Call) RunAndReturn(run func(context.Context, *types.CollectionFilter, int, int) ([]database.Collection, int, error)) *MockCollectionStore_QueryByTrending_Call { + _c.Call.Return(run) + return _c +} + +// RemoveCollectionRepos provides a mock function with given fields: ctx, crs +func (_m *MockCollectionStore) RemoveCollectionRepos(ctx context.Context, crs []database.CollectionRepository) error { + ret := _m.Called(ctx, crs) + + if len(ret) == 0 { + panic("no return value specified for RemoveCollectionRepos") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []database.CollectionRepository) error); ok { + r0 = rf(ctx, crs) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockCollectionStore_RemoveCollectionRepos_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveCollectionRepos' +type MockCollectionStore_RemoveCollectionRepos_Call struct { + *mock.Call +} + +// RemoveCollectionRepos is a helper method to define mock.On call +// - ctx context.Context +// - crs []database.CollectionRepository +func (_e *MockCollectionStore_Expecter) RemoveCollectionRepos(ctx interface{}, crs interface{}) *MockCollectionStore_RemoveCollectionRepos_Call { + return &MockCollectionStore_RemoveCollectionRepos_Call{Call: _e.mock.On("RemoveCollectionRepos", ctx, crs)} +} + +func (_c *MockCollectionStore_RemoveCollectionRepos_Call) Run(run func(ctx context.Context, crs []database.CollectionRepository)) *MockCollectionStore_RemoveCollectionRepos_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]database.CollectionRepository)) + }) + return _c +} + +func (_c *MockCollectionStore_RemoveCollectionRepos_Call) Return(_a0 error) *MockCollectionStore_RemoveCollectionRepos_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockCollectionStore_RemoveCollectionRepos_Call) RunAndReturn(run func(context.Context, []database.CollectionRepository) error) *MockCollectionStore_RemoveCollectionRepos_Call { + _c.Call.Return(run) + return _c +} + +// UpdateCollection provides a mock function with given fields: ctx, collection +func (_m *MockCollectionStore) UpdateCollection(ctx context.Context, collection database.Collection) (*database.Collection, error) { + ret := _m.Called(ctx, collection) + + if len(ret) == 0 { + panic("no return value specified for UpdateCollection") + } + + var r0 *database.Collection + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Collection) (*database.Collection, error)); ok { + return rf(ctx, collection) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Collection) *database.Collection); ok { + r0 = rf(ctx, collection) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Collection) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Collection) error); ok { + r1 = rf(ctx, collection) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockCollectionStore_UpdateCollection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateCollection' +type MockCollectionStore_UpdateCollection_Call struct { + *mock.Call +} + +// UpdateCollection is a helper method to define mock.On call +// - ctx context.Context +// - collection database.Collection +func (_e *MockCollectionStore_Expecter) UpdateCollection(ctx interface{}, collection interface{}) *MockCollectionStore_UpdateCollection_Call { + return &MockCollectionStore_UpdateCollection_Call{Call: _e.mock.On("UpdateCollection", ctx, collection)} +} + +func (_c *MockCollectionStore_UpdateCollection_Call) Run(run func(ctx context.Context, collection database.Collection)) *MockCollectionStore_UpdateCollection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Collection)) + }) + return _c +} + +func (_c *MockCollectionStore_UpdateCollection_Call) Return(_a0 *database.Collection, _a1 error) *MockCollectionStore_UpdateCollection_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockCollectionStore_UpdateCollection_Call) RunAndReturn(run func(context.Context, database.Collection) (*database.Collection, error)) *MockCollectionStore_UpdateCollection_Call { + _c.Call.Return(run) + return _c +} + +// NewMockCollectionStore creates a new instance of MockCollectionStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockCollectionStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockCollectionStore { + mock := &MockCollectionStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DatasetStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DatasetStore.go index b6ba3745..54033515 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DatasetStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DatasetStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DeployTaskStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DeployTaskStore.go new file mode 100644 index 00000000..db980c72 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DeployTaskStore.go @@ -0,0 +1,1183 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" + + types "opencsg.com/csghub-server/common/types" +) + +// MockDeployTaskStore is an autogenerated mock type for the DeployTaskStore type +type MockDeployTaskStore struct { + mock.Mock +} + +type MockDeployTaskStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockDeployTaskStore) EXPECT() *MockDeployTaskStore_Expecter { + return &MockDeployTaskStore_Expecter{mock: &_m.Mock} +} + +// CreateDeploy provides a mock function with given fields: ctx, deploy +func (_m *MockDeployTaskStore) CreateDeploy(ctx context.Context, deploy *database.Deploy) error { + ret := _m.Called(ctx, deploy) + + if len(ret) == 0 { + panic("no return value specified for CreateDeploy") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Deploy) error); ok { + r0 = rf(ctx, deploy) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployTaskStore_CreateDeploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateDeploy' +type MockDeployTaskStore_CreateDeploy_Call struct { + *mock.Call +} + +// CreateDeploy is a helper method to define mock.On call +// - ctx context.Context +// - deploy *database.Deploy +func (_e *MockDeployTaskStore_Expecter) CreateDeploy(ctx interface{}, deploy interface{}) *MockDeployTaskStore_CreateDeploy_Call { + return &MockDeployTaskStore_CreateDeploy_Call{Call: _e.mock.On("CreateDeploy", ctx, deploy)} +} + +func (_c *MockDeployTaskStore_CreateDeploy_Call) Run(run func(ctx context.Context, deploy *database.Deploy)) *MockDeployTaskStore_CreateDeploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Deploy)) + }) + return _c +} + +func (_c *MockDeployTaskStore_CreateDeploy_Call) Return(_a0 error) *MockDeployTaskStore_CreateDeploy_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDeployTaskStore_CreateDeploy_Call) RunAndReturn(run func(context.Context, *database.Deploy) error) *MockDeployTaskStore_CreateDeploy_Call { + _c.Call.Return(run) + return _c +} + +// CreateDeployTask provides a mock function with given fields: ctx, deployTask +func (_m *MockDeployTaskStore) CreateDeployTask(ctx context.Context, deployTask *database.DeployTask) error { + ret := _m.Called(ctx, deployTask) + + if len(ret) == 0 { + panic("no return value specified for CreateDeployTask") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.DeployTask) error); ok { + r0 = rf(ctx, deployTask) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployTaskStore_CreateDeployTask_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateDeployTask' +type MockDeployTaskStore_CreateDeployTask_Call struct { + *mock.Call +} + +// CreateDeployTask is a helper method to define mock.On call +// - ctx context.Context +// - deployTask *database.DeployTask +func (_e *MockDeployTaskStore_Expecter) CreateDeployTask(ctx interface{}, deployTask interface{}) *MockDeployTaskStore_CreateDeployTask_Call { + return &MockDeployTaskStore_CreateDeployTask_Call{Call: _e.mock.On("CreateDeployTask", ctx, deployTask)} +} + +func (_c *MockDeployTaskStore_CreateDeployTask_Call) Run(run func(ctx context.Context, deployTask *database.DeployTask)) *MockDeployTaskStore_CreateDeployTask_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.DeployTask)) + }) + return _c +} + +func (_c *MockDeployTaskStore_CreateDeployTask_Call) Return(_a0 error) *MockDeployTaskStore_CreateDeployTask_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDeployTaskStore_CreateDeployTask_Call) RunAndReturn(run func(context.Context, *database.DeployTask) error) *MockDeployTaskStore_CreateDeployTask_Call { + _c.Call.Return(run) + return _c +} + +// DeleteDeploy provides a mock function with given fields: ctx, repoType, repoID, userID, deployID +func (_m *MockDeployTaskStore) DeleteDeploy(ctx context.Context, repoType types.RepositoryType, repoID int64, userID int64, deployID int64) error { + ret := _m.Called(ctx, repoType, repoID, userID, deployID) + + if len(ret) == 0 { + panic("no return value specified for DeleteDeploy") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, int64, int64, int64) error); ok { + r0 = rf(ctx, repoType, repoID, userID, deployID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployTaskStore_DeleteDeploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteDeploy' +type MockDeployTaskStore_DeleteDeploy_Call struct { + *mock.Call +} + +// DeleteDeploy is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - repoID int64 +// - userID int64 +// - deployID int64 +func (_e *MockDeployTaskStore_Expecter) DeleteDeploy(ctx interface{}, repoType interface{}, repoID interface{}, userID interface{}, deployID interface{}) *MockDeployTaskStore_DeleteDeploy_Call { + return &MockDeployTaskStore_DeleteDeploy_Call{Call: _e.mock.On("DeleteDeploy", ctx, repoType, repoID, userID, deployID)} +} + +func (_c *MockDeployTaskStore_DeleteDeploy_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, repoID int64, userID int64, deployID int64)) *MockDeployTaskStore_DeleteDeploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(int64), args[3].(int64), args[4].(int64)) + }) + return _c +} + +func (_c *MockDeployTaskStore_DeleteDeploy_Call) Return(_a0 error) *MockDeployTaskStore_DeleteDeploy_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDeployTaskStore_DeleteDeploy_Call) RunAndReturn(run func(context.Context, types.RepositoryType, int64, int64, int64) error) *MockDeployTaskStore_DeleteDeploy_Call { + _c.Call.Return(run) + return _c +} + +// GetDeployByID provides a mock function with given fields: ctx, deployID +func (_m *MockDeployTaskStore) GetDeployByID(ctx context.Context, deployID int64) (*database.Deploy, error) { + ret := _m.Called(ctx, deployID) + + if len(ret) == 0 { + panic("no return value specified for GetDeployByID") + } + + var r0 *database.Deploy + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Deploy, error)); ok { + return rf(ctx, deployID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Deploy); ok { + r0 = rf(ctx, deployID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Deploy) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, deployID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployTaskStore_GetDeployByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDeployByID' +type MockDeployTaskStore_GetDeployByID_Call struct { + *mock.Call +} + +// GetDeployByID is a helper method to define mock.On call +// - ctx context.Context +// - deployID int64 +func (_e *MockDeployTaskStore_Expecter) GetDeployByID(ctx interface{}, deployID interface{}) *MockDeployTaskStore_GetDeployByID_Call { + return &MockDeployTaskStore_GetDeployByID_Call{Call: _e.mock.On("GetDeployByID", ctx, deployID)} +} + +func (_c *MockDeployTaskStore_GetDeployByID_Call) Run(run func(ctx context.Context, deployID int64)) *MockDeployTaskStore_GetDeployByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDeployTaskStore_GetDeployByID_Call) Return(_a0 *database.Deploy, _a1 error) *MockDeployTaskStore_GetDeployByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployTaskStore_GetDeployByID_Call) RunAndReturn(run func(context.Context, int64) (*database.Deploy, error)) *MockDeployTaskStore_GetDeployByID_Call { + _c.Call.Return(run) + return _c +} + +// GetDeployBySvcName provides a mock function with given fields: ctx, svcName +func (_m *MockDeployTaskStore) GetDeployBySvcName(ctx context.Context, svcName string) (*database.Deploy, error) { + ret := _m.Called(ctx, svcName) + + if len(ret) == 0 { + panic("no return value specified for GetDeployBySvcName") + } + + var r0 *database.Deploy + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.Deploy, error)); ok { + return rf(ctx, svcName) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.Deploy); ok { + r0 = rf(ctx, svcName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Deploy) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, svcName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployTaskStore_GetDeployBySvcName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDeployBySvcName' +type MockDeployTaskStore_GetDeployBySvcName_Call struct { + *mock.Call +} + +// GetDeployBySvcName is a helper method to define mock.On call +// - ctx context.Context +// - svcName string +func (_e *MockDeployTaskStore_Expecter) GetDeployBySvcName(ctx interface{}, svcName interface{}) *MockDeployTaskStore_GetDeployBySvcName_Call { + return &MockDeployTaskStore_GetDeployBySvcName_Call{Call: _e.mock.On("GetDeployBySvcName", ctx, svcName)} +} + +func (_c *MockDeployTaskStore_GetDeployBySvcName_Call) Run(run func(ctx context.Context, svcName string)) *MockDeployTaskStore_GetDeployBySvcName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockDeployTaskStore_GetDeployBySvcName_Call) Return(_a0 *database.Deploy, _a1 error) *MockDeployTaskStore_GetDeployBySvcName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployTaskStore_GetDeployBySvcName_Call) RunAndReturn(run func(context.Context, string) (*database.Deploy, error)) *MockDeployTaskStore_GetDeployBySvcName_Call { + _c.Call.Return(run) + return _c +} + +// GetDeployTask provides a mock function with given fields: ctx, id +func (_m *MockDeployTaskStore) GetDeployTask(ctx context.Context, id int64) (*database.DeployTask, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetDeployTask") + } + + var r0 *database.DeployTask + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.DeployTask, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.DeployTask); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.DeployTask) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployTaskStore_GetDeployTask_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDeployTask' +type MockDeployTaskStore_GetDeployTask_Call struct { + *mock.Call +} + +// GetDeployTask is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockDeployTaskStore_Expecter) GetDeployTask(ctx interface{}, id interface{}) *MockDeployTaskStore_GetDeployTask_Call { + return &MockDeployTaskStore_GetDeployTask_Call{Call: _e.mock.On("GetDeployTask", ctx, id)} +} + +func (_c *MockDeployTaskStore_GetDeployTask_Call) Run(run func(ctx context.Context, id int64)) *MockDeployTaskStore_GetDeployTask_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDeployTaskStore_GetDeployTask_Call) Return(_a0 *database.DeployTask, _a1 error) *MockDeployTaskStore_GetDeployTask_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployTaskStore_GetDeployTask_Call) RunAndReturn(run func(context.Context, int64) (*database.DeployTask, error)) *MockDeployTaskStore_GetDeployTask_Call { + _c.Call.Return(run) + return _c +} + +// GetDeployTasksOfDeploy provides a mock function with given fields: ctx, deployID +func (_m *MockDeployTaskStore) GetDeployTasksOfDeploy(ctx context.Context, deployID int64) ([]*database.DeployTask, error) { + ret := _m.Called(ctx, deployID) + + if len(ret) == 0 { + panic("no return value specified for GetDeployTasksOfDeploy") + } + + var r0 []*database.DeployTask + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]*database.DeployTask, error)); ok { + return rf(ctx, deployID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []*database.DeployTask); ok { + r0 = rf(ctx, deployID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.DeployTask) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, deployID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployTaskStore_GetDeployTasksOfDeploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDeployTasksOfDeploy' +type MockDeployTaskStore_GetDeployTasksOfDeploy_Call struct { + *mock.Call +} + +// GetDeployTasksOfDeploy is a helper method to define mock.On call +// - ctx context.Context +// - deployID int64 +func (_e *MockDeployTaskStore_Expecter) GetDeployTasksOfDeploy(ctx interface{}, deployID interface{}) *MockDeployTaskStore_GetDeployTasksOfDeploy_Call { + return &MockDeployTaskStore_GetDeployTasksOfDeploy_Call{Call: _e.mock.On("GetDeployTasksOfDeploy", ctx, deployID)} +} + +func (_c *MockDeployTaskStore_GetDeployTasksOfDeploy_Call) Run(run func(ctx context.Context, deployID int64)) *MockDeployTaskStore_GetDeployTasksOfDeploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDeployTaskStore_GetDeployTasksOfDeploy_Call) Return(_a0 []*database.DeployTask, _a1 error) *MockDeployTaskStore_GetDeployTasksOfDeploy_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployTaskStore_GetDeployTasksOfDeploy_Call) RunAndReturn(run func(context.Context, int64) ([]*database.DeployTask, error)) *MockDeployTaskStore_GetDeployTasksOfDeploy_Call { + _c.Call.Return(run) + return _c +} + +// GetLatestDeployBySpaceID provides a mock function with given fields: ctx, spaceID +func (_m *MockDeployTaskStore) GetLatestDeployBySpaceID(ctx context.Context, spaceID int64) (*database.Deploy, error) { + ret := _m.Called(ctx, spaceID) + + if len(ret) == 0 { + panic("no return value specified for GetLatestDeployBySpaceID") + } + + var r0 *database.Deploy + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Deploy, error)); ok { + return rf(ctx, spaceID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Deploy); ok { + r0 = rf(ctx, spaceID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Deploy) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, spaceID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployTaskStore_GetLatestDeployBySpaceID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLatestDeployBySpaceID' +type MockDeployTaskStore_GetLatestDeployBySpaceID_Call struct { + *mock.Call +} + +// GetLatestDeployBySpaceID is a helper method to define mock.On call +// - ctx context.Context +// - spaceID int64 +func (_e *MockDeployTaskStore_Expecter) GetLatestDeployBySpaceID(ctx interface{}, spaceID interface{}) *MockDeployTaskStore_GetLatestDeployBySpaceID_Call { + return &MockDeployTaskStore_GetLatestDeployBySpaceID_Call{Call: _e.mock.On("GetLatestDeployBySpaceID", ctx, spaceID)} +} + +func (_c *MockDeployTaskStore_GetLatestDeployBySpaceID_Call) Run(run func(ctx context.Context, spaceID int64)) *MockDeployTaskStore_GetLatestDeployBySpaceID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDeployTaskStore_GetLatestDeployBySpaceID_Call) Return(_a0 *database.Deploy, _a1 error) *MockDeployTaskStore_GetLatestDeployBySpaceID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployTaskStore_GetLatestDeployBySpaceID_Call) RunAndReturn(run func(context.Context, int64) (*database.Deploy, error)) *MockDeployTaskStore_GetLatestDeployBySpaceID_Call { + _c.Call.Return(run) + return _c +} + +// GetNewTaskAfter provides a mock function with given fields: ctx, currentDeployTaskID +func (_m *MockDeployTaskStore) GetNewTaskAfter(ctx context.Context, currentDeployTaskID int64) (*database.DeployTask, error) { + ret := _m.Called(ctx, currentDeployTaskID) + + if len(ret) == 0 { + panic("no return value specified for GetNewTaskAfter") + } + + var r0 *database.DeployTask + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.DeployTask, error)); ok { + return rf(ctx, currentDeployTaskID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.DeployTask); ok { + r0 = rf(ctx, currentDeployTaskID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.DeployTask) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, currentDeployTaskID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployTaskStore_GetNewTaskAfter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNewTaskAfter' +type MockDeployTaskStore_GetNewTaskAfter_Call struct { + *mock.Call +} + +// GetNewTaskAfter is a helper method to define mock.On call +// - ctx context.Context +// - currentDeployTaskID int64 +func (_e *MockDeployTaskStore_Expecter) GetNewTaskAfter(ctx interface{}, currentDeployTaskID interface{}) *MockDeployTaskStore_GetNewTaskAfter_Call { + return &MockDeployTaskStore_GetNewTaskAfter_Call{Call: _e.mock.On("GetNewTaskAfter", ctx, currentDeployTaskID)} +} + +func (_c *MockDeployTaskStore_GetNewTaskAfter_Call) Run(run func(ctx context.Context, currentDeployTaskID int64)) *MockDeployTaskStore_GetNewTaskAfter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDeployTaskStore_GetNewTaskAfter_Call) Return(_a0 *database.DeployTask, _a1 error) *MockDeployTaskStore_GetNewTaskAfter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployTaskStore_GetNewTaskAfter_Call) RunAndReturn(run func(context.Context, int64) (*database.DeployTask, error)) *MockDeployTaskStore_GetNewTaskAfter_Call { + _c.Call.Return(run) + return _c +} + +// GetNewTaskFirst provides a mock function with given fields: ctx +func (_m *MockDeployTaskStore) GetNewTaskFirst(ctx context.Context) (*database.DeployTask, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetNewTaskFirst") + } + + var r0 *database.DeployTask + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*database.DeployTask, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *database.DeployTask); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.DeployTask) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployTaskStore_GetNewTaskFirst_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNewTaskFirst' +type MockDeployTaskStore_GetNewTaskFirst_Call struct { + *mock.Call +} + +// GetNewTaskFirst is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockDeployTaskStore_Expecter) GetNewTaskFirst(ctx interface{}) *MockDeployTaskStore_GetNewTaskFirst_Call { + return &MockDeployTaskStore_GetNewTaskFirst_Call{Call: _e.mock.On("GetNewTaskFirst", ctx)} +} + +func (_c *MockDeployTaskStore_GetNewTaskFirst_Call) Run(run func(ctx context.Context)) *MockDeployTaskStore_GetNewTaskFirst_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockDeployTaskStore_GetNewTaskFirst_Call) Return(_a0 *database.DeployTask, _a1 error) *MockDeployTaskStore_GetNewTaskFirst_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployTaskStore_GetNewTaskFirst_Call) RunAndReturn(run func(context.Context) (*database.DeployTask, error)) *MockDeployTaskStore_GetNewTaskFirst_Call { + _c.Call.Return(run) + return _c +} + +// GetServerlessDeployByRepID provides a mock function with given fields: ctx, repoID +func (_m *MockDeployTaskStore) GetServerlessDeployByRepID(ctx context.Context, repoID int64) (*database.Deploy, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for GetServerlessDeployByRepID") + } + + var r0 *database.Deploy + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Deploy, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Deploy); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Deploy) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployTaskStore_GetServerlessDeployByRepID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetServerlessDeployByRepID' +type MockDeployTaskStore_GetServerlessDeployByRepID_Call struct { + *mock.Call +} + +// GetServerlessDeployByRepID is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockDeployTaskStore_Expecter) GetServerlessDeployByRepID(ctx interface{}, repoID interface{}) *MockDeployTaskStore_GetServerlessDeployByRepID_Call { + return &MockDeployTaskStore_GetServerlessDeployByRepID_Call{Call: _e.mock.On("GetServerlessDeployByRepID", ctx, repoID)} +} + +func (_c *MockDeployTaskStore_GetServerlessDeployByRepID_Call) Run(run func(ctx context.Context, repoID int64)) *MockDeployTaskStore_GetServerlessDeployByRepID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDeployTaskStore_GetServerlessDeployByRepID_Call) Return(_a0 *database.Deploy, _a1 error) *MockDeployTaskStore_GetServerlessDeployByRepID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployTaskStore_GetServerlessDeployByRepID_Call) RunAndReturn(run func(context.Context, int64) (*database.Deploy, error)) *MockDeployTaskStore_GetServerlessDeployByRepID_Call { + _c.Call.Return(run) + return _c +} + +// ListAllDeployments provides a mock function with given fields: ctx, userID +func (_m *MockDeployTaskStore) ListAllDeployments(ctx context.Context, userID int64) ([]database.Deploy, error) { + ret := _m.Called(ctx, userID) + + if len(ret) == 0 { + panic("no return value specified for ListAllDeployments") + } + + var r0 []database.Deploy + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.Deploy, error)); ok { + return rf(ctx, userID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.Deploy); ok { + r0 = rf(ctx, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Deploy) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployTaskStore_ListAllDeployments_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAllDeployments' +type MockDeployTaskStore_ListAllDeployments_Call struct { + *mock.Call +} + +// ListAllDeployments is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +func (_e *MockDeployTaskStore_Expecter) ListAllDeployments(ctx interface{}, userID interface{}) *MockDeployTaskStore_ListAllDeployments_Call { + return &MockDeployTaskStore_ListAllDeployments_Call{Call: _e.mock.On("ListAllDeployments", ctx, userID)} +} + +func (_c *MockDeployTaskStore_ListAllDeployments_Call) Run(run func(ctx context.Context, userID int64)) *MockDeployTaskStore_ListAllDeployments_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDeployTaskStore_ListAllDeployments_Call) Return(_a0 []database.Deploy, _a1 error) *MockDeployTaskStore_ListAllDeployments_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployTaskStore_ListAllDeployments_Call) RunAndReturn(run func(context.Context, int64) ([]database.Deploy, error)) *MockDeployTaskStore_ListAllDeployments_Call { + _c.Call.Return(run) + return _c +} + +// ListDeploy provides a mock function with given fields: ctx, repoType, repoID, userID +func (_m *MockDeployTaskStore) ListDeploy(ctx context.Context, repoType types.RepositoryType, repoID int64, userID int64) ([]database.Deploy, error) { + ret := _m.Called(ctx, repoType, repoID, userID) + + if len(ret) == 0 { + panic("no return value specified for ListDeploy") + } + + var r0 []database.Deploy + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, int64, int64) ([]database.Deploy, error)); ok { + return rf(ctx, repoType, repoID, userID) + } + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, int64, int64) []database.Deploy); ok { + r0 = rf(ctx, repoType, repoID, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Deploy) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.RepositoryType, int64, int64) error); ok { + r1 = rf(ctx, repoType, repoID, userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDeployTaskStore_ListDeploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListDeploy' +type MockDeployTaskStore_ListDeploy_Call struct { + *mock.Call +} + +// ListDeploy is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - repoID int64 +// - userID int64 +func (_e *MockDeployTaskStore_Expecter) ListDeploy(ctx interface{}, repoType interface{}, repoID interface{}, userID interface{}) *MockDeployTaskStore_ListDeploy_Call { + return &MockDeployTaskStore_ListDeploy_Call{Call: _e.mock.On("ListDeploy", ctx, repoType, repoID, userID)} +} + +func (_c *MockDeployTaskStore_ListDeploy_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, repoID int64, userID int64)) *MockDeployTaskStore_ListDeploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(int64), args[3].(int64)) + }) + return _c +} + +func (_c *MockDeployTaskStore_ListDeploy_Call) Return(_a0 []database.Deploy, _a1 error) *MockDeployTaskStore_ListDeploy_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDeployTaskStore_ListDeploy_Call) RunAndReturn(run func(context.Context, types.RepositoryType, int64, int64) ([]database.Deploy, error)) *MockDeployTaskStore_ListDeploy_Call { + _c.Call.Return(run) + return _c +} + +// ListDeployByUserID provides a mock function with given fields: ctx, userID, req +func (_m *MockDeployTaskStore) ListDeployByUserID(ctx context.Context, userID int64, req *types.DeployReq) ([]database.Deploy, int, error) { + ret := _m.Called(ctx, userID, req) + + if len(ret) == 0 { + panic("no return value specified for ListDeployByUserID") + } + + var r0 []database.Deploy + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, int64, *types.DeployReq) ([]database.Deploy, int, error)); ok { + return rf(ctx, userID, req) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, *types.DeployReq) []database.Deploy); ok { + r0 = rf(ctx, userID, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Deploy) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, *types.DeployReq) int); ok { + r1 = rf(ctx, userID, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, int64, *types.DeployReq) error); ok { + r2 = rf(ctx, userID, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockDeployTaskStore_ListDeployByUserID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListDeployByUserID' +type MockDeployTaskStore_ListDeployByUserID_Call struct { + *mock.Call +} + +// ListDeployByUserID is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +// - req *types.DeployReq +func (_e *MockDeployTaskStore_Expecter) ListDeployByUserID(ctx interface{}, userID interface{}, req interface{}) *MockDeployTaskStore_ListDeployByUserID_Call { + return &MockDeployTaskStore_ListDeployByUserID_Call{Call: _e.mock.On("ListDeployByUserID", ctx, userID, req)} +} + +func (_c *MockDeployTaskStore_ListDeployByUserID_Call) Run(run func(ctx context.Context, userID int64, req *types.DeployReq)) *MockDeployTaskStore_ListDeployByUserID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(*types.DeployReq)) + }) + return _c +} + +func (_c *MockDeployTaskStore_ListDeployByUserID_Call) Return(_a0 []database.Deploy, _a1 int, _a2 error) *MockDeployTaskStore_ListDeployByUserID_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockDeployTaskStore_ListDeployByUserID_Call) RunAndReturn(run func(context.Context, int64, *types.DeployReq) ([]database.Deploy, int, error)) *MockDeployTaskStore_ListDeployByUserID_Call { + _c.Call.Return(run) + return _c +} + +// ListInstancesByUserID provides a mock function with given fields: ctx, userID, per, page +func (_m *MockDeployTaskStore) ListInstancesByUserID(ctx context.Context, userID int64, per int, page int) ([]database.Deploy, int, error) { + ret := _m.Called(ctx, userID, per, page) + + if len(ret) == 0 { + panic("no return value specified for ListInstancesByUserID") + } + + var r0 []database.Deploy + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) ([]database.Deploy, int, error)); ok { + return rf(ctx, userID, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) []database.Deploy); ok { + r0 = rf(ctx, userID, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Deploy) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int, int) int); ok { + r1 = rf(ctx, userID, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, int64, int, int) error); ok { + r2 = rf(ctx, userID, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockDeployTaskStore_ListInstancesByUserID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListInstancesByUserID' +type MockDeployTaskStore_ListInstancesByUserID_Call struct { + *mock.Call +} + +// ListInstancesByUserID is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +// - per int +// - page int +func (_e *MockDeployTaskStore_Expecter) ListInstancesByUserID(ctx interface{}, userID interface{}, per interface{}, page interface{}) *MockDeployTaskStore_ListInstancesByUserID_Call { + return &MockDeployTaskStore_ListInstancesByUserID_Call{Call: _e.mock.On("ListInstancesByUserID", ctx, userID, per, page)} +} + +func (_c *MockDeployTaskStore_ListInstancesByUserID_Call) Run(run func(ctx context.Context, userID int64, per int, page int)) *MockDeployTaskStore_ListInstancesByUserID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockDeployTaskStore_ListInstancesByUserID_Call) Return(_a0 []database.Deploy, _a1 int, _a2 error) *MockDeployTaskStore_ListInstancesByUserID_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockDeployTaskStore_ListInstancesByUserID_Call) RunAndReturn(run func(context.Context, int64, int, int) ([]database.Deploy, int, error)) *MockDeployTaskStore_ListInstancesByUserID_Call { + _c.Call.Return(run) + return _c +} + +// ListServerless provides a mock function with given fields: ctx, req +func (_m *MockDeployTaskStore) ListServerless(ctx context.Context, req types.DeployReq) ([]database.Deploy, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for ListServerless") + } + + var r0 []database.Deploy + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, types.DeployReq) ([]database.Deploy, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.DeployReq) []database.Deploy); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Deploy) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.DeployReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, types.DeployReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockDeployTaskStore_ListServerless_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListServerless' +type MockDeployTaskStore_ListServerless_Call struct { + *mock.Call +} + +// ListServerless is a helper method to define mock.On call +// - ctx context.Context +// - req types.DeployReq +func (_e *MockDeployTaskStore_Expecter) ListServerless(ctx interface{}, req interface{}) *MockDeployTaskStore_ListServerless_Call { + return &MockDeployTaskStore_ListServerless_Call{Call: _e.mock.On("ListServerless", ctx, req)} +} + +func (_c *MockDeployTaskStore_ListServerless_Call) Run(run func(ctx context.Context, req types.DeployReq)) *MockDeployTaskStore_ListServerless_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.DeployReq)) + }) + return _c +} + +func (_c *MockDeployTaskStore_ListServerless_Call) Return(_a0 []database.Deploy, _a1 int, _a2 error) *MockDeployTaskStore_ListServerless_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockDeployTaskStore_ListServerless_Call) RunAndReturn(run func(context.Context, types.DeployReq) ([]database.Deploy, int, error)) *MockDeployTaskStore_ListServerless_Call { + _c.Call.Return(run) + return _c +} + +// StopDeploy provides a mock function with given fields: ctx, repoType, repoID, userID, deployID +func (_m *MockDeployTaskStore) StopDeploy(ctx context.Context, repoType types.RepositoryType, repoID int64, userID int64, deployID int64) error { + ret := _m.Called(ctx, repoType, repoID, userID, deployID) + + if len(ret) == 0 { + panic("no return value specified for StopDeploy") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, int64, int64, int64) error); ok { + r0 = rf(ctx, repoType, repoID, userID, deployID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployTaskStore_StopDeploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'StopDeploy' +type MockDeployTaskStore_StopDeploy_Call struct { + *mock.Call +} + +// StopDeploy is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - repoID int64 +// - userID int64 +// - deployID int64 +func (_e *MockDeployTaskStore_Expecter) StopDeploy(ctx interface{}, repoType interface{}, repoID interface{}, userID interface{}, deployID interface{}) *MockDeployTaskStore_StopDeploy_Call { + return &MockDeployTaskStore_StopDeploy_Call{Call: _e.mock.On("StopDeploy", ctx, repoType, repoID, userID, deployID)} +} + +func (_c *MockDeployTaskStore_StopDeploy_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, repoID int64, userID int64, deployID int64)) *MockDeployTaskStore_StopDeploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(int64), args[3].(int64), args[4].(int64)) + }) + return _c +} + +func (_c *MockDeployTaskStore_StopDeploy_Call) Return(_a0 error) *MockDeployTaskStore_StopDeploy_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDeployTaskStore_StopDeploy_Call) RunAndReturn(run func(context.Context, types.RepositoryType, int64, int64, int64) error) *MockDeployTaskStore_StopDeploy_Call { + _c.Call.Return(run) + return _c +} + +// UpdateDeploy provides a mock function with given fields: ctx, deploy +func (_m *MockDeployTaskStore) UpdateDeploy(ctx context.Context, deploy *database.Deploy) error { + ret := _m.Called(ctx, deploy) + + if len(ret) == 0 { + panic("no return value specified for UpdateDeploy") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Deploy) error); ok { + r0 = rf(ctx, deploy) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployTaskStore_UpdateDeploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateDeploy' +type MockDeployTaskStore_UpdateDeploy_Call struct { + *mock.Call +} + +// UpdateDeploy is a helper method to define mock.On call +// - ctx context.Context +// - deploy *database.Deploy +func (_e *MockDeployTaskStore_Expecter) UpdateDeploy(ctx interface{}, deploy interface{}) *MockDeployTaskStore_UpdateDeploy_Call { + return &MockDeployTaskStore_UpdateDeploy_Call{Call: _e.mock.On("UpdateDeploy", ctx, deploy)} +} + +func (_c *MockDeployTaskStore_UpdateDeploy_Call) Run(run func(ctx context.Context, deploy *database.Deploy)) *MockDeployTaskStore_UpdateDeploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Deploy)) + }) + return _c +} + +func (_c *MockDeployTaskStore_UpdateDeploy_Call) Return(_a0 error) *MockDeployTaskStore_UpdateDeploy_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDeployTaskStore_UpdateDeploy_Call) RunAndReturn(run func(context.Context, *database.Deploy) error) *MockDeployTaskStore_UpdateDeploy_Call { + _c.Call.Return(run) + return _c +} + +// UpdateDeployTask provides a mock function with given fields: ctx, deployTask +func (_m *MockDeployTaskStore) UpdateDeployTask(ctx context.Context, deployTask *database.DeployTask) error { + ret := _m.Called(ctx, deployTask) + + if len(ret) == 0 { + panic("no return value specified for UpdateDeployTask") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.DeployTask) error); ok { + r0 = rf(ctx, deployTask) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployTaskStore_UpdateDeployTask_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateDeployTask' +type MockDeployTaskStore_UpdateDeployTask_Call struct { + *mock.Call +} + +// UpdateDeployTask is a helper method to define mock.On call +// - ctx context.Context +// - deployTask *database.DeployTask +func (_e *MockDeployTaskStore_Expecter) UpdateDeployTask(ctx interface{}, deployTask interface{}) *MockDeployTaskStore_UpdateDeployTask_Call { + return &MockDeployTaskStore_UpdateDeployTask_Call{Call: _e.mock.On("UpdateDeployTask", ctx, deployTask)} +} + +func (_c *MockDeployTaskStore_UpdateDeployTask_Call) Run(run func(ctx context.Context, deployTask *database.DeployTask)) *MockDeployTaskStore_UpdateDeployTask_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.DeployTask)) + }) + return _c +} + +func (_c *MockDeployTaskStore_UpdateDeployTask_Call) Return(_a0 error) *MockDeployTaskStore_UpdateDeployTask_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDeployTaskStore_UpdateDeployTask_Call) RunAndReturn(run func(context.Context, *database.DeployTask) error) *MockDeployTaskStore_UpdateDeployTask_Call { + _c.Call.Return(run) + return _c +} + +// UpdateInTx provides a mock function with given fields: ctx, deployColumns, deployTaskColumns, deploy, deployTasks +func (_m *MockDeployTaskStore) UpdateInTx(ctx context.Context, deployColumns []string, deployTaskColumns []string, deploy *database.Deploy, deployTasks ...*database.DeployTask) error { + _va := make([]interface{}, len(deployTasks)) + for _i := range deployTasks { + _va[_i] = deployTasks[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, deployColumns, deployTaskColumns, deploy) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for UpdateInTx") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []string, []string, *database.Deploy, ...*database.DeployTask) error); ok { + r0 = rf(ctx, deployColumns, deployTaskColumns, deploy, deployTasks...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDeployTaskStore_UpdateInTx_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateInTx' +type MockDeployTaskStore_UpdateInTx_Call struct { + *mock.Call +} + +// UpdateInTx is a helper method to define mock.On call +// - ctx context.Context +// - deployColumns []string +// - deployTaskColumns []string +// - deploy *database.Deploy +// - deployTasks ...*database.DeployTask +func (_e *MockDeployTaskStore_Expecter) UpdateInTx(ctx interface{}, deployColumns interface{}, deployTaskColumns interface{}, deploy interface{}, deployTasks ...interface{}) *MockDeployTaskStore_UpdateInTx_Call { + return &MockDeployTaskStore_UpdateInTx_Call{Call: _e.mock.On("UpdateInTx", + append([]interface{}{ctx, deployColumns, deployTaskColumns, deploy}, deployTasks...)...)} +} + +func (_c *MockDeployTaskStore_UpdateInTx_Call) Run(run func(ctx context.Context, deployColumns []string, deployTaskColumns []string, deploy *database.Deploy, deployTasks ...*database.DeployTask)) *MockDeployTaskStore_UpdateInTx_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]*database.DeployTask, len(args)-4) + for i, a := range args[4:] { + if a != nil { + variadicArgs[i] = a.(*database.DeployTask) + } + } + run(args[0].(context.Context), args[1].([]string), args[2].([]string), args[3].(*database.Deploy), variadicArgs...) + }) + return _c +} + +func (_c *MockDeployTaskStore_UpdateInTx_Call) Return(_a0 error) *MockDeployTaskStore_UpdateInTx_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDeployTaskStore_UpdateInTx_Call) RunAndReturn(run func(context.Context, []string, []string, *database.Deploy, ...*database.DeployTask) error) *MockDeployTaskStore_UpdateInTx_Call { + _c.Call.Return(run) + return _c +} + +// NewMockDeployTaskStore creates a new instance of MockDeployTaskStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockDeployTaskStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockDeployTaskStore { + mock := &MockDeployTaskStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DiscussionStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DiscussionStore.go new file mode 100644 index 00000000..4b637cec --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_DiscussionStore.go @@ -0,0 +1,582 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockDiscussionStore is an autogenerated mock type for the DiscussionStore type +type MockDiscussionStore struct { + mock.Mock +} + +type MockDiscussionStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockDiscussionStore) EXPECT() *MockDiscussionStore_Expecter { + return &MockDiscussionStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, discussion +func (_m *MockDiscussionStore) Create(ctx context.Context, discussion database.Discussion) (*database.Discussion, error) { + ret := _m.Called(ctx, discussion) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.Discussion + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Discussion) (*database.Discussion, error)); ok { + return rf(ctx, discussion) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Discussion) *database.Discussion); ok { + r0 = rf(ctx, discussion) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Discussion) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Discussion) error); ok { + r1 = rf(ctx, discussion) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDiscussionStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockDiscussionStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - discussion database.Discussion +func (_e *MockDiscussionStore_Expecter) Create(ctx interface{}, discussion interface{}) *MockDiscussionStore_Create_Call { + return &MockDiscussionStore_Create_Call{Call: _e.mock.On("Create", ctx, discussion)} +} + +func (_c *MockDiscussionStore_Create_Call) Run(run func(ctx context.Context, discussion database.Discussion)) *MockDiscussionStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Discussion)) + }) + return _c +} + +func (_c *MockDiscussionStore_Create_Call) Return(_a0 *database.Discussion, _a1 error) *MockDiscussionStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDiscussionStore_Create_Call) RunAndReturn(run func(context.Context, database.Discussion) (*database.Discussion, error)) *MockDiscussionStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// CreateComment provides a mock function with given fields: ctx, comment +func (_m *MockDiscussionStore) CreateComment(ctx context.Context, comment database.Comment) (*database.Comment, error) { + ret := _m.Called(ctx, comment) + + if len(ret) == 0 { + panic("no return value specified for CreateComment") + } + + var r0 *database.Comment + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Comment) (*database.Comment, error)); ok { + return rf(ctx, comment) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Comment) *database.Comment); ok { + r0 = rf(ctx, comment) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Comment) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Comment) error); ok { + r1 = rf(ctx, comment) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDiscussionStore_CreateComment_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateComment' +type MockDiscussionStore_CreateComment_Call struct { + *mock.Call +} + +// CreateComment is a helper method to define mock.On call +// - ctx context.Context +// - comment database.Comment +func (_e *MockDiscussionStore_Expecter) CreateComment(ctx interface{}, comment interface{}) *MockDiscussionStore_CreateComment_Call { + return &MockDiscussionStore_CreateComment_Call{Call: _e.mock.On("CreateComment", ctx, comment)} +} + +func (_c *MockDiscussionStore_CreateComment_Call) Run(run func(ctx context.Context, comment database.Comment)) *MockDiscussionStore_CreateComment_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Comment)) + }) + return _c +} + +func (_c *MockDiscussionStore_CreateComment_Call) Return(_a0 *database.Comment, _a1 error) *MockDiscussionStore_CreateComment_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDiscussionStore_CreateComment_Call) RunAndReturn(run func(context.Context, database.Comment) (*database.Comment, error)) *MockDiscussionStore_CreateComment_Call { + _c.Call.Return(run) + return _c +} + +// DeleteByID provides a mock function with given fields: ctx, id +func (_m *MockDiscussionStore) DeleteByID(ctx context.Context, id int64) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for DeleteByID") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDiscussionStore_DeleteByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteByID' +type MockDiscussionStore_DeleteByID_Call struct { + *mock.Call +} + +// DeleteByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockDiscussionStore_Expecter) DeleteByID(ctx interface{}, id interface{}) *MockDiscussionStore_DeleteByID_Call { + return &MockDiscussionStore_DeleteByID_Call{Call: _e.mock.On("DeleteByID", ctx, id)} +} + +func (_c *MockDiscussionStore_DeleteByID_Call) Run(run func(ctx context.Context, id int64)) *MockDiscussionStore_DeleteByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDiscussionStore_DeleteByID_Call) Return(_a0 error) *MockDiscussionStore_DeleteByID_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDiscussionStore_DeleteByID_Call) RunAndReturn(run func(context.Context, int64) error) *MockDiscussionStore_DeleteByID_Call { + _c.Call.Return(run) + return _c +} + +// DeleteComment provides a mock function with given fields: ctx, id +func (_m *MockDiscussionStore) DeleteComment(ctx context.Context, id int64) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for DeleteComment") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDiscussionStore_DeleteComment_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteComment' +type MockDiscussionStore_DeleteComment_Call struct { + *mock.Call +} + +// DeleteComment is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockDiscussionStore_Expecter) DeleteComment(ctx interface{}, id interface{}) *MockDiscussionStore_DeleteComment_Call { + return &MockDiscussionStore_DeleteComment_Call{Call: _e.mock.On("DeleteComment", ctx, id)} +} + +func (_c *MockDiscussionStore_DeleteComment_Call) Run(run func(ctx context.Context, id int64)) *MockDiscussionStore_DeleteComment_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDiscussionStore_DeleteComment_Call) Return(_a0 error) *MockDiscussionStore_DeleteComment_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDiscussionStore_DeleteComment_Call) RunAndReturn(run func(context.Context, int64) error) *MockDiscussionStore_DeleteComment_Call { + _c.Call.Return(run) + return _c +} + +// FindByDiscussionableID provides a mock function with given fields: ctx, discussionableType, discussionableID +func (_m *MockDiscussionStore) FindByDiscussionableID(ctx context.Context, discussionableType string, discussionableID int64) ([]database.Discussion, error) { + ret := _m.Called(ctx, discussionableType, discussionableID) + + if len(ret) == 0 { + panic("no return value specified for FindByDiscussionableID") + } + + var r0 []database.Discussion + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, int64) ([]database.Discussion, error)); ok { + return rf(ctx, discussionableType, discussionableID) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int64) []database.Discussion); ok { + r0 = rf(ctx, discussionableType, discussionableID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Discussion) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int64) error); ok { + r1 = rf(ctx, discussionableType, discussionableID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDiscussionStore_FindByDiscussionableID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByDiscussionableID' +type MockDiscussionStore_FindByDiscussionableID_Call struct { + *mock.Call +} + +// FindByDiscussionableID is a helper method to define mock.On call +// - ctx context.Context +// - discussionableType string +// - discussionableID int64 +func (_e *MockDiscussionStore_Expecter) FindByDiscussionableID(ctx interface{}, discussionableType interface{}, discussionableID interface{}) *MockDiscussionStore_FindByDiscussionableID_Call { + return &MockDiscussionStore_FindByDiscussionableID_Call{Call: _e.mock.On("FindByDiscussionableID", ctx, discussionableType, discussionableID)} +} + +func (_c *MockDiscussionStore_FindByDiscussionableID_Call) Run(run func(ctx context.Context, discussionableType string, discussionableID int64)) *MockDiscussionStore_FindByDiscussionableID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int64)) + }) + return _c +} + +func (_c *MockDiscussionStore_FindByDiscussionableID_Call) Return(_a0 []database.Discussion, _a1 error) *MockDiscussionStore_FindByDiscussionableID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDiscussionStore_FindByDiscussionableID_Call) RunAndReturn(run func(context.Context, string, int64) ([]database.Discussion, error)) *MockDiscussionStore_FindByDiscussionableID_Call { + _c.Call.Return(run) + return _c +} + +// FindByID provides a mock function with given fields: ctx, id +func (_m *MockDiscussionStore) FindByID(ctx context.Context, id int64) (*database.Discussion, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for FindByID") + } + + var r0 *database.Discussion + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Discussion, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Discussion); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Discussion) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDiscussionStore_FindByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByID' +type MockDiscussionStore_FindByID_Call struct { + *mock.Call +} + +// FindByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockDiscussionStore_Expecter) FindByID(ctx interface{}, id interface{}) *MockDiscussionStore_FindByID_Call { + return &MockDiscussionStore_FindByID_Call{Call: _e.mock.On("FindByID", ctx, id)} +} + +func (_c *MockDiscussionStore_FindByID_Call) Run(run func(ctx context.Context, id int64)) *MockDiscussionStore_FindByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDiscussionStore_FindByID_Call) Return(_a0 *database.Discussion, _a1 error) *MockDiscussionStore_FindByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDiscussionStore_FindByID_Call) RunAndReturn(run func(context.Context, int64) (*database.Discussion, error)) *MockDiscussionStore_FindByID_Call { + _c.Call.Return(run) + return _c +} + +// FindCommentByID provides a mock function with given fields: ctx, id +func (_m *MockDiscussionStore) FindCommentByID(ctx context.Context, id int64) (*database.Comment, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for FindCommentByID") + } + + var r0 *database.Comment + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Comment, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Comment); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Comment) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDiscussionStore_FindCommentByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindCommentByID' +type MockDiscussionStore_FindCommentByID_Call struct { + *mock.Call +} + +// FindCommentByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockDiscussionStore_Expecter) FindCommentByID(ctx interface{}, id interface{}) *MockDiscussionStore_FindCommentByID_Call { + return &MockDiscussionStore_FindCommentByID_Call{Call: _e.mock.On("FindCommentByID", ctx, id)} +} + +func (_c *MockDiscussionStore_FindCommentByID_Call) Run(run func(ctx context.Context, id int64)) *MockDiscussionStore_FindCommentByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDiscussionStore_FindCommentByID_Call) Return(_a0 *database.Comment, _a1 error) *MockDiscussionStore_FindCommentByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDiscussionStore_FindCommentByID_Call) RunAndReturn(run func(context.Context, int64) (*database.Comment, error)) *MockDiscussionStore_FindCommentByID_Call { + _c.Call.Return(run) + return _c +} + +// FindDiscussionComments provides a mock function with given fields: ctx, discussionID +func (_m *MockDiscussionStore) FindDiscussionComments(ctx context.Context, discussionID int64) ([]database.Comment, error) { + ret := _m.Called(ctx, discussionID) + + if len(ret) == 0 { + panic("no return value specified for FindDiscussionComments") + } + + var r0 []database.Comment + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.Comment, error)); ok { + return rf(ctx, discussionID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.Comment); ok { + r0 = rf(ctx, discussionID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Comment) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, discussionID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockDiscussionStore_FindDiscussionComments_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindDiscussionComments' +type MockDiscussionStore_FindDiscussionComments_Call struct { + *mock.Call +} + +// FindDiscussionComments is a helper method to define mock.On call +// - ctx context.Context +// - discussionID int64 +func (_e *MockDiscussionStore_Expecter) FindDiscussionComments(ctx interface{}, discussionID interface{}) *MockDiscussionStore_FindDiscussionComments_Call { + return &MockDiscussionStore_FindDiscussionComments_Call{Call: _e.mock.On("FindDiscussionComments", ctx, discussionID)} +} + +func (_c *MockDiscussionStore_FindDiscussionComments_Call) Run(run func(ctx context.Context, discussionID int64)) *MockDiscussionStore_FindDiscussionComments_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockDiscussionStore_FindDiscussionComments_Call) Return(_a0 []database.Comment, _a1 error) *MockDiscussionStore_FindDiscussionComments_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockDiscussionStore_FindDiscussionComments_Call) RunAndReturn(run func(context.Context, int64) ([]database.Comment, error)) *MockDiscussionStore_FindDiscussionComments_Call { + _c.Call.Return(run) + return _c +} + +// UpdateByID provides a mock function with given fields: ctx, id, title +func (_m *MockDiscussionStore) UpdateByID(ctx context.Context, id int64, title string) error { + ret := _m.Called(ctx, id, title) + + if len(ret) == 0 { + panic("no return value specified for UpdateByID") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) error); ok { + r0 = rf(ctx, id, title) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDiscussionStore_UpdateByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateByID' +type MockDiscussionStore_UpdateByID_Call struct { + *mock.Call +} + +// UpdateByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +// - title string +func (_e *MockDiscussionStore_Expecter) UpdateByID(ctx interface{}, id interface{}, title interface{}) *MockDiscussionStore_UpdateByID_Call { + return &MockDiscussionStore_UpdateByID_Call{Call: _e.mock.On("UpdateByID", ctx, id, title)} +} + +func (_c *MockDiscussionStore_UpdateByID_Call) Run(run func(ctx context.Context, id int64, title string)) *MockDiscussionStore_UpdateByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockDiscussionStore_UpdateByID_Call) Return(_a0 error) *MockDiscussionStore_UpdateByID_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDiscussionStore_UpdateByID_Call) RunAndReturn(run func(context.Context, int64, string) error) *MockDiscussionStore_UpdateByID_Call { + _c.Call.Return(run) + return _c +} + +// UpdateComment provides a mock function with given fields: ctx, id, content +func (_m *MockDiscussionStore) UpdateComment(ctx context.Context, id int64, content string) error { + ret := _m.Called(ctx, id, content) + + if len(ret) == 0 { + panic("no return value specified for UpdateComment") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) error); ok { + r0 = rf(ctx, id, content) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockDiscussionStore_UpdateComment_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateComment' +type MockDiscussionStore_UpdateComment_Call struct { + *mock.Call +} + +// UpdateComment is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +// - content string +func (_e *MockDiscussionStore_Expecter) UpdateComment(ctx interface{}, id interface{}, content interface{}) *MockDiscussionStore_UpdateComment_Call { + return &MockDiscussionStore_UpdateComment_Call{Call: _e.mock.On("UpdateComment", ctx, id, content)} +} + +func (_c *MockDiscussionStore_UpdateComment_Call) Run(run func(ctx context.Context, id int64, content string)) *MockDiscussionStore_UpdateComment_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockDiscussionStore_UpdateComment_Call) Return(_a0 error) *MockDiscussionStore_UpdateComment_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockDiscussionStore_UpdateComment_Call) RunAndReturn(run func(context.Context, int64, string) error) *MockDiscussionStore_UpdateComment_Call { + _c.Call.Return(run) + return _c +} + +// NewMockDiscussionStore creates a new instance of MockDiscussionStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockDiscussionStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockDiscussionStore { + mock := &MockDiscussionStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_EventStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_EventStore.go new file mode 100644 index 00000000..d702de0a --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_EventStore.go @@ -0,0 +1,131 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockEventStore is an autogenerated mock type for the EventStore type +type MockEventStore struct { + mock.Mock +} + +type MockEventStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockEventStore) EXPECT() *MockEventStore_Expecter { + return &MockEventStore_Expecter{mock: &_m.Mock} +} + +// BatchSave provides a mock function with given fields: ctx, events +func (_m *MockEventStore) BatchSave(ctx context.Context, events []database.Event) error { + ret := _m.Called(ctx, events) + + if len(ret) == 0 { + panic("no return value specified for BatchSave") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []database.Event) error); ok { + r0 = rf(ctx, events) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockEventStore_BatchSave_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchSave' +type MockEventStore_BatchSave_Call struct { + *mock.Call +} + +// BatchSave is a helper method to define mock.On call +// - ctx context.Context +// - events []database.Event +func (_e *MockEventStore_Expecter) BatchSave(ctx interface{}, events interface{}) *MockEventStore_BatchSave_Call { + return &MockEventStore_BatchSave_Call{Call: _e.mock.On("BatchSave", ctx, events)} +} + +func (_c *MockEventStore_BatchSave_Call) Run(run func(ctx context.Context, events []database.Event)) *MockEventStore_BatchSave_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]database.Event)) + }) + return _c +} + +func (_c *MockEventStore_BatchSave_Call) Return(_a0 error) *MockEventStore_BatchSave_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockEventStore_BatchSave_Call) RunAndReturn(run func(context.Context, []database.Event) error) *MockEventStore_BatchSave_Call { + _c.Call.Return(run) + return _c +} + +// Save provides a mock function with given fields: ctx, event +func (_m *MockEventStore) Save(ctx context.Context, event database.Event) error { + ret := _m.Called(ctx, event) + + if len(ret) == 0 { + panic("no return value specified for Save") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.Event) error); ok { + r0 = rf(ctx, event) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockEventStore_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' +type MockEventStore_Save_Call struct { + *mock.Call +} + +// Save is a helper method to define mock.On call +// - ctx context.Context +// - event database.Event +func (_e *MockEventStore_Expecter) Save(ctx interface{}, event interface{}) *MockEventStore_Save_Call { + return &MockEventStore_Save_Call{Call: _e.mock.On("Save", ctx, event)} +} + +func (_c *MockEventStore_Save_Call) Run(run func(ctx context.Context, event database.Event)) *MockEventStore_Save_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Event)) + }) + return _c +} + +func (_c *MockEventStore_Save_Call) Return(_a0 error) *MockEventStore_Save_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockEventStore_Save_Call) RunAndReturn(run func(context.Context, database.Event) error) *MockEventStore_Save_Call { + _c.Call.Return(run) + return _c +} + +// NewMockEventStore creates a new instance of MockEventStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockEventStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockEventStore { + mock := &MockEventStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_FileStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_FileStore.go new file mode 100644 index 00000000..2d9ef29f --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_FileStore.go @@ -0,0 +1,144 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockFileStore is an autogenerated mock type for the FileStore type +type MockFileStore struct { + mock.Mock +} + +type MockFileStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockFileStore) EXPECT() *MockFileStore_Expecter { + return &MockFileStore_Expecter{mock: &_m.Mock} +} + +// BatchCreate provides a mock function with given fields: ctx, files +func (_m *MockFileStore) BatchCreate(ctx context.Context, files []database.File) error { + ret := _m.Called(ctx, files) + + if len(ret) == 0 { + panic("no return value specified for BatchCreate") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []database.File) error); ok { + r0 = rf(ctx, files) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockFileStore_BatchCreate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchCreate' +type MockFileStore_BatchCreate_Call struct { + *mock.Call +} + +// BatchCreate is a helper method to define mock.On call +// - ctx context.Context +// - files []database.File +func (_e *MockFileStore_Expecter) BatchCreate(ctx interface{}, files interface{}) *MockFileStore_BatchCreate_Call { + return &MockFileStore_BatchCreate_Call{Call: _e.mock.On("BatchCreate", ctx, files)} +} + +func (_c *MockFileStore_BatchCreate_Call) Run(run func(ctx context.Context, files []database.File)) *MockFileStore_BatchCreate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]database.File)) + }) + return _c +} + +func (_c *MockFileStore_BatchCreate_Call) Return(_a0 error) *MockFileStore_BatchCreate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockFileStore_BatchCreate_Call) RunAndReturn(run func(context.Context, []database.File) error) *MockFileStore_BatchCreate_Call { + _c.Call.Return(run) + return _c +} + +// FindByParentPath provides a mock function with given fields: ctx, repoID, path +func (_m *MockFileStore) FindByParentPath(ctx context.Context, repoID int64, path string) ([]database.File, error) { + ret := _m.Called(ctx, repoID, path) + + if len(ret) == 0 { + panic("no return value specified for FindByParentPath") + } + + var r0 []database.File + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) ([]database.File, error)); ok { + return rf(ctx, repoID, path) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, string) []database.File); ok { + r0 = rf(ctx, repoID, path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.File) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, string) error); ok { + r1 = rf(ctx, repoID, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockFileStore_FindByParentPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByParentPath' +type MockFileStore_FindByParentPath_Call struct { + *mock.Call +} + +// FindByParentPath is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - path string +func (_e *MockFileStore_Expecter) FindByParentPath(ctx interface{}, repoID interface{}, path interface{}) *MockFileStore_FindByParentPath_Call { + return &MockFileStore_FindByParentPath_Call{Call: _e.mock.On("FindByParentPath", ctx, repoID, path)} +} + +func (_c *MockFileStore_FindByParentPath_Call) Run(run func(ctx context.Context, repoID int64, path string)) *MockFileStore_FindByParentPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockFileStore_FindByParentPath_Call) Return(_a0 []database.File, _a1 error) *MockFileStore_FindByParentPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockFileStore_FindByParentPath_Call) RunAndReturn(run func(context.Context, int64, string) ([]database.File, error)) *MockFileStore_FindByParentPath_Call { + _c.Call.Return(run) + return _c +} + +// NewMockFileStore creates a new instance of MockFileStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockFileStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockFileStore { + mock := &MockFileStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_GitServerAccessTokenStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_GitServerAccessTokenStore.go new file mode 100644 index 00000000..b90e0ebd --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_GitServerAccessTokenStore.go @@ -0,0 +1,213 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockGitServerAccessTokenStore is an autogenerated mock type for the GitServerAccessTokenStore type +type MockGitServerAccessTokenStore struct { + mock.Mock +} + +type MockGitServerAccessTokenStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockGitServerAccessTokenStore) EXPECT() *MockGitServerAccessTokenStore_Expecter { + return &MockGitServerAccessTokenStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, gToken +func (_m *MockGitServerAccessTokenStore) Create(ctx context.Context, gToken *database.GitServerAccessToken) (*database.GitServerAccessToken, error) { + ret := _m.Called(ctx, gToken) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.GitServerAccessToken + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *database.GitServerAccessToken) (*database.GitServerAccessToken, error)); ok { + return rf(ctx, gToken) + } + if rf, ok := ret.Get(0).(func(context.Context, *database.GitServerAccessToken) *database.GitServerAccessToken); ok { + r0 = rf(ctx, gToken) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.GitServerAccessToken) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *database.GitServerAccessToken) error); ok { + r1 = rf(ctx, gToken) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServerAccessTokenStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockGitServerAccessTokenStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - gToken *database.GitServerAccessToken +func (_e *MockGitServerAccessTokenStore_Expecter) Create(ctx interface{}, gToken interface{}) *MockGitServerAccessTokenStore_Create_Call { + return &MockGitServerAccessTokenStore_Create_Call{Call: _e.mock.On("Create", ctx, gToken)} +} + +func (_c *MockGitServerAccessTokenStore_Create_Call) Run(run func(ctx context.Context, gToken *database.GitServerAccessToken)) *MockGitServerAccessTokenStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.GitServerAccessToken)) + }) + return _c +} + +func (_c *MockGitServerAccessTokenStore_Create_Call) Return(_a0 *database.GitServerAccessToken, _a1 error) *MockGitServerAccessTokenStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServerAccessTokenStore_Create_Call) RunAndReturn(run func(context.Context, *database.GitServerAccessToken) (*database.GitServerAccessToken, error)) *MockGitServerAccessTokenStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// FindByType provides a mock function with given fields: ctx, serverType +func (_m *MockGitServerAccessTokenStore) FindByType(ctx context.Context, serverType string) ([]database.GitServerAccessToken, error) { + ret := _m.Called(ctx, serverType) + + if len(ret) == 0 { + panic("no return value specified for FindByType") + } + + var r0 []database.GitServerAccessToken + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]database.GitServerAccessToken, error)); ok { + return rf(ctx, serverType) + } + if rf, ok := ret.Get(0).(func(context.Context, string) []database.GitServerAccessToken); ok { + r0 = rf(ctx, serverType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.GitServerAccessToken) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, serverType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServerAccessTokenStore_FindByType_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByType' +type MockGitServerAccessTokenStore_FindByType_Call struct { + *mock.Call +} + +// FindByType is a helper method to define mock.On call +// - ctx context.Context +// - serverType string +func (_e *MockGitServerAccessTokenStore_Expecter) FindByType(ctx interface{}, serverType interface{}) *MockGitServerAccessTokenStore_FindByType_Call { + return &MockGitServerAccessTokenStore_FindByType_Call{Call: _e.mock.On("FindByType", ctx, serverType)} +} + +func (_c *MockGitServerAccessTokenStore_FindByType_Call) Run(run func(ctx context.Context, serverType string)) *MockGitServerAccessTokenStore_FindByType_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockGitServerAccessTokenStore_FindByType_Call) Return(_a0 []database.GitServerAccessToken, _a1 error) *MockGitServerAccessTokenStore_FindByType_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServerAccessTokenStore_FindByType_Call) RunAndReturn(run func(context.Context, string) ([]database.GitServerAccessToken, error)) *MockGitServerAccessTokenStore_FindByType_Call { + _c.Call.Return(run) + return _c +} + +// Index provides a mock function with given fields: ctx +func (_m *MockGitServerAccessTokenStore) Index(ctx context.Context) ([]database.GitServerAccessToken, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Index") + } + + var r0 []database.GitServerAccessToken + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.GitServerAccessToken, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.GitServerAccessToken); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.GitServerAccessToken) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockGitServerAccessTokenStore_Index_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Index' +type MockGitServerAccessTokenStore_Index_Call struct { + *mock.Call +} + +// Index is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockGitServerAccessTokenStore_Expecter) Index(ctx interface{}) *MockGitServerAccessTokenStore_Index_Call { + return &MockGitServerAccessTokenStore_Index_Call{Call: _e.mock.On("Index", ctx)} +} + +func (_c *MockGitServerAccessTokenStore_Index_Call) Run(run func(ctx context.Context)) *MockGitServerAccessTokenStore_Index_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockGitServerAccessTokenStore_Index_Call) Return(_a0 []database.GitServerAccessToken, _a1 error) *MockGitServerAccessTokenStore_Index_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockGitServerAccessTokenStore_Index_Call) RunAndReturn(run func(context.Context) ([]database.GitServerAccessToken, error)) *MockGitServerAccessTokenStore_Index_Call { + _c.Call.Return(run) + return _c +} + +// NewMockGitServerAccessTokenStore creates a new instance of MockGitServerAccessTokenStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockGitServerAccessTokenStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockGitServerAccessTokenStore { + mock := &MockGitServerAccessTokenStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LLMConfigStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LLMConfigStore.go index a92a1623..da51be0d 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LLMConfigStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LLMConfigStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LfsLockStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LfsLockStore.go new file mode 100644 index 00000000..89344c3a --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LfsLockStore.go @@ -0,0 +1,323 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockLfsLockStore is an autogenerated mock type for the LfsLockStore type +type MockLfsLockStore struct { + mock.Mock +} + +type MockLfsLockStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockLfsLockStore) EXPECT() *MockLfsLockStore_Expecter { + return &MockLfsLockStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, lfsLock +func (_m *MockLfsLockStore) Create(ctx context.Context, lfsLock database.LfsLock) (*database.LfsLock, error) { + ret := _m.Called(ctx, lfsLock) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.LfsLock + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.LfsLock) (*database.LfsLock, error)); ok { + return rf(ctx, lfsLock) + } + if rf, ok := ret.Get(0).(func(context.Context, database.LfsLock) *database.LfsLock); ok { + r0 = rf(ctx, lfsLock) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.LfsLock) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.LfsLock) error); ok { + r1 = rf(ctx, lfsLock) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockLfsLockStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockLfsLockStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - lfsLock database.LfsLock +func (_e *MockLfsLockStore_Expecter) Create(ctx interface{}, lfsLock interface{}) *MockLfsLockStore_Create_Call { + return &MockLfsLockStore_Create_Call{Call: _e.mock.On("Create", ctx, lfsLock)} +} + +func (_c *MockLfsLockStore_Create_Call) Run(run func(ctx context.Context, lfsLock database.LfsLock)) *MockLfsLockStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.LfsLock)) + }) + return _c +} + +func (_c *MockLfsLockStore_Create_Call) Return(_a0 *database.LfsLock, _a1 error) *MockLfsLockStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockLfsLockStore_Create_Call) RunAndReturn(run func(context.Context, database.LfsLock) (*database.LfsLock, error)) *MockLfsLockStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// FindByID provides a mock function with given fields: ctx, ID +func (_m *MockLfsLockStore) FindByID(ctx context.Context, ID int64) (*database.LfsLock, error) { + ret := _m.Called(ctx, ID) + + if len(ret) == 0 { + panic("no return value specified for FindByID") + } + + var r0 *database.LfsLock + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.LfsLock, error)); ok { + return rf(ctx, ID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.LfsLock); ok { + r0 = rf(ctx, ID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.LfsLock) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, ID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockLfsLockStore_FindByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByID' +type MockLfsLockStore_FindByID_Call struct { + *mock.Call +} + +// FindByID is a helper method to define mock.On call +// - ctx context.Context +// - ID int64 +func (_e *MockLfsLockStore_Expecter) FindByID(ctx interface{}, ID interface{}) *MockLfsLockStore_FindByID_Call { + return &MockLfsLockStore_FindByID_Call{Call: _e.mock.On("FindByID", ctx, ID)} +} + +func (_c *MockLfsLockStore_FindByID_Call) Run(run func(ctx context.Context, ID int64)) *MockLfsLockStore_FindByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockLfsLockStore_FindByID_Call) Return(_a0 *database.LfsLock, _a1 error) *MockLfsLockStore_FindByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockLfsLockStore_FindByID_Call) RunAndReturn(run func(context.Context, int64) (*database.LfsLock, error)) *MockLfsLockStore_FindByID_Call { + _c.Call.Return(run) + return _c +} + +// FindByPath provides a mock function with given fields: ctx, RepoId, path +func (_m *MockLfsLockStore) FindByPath(ctx context.Context, RepoId int64, path string) (*database.LfsLock, error) { + ret := _m.Called(ctx, RepoId, path) + + if len(ret) == 0 { + panic("no return value specified for FindByPath") + } + + var r0 *database.LfsLock + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) (*database.LfsLock, error)); ok { + return rf(ctx, RepoId, path) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, string) *database.LfsLock); ok { + r0 = rf(ctx, RepoId, path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.LfsLock) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, string) error); ok { + r1 = rf(ctx, RepoId, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockLfsLockStore_FindByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByPath' +type MockLfsLockStore_FindByPath_Call struct { + *mock.Call +} + +// FindByPath is a helper method to define mock.On call +// - ctx context.Context +// - RepoId int64 +// - path string +func (_e *MockLfsLockStore_Expecter) FindByPath(ctx interface{}, RepoId interface{}, path interface{}) *MockLfsLockStore_FindByPath_Call { + return &MockLfsLockStore_FindByPath_Call{Call: _e.mock.On("FindByPath", ctx, RepoId, path)} +} + +func (_c *MockLfsLockStore_FindByPath_Call) Run(run func(ctx context.Context, RepoId int64, path string)) *MockLfsLockStore_FindByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockLfsLockStore_FindByPath_Call) Return(_a0 *database.LfsLock, _a1 error) *MockLfsLockStore_FindByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockLfsLockStore_FindByPath_Call) RunAndReturn(run func(context.Context, int64, string) (*database.LfsLock, error)) *MockLfsLockStore_FindByPath_Call { + _c.Call.Return(run) + return _c +} + +// FindByRepoID provides a mock function with given fields: ctx, RepoId, page, per +func (_m *MockLfsLockStore) FindByRepoID(ctx context.Context, RepoId int64, page int, per int) ([]database.LfsLock, error) { + ret := _m.Called(ctx, RepoId, page, per) + + if len(ret) == 0 { + panic("no return value specified for FindByRepoID") + } + + var r0 []database.LfsLock + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) ([]database.LfsLock, error)); ok { + return rf(ctx, RepoId, page, per) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) []database.LfsLock); ok { + r0 = rf(ctx, RepoId, page, per) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.LfsLock) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int, int) error); ok { + r1 = rf(ctx, RepoId, page, per) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockLfsLockStore_FindByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByRepoID' +type MockLfsLockStore_FindByRepoID_Call struct { + *mock.Call +} + +// FindByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - RepoId int64 +// - page int +// - per int +func (_e *MockLfsLockStore_Expecter) FindByRepoID(ctx interface{}, RepoId interface{}, page interface{}, per interface{}) *MockLfsLockStore_FindByRepoID_Call { + return &MockLfsLockStore_FindByRepoID_Call{Call: _e.mock.On("FindByRepoID", ctx, RepoId, page, per)} +} + +func (_c *MockLfsLockStore_FindByRepoID_Call) Run(run func(ctx context.Context, RepoId int64, page int, per int)) *MockLfsLockStore_FindByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockLfsLockStore_FindByRepoID_Call) Return(_a0 []database.LfsLock, _a1 error) *MockLfsLockStore_FindByRepoID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockLfsLockStore_FindByRepoID_Call) RunAndReturn(run func(context.Context, int64, int, int) ([]database.LfsLock, error)) *MockLfsLockStore_FindByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// RemoveByID provides a mock function with given fields: ctx, ID +func (_m *MockLfsLockStore) RemoveByID(ctx context.Context, ID int64) error { + ret := _m.Called(ctx, ID) + + if len(ret) == 0 { + panic("no return value specified for RemoveByID") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, ID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockLfsLockStore_RemoveByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveByID' +type MockLfsLockStore_RemoveByID_Call struct { + *mock.Call +} + +// RemoveByID is a helper method to define mock.On call +// - ctx context.Context +// - ID int64 +func (_e *MockLfsLockStore_Expecter) RemoveByID(ctx interface{}, ID interface{}) *MockLfsLockStore_RemoveByID_Call { + return &MockLfsLockStore_RemoveByID_Call{Call: _e.mock.On("RemoveByID", ctx, ID)} +} + +func (_c *MockLfsLockStore_RemoveByID_Call) Run(run func(ctx context.Context, ID int64)) *MockLfsLockStore_RemoveByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockLfsLockStore_RemoveByID_Call) Return(_a0 error) *MockLfsLockStore_RemoveByID_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockLfsLockStore_RemoveByID_Call) RunAndReturn(run func(context.Context, int64) error) *MockLfsLockStore_RemoveByID_Call { + _c.Call.Return(run) + return _c +} + +// NewMockLfsLockStore creates a new instance of MockLfsLockStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockLfsLockStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockLfsLockStore { + mock := &MockLfsLockStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LfsMetaObjectStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LfsMetaObjectStore.go new file mode 100644 index 00000000..ddae5225 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_LfsMetaObjectStore.go @@ -0,0 +1,369 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockLfsMetaObjectStore is an autogenerated mock type for the LfsMetaObjectStore type +type MockLfsMetaObjectStore struct { + mock.Mock +} + +type MockLfsMetaObjectStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockLfsMetaObjectStore) EXPECT() *MockLfsMetaObjectStore_Expecter { + return &MockLfsMetaObjectStore_Expecter{mock: &_m.Mock} +} + +// BulkUpdateOrCreate provides a mock function with given fields: ctx, input +func (_m *MockLfsMetaObjectStore) BulkUpdateOrCreate(ctx context.Context, input []database.LfsMetaObject) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for BulkUpdateOrCreate") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []database.LfsMetaObject) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockLfsMetaObjectStore_BulkUpdateOrCreate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BulkUpdateOrCreate' +type MockLfsMetaObjectStore_BulkUpdateOrCreate_Call struct { + *mock.Call +} + +// BulkUpdateOrCreate is a helper method to define mock.On call +// - ctx context.Context +// - input []database.LfsMetaObject +func (_e *MockLfsMetaObjectStore_Expecter) BulkUpdateOrCreate(ctx interface{}, input interface{}) *MockLfsMetaObjectStore_BulkUpdateOrCreate_Call { + return &MockLfsMetaObjectStore_BulkUpdateOrCreate_Call{Call: _e.mock.On("BulkUpdateOrCreate", ctx, input)} +} + +func (_c *MockLfsMetaObjectStore_BulkUpdateOrCreate_Call) Run(run func(ctx context.Context, input []database.LfsMetaObject)) *MockLfsMetaObjectStore_BulkUpdateOrCreate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]database.LfsMetaObject)) + }) + return _c +} + +func (_c *MockLfsMetaObjectStore_BulkUpdateOrCreate_Call) Return(_a0 error) *MockLfsMetaObjectStore_BulkUpdateOrCreate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockLfsMetaObjectStore_BulkUpdateOrCreate_Call) RunAndReturn(run func(context.Context, []database.LfsMetaObject) error) *MockLfsMetaObjectStore_BulkUpdateOrCreate_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, lfsObj +func (_m *MockLfsMetaObjectStore) Create(ctx context.Context, lfsObj database.LfsMetaObject) (*database.LfsMetaObject, error) { + ret := _m.Called(ctx, lfsObj) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.LfsMetaObject + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.LfsMetaObject) (*database.LfsMetaObject, error)); ok { + return rf(ctx, lfsObj) + } + if rf, ok := ret.Get(0).(func(context.Context, database.LfsMetaObject) *database.LfsMetaObject); ok { + r0 = rf(ctx, lfsObj) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.LfsMetaObject) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.LfsMetaObject) error); ok { + r1 = rf(ctx, lfsObj) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockLfsMetaObjectStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockLfsMetaObjectStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - lfsObj database.LfsMetaObject +func (_e *MockLfsMetaObjectStore_Expecter) Create(ctx interface{}, lfsObj interface{}) *MockLfsMetaObjectStore_Create_Call { + return &MockLfsMetaObjectStore_Create_Call{Call: _e.mock.On("Create", ctx, lfsObj)} +} + +func (_c *MockLfsMetaObjectStore_Create_Call) Run(run func(ctx context.Context, lfsObj database.LfsMetaObject)) *MockLfsMetaObjectStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.LfsMetaObject)) + }) + return _c +} + +func (_c *MockLfsMetaObjectStore_Create_Call) Return(_a0 *database.LfsMetaObject, _a1 error) *MockLfsMetaObjectStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockLfsMetaObjectStore_Create_Call) RunAndReturn(run func(context.Context, database.LfsMetaObject) (*database.LfsMetaObject, error)) *MockLfsMetaObjectStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// FindByOID provides a mock function with given fields: ctx, RepoId, Oid +func (_m *MockLfsMetaObjectStore) FindByOID(ctx context.Context, RepoId int64, Oid string) (*database.LfsMetaObject, error) { + ret := _m.Called(ctx, RepoId, Oid) + + if len(ret) == 0 { + panic("no return value specified for FindByOID") + } + + var r0 *database.LfsMetaObject + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) (*database.LfsMetaObject, error)); ok { + return rf(ctx, RepoId, Oid) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, string) *database.LfsMetaObject); ok { + r0 = rf(ctx, RepoId, Oid) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.LfsMetaObject) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, string) error); ok { + r1 = rf(ctx, RepoId, Oid) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockLfsMetaObjectStore_FindByOID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByOID' +type MockLfsMetaObjectStore_FindByOID_Call struct { + *mock.Call +} + +// FindByOID is a helper method to define mock.On call +// - ctx context.Context +// - RepoId int64 +// - Oid string +func (_e *MockLfsMetaObjectStore_Expecter) FindByOID(ctx interface{}, RepoId interface{}, Oid interface{}) *MockLfsMetaObjectStore_FindByOID_Call { + return &MockLfsMetaObjectStore_FindByOID_Call{Call: _e.mock.On("FindByOID", ctx, RepoId, Oid)} +} + +func (_c *MockLfsMetaObjectStore_FindByOID_Call) Run(run func(ctx context.Context, RepoId int64, Oid string)) *MockLfsMetaObjectStore_FindByOID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockLfsMetaObjectStore_FindByOID_Call) Return(_a0 *database.LfsMetaObject, _a1 error) *MockLfsMetaObjectStore_FindByOID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockLfsMetaObjectStore_FindByOID_Call) RunAndReturn(run func(context.Context, int64, string) (*database.LfsMetaObject, error)) *MockLfsMetaObjectStore_FindByOID_Call { + _c.Call.Return(run) + return _c +} + +// FindByRepoID provides a mock function with given fields: ctx, repoID +func (_m *MockLfsMetaObjectStore) FindByRepoID(ctx context.Context, repoID int64) ([]database.LfsMetaObject, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for FindByRepoID") + } + + var r0 []database.LfsMetaObject + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.LfsMetaObject, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.LfsMetaObject); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.LfsMetaObject) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockLfsMetaObjectStore_FindByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByRepoID' +type MockLfsMetaObjectStore_FindByRepoID_Call struct { + *mock.Call +} + +// FindByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockLfsMetaObjectStore_Expecter) FindByRepoID(ctx interface{}, repoID interface{}) *MockLfsMetaObjectStore_FindByRepoID_Call { + return &MockLfsMetaObjectStore_FindByRepoID_Call{Call: _e.mock.On("FindByRepoID", ctx, repoID)} +} + +func (_c *MockLfsMetaObjectStore_FindByRepoID_Call) Run(run func(ctx context.Context, repoID int64)) *MockLfsMetaObjectStore_FindByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockLfsMetaObjectStore_FindByRepoID_Call) Return(_a0 []database.LfsMetaObject, _a1 error) *MockLfsMetaObjectStore_FindByRepoID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockLfsMetaObjectStore_FindByRepoID_Call) RunAndReturn(run func(context.Context, int64) ([]database.LfsMetaObject, error)) *MockLfsMetaObjectStore_FindByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// RemoveByOid provides a mock function with given fields: ctx, oid, repoID +func (_m *MockLfsMetaObjectStore) RemoveByOid(ctx context.Context, oid string, repoID int64) error { + ret := _m.Called(ctx, oid, repoID) + + if len(ret) == 0 { + panic("no return value specified for RemoveByOid") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, int64) error); ok { + r0 = rf(ctx, oid, repoID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockLfsMetaObjectStore_RemoveByOid_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveByOid' +type MockLfsMetaObjectStore_RemoveByOid_Call struct { + *mock.Call +} + +// RemoveByOid is a helper method to define mock.On call +// - ctx context.Context +// - oid string +// - repoID int64 +func (_e *MockLfsMetaObjectStore_Expecter) RemoveByOid(ctx interface{}, oid interface{}, repoID interface{}) *MockLfsMetaObjectStore_RemoveByOid_Call { + return &MockLfsMetaObjectStore_RemoveByOid_Call{Call: _e.mock.On("RemoveByOid", ctx, oid, repoID)} +} + +func (_c *MockLfsMetaObjectStore_RemoveByOid_Call) Run(run func(ctx context.Context, oid string, repoID int64)) *MockLfsMetaObjectStore_RemoveByOid_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int64)) + }) + return _c +} + +func (_c *MockLfsMetaObjectStore_RemoveByOid_Call) Return(_a0 error) *MockLfsMetaObjectStore_RemoveByOid_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockLfsMetaObjectStore_RemoveByOid_Call) RunAndReturn(run func(context.Context, string, int64) error) *MockLfsMetaObjectStore_RemoveByOid_Call { + _c.Call.Return(run) + return _c +} + +// UpdateOrCreate provides a mock function with given fields: ctx, input +func (_m *MockLfsMetaObjectStore) UpdateOrCreate(ctx context.Context, input database.LfsMetaObject) (*database.LfsMetaObject, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for UpdateOrCreate") + } + + var r0 *database.LfsMetaObject + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.LfsMetaObject) (*database.LfsMetaObject, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.LfsMetaObject) *database.LfsMetaObject); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.LfsMetaObject) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.LfsMetaObject) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockLfsMetaObjectStore_UpdateOrCreate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateOrCreate' +type MockLfsMetaObjectStore_UpdateOrCreate_Call struct { + *mock.Call +} + +// UpdateOrCreate is a helper method to define mock.On call +// - ctx context.Context +// - input database.LfsMetaObject +func (_e *MockLfsMetaObjectStore_Expecter) UpdateOrCreate(ctx interface{}, input interface{}) *MockLfsMetaObjectStore_UpdateOrCreate_Call { + return &MockLfsMetaObjectStore_UpdateOrCreate_Call{Call: _e.mock.On("UpdateOrCreate", ctx, input)} +} + +func (_c *MockLfsMetaObjectStore_UpdateOrCreate_Call) Run(run func(ctx context.Context, input database.LfsMetaObject)) *MockLfsMetaObjectStore_UpdateOrCreate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.LfsMetaObject)) + }) + return _c +} + +func (_c *MockLfsMetaObjectStore_UpdateOrCreate_Call) Return(_a0 *database.LfsMetaObject, _a1 error) *MockLfsMetaObjectStore_UpdateOrCreate_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockLfsMetaObjectStore_UpdateOrCreate_Call) RunAndReturn(run func(context.Context, database.LfsMetaObject) (*database.LfsMetaObject, error)) *MockLfsMetaObjectStore_UpdateOrCreate_Call { + _c.Call.Return(run) + return _c +} + +// NewMockLfsMetaObjectStore creates a new instance of MockLfsMetaObjectStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockLfsMetaObjectStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockLfsMetaObjectStore { + mock := &MockLfsMetaObjectStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MemberStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MemberStore.go index 1a5564b0..010ed3ea 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MemberStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MemberStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorSourceStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorSourceStore.go new file mode 100644 index 00000000..1c2de605 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorSourceStore.go @@ -0,0 +1,366 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockMirrorSourceStore is an autogenerated mock type for the MirrorSourceStore type +type MockMirrorSourceStore struct { + mock.Mock +} + +type MockMirrorSourceStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockMirrorSourceStore) EXPECT() *MockMirrorSourceStore_Expecter { + return &MockMirrorSourceStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, mirrorSource +func (_m *MockMirrorSourceStore) Create(ctx context.Context, mirrorSource *database.MirrorSource) (*database.MirrorSource, error) { + ret := _m.Called(ctx, mirrorSource) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.MirrorSource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *database.MirrorSource) (*database.MirrorSource, error)); ok { + return rf(ctx, mirrorSource) + } + if rf, ok := ret.Get(0).(func(context.Context, *database.MirrorSource) *database.MirrorSource); ok { + r0 = rf(ctx, mirrorSource) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.MirrorSource) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *database.MirrorSource) error); ok { + r1 = rf(ctx, mirrorSource) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorSourceStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockMirrorSourceStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - mirrorSource *database.MirrorSource +func (_e *MockMirrorSourceStore_Expecter) Create(ctx interface{}, mirrorSource interface{}) *MockMirrorSourceStore_Create_Call { + return &MockMirrorSourceStore_Create_Call{Call: _e.mock.On("Create", ctx, mirrorSource)} +} + +func (_c *MockMirrorSourceStore_Create_Call) Run(run func(ctx context.Context, mirrorSource *database.MirrorSource)) *MockMirrorSourceStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.MirrorSource)) + }) + return _c +} + +func (_c *MockMirrorSourceStore_Create_Call) Return(_a0 *database.MirrorSource, _a1 error) *MockMirrorSourceStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorSourceStore_Create_Call) RunAndReturn(run func(context.Context, *database.MirrorSource) (*database.MirrorSource, error)) *MockMirrorSourceStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, mirrorSource +func (_m *MockMirrorSourceStore) Delete(ctx context.Context, mirrorSource *database.MirrorSource) error { + ret := _m.Called(ctx, mirrorSource) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.MirrorSource) error); ok { + r0 = rf(ctx, mirrorSource) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMirrorSourceStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockMirrorSourceStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - mirrorSource *database.MirrorSource +func (_e *MockMirrorSourceStore_Expecter) Delete(ctx interface{}, mirrorSource interface{}) *MockMirrorSourceStore_Delete_Call { + return &MockMirrorSourceStore_Delete_Call{Call: _e.mock.On("Delete", ctx, mirrorSource)} +} + +func (_c *MockMirrorSourceStore_Delete_Call) Run(run func(ctx context.Context, mirrorSource *database.MirrorSource)) *MockMirrorSourceStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.MirrorSource)) + }) + return _c +} + +func (_c *MockMirrorSourceStore_Delete_Call) Return(err error) *MockMirrorSourceStore_Delete_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockMirrorSourceStore_Delete_Call) RunAndReturn(run func(context.Context, *database.MirrorSource) error) *MockMirrorSourceStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindByName provides a mock function with given fields: ctx, name +func (_m *MockMirrorSourceStore) FindByName(ctx context.Context, name string) (*database.MirrorSource, error) { + ret := _m.Called(ctx, name) + + if len(ret) == 0 { + panic("no return value specified for FindByName") + } + + var r0 *database.MirrorSource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.MirrorSource, error)); ok { + return rf(ctx, name) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.MirrorSource); ok { + r0 = rf(ctx, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.MirrorSource) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorSourceStore_FindByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByName' +type MockMirrorSourceStore_FindByName_Call struct { + *mock.Call +} + +// FindByName is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *MockMirrorSourceStore_Expecter) FindByName(ctx interface{}, name interface{}) *MockMirrorSourceStore_FindByName_Call { + return &MockMirrorSourceStore_FindByName_Call{Call: _e.mock.On("FindByName", ctx, name)} +} + +func (_c *MockMirrorSourceStore_FindByName_Call) Run(run func(ctx context.Context, name string)) *MockMirrorSourceStore_FindByName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockMirrorSourceStore_FindByName_Call) Return(_a0 *database.MirrorSource, _a1 error) *MockMirrorSourceStore_FindByName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorSourceStore_FindByName_Call) RunAndReturn(run func(context.Context, string) (*database.MirrorSource, error)) *MockMirrorSourceStore_FindByName_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function with given fields: ctx, id +func (_m *MockMirrorSourceStore) Get(ctx context.Context, id int64) (*database.MirrorSource, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 *database.MirrorSource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.MirrorSource, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.MirrorSource); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.MirrorSource) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorSourceStore_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type MockMirrorSourceStore_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockMirrorSourceStore_Expecter) Get(ctx interface{}, id interface{}) *MockMirrorSourceStore_Get_Call { + return &MockMirrorSourceStore_Get_Call{Call: _e.mock.On("Get", ctx, id)} +} + +func (_c *MockMirrorSourceStore_Get_Call) Run(run func(ctx context.Context, id int64)) *MockMirrorSourceStore_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockMirrorSourceStore_Get_Call) Return(_a0 *database.MirrorSource, _a1 error) *MockMirrorSourceStore_Get_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorSourceStore_Get_Call) RunAndReturn(run func(context.Context, int64) (*database.MirrorSource, error)) *MockMirrorSourceStore_Get_Call { + _c.Call.Return(run) + return _c +} + +// Index provides a mock function with given fields: ctx +func (_m *MockMirrorSourceStore) Index(ctx context.Context) ([]database.MirrorSource, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Index") + } + + var r0 []database.MirrorSource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.MirrorSource, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.MirrorSource); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.MirrorSource) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMirrorSourceStore_Index_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Index' +type MockMirrorSourceStore_Index_Call struct { + *mock.Call +} + +// Index is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockMirrorSourceStore_Expecter) Index(ctx interface{}) *MockMirrorSourceStore_Index_Call { + return &MockMirrorSourceStore_Index_Call{Call: _e.mock.On("Index", ctx)} +} + +func (_c *MockMirrorSourceStore_Index_Call) Run(run func(ctx context.Context)) *MockMirrorSourceStore_Index_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockMirrorSourceStore_Index_Call) Return(_a0 []database.MirrorSource, _a1 error) *MockMirrorSourceStore_Index_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMirrorSourceStore_Index_Call) RunAndReturn(run func(context.Context) ([]database.MirrorSource, error)) *MockMirrorSourceStore_Index_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, mirrorSource +func (_m *MockMirrorSourceStore) Update(ctx context.Context, mirrorSource *database.MirrorSource) error { + ret := _m.Called(ctx, mirrorSource) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.MirrorSource) error); ok { + r0 = rf(ctx, mirrorSource) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMirrorSourceStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockMirrorSourceStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - mirrorSource *database.MirrorSource +func (_e *MockMirrorSourceStore_Expecter) Update(ctx interface{}, mirrorSource interface{}) *MockMirrorSourceStore_Update_Call { + return &MockMirrorSourceStore_Update_Call{Call: _e.mock.On("Update", ctx, mirrorSource)} +} + +func (_c *MockMirrorSourceStore_Update_Call) Run(run func(ctx context.Context, mirrorSource *database.MirrorSource)) *MockMirrorSourceStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.MirrorSource)) + }) + return _c +} + +func (_c *MockMirrorSourceStore_Update_Call) Return(err error) *MockMirrorSourceStore_Update_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockMirrorSourceStore_Update_Call) RunAndReturn(run func(context.Context, *database.MirrorSource) error) *MockMirrorSourceStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockMirrorSourceStore creates a new instance of MockMirrorSourceStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockMirrorSourceStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockMirrorSourceStore { + mock := &MockMirrorSourceStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorStore.go index 1daf5c96..4f47d431 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MirrorStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ModelStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ModelStore.go index 1a8d68a9..b9a6e3d9 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ModelStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ModelStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MultiSyncStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MultiSyncStore.go new file mode 100644 index 00000000..e8b05621 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_MultiSyncStore.go @@ -0,0 +1,271 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockMultiSyncStore is an autogenerated mock type for the MultiSyncStore type +type MockMultiSyncStore struct { + mock.Mock +} + +type MockMultiSyncStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockMultiSyncStore) EXPECT() *MockMultiSyncStore_Expecter { + return &MockMultiSyncStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, v +func (_m *MockMultiSyncStore) Create(ctx context.Context, v database.SyncVersion) (*database.SyncVersion, error) { + ret := _m.Called(ctx, v) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.SyncVersion + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.SyncVersion) (*database.SyncVersion, error)); ok { + return rf(ctx, v) + } + if rf, ok := ret.Get(0).(func(context.Context, database.SyncVersion) *database.SyncVersion); ok { + r0 = rf(ctx, v) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SyncVersion) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.SyncVersion) error); ok { + r1 = rf(ctx, v) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMultiSyncStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockMultiSyncStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - v database.SyncVersion +func (_e *MockMultiSyncStore_Expecter) Create(ctx interface{}, v interface{}) *MockMultiSyncStore_Create_Call { + return &MockMultiSyncStore_Create_Call{Call: _e.mock.On("Create", ctx, v)} +} + +func (_c *MockMultiSyncStore_Create_Call) Run(run func(ctx context.Context, v database.SyncVersion)) *MockMultiSyncStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.SyncVersion)) + }) + return _c +} + +func (_c *MockMultiSyncStore_Create_Call) Return(_a0 *database.SyncVersion, _a1 error) *MockMultiSyncStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMultiSyncStore_Create_Call) RunAndReturn(run func(context.Context, database.SyncVersion) (*database.SyncVersion, error)) *MockMultiSyncStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// GetAfter provides a mock function with given fields: ctx, version, limit +func (_m *MockMultiSyncStore) GetAfter(ctx context.Context, version int64, limit int64) ([]database.SyncVersion, error) { + ret := _m.Called(ctx, version, limit) + + if len(ret) == 0 { + panic("no return value specified for GetAfter") + } + + var r0 []database.SyncVersion + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64) ([]database.SyncVersion, error)); ok { + return rf(ctx, version, limit) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int64) []database.SyncVersion); ok { + r0 = rf(ctx, version, limit) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.SyncVersion) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int64) error); ok { + r1 = rf(ctx, version, limit) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMultiSyncStore_GetAfter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAfter' +type MockMultiSyncStore_GetAfter_Call struct { + *mock.Call +} + +// GetAfter is a helper method to define mock.On call +// - ctx context.Context +// - version int64 +// - limit int64 +func (_e *MockMultiSyncStore_Expecter) GetAfter(ctx interface{}, version interface{}, limit interface{}) *MockMultiSyncStore_GetAfter_Call { + return &MockMultiSyncStore_GetAfter_Call{Call: _e.mock.On("GetAfter", ctx, version, limit)} +} + +func (_c *MockMultiSyncStore_GetAfter_Call) Run(run func(ctx context.Context, version int64, limit int64)) *MockMultiSyncStore_GetAfter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64)) + }) + return _c +} + +func (_c *MockMultiSyncStore_GetAfter_Call) Return(_a0 []database.SyncVersion, _a1 error) *MockMultiSyncStore_GetAfter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMultiSyncStore_GetAfter_Call) RunAndReturn(run func(context.Context, int64, int64) ([]database.SyncVersion, error)) *MockMultiSyncStore_GetAfter_Call { + _c.Call.Return(run) + return _c +} + +// GetAfterDistinct provides a mock function with given fields: ctx, version +func (_m *MockMultiSyncStore) GetAfterDistinct(ctx context.Context, version int64) ([]database.SyncVersion, error) { + ret := _m.Called(ctx, version) + + if len(ret) == 0 { + panic("no return value specified for GetAfterDistinct") + } + + var r0 []database.SyncVersion + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.SyncVersion, error)); ok { + return rf(ctx, version) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.SyncVersion); ok { + r0 = rf(ctx, version) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.SyncVersion) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, version) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMultiSyncStore_GetAfterDistinct_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAfterDistinct' +type MockMultiSyncStore_GetAfterDistinct_Call struct { + *mock.Call +} + +// GetAfterDistinct is a helper method to define mock.On call +// - ctx context.Context +// - version int64 +func (_e *MockMultiSyncStore_Expecter) GetAfterDistinct(ctx interface{}, version interface{}) *MockMultiSyncStore_GetAfterDistinct_Call { + return &MockMultiSyncStore_GetAfterDistinct_Call{Call: _e.mock.On("GetAfterDistinct", ctx, version)} +} + +func (_c *MockMultiSyncStore_GetAfterDistinct_Call) Run(run func(ctx context.Context, version int64)) *MockMultiSyncStore_GetAfterDistinct_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockMultiSyncStore_GetAfterDistinct_Call) Return(_a0 []database.SyncVersion, _a1 error) *MockMultiSyncStore_GetAfterDistinct_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMultiSyncStore_GetAfterDistinct_Call) RunAndReturn(run func(context.Context, int64) ([]database.SyncVersion, error)) *MockMultiSyncStore_GetAfterDistinct_Call { + _c.Call.Return(run) + return _c +} + +// GetLatest provides a mock function with given fields: ctx +func (_m *MockMultiSyncStore) GetLatest(ctx context.Context) (database.SyncVersion, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetLatest") + } + + var r0 database.SyncVersion + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (database.SyncVersion, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) database.SyncVersion); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(database.SyncVersion) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMultiSyncStore_GetLatest_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLatest' +type MockMultiSyncStore_GetLatest_Call struct { + *mock.Call +} + +// GetLatest is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockMultiSyncStore_Expecter) GetLatest(ctx interface{}) *MockMultiSyncStore_GetLatest_Call { + return &MockMultiSyncStore_GetLatest_Call{Call: _e.mock.On("GetLatest", ctx)} +} + +func (_c *MockMultiSyncStore_GetLatest_Call) Run(run func(ctx context.Context)) *MockMultiSyncStore_GetLatest_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockMultiSyncStore_GetLatest_Call) Return(_a0 database.SyncVersion, _a1 error) *MockMultiSyncStore_GetLatest_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMultiSyncStore_GetLatest_Call) RunAndReturn(run func(context.Context) (database.SyncVersion, error)) *MockMultiSyncStore_GetLatest_Call { + _c.Call.Return(run) + return _c +} + +// NewMockMultiSyncStore creates a new instance of MockMultiSyncStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockMultiSyncStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockMultiSyncStore { + mock := &MockMultiSyncStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_NamespaceStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_NamespaceStore.go index 0e1250ff..5914b6a7 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_NamespaceStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_NamespaceStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database @@ -69,8 +69,8 @@ func (_c *MockNamespaceStore_Exists_Call) Run(run func(ctx context.Context, path return _c } -func (_c *MockNamespaceStore_Exists_Call) Return(exists bool, err error) *MockNamespaceStore_Exists_Call { - _c.Call.Return(exists, err) +func (_c *MockNamespaceStore_Exists_Call) Return(_a0 bool, _a1 error) *MockNamespaceStore_Exists_Call { + _c.Call.Return(_a0, _a1) return _c } @@ -126,8 +126,8 @@ func (_c *MockNamespaceStore_FindByPath_Call) Run(run func(ctx context.Context, return _c } -func (_c *MockNamespaceStore_FindByPath_Call) Return(namespace database.Namespace, err error) *MockNamespaceStore_FindByPath_Call { - _c.Call.Return(namespace, err) +func (_c *MockNamespaceStore_FindByPath_Call) Return(_a0 database.Namespace, _a1 error) *MockNamespaceStore_FindByPath_Call { + _c.Call.Return(_a0, _a1) return _c } diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_OrgStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_OrgStore.go index 0827a6b5..738d22eb 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_OrgStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_OrgStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptConversationStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptConversationStore.go index c561bdf9..5fdc0c55 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptConversationStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptConversationStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptPrefixStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptPrefixStore.go index 15f164b4..6f502553 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptPrefixStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptPrefixStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptStore.go index 68c5c51a..60661712 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_PromptStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RecomStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RecomStore.go new file mode 100644 index 00000000..61e40c5d --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RecomStore.go @@ -0,0 +1,309 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockRecomStore is an autogenerated mock type for the RecomStore type +type MockRecomStore struct { + mock.Mock +} + +type MockRecomStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRecomStore) EXPECT() *MockRecomStore_Expecter { + return &MockRecomStore_Expecter{mock: &_m.Mock} +} + +// Index provides a mock function with given fields: ctx, page, pageSize +func (_m *MockRecomStore) Index(ctx context.Context, page int, pageSize int) ([]*database.RecomRepoScore, error) { + ret := _m.Called(ctx, page, pageSize) + + if len(ret) == 0 { + panic("no return value specified for Index") + } + + var r0 []*database.RecomRepoScore + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int, int) ([]*database.RecomRepoScore, error)); ok { + return rf(ctx, page, pageSize) + } + if rf, ok := ret.Get(0).(func(context.Context, int, int) []*database.RecomRepoScore); ok { + r0 = rf(ctx, page, pageSize) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.RecomRepoScore) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int, int) error); ok { + r1 = rf(ctx, page, pageSize) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRecomStore_Index_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Index' +type MockRecomStore_Index_Call struct { + *mock.Call +} + +// Index is a helper method to define mock.On call +// - ctx context.Context +// - page int +// - pageSize int +func (_e *MockRecomStore_Expecter) Index(ctx interface{}, page interface{}, pageSize interface{}) *MockRecomStore_Index_Call { + return &MockRecomStore_Index_Call{Call: _e.mock.On("Index", ctx, page, pageSize)} +} + +func (_c *MockRecomStore_Index_Call) Run(run func(ctx context.Context, page int, pageSize int)) *MockRecomStore_Index_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int), args[2].(int)) + }) + return _c +} + +func (_c *MockRecomStore_Index_Call) Return(_a0 []*database.RecomRepoScore, _a1 error) *MockRecomStore_Index_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRecomStore_Index_Call) RunAndReturn(run func(context.Context, int, int) ([]*database.RecomRepoScore, error)) *MockRecomStore_Index_Call { + _c.Call.Return(run) + return _c +} + +// LoadOpWeights provides a mock function with given fields: ctx +func (_m *MockRecomStore) LoadOpWeights(ctx context.Context) ([]*database.RecomOpWeight, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for LoadOpWeights") + } + + var r0 []*database.RecomOpWeight + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]*database.RecomOpWeight, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []*database.RecomOpWeight); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.RecomOpWeight) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRecomStore_LoadOpWeights_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadOpWeights' +type MockRecomStore_LoadOpWeights_Call struct { + *mock.Call +} + +// LoadOpWeights is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockRecomStore_Expecter) LoadOpWeights(ctx interface{}) *MockRecomStore_LoadOpWeights_Call { + return &MockRecomStore_LoadOpWeights_Call{Call: _e.mock.On("LoadOpWeights", ctx)} +} + +func (_c *MockRecomStore_LoadOpWeights_Call) Run(run func(ctx context.Context)) *MockRecomStore_LoadOpWeights_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockRecomStore_LoadOpWeights_Call) Return(_a0 []*database.RecomOpWeight, _a1 error) *MockRecomStore_LoadOpWeights_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRecomStore_LoadOpWeights_Call) RunAndReturn(run func(context.Context) ([]*database.RecomOpWeight, error)) *MockRecomStore_LoadOpWeights_Call { + _c.Call.Return(run) + return _c +} + +// LoadWeights provides a mock function with given fields: ctx +func (_m *MockRecomStore) LoadWeights(ctx context.Context) ([]*database.RecomWeight, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for LoadWeights") + } + + var r0 []*database.RecomWeight + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]*database.RecomWeight, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []*database.RecomWeight); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.RecomWeight) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRecomStore_LoadWeights_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadWeights' +type MockRecomStore_LoadWeights_Call struct { + *mock.Call +} + +// LoadWeights is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockRecomStore_Expecter) LoadWeights(ctx interface{}) *MockRecomStore_LoadWeights_Call { + return &MockRecomStore_LoadWeights_Call{Call: _e.mock.On("LoadWeights", ctx)} +} + +func (_c *MockRecomStore_LoadWeights_Call) Run(run func(ctx context.Context)) *MockRecomStore_LoadWeights_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockRecomStore_LoadWeights_Call) Return(_a0 []*database.RecomWeight, _a1 error) *MockRecomStore_LoadWeights_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRecomStore_LoadWeights_Call) RunAndReturn(run func(context.Context) ([]*database.RecomWeight, error)) *MockRecomStore_LoadWeights_Call { + _c.Call.Return(run) + return _c +} + +// UpsertScore provides a mock function with given fields: ctx, repoID, score +func (_m *MockRecomStore) UpsertScore(ctx context.Context, repoID int64, score float64) error { + ret := _m.Called(ctx, repoID, score) + + if len(ret) == 0 { + panic("no return value specified for UpsertScore") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, float64) error); ok { + r0 = rf(ctx, repoID, score) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRecomStore_UpsertScore_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpsertScore' +type MockRecomStore_UpsertScore_Call struct { + *mock.Call +} + +// UpsertScore is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - score float64 +func (_e *MockRecomStore_Expecter) UpsertScore(ctx interface{}, repoID interface{}, score interface{}) *MockRecomStore_UpsertScore_Call { + return &MockRecomStore_UpsertScore_Call{Call: _e.mock.On("UpsertScore", ctx, repoID, score)} +} + +func (_c *MockRecomStore_UpsertScore_Call) Run(run func(ctx context.Context, repoID int64, score float64)) *MockRecomStore_UpsertScore_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(float64)) + }) + return _c +} + +func (_c *MockRecomStore_UpsertScore_Call) Return(_a0 error) *MockRecomStore_UpsertScore_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRecomStore_UpsertScore_Call) RunAndReturn(run func(context.Context, int64, float64) error) *MockRecomStore_UpsertScore_Call { + _c.Call.Return(run) + return _c +} + +// UpsetOpWeights provides a mock function with given fields: ctx, repoID, weight +func (_m *MockRecomStore) UpsetOpWeights(ctx context.Context, repoID int64, weight int64) error { + ret := _m.Called(ctx, repoID, weight) + + if len(ret) == 0 { + panic("no return value specified for UpsetOpWeights") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64) error); ok { + r0 = rf(ctx, repoID, weight) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRecomStore_UpsetOpWeights_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpsetOpWeights' +type MockRecomStore_UpsetOpWeights_Call struct { + *mock.Call +} + +// UpsetOpWeights is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - weight int64 +func (_e *MockRecomStore_Expecter) UpsetOpWeights(ctx interface{}, repoID interface{}, weight interface{}) *MockRecomStore_UpsetOpWeights_Call { + return &MockRecomStore_UpsetOpWeights_Call{Call: _e.mock.On("UpsetOpWeights", ctx, repoID, weight)} +} + +func (_c *MockRecomStore_UpsetOpWeights_Call) Run(run func(ctx context.Context, repoID int64, weight int64)) *MockRecomStore_UpsetOpWeights_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64)) + }) + return _c +} + +func (_c *MockRecomStore_UpsetOpWeights_Call) Return(_a0 error) *MockRecomStore_UpsetOpWeights_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRecomStore_UpsetOpWeights_Call) RunAndReturn(run func(context.Context, int64, int64) error) *MockRecomStore_UpsetOpWeights_Call { + _c.Call.Return(run) + return _c +} + +// NewMockRecomStore creates a new instance of MockRecomStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRecomStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRecomStore { + mock := &MockRecomStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoFileCheckStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoFileCheckStore.go new file mode 100644 index 00000000..e67881cd --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoFileCheckStore.go @@ -0,0 +1,131 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockRepoFileCheckStore is an autogenerated mock type for the RepoFileCheckStore type +type MockRepoFileCheckStore struct { + mock.Mock +} + +type MockRepoFileCheckStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRepoFileCheckStore) EXPECT() *MockRepoFileCheckStore_Expecter { + return &MockRepoFileCheckStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, history +func (_m *MockRepoFileCheckStore) Create(ctx context.Context, history database.RepositoryFileCheck) error { + ret := _m.Called(ctx, history) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.RepositoryFileCheck) error); ok { + r0 = rf(ctx, history) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoFileCheckStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockRepoFileCheckStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - history database.RepositoryFileCheck +func (_e *MockRepoFileCheckStore_Expecter) Create(ctx interface{}, history interface{}) *MockRepoFileCheckStore_Create_Call { + return &MockRepoFileCheckStore_Create_Call{Call: _e.mock.On("Create", ctx, history)} +} + +func (_c *MockRepoFileCheckStore_Create_Call) Run(run func(ctx context.Context, history database.RepositoryFileCheck)) *MockRepoFileCheckStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.RepositoryFileCheck)) + }) + return _c +} + +func (_c *MockRepoFileCheckStore_Create_Call) Return(_a0 error) *MockRepoFileCheckStore_Create_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoFileCheckStore_Create_Call) RunAndReturn(run func(context.Context, database.RepositoryFileCheck) error) *MockRepoFileCheckStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Upsert provides a mock function with given fields: ctx, history +func (_m *MockRepoFileCheckStore) Upsert(ctx context.Context, history database.RepositoryFileCheck) error { + ret := _m.Called(ctx, history) + + if len(ret) == 0 { + panic("no return value specified for Upsert") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.RepositoryFileCheck) error); ok { + r0 = rf(ctx, history) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoFileCheckStore_Upsert_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Upsert' +type MockRepoFileCheckStore_Upsert_Call struct { + *mock.Call +} + +// Upsert is a helper method to define mock.On call +// - ctx context.Context +// - history database.RepositoryFileCheck +func (_e *MockRepoFileCheckStore_Expecter) Upsert(ctx interface{}, history interface{}) *MockRepoFileCheckStore_Upsert_Call { + return &MockRepoFileCheckStore_Upsert_Call{Call: _e.mock.On("Upsert", ctx, history)} +} + +func (_c *MockRepoFileCheckStore_Upsert_Call) Run(run func(ctx context.Context, history database.RepositoryFileCheck)) *MockRepoFileCheckStore_Upsert_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.RepositoryFileCheck)) + }) + return _c +} + +func (_c *MockRepoFileCheckStore_Upsert_Call) Return(_a0 error) *MockRepoFileCheckStore_Upsert_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoFileCheckStore_Upsert_Call) RunAndReturn(run func(context.Context, database.RepositoryFileCheck) error) *MockRepoFileCheckStore_Upsert_Call { + _c.Call.Return(run) + return _c +} + +// NewMockRepoFileCheckStore creates a new instance of MockRepoFileCheckStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepoFileCheckStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRepoFileCheckStore { + mock := &MockRepoFileCheckStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoFileStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoFileStore.go new file mode 100644 index 00000000..0be248e3 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoFileStore.go @@ -0,0 +1,324 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" + + types "opencsg.com/csghub-server/common/types" +) + +// MockRepoFileStore is an autogenerated mock type for the RepoFileStore type +type MockRepoFileStore struct { + mock.Mock +} + +type MockRepoFileStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRepoFileStore) EXPECT() *MockRepoFileStore_Expecter { + return &MockRepoFileStore_Expecter{mock: &_m.Mock} +} + +// BatchGet provides a mock function with given fields: ctx, repoID, lastRepoFileID, batch +func (_m *MockRepoFileStore) BatchGet(ctx context.Context, repoID int64, lastRepoFileID int64, batch int64) ([]*database.RepositoryFile, error) { + ret := _m.Called(ctx, repoID, lastRepoFileID, batch) + + if len(ret) == 0 { + panic("no return value specified for BatchGet") + } + + var r0 []*database.RepositoryFile + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64, int64) ([]*database.RepositoryFile, error)); ok { + return rf(ctx, repoID, lastRepoFileID, batch) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int64, int64) []*database.RepositoryFile); ok { + r0 = rf(ctx, repoID, lastRepoFileID, batch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.RepositoryFile) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int64, int64) error); ok { + r1 = rf(ctx, repoID, lastRepoFileID, batch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoFileStore_BatchGet_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchGet' +type MockRepoFileStore_BatchGet_Call struct { + *mock.Call +} + +// BatchGet is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - lastRepoFileID int64 +// - batch int64 +func (_e *MockRepoFileStore_Expecter) BatchGet(ctx interface{}, repoID interface{}, lastRepoFileID interface{}, batch interface{}) *MockRepoFileStore_BatchGet_Call { + return &MockRepoFileStore_BatchGet_Call{Call: _e.mock.On("BatchGet", ctx, repoID, lastRepoFileID, batch)} +} + +func (_c *MockRepoFileStore_BatchGet_Call) Run(run func(ctx context.Context, repoID int64, lastRepoFileID int64, batch int64)) *MockRepoFileStore_BatchGet_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64), args[3].(int64)) + }) + return _c +} + +func (_c *MockRepoFileStore_BatchGet_Call) Return(_a0 []*database.RepositoryFile, _a1 error) *MockRepoFileStore_BatchGet_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoFileStore_BatchGet_Call) RunAndReturn(run func(context.Context, int64, int64, int64) ([]*database.RepositoryFile, error)) *MockRepoFileStore_BatchGet_Call { + _c.Call.Return(run) + return _c +} + +// BatchGetUnchcked provides a mock function with given fields: ctx, repoID, lastRepoFileID, batch +func (_m *MockRepoFileStore) BatchGetUnchcked(ctx context.Context, repoID int64, lastRepoFileID int64, batch int64) ([]*database.RepositoryFile, error) { + ret := _m.Called(ctx, repoID, lastRepoFileID, batch) + + if len(ret) == 0 { + panic("no return value specified for BatchGetUnchcked") + } + + var r0 []*database.RepositoryFile + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64, int64) ([]*database.RepositoryFile, error)); ok { + return rf(ctx, repoID, lastRepoFileID, batch) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int64, int64) []*database.RepositoryFile); ok { + r0 = rf(ctx, repoID, lastRepoFileID, batch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.RepositoryFile) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int64, int64) error); ok { + r1 = rf(ctx, repoID, lastRepoFileID, batch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoFileStore_BatchGetUnchcked_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchGetUnchcked' +type MockRepoFileStore_BatchGetUnchcked_Call struct { + *mock.Call +} + +// BatchGetUnchcked is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - lastRepoFileID int64 +// - batch int64 +func (_e *MockRepoFileStore_Expecter) BatchGetUnchcked(ctx interface{}, repoID interface{}, lastRepoFileID interface{}, batch interface{}) *MockRepoFileStore_BatchGetUnchcked_Call { + return &MockRepoFileStore_BatchGetUnchcked_Call{Call: _e.mock.On("BatchGetUnchcked", ctx, repoID, lastRepoFileID, batch)} +} + +func (_c *MockRepoFileStore_BatchGetUnchcked_Call) Run(run func(ctx context.Context, repoID int64, lastRepoFileID int64, batch int64)) *MockRepoFileStore_BatchGetUnchcked_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64), args[3].(int64)) + }) + return _c +} + +func (_c *MockRepoFileStore_BatchGetUnchcked_Call) Return(_a0 []*database.RepositoryFile, _a1 error) *MockRepoFileStore_BatchGetUnchcked_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoFileStore_BatchGetUnchcked_Call) RunAndReturn(run func(context.Context, int64, int64, int64) ([]*database.RepositoryFile, error)) *MockRepoFileStore_BatchGetUnchcked_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, file +func (_m *MockRepoFileStore) Create(ctx context.Context, file *database.RepositoryFile) error { + ret := _m.Called(ctx, file) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.RepositoryFile) error); ok { + r0 = rf(ctx, file) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoFileStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockRepoFileStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - file *database.RepositoryFile +func (_e *MockRepoFileStore_Expecter) Create(ctx interface{}, file interface{}) *MockRepoFileStore_Create_Call { + return &MockRepoFileStore_Create_Call{Call: _e.mock.On("Create", ctx, file)} +} + +func (_c *MockRepoFileStore_Create_Call) Run(run func(ctx context.Context, file *database.RepositoryFile)) *MockRepoFileStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.RepositoryFile)) + }) + return _c +} + +func (_c *MockRepoFileStore_Create_Call) Return(_a0 error) *MockRepoFileStore_Create_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoFileStore_Create_Call) RunAndReturn(run func(context.Context, *database.RepositoryFile) error) *MockRepoFileStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Exists provides a mock function with given fields: ctx, file +func (_m *MockRepoFileStore) Exists(ctx context.Context, file database.RepositoryFile) (bool, error) { + ret := _m.Called(ctx, file) + + if len(ret) == 0 { + panic("no return value specified for Exists") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.RepositoryFile) (bool, error)); ok { + return rf(ctx, file) + } + if rf, ok := ret.Get(0).(func(context.Context, database.RepositoryFile) bool); ok { + r0 = rf(ctx, file) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, database.RepositoryFile) error); ok { + r1 = rf(ctx, file) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoFileStore_Exists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Exists' +type MockRepoFileStore_Exists_Call struct { + *mock.Call +} + +// Exists is a helper method to define mock.On call +// - ctx context.Context +// - file database.RepositoryFile +func (_e *MockRepoFileStore_Expecter) Exists(ctx interface{}, file interface{}) *MockRepoFileStore_Exists_Call { + return &MockRepoFileStore_Exists_Call{Call: _e.mock.On("Exists", ctx, file)} +} + +func (_c *MockRepoFileStore_Exists_Call) Run(run func(ctx context.Context, file database.RepositoryFile)) *MockRepoFileStore_Exists_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.RepositoryFile)) + }) + return _c +} + +func (_c *MockRepoFileStore_Exists_Call) Return(_a0 bool, _a1 error) *MockRepoFileStore_Exists_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoFileStore_Exists_Call) RunAndReturn(run func(context.Context, database.RepositoryFile) (bool, error)) *MockRepoFileStore_Exists_Call { + _c.Call.Return(run) + return _c +} + +// ExistsSensitiveCheckRecord provides a mock function with given fields: ctx, repoID, branch, status +func (_m *MockRepoFileStore) ExistsSensitiveCheckRecord(ctx context.Context, repoID int64, branch string, status types.SensitiveCheckStatus) (bool, error) { + ret := _m.Called(ctx, repoID, branch, status) + + if len(ret) == 0 { + panic("no return value specified for ExistsSensitiveCheckRecord") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string, types.SensitiveCheckStatus) (bool, error)); ok { + return rf(ctx, repoID, branch, status) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, string, types.SensitiveCheckStatus) bool); ok { + r0 = rf(ctx, repoID, branch, status) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, string, types.SensitiveCheckStatus) error); ok { + r1 = rf(ctx, repoID, branch, status) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoFileStore_ExistsSensitiveCheckRecord_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ExistsSensitiveCheckRecord' +type MockRepoFileStore_ExistsSensitiveCheckRecord_Call struct { + *mock.Call +} + +// ExistsSensitiveCheckRecord is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - branch string +// - status types.SensitiveCheckStatus +func (_e *MockRepoFileStore_Expecter) ExistsSensitiveCheckRecord(ctx interface{}, repoID interface{}, branch interface{}, status interface{}) *MockRepoFileStore_ExistsSensitiveCheckRecord_Call { + return &MockRepoFileStore_ExistsSensitiveCheckRecord_Call{Call: _e.mock.On("ExistsSensitiveCheckRecord", ctx, repoID, branch, status)} +} + +func (_c *MockRepoFileStore_ExistsSensitiveCheckRecord_Call) Run(run func(ctx context.Context, repoID int64, branch string, status types.SensitiveCheckStatus)) *MockRepoFileStore_ExistsSensitiveCheckRecord_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string), args[3].(types.SensitiveCheckStatus)) + }) + return _c +} + +func (_c *MockRepoFileStore_ExistsSensitiveCheckRecord_Call) Return(_a0 bool, _a1 error) *MockRepoFileStore_ExistsSensitiveCheckRecord_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoFileStore_ExistsSensitiveCheckRecord_Call) RunAndReturn(run func(context.Context, int64, string, types.SensitiveCheckStatus) (bool, error)) *MockRepoFileStore_ExistsSensitiveCheckRecord_Call { + _c.Call.Return(run) + return _c +} + +// NewMockRepoFileStore creates a new instance of MockRepoFileStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepoFileStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRepoFileStore { + mock := &MockRepoFileStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoRelationsStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoRelationsStore.go new file mode 100644 index 00000000..c534b855 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoRelationsStore.go @@ -0,0 +1,265 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockRepoRelationsStore is an autogenerated mock type for the RepoRelationsStore type +type MockRepoRelationsStore struct { + mock.Mock +} + +type MockRepoRelationsStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRepoRelationsStore) EXPECT() *MockRepoRelationsStore_Expecter { + return &MockRepoRelationsStore_Expecter{mock: &_m.Mock} +} + +// Delete provides a mock function with given fields: ctx, from, to +func (_m *MockRepoRelationsStore) Delete(ctx context.Context, from int64, to int64) error { + ret := _m.Called(ctx, from, to) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64) error); ok { + r0 = rf(ctx, from, to) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoRelationsStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockRepoRelationsStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - from int64 +// - to int64 +func (_e *MockRepoRelationsStore_Expecter) Delete(ctx interface{}, from interface{}, to interface{}) *MockRepoRelationsStore_Delete_Call { + return &MockRepoRelationsStore_Delete_Call{Call: _e.mock.On("Delete", ctx, from, to)} +} + +func (_c *MockRepoRelationsStore_Delete_Call) Run(run func(ctx context.Context, from int64, to int64)) *MockRepoRelationsStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64)) + }) + return _c +} + +func (_c *MockRepoRelationsStore_Delete_Call) Return(_a0 error) *MockRepoRelationsStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoRelationsStore_Delete_Call) RunAndReturn(run func(context.Context, int64, int64) error) *MockRepoRelationsStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// From provides a mock function with given fields: ctx, repoID +func (_m *MockRepoRelationsStore) From(ctx context.Context, repoID int64) ([]*database.RepoRelation, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for From") + } + + var r0 []*database.RepoRelation + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]*database.RepoRelation, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []*database.RepoRelation); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.RepoRelation) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoRelationsStore_From_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'From' +type MockRepoRelationsStore_From_Call struct { + *mock.Call +} + +// From is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockRepoRelationsStore_Expecter) From(ctx interface{}, repoID interface{}) *MockRepoRelationsStore_From_Call { + return &MockRepoRelationsStore_From_Call{Call: _e.mock.On("From", ctx, repoID)} +} + +func (_c *MockRepoRelationsStore_From_Call) Run(run func(ctx context.Context, repoID int64)) *MockRepoRelationsStore_From_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepoRelationsStore_From_Call) Return(_a0 []*database.RepoRelation, _a1 error) *MockRepoRelationsStore_From_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoRelationsStore_From_Call) RunAndReturn(run func(context.Context, int64) ([]*database.RepoRelation, error)) *MockRepoRelationsStore_From_Call { + _c.Call.Return(run) + return _c +} + +// Override provides a mock function with given fields: ctx, from, to +func (_m *MockRepoRelationsStore) Override(ctx context.Context, from int64, to ...int64) error { + _va := make([]interface{}, len(to)) + for _i := range to { + _va[_i] = to[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, from) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Override") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, ...int64) error); ok { + r0 = rf(ctx, from, to...) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepoRelationsStore_Override_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Override' +type MockRepoRelationsStore_Override_Call struct { + *mock.Call +} + +// Override is a helper method to define mock.On call +// - ctx context.Context +// - from int64 +// - to ...int64 +func (_e *MockRepoRelationsStore_Expecter) Override(ctx interface{}, from interface{}, to ...interface{}) *MockRepoRelationsStore_Override_Call { + return &MockRepoRelationsStore_Override_Call{Call: _e.mock.On("Override", + append([]interface{}{ctx, from}, to...)...)} +} + +func (_c *MockRepoRelationsStore_Override_Call) Run(run func(ctx context.Context, from int64, to ...int64)) *MockRepoRelationsStore_Override_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]int64, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(int64) + } + } + run(args[0].(context.Context), args[1].(int64), variadicArgs...) + }) + return _c +} + +func (_c *MockRepoRelationsStore_Override_Call) Return(_a0 error) *MockRepoRelationsStore_Override_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoRelationsStore_Override_Call) RunAndReturn(run func(context.Context, int64, ...int64) error) *MockRepoRelationsStore_Override_Call { + _c.Call.Return(run) + return _c +} + +// To provides a mock function with given fields: ctx, repoID +func (_m *MockRepoRelationsStore) To(ctx context.Context, repoID int64) ([]*database.RepoRelation, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for To") + } + + var r0 []*database.RepoRelation + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]*database.RepoRelation, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []*database.RepoRelation); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.RepoRelation) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoRelationsStore_To_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'To' +type MockRepoRelationsStore_To_Call struct { + *mock.Call +} + +// To is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockRepoRelationsStore_Expecter) To(ctx interface{}, repoID interface{}) *MockRepoRelationsStore_To_Call { + return &MockRepoRelationsStore_To_Call{Call: _e.mock.On("To", ctx, repoID)} +} + +func (_c *MockRepoRelationsStore_To_Call) Run(run func(ctx context.Context, repoID int64)) *MockRepoRelationsStore_To_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepoRelationsStore_To_Call) Return(_a0 []*database.RepoRelation, _a1 error) *MockRepoRelationsStore_To_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoRelationsStore_To_Call) RunAndReturn(run func(context.Context, int64) ([]*database.RepoRelation, error)) *MockRepoRelationsStore_To_Call { + _c.Call.Return(run) + return _c +} + +// NewMockRepoRelationsStore creates a new instance of MockRepoRelationsStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepoRelationsStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRepoRelationsStore { + mock := &MockRepoRelationsStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoStore.go index 298c3f48..19be0853 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepoStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepositoriesRuntimeFrameworkStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepositoriesRuntimeFrameworkStore.go new file mode 100644 index 00000000..fb5239a0 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RepositoriesRuntimeFrameworkStore.go @@ -0,0 +1,481 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockRepositoriesRuntimeFrameworkStore is an autogenerated mock type for the RepositoriesRuntimeFrameworkStore type +type MockRepositoriesRuntimeFrameworkStore struct { + mock.Mock +} + +type MockRepositoriesRuntimeFrameworkStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRepositoriesRuntimeFrameworkStore) EXPECT() *MockRepositoriesRuntimeFrameworkStore_Expecter { + return &MockRepositoriesRuntimeFrameworkStore_Expecter{mock: &_m.Mock} +} + +// Add provides a mock function with given fields: ctx, runtimeFrameworkID, repoID, deployType +func (_m *MockRepositoriesRuntimeFrameworkStore) Add(ctx context.Context, runtimeFrameworkID int64, repoID int64, deployType int) error { + ret := _m.Called(ctx, runtimeFrameworkID, repoID, deployType) + + if len(ret) == 0 { + panic("no return value specified for Add") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64, int) error); ok { + r0 = rf(ctx, runtimeFrameworkID, repoID, deployType) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepositoriesRuntimeFrameworkStore_Add_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Add' +type MockRepositoriesRuntimeFrameworkStore_Add_Call struct { + *mock.Call +} + +// Add is a helper method to define mock.On call +// - ctx context.Context +// - runtimeFrameworkID int64 +// - repoID int64 +// - deployType int +func (_e *MockRepositoriesRuntimeFrameworkStore_Expecter) Add(ctx interface{}, runtimeFrameworkID interface{}, repoID interface{}, deployType interface{}) *MockRepositoriesRuntimeFrameworkStore_Add_Call { + return &MockRepositoriesRuntimeFrameworkStore_Add_Call{Call: _e.mock.On("Add", ctx, runtimeFrameworkID, repoID, deployType)} +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_Add_Call) Run(run func(ctx context.Context, runtimeFrameworkID int64, repoID int64, deployType int)) *MockRepositoriesRuntimeFrameworkStore_Add_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64), args[3].(int)) + }) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_Add_Call) Return(_a0 error) *MockRepositoriesRuntimeFrameworkStore_Add_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_Add_Call) RunAndReturn(run func(context.Context, int64, int64, int) error) *MockRepositoriesRuntimeFrameworkStore_Add_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, runtimeFrameworkID, repoID, deployType +func (_m *MockRepositoriesRuntimeFrameworkStore) Delete(ctx context.Context, runtimeFrameworkID int64, repoID int64, deployType int) error { + ret := _m.Called(ctx, runtimeFrameworkID, repoID, deployType) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64, int) error); ok { + r0 = rf(ctx, runtimeFrameworkID, repoID, deployType) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepositoriesRuntimeFrameworkStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockRepositoriesRuntimeFrameworkStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - runtimeFrameworkID int64 +// - repoID int64 +// - deployType int +func (_e *MockRepositoriesRuntimeFrameworkStore_Expecter) Delete(ctx interface{}, runtimeFrameworkID interface{}, repoID interface{}, deployType interface{}) *MockRepositoriesRuntimeFrameworkStore_Delete_Call { + return &MockRepositoriesRuntimeFrameworkStore_Delete_Call{Call: _e.mock.On("Delete", ctx, runtimeFrameworkID, repoID, deployType)} +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_Delete_Call) Run(run func(ctx context.Context, runtimeFrameworkID int64, repoID int64, deployType int)) *MockRepositoriesRuntimeFrameworkStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64), args[3].(int)) + }) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_Delete_Call) Return(_a0 error) *MockRepositoriesRuntimeFrameworkStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_Delete_Call) RunAndReturn(run func(context.Context, int64, int64, int) error) *MockRepositoriesRuntimeFrameworkStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// DeleteByRepoID provides a mock function with given fields: ctx, repoID +func (_m *MockRepositoriesRuntimeFrameworkStore) DeleteByRepoID(ctx context.Context, repoID int64) error { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for DeleteByRepoID") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, repoID) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRepositoriesRuntimeFrameworkStore_DeleteByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteByRepoID' +type MockRepositoriesRuntimeFrameworkStore_DeleteByRepoID_Call struct { + *mock.Call +} + +// DeleteByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockRepositoriesRuntimeFrameworkStore_Expecter) DeleteByRepoID(ctx interface{}, repoID interface{}) *MockRepositoriesRuntimeFrameworkStore_DeleteByRepoID_Call { + return &MockRepositoriesRuntimeFrameworkStore_DeleteByRepoID_Call{Call: _e.mock.On("DeleteByRepoID", ctx, repoID)} +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_DeleteByRepoID_Call) Run(run func(ctx context.Context, repoID int64)) *MockRepositoriesRuntimeFrameworkStore_DeleteByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_DeleteByRepoID_Call) Return(_a0 error) *MockRepositoriesRuntimeFrameworkStore_DeleteByRepoID_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_DeleteByRepoID_Call) RunAndReturn(run func(context.Context, int64) error) *MockRepositoriesRuntimeFrameworkStore_DeleteByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// GetByIDsAndType provides a mock function with given fields: ctx, runtimeFrameworkID, repoID, deployType +func (_m *MockRepositoriesRuntimeFrameworkStore) GetByIDsAndType(ctx context.Context, runtimeFrameworkID int64, repoID int64, deployType int) ([]database.RepositoriesRuntimeFramework, error) { + ret := _m.Called(ctx, runtimeFrameworkID, repoID, deployType) + + if len(ret) == 0 { + panic("no return value specified for GetByIDsAndType") + } + + var r0 []database.RepositoriesRuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int64, int) ([]database.RepositoriesRuntimeFramework, error)); ok { + return rf(ctx, runtimeFrameworkID, repoID, deployType) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int64, int) []database.RepositoriesRuntimeFramework); ok { + r0 = rf(ctx, runtimeFrameworkID, repoID, deployType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RepositoriesRuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int64, int) error); ok { + r1 = rf(ctx, runtimeFrameworkID, repoID, deployType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepositoriesRuntimeFrameworkStore_GetByIDsAndType_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByIDsAndType' +type MockRepositoriesRuntimeFrameworkStore_GetByIDsAndType_Call struct { + *mock.Call +} + +// GetByIDsAndType is a helper method to define mock.On call +// - ctx context.Context +// - runtimeFrameworkID int64 +// - repoID int64 +// - deployType int +func (_e *MockRepositoriesRuntimeFrameworkStore_Expecter) GetByIDsAndType(ctx interface{}, runtimeFrameworkID interface{}, repoID interface{}, deployType interface{}) *MockRepositoriesRuntimeFrameworkStore_GetByIDsAndType_Call { + return &MockRepositoriesRuntimeFrameworkStore_GetByIDsAndType_Call{Call: _e.mock.On("GetByIDsAndType", ctx, runtimeFrameworkID, repoID, deployType)} +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_GetByIDsAndType_Call) Run(run func(ctx context.Context, runtimeFrameworkID int64, repoID int64, deployType int)) *MockRepositoriesRuntimeFrameworkStore_GetByIDsAndType_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int64), args[3].(int)) + }) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_GetByIDsAndType_Call) Return(_a0 []database.RepositoriesRuntimeFramework, _a1 error) *MockRepositoriesRuntimeFrameworkStore_GetByIDsAndType_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_GetByIDsAndType_Call) RunAndReturn(run func(context.Context, int64, int64, int) ([]database.RepositoriesRuntimeFramework, error)) *MockRepositoriesRuntimeFrameworkStore_GetByIDsAndType_Call { + _c.Call.Return(run) + return _c +} + +// GetByRepoIDs provides a mock function with given fields: ctx, repoID +func (_m *MockRepositoriesRuntimeFrameworkStore) GetByRepoIDs(ctx context.Context, repoID int64) ([]database.RepositoriesRuntimeFramework, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for GetByRepoIDs") + } + + var r0 []database.RepositoriesRuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.RepositoriesRuntimeFramework, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.RepositoriesRuntimeFramework); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RepositoriesRuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepositoriesRuntimeFrameworkStore_GetByRepoIDs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByRepoIDs' +type MockRepositoriesRuntimeFrameworkStore_GetByRepoIDs_Call struct { + *mock.Call +} + +// GetByRepoIDs is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockRepositoriesRuntimeFrameworkStore_Expecter) GetByRepoIDs(ctx interface{}, repoID interface{}) *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDs_Call { + return &MockRepositoriesRuntimeFrameworkStore_GetByRepoIDs_Call{Call: _e.mock.On("GetByRepoIDs", ctx, repoID)} +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDs_Call) Run(run func(ctx context.Context, repoID int64)) *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDs_Call) Return(_a0 []database.RepositoriesRuntimeFramework, _a1 error) *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDs_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDs_Call) RunAndReturn(run func(context.Context, int64) ([]database.RepositoriesRuntimeFramework, error)) *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDs_Call { + _c.Call.Return(run) + return _c +} + +// GetByRepoIDsAndType provides a mock function with given fields: ctx, repoID, deployType +func (_m *MockRepositoriesRuntimeFrameworkStore) GetByRepoIDsAndType(ctx context.Context, repoID int64, deployType int) ([]database.RepositoriesRuntimeFramework, error) { + ret := _m.Called(ctx, repoID, deployType) + + if len(ret) == 0 { + panic("no return value specified for GetByRepoIDsAndType") + } + + var r0 []database.RepositoriesRuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int) ([]database.RepositoriesRuntimeFramework, error)); ok { + return rf(ctx, repoID, deployType) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int) []database.RepositoriesRuntimeFramework); ok { + r0 = rf(ctx, repoID, deployType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RepositoriesRuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int) error); ok { + r1 = rf(ctx, repoID, deployType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepositoriesRuntimeFrameworkStore_GetByRepoIDsAndType_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByRepoIDsAndType' +type MockRepositoriesRuntimeFrameworkStore_GetByRepoIDsAndType_Call struct { + *mock.Call +} + +// GetByRepoIDsAndType is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - deployType int +func (_e *MockRepositoriesRuntimeFrameworkStore_Expecter) GetByRepoIDsAndType(ctx interface{}, repoID interface{}, deployType interface{}) *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDsAndType_Call { + return &MockRepositoriesRuntimeFrameworkStore_GetByRepoIDsAndType_Call{Call: _e.mock.On("GetByRepoIDsAndType", ctx, repoID, deployType)} +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDsAndType_Call) Run(run func(ctx context.Context, repoID int64, deployType int)) *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDsAndType_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int)) + }) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDsAndType_Call) Return(_a0 []database.RepositoriesRuntimeFramework, _a1 error) *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDsAndType_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDsAndType_Call) RunAndReturn(run func(context.Context, int64, int) ([]database.RepositoriesRuntimeFramework, error)) *MockRepositoriesRuntimeFrameworkStore_GetByRepoIDsAndType_Call { + _c.Call.Return(run) + return _c +} + +// ListByRuntimeFrameworkID provides a mock function with given fields: ctx, runtimeFrameworkID, deployType +func (_m *MockRepositoriesRuntimeFrameworkStore) ListByRuntimeFrameworkID(ctx context.Context, runtimeFrameworkID int64, deployType int) ([]database.RepositoriesRuntimeFramework, error) { + ret := _m.Called(ctx, runtimeFrameworkID, deployType) + + if len(ret) == 0 { + panic("no return value specified for ListByRuntimeFrameworkID") + } + + var r0 []database.RepositoriesRuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int) ([]database.RepositoriesRuntimeFramework, error)); ok { + return rf(ctx, runtimeFrameworkID, deployType) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int) []database.RepositoriesRuntimeFramework); ok { + r0 = rf(ctx, runtimeFrameworkID, deployType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RepositoriesRuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int) error); ok { + r1 = rf(ctx, runtimeFrameworkID, deployType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepositoriesRuntimeFrameworkStore_ListByRuntimeFrameworkID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByRuntimeFrameworkID' +type MockRepositoriesRuntimeFrameworkStore_ListByRuntimeFrameworkID_Call struct { + *mock.Call +} + +// ListByRuntimeFrameworkID is a helper method to define mock.On call +// - ctx context.Context +// - runtimeFrameworkID int64 +// - deployType int +func (_e *MockRepositoriesRuntimeFrameworkStore_Expecter) ListByRuntimeFrameworkID(ctx interface{}, runtimeFrameworkID interface{}, deployType interface{}) *MockRepositoriesRuntimeFrameworkStore_ListByRuntimeFrameworkID_Call { + return &MockRepositoriesRuntimeFrameworkStore_ListByRuntimeFrameworkID_Call{Call: _e.mock.On("ListByRuntimeFrameworkID", ctx, runtimeFrameworkID, deployType)} +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_ListByRuntimeFrameworkID_Call) Run(run func(ctx context.Context, runtimeFrameworkID int64, deployType int)) *MockRepositoriesRuntimeFrameworkStore_ListByRuntimeFrameworkID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int)) + }) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_ListByRuntimeFrameworkID_Call) Return(_a0 []database.RepositoriesRuntimeFramework, _a1 error) *MockRepositoriesRuntimeFrameworkStore_ListByRuntimeFrameworkID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_ListByRuntimeFrameworkID_Call) RunAndReturn(run func(context.Context, int64, int) ([]database.RepositoriesRuntimeFramework, error)) *MockRepositoriesRuntimeFrameworkStore_ListByRuntimeFrameworkID_Call { + _c.Call.Return(run) + return _c +} + +// ListRepoIDsByType provides a mock function with given fields: ctx, deployType +func (_m *MockRepositoriesRuntimeFrameworkStore) ListRepoIDsByType(ctx context.Context, deployType int) ([]database.RepositoriesRuntimeFramework, error) { + ret := _m.Called(ctx, deployType) + + if len(ret) == 0 { + panic("no return value specified for ListRepoIDsByType") + } + + var r0 []database.RepositoriesRuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int) ([]database.RepositoriesRuntimeFramework, error)); ok { + return rf(ctx, deployType) + } + if rf, ok := ret.Get(0).(func(context.Context, int) []database.RepositoriesRuntimeFramework); ok { + r0 = rf(ctx, deployType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RepositoriesRuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int) error); ok { + r1 = rf(ctx, deployType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepositoriesRuntimeFrameworkStore_ListRepoIDsByType_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListRepoIDsByType' +type MockRepositoriesRuntimeFrameworkStore_ListRepoIDsByType_Call struct { + *mock.Call +} + +// ListRepoIDsByType is a helper method to define mock.On call +// - ctx context.Context +// - deployType int +func (_e *MockRepositoriesRuntimeFrameworkStore_Expecter) ListRepoIDsByType(ctx interface{}, deployType interface{}) *MockRepositoriesRuntimeFrameworkStore_ListRepoIDsByType_Call { + return &MockRepositoriesRuntimeFrameworkStore_ListRepoIDsByType_Call{Call: _e.mock.On("ListRepoIDsByType", ctx, deployType)} +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_ListRepoIDsByType_Call) Run(run func(ctx context.Context, deployType int)) *MockRepositoriesRuntimeFrameworkStore_ListRepoIDsByType_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int)) + }) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_ListRepoIDsByType_Call) Return(_a0 []database.RepositoriesRuntimeFramework, _a1 error) *MockRepositoriesRuntimeFrameworkStore_ListRepoIDsByType_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepositoriesRuntimeFrameworkStore_ListRepoIDsByType_Call) RunAndReturn(run func(context.Context, int) ([]database.RepositoriesRuntimeFramework, error)) *MockRepositoriesRuntimeFrameworkStore_ListRepoIDsByType_Call { + _c.Call.Return(run) + return _c +} + +// NewMockRepositoriesRuntimeFrameworkStore creates a new instance of MockRepositoriesRuntimeFrameworkStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepositoriesRuntimeFrameworkStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRepositoriesRuntimeFrameworkStore { + mock := &MockRepositoriesRuntimeFrameworkStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ResourceModelStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ResourceModelStore.go new file mode 100644 index 00000000..f1be1c9d --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_ResourceModelStore.go @@ -0,0 +1,156 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockResourceModelStore is an autogenerated mock type for the ResourceModelStore type +type MockResourceModelStore struct { + mock.Mock +} + +type MockResourceModelStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockResourceModelStore) EXPECT() *MockResourceModelStore_Expecter { + return &MockResourceModelStore_Expecter{mock: &_m.Mock} +} + +// CheckModelNameNotInRFRepo provides a mock function with given fields: ctx, modelName, repoId +func (_m *MockResourceModelStore) CheckModelNameNotInRFRepo(ctx context.Context, modelName string, repoId int64) (*database.ResourceModel, error) { + ret := _m.Called(ctx, modelName, repoId) + + if len(ret) == 0 { + panic("no return value specified for CheckModelNameNotInRFRepo") + } + + var r0 *database.ResourceModel + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, int64) (*database.ResourceModel, error)); ok { + return rf(ctx, modelName, repoId) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int64) *database.ResourceModel); ok { + r0 = rf(ctx, modelName, repoId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.ResourceModel) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int64) error); ok { + r1 = rf(ctx, modelName, repoId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockResourceModelStore_CheckModelNameNotInRFRepo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckModelNameNotInRFRepo' +type MockResourceModelStore_CheckModelNameNotInRFRepo_Call struct { + *mock.Call +} + +// CheckModelNameNotInRFRepo is a helper method to define mock.On call +// - ctx context.Context +// - modelName string +// - repoId int64 +func (_e *MockResourceModelStore_Expecter) CheckModelNameNotInRFRepo(ctx interface{}, modelName interface{}, repoId interface{}) *MockResourceModelStore_CheckModelNameNotInRFRepo_Call { + return &MockResourceModelStore_CheckModelNameNotInRFRepo_Call{Call: _e.mock.On("CheckModelNameNotInRFRepo", ctx, modelName, repoId)} +} + +func (_c *MockResourceModelStore_CheckModelNameNotInRFRepo_Call) Run(run func(ctx context.Context, modelName string, repoId int64)) *MockResourceModelStore_CheckModelNameNotInRFRepo_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int64)) + }) + return _c +} + +func (_c *MockResourceModelStore_CheckModelNameNotInRFRepo_Call) Return(_a0 *database.ResourceModel, _a1 error) *MockResourceModelStore_CheckModelNameNotInRFRepo_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockResourceModelStore_CheckModelNameNotInRFRepo_Call) RunAndReturn(run func(context.Context, string, int64) (*database.ResourceModel, error)) *MockResourceModelStore_CheckModelNameNotInRFRepo_Call { + _c.Call.Return(run) + return _c +} + +// FindByModelName provides a mock function with given fields: ctx, modelName +func (_m *MockResourceModelStore) FindByModelName(ctx context.Context, modelName string) ([]*database.ResourceModel, error) { + ret := _m.Called(ctx, modelName) + + if len(ret) == 0 { + panic("no return value specified for FindByModelName") + } + + var r0 []*database.ResourceModel + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]*database.ResourceModel, error)); ok { + return rf(ctx, modelName) + } + if rf, ok := ret.Get(0).(func(context.Context, string) []*database.ResourceModel); ok { + r0 = rf(ctx, modelName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.ResourceModel) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, modelName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockResourceModelStore_FindByModelName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByModelName' +type MockResourceModelStore_FindByModelName_Call struct { + *mock.Call +} + +// FindByModelName is a helper method to define mock.On call +// - ctx context.Context +// - modelName string +func (_e *MockResourceModelStore_Expecter) FindByModelName(ctx interface{}, modelName interface{}) *MockResourceModelStore_FindByModelName_Call { + return &MockResourceModelStore_FindByModelName_Call{Call: _e.mock.On("FindByModelName", ctx, modelName)} +} + +func (_c *MockResourceModelStore_FindByModelName_Call) Run(run func(ctx context.Context, modelName string)) *MockResourceModelStore_FindByModelName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockResourceModelStore_FindByModelName_Call) Return(_a0 []*database.ResourceModel, _a1 error) *MockResourceModelStore_FindByModelName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockResourceModelStore_FindByModelName_Call) RunAndReturn(run func(context.Context, string) ([]*database.ResourceModel, error)) *MockResourceModelStore_FindByModelName_Call { + _c.Call.Return(run) + return _c +} + +// NewMockResourceModelStore creates a new instance of MockResourceModelStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockResourceModelStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockResourceModelStore { + mock := &MockResourceModelStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RuntimeArchitecturesStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RuntimeArchitecturesStore.go new file mode 100644 index 00000000..d7e98ced --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RuntimeArchitecturesStore.go @@ -0,0 +1,430 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockRuntimeArchitecturesStore is an autogenerated mock type for the RuntimeArchitecturesStore type +type MockRuntimeArchitecturesStore struct { + mock.Mock +} + +type MockRuntimeArchitecturesStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRuntimeArchitecturesStore) EXPECT() *MockRuntimeArchitecturesStore_Expecter { + return &MockRuntimeArchitecturesStore_Expecter{mock: &_m.Mock} +} + +// Add provides a mock function with given fields: ctx, arch +func (_m *MockRuntimeArchitecturesStore) Add(ctx context.Context, arch database.RuntimeArchitecture) error { + ret := _m.Called(ctx, arch) + + if len(ret) == 0 { + panic("no return value specified for Add") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.RuntimeArchitecture) error); ok { + r0 = rf(ctx, arch) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntimeArchitecturesStore_Add_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Add' +type MockRuntimeArchitecturesStore_Add_Call struct { + *mock.Call +} + +// Add is a helper method to define mock.On call +// - ctx context.Context +// - arch database.RuntimeArchitecture +func (_e *MockRuntimeArchitecturesStore_Expecter) Add(ctx interface{}, arch interface{}) *MockRuntimeArchitecturesStore_Add_Call { + return &MockRuntimeArchitecturesStore_Add_Call{Call: _e.mock.On("Add", ctx, arch)} +} + +func (_c *MockRuntimeArchitecturesStore_Add_Call) Run(run func(ctx context.Context, arch database.RuntimeArchitecture)) *MockRuntimeArchitecturesStore_Add_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.RuntimeArchitecture)) + }) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_Add_Call) Return(_a0 error) *MockRuntimeArchitecturesStore_Add_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_Add_Call) RunAndReturn(run func(context.Context, database.RuntimeArchitecture) error) *MockRuntimeArchitecturesStore_Add_Call { + _c.Call.Return(run) + return _c +} + +// DeleteByRuntimeIDAndArchName provides a mock function with given fields: ctx, id, archName +func (_m *MockRuntimeArchitecturesStore) DeleteByRuntimeIDAndArchName(ctx context.Context, id int64, archName string) error { + ret := _m.Called(ctx, id, archName) + + if len(ret) == 0 { + panic("no return value specified for DeleteByRuntimeIDAndArchName") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) error); ok { + r0 = rf(ctx, id, archName) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntimeArchitecturesStore_DeleteByRuntimeIDAndArchName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteByRuntimeIDAndArchName' +type MockRuntimeArchitecturesStore_DeleteByRuntimeIDAndArchName_Call struct { + *mock.Call +} + +// DeleteByRuntimeIDAndArchName is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +// - archName string +func (_e *MockRuntimeArchitecturesStore_Expecter) DeleteByRuntimeIDAndArchName(ctx interface{}, id interface{}, archName interface{}) *MockRuntimeArchitecturesStore_DeleteByRuntimeIDAndArchName_Call { + return &MockRuntimeArchitecturesStore_DeleteByRuntimeIDAndArchName_Call{Call: _e.mock.On("DeleteByRuntimeIDAndArchName", ctx, id, archName)} +} + +func (_c *MockRuntimeArchitecturesStore_DeleteByRuntimeIDAndArchName_Call) Run(run func(ctx context.Context, id int64, archName string)) *MockRuntimeArchitecturesStore_DeleteByRuntimeIDAndArchName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_DeleteByRuntimeIDAndArchName_Call) Return(_a0 error) *MockRuntimeArchitecturesStore_DeleteByRuntimeIDAndArchName_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_DeleteByRuntimeIDAndArchName_Call) RunAndReturn(run func(context.Context, int64, string) error) *MockRuntimeArchitecturesStore_DeleteByRuntimeIDAndArchName_Call { + _c.Call.Return(run) + return _c +} + +// FindByRuntimeIDAndArchName provides a mock function with given fields: ctx, id, archName +func (_m *MockRuntimeArchitecturesStore) FindByRuntimeIDAndArchName(ctx context.Context, id int64, archName string) (*database.RuntimeArchitecture, error) { + ret := _m.Called(ctx, id, archName) + + if len(ret) == 0 { + panic("no return value specified for FindByRuntimeIDAndArchName") + } + + var r0 *database.RuntimeArchitecture + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) (*database.RuntimeArchitecture, error)); ok { + return rf(ctx, id, archName) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, string) *database.RuntimeArchitecture); ok { + r0 = rf(ctx, id, archName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.RuntimeArchitecture) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, string) error); ok { + r1 = rf(ctx, id, archName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeArchitecturesStore_FindByRuntimeIDAndArchName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByRuntimeIDAndArchName' +type MockRuntimeArchitecturesStore_FindByRuntimeIDAndArchName_Call struct { + *mock.Call +} + +// FindByRuntimeIDAndArchName is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +// - archName string +func (_e *MockRuntimeArchitecturesStore_Expecter) FindByRuntimeIDAndArchName(ctx interface{}, id interface{}, archName interface{}) *MockRuntimeArchitecturesStore_FindByRuntimeIDAndArchName_Call { + return &MockRuntimeArchitecturesStore_FindByRuntimeIDAndArchName_Call{Call: _e.mock.On("FindByRuntimeIDAndArchName", ctx, id, archName)} +} + +func (_c *MockRuntimeArchitecturesStore_FindByRuntimeIDAndArchName_Call) Run(run func(ctx context.Context, id int64, archName string)) *MockRuntimeArchitecturesStore_FindByRuntimeIDAndArchName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_FindByRuntimeIDAndArchName_Call) Return(_a0 *database.RuntimeArchitecture, _a1 error) *MockRuntimeArchitecturesStore_FindByRuntimeIDAndArchName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_FindByRuntimeIDAndArchName_Call) RunAndReturn(run func(context.Context, int64, string) (*database.RuntimeArchitecture, error)) *MockRuntimeArchitecturesStore_FindByRuntimeIDAndArchName_Call { + _c.Call.Return(run) + return _c +} + +// GetRuntimeByModelName provides a mock function with given fields: ctx, archName, modelName +func (_m *MockRuntimeArchitecturesStore) GetRuntimeByModelName(ctx context.Context, archName string, modelName string) ([]database.RuntimeArchitecture, error) { + ret := _m.Called(ctx, archName, modelName) + + if len(ret) == 0 { + panic("no return value specified for GetRuntimeByModelName") + } + + var r0 []database.RuntimeArchitecture + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) ([]database.RuntimeArchitecture, error)); ok { + return rf(ctx, archName, modelName) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) []database.RuntimeArchitecture); ok { + r0 = rf(ctx, archName, modelName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RuntimeArchitecture) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, archName, modelName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeArchitecturesStore_GetRuntimeByModelName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetRuntimeByModelName' +type MockRuntimeArchitecturesStore_GetRuntimeByModelName_Call struct { + *mock.Call +} + +// GetRuntimeByModelName is a helper method to define mock.On call +// - ctx context.Context +// - archName string +// - modelName string +func (_e *MockRuntimeArchitecturesStore_Expecter) GetRuntimeByModelName(ctx interface{}, archName interface{}, modelName interface{}) *MockRuntimeArchitecturesStore_GetRuntimeByModelName_Call { + return &MockRuntimeArchitecturesStore_GetRuntimeByModelName_Call{Call: _e.mock.On("GetRuntimeByModelName", ctx, archName, modelName)} +} + +func (_c *MockRuntimeArchitecturesStore_GetRuntimeByModelName_Call) Run(run func(ctx context.Context, archName string, modelName string)) *MockRuntimeArchitecturesStore_GetRuntimeByModelName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_GetRuntimeByModelName_Call) Return(_a0 []database.RuntimeArchitecture, _a1 error) *MockRuntimeArchitecturesStore_GetRuntimeByModelName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_GetRuntimeByModelName_Call) RunAndReturn(run func(context.Context, string, string) ([]database.RuntimeArchitecture, error)) *MockRuntimeArchitecturesStore_GetRuntimeByModelName_Call { + _c.Call.Return(run) + return _c +} + +// ListByRArchName provides a mock function with given fields: ctx, archName +func (_m *MockRuntimeArchitecturesStore) ListByRArchName(ctx context.Context, archName string) ([]database.RuntimeArchitecture, error) { + ret := _m.Called(ctx, archName) + + if len(ret) == 0 { + panic("no return value specified for ListByRArchName") + } + + var r0 []database.RuntimeArchitecture + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) ([]database.RuntimeArchitecture, error)); ok { + return rf(ctx, archName) + } + if rf, ok := ret.Get(0).(func(context.Context, string) []database.RuntimeArchitecture); ok { + r0 = rf(ctx, archName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RuntimeArchitecture) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, archName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeArchitecturesStore_ListByRArchName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByRArchName' +type MockRuntimeArchitecturesStore_ListByRArchName_Call struct { + *mock.Call +} + +// ListByRArchName is a helper method to define mock.On call +// - ctx context.Context +// - archName string +func (_e *MockRuntimeArchitecturesStore_Expecter) ListByRArchName(ctx interface{}, archName interface{}) *MockRuntimeArchitecturesStore_ListByRArchName_Call { + return &MockRuntimeArchitecturesStore_ListByRArchName_Call{Call: _e.mock.On("ListByRArchName", ctx, archName)} +} + +func (_c *MockRuntimeArchitecturesStore_ListByRArchName_Call) Run(run func(ctx context.Context, archName string)) *MockRuntimeArchitecturesStore_ListByRArchName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_ListByRArchName_Call) Return(_a0 []database.RuntimeArchitecture, _a1 error) *MockRuntimeArchitecturesStore_ListByRArchName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_ListByRArchName_Call) RunAndReturn(run func(context.Context, string) ([]database.RuntimeArchitecture, error)) *MockRuntimeArchitecturesStore_ListByRArchName_Call { + _c.Call.Return(run) + return _c +} + +// ListByRArchNameAndModel provides a mock function with given fields: ctx, archName, modelName +func (_m *MockRuntimeArchitecturesStore) ListByRArchNameAndModel(ctx context.Context, archName string, modelName string) ([]database.RuntimeArchitecture, error) { + ret := _m.Called(ctx, archName, modelName) + + if len(ret) == 0 { + panic("no return value specified for ListByRArchNameAndModel") + } + + var r0 []database.RuntimeArchitecture + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) ([]database.RuntimeArchitecture, error)); ok { + return rf(ctx, archName, modelName) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) []database.RuntimeArchitecture); ok { + r0 = rf(ctx, archName, modelName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RuntimeArchitecture) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, archName, modelName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeArchitecturesStore_ListByRArchNameAndModel_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByRArchNameAndModel' +type MockRuntimeArchitecturesStore_ListByRArchNameAndModel_Call struct { + *mock.Call +} + +// ListByRArchNameAndModel is a helper method to define mock.On call +// - ctx context.Context +// - archName string +// - modelName string +func (_e *MockRuntimeArchitecturesStore_Expecter) ListByRArchNameAndModel(ctx interface{}, archName interface{}, modelName interface{}) *MockRuntimeArchitecturesStore_ListByRArchNameAndModel_Call { + return &MockRuntimeArchitecturesStore_ListByRArchNameAndModel_Call{Call: _e.mock.On("ListByRArchNameAndModel", ctx, archName, modelName)} +} + +func (_c *MockRuntimeArchitecturesStore_ListByRArchNameAndModel_Call) Run(run func(ctx context.Context, archName string, modelName string)) *MockRuntimeArchitecturesStore_ListByRArchNameAndModel_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_ListByRArchNameAndModel_Call) Return(_a0 []database.RuntimeArchitecture, _a1 error) *MockRuntimeArchitecturesStore_ListByRArchNameAndModel_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_ListByRArchNameAndModel_Call) RunAndReturn(run func(context.Context, string, string) ([]database.RuntimeArchitecture, error)) *MockRuntimeArchitecturesStore_ListByRArchNameAndModel_Call { + _c.Call.Return(run) + return _c +} + +// ListByRuntimeFrameworkID provides a mock function with given fields: ctx, id +func (_m *MockRuntimeArchitecturesStore) ListByRuntimeFrameworkID(ctx context.Context, id int64) ([]database.RuntimeArchitecture, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for ListByRuntimeFrameworkID") + } + + var r0 []database.RuntimeArchitecture + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.RuntimeArchitecture, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.RuntimeArchitecture); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RuntimeArchitecture) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeArchitecturesStore_ListByRuntimeFrameworkID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByRuntimeFrameworkID' +type MockRuntimeArchitecturesStore_ListByRuntimeFrameworkID_Call struct { + *mock.Call +} + +// ListByRuntimeFrameworkID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockRuntimeArchitecturesStore_Expecter) ListByRuntimeFrameworkID(ctx interface{}, id interface{}) *MockRuntimeArchitecturesStore_ListByRuntimeFrameworkID_Call { + return &MockRuntimeArchitecturesStore_ListByRuntimeFrameworkID_Call{Call: _e.mock.On("ListByRuntimeFrameworkID", ctx, id)} +} + +func (_c *MockRuntimeArchitecturesStore_ListByRuntimeFrameworkID_Call) Run(run func(ctx context.Context, id int64)) *MockRuntimeArchitecturesStore_ListByRuntimeFrameworkID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_ListByRuntimeFrameworkID_Call) Return(_a0 []database.RuntimeArchitecture, _a1 error) *MockRuntimeArchitecturesStore_ListByRuntimeFrameworkID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeArchitecturesStore_ListByRuntimeFrameworkID_Call) RunAndReturn(run func(context.Context, int64) ([]database.RuntimeArchitecture, error)) *MockRuntimeArchitecturesStore_ListByRuntimeFrameworkID_Call { + _c.Call.Return(run) + return _c +} + +// NewMockRuntimeArchitecturesStore creates a new instance of MockRuntimeArchitecturesStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRuntimeArchitecturesStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRuntimeArchitecturesStore { + mock := &MockRuntimeArchitecturesStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RuntimeFrameworksStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RuntimeFrameworksStore.go new file mode 100644 index 00000000..085670b3 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_RuntimeFrameworksStore.go @@ -0,0 +1,603 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockRuntimeFrameworksStore is an autogenerated mock type for the RuntimeFrameworksStore type +type MockRuntimeFrameworksStore struct { + mock.Mock +} + +type MockRuntimeFrameworksStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRuntimeFrameworksStore) EXPECT() *MockRuntimeFrameworksStore_Expecter { + return &MockRuntimeFrameworksStore_Expecter{mock: &_m.Mock} +} + +// Add provides a mock function with given fields: ctx, frame +func (_m *MockRuntimeFrameworksStore) Add(ctx context.Context, frame database.RuntimeFramework) error { + ret := _m.Called(ctx, frame) + + if len(ret) == 0 { + panic("no return value specified for Add") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.RuntimeFramework) error); ok { + r0 = rf(ctx, frame) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntimeFrameworksStore_Add_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Add' +type MockRuntimeFrameworksStore_Add_Call struct { + *mock.Call +} + +// Add is a helper method to define mock.On call +// - ctx context.Context +// - frame database.RuntimeFramework +func (_e *MockRuntimeFrameworksStore_Expecter) Add(ctx interface{}, frame interface{}) *MockRuntimeFrameworksStore_Add_Call { + return &MockRuntimeFrameworksStore_Add_Call{Call: _e.mock.On("Add", ctx, frame)} +} + +func (_c *MockRuntimeFrameworksStore_Add_Call) Run(run func(ctx context.Context, frame database.RuntimeFramework)) *MockRuntimeFrameworksStore_Add_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.RuntimeFramework)) + }) + return _c +} + +func (_c *MockRuntimeFrameworksStore_Add_Call) Return(_a0 error) *MockRuntimeFrameworksStore_Add_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntimeFrameworksStore_Add_Call) RunAndReturn(run func(context.Context, database.RuntimeFramework) error) *MockRuntimeFrameworksStore_Add_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, frame +func (_m *MockRuntimeFrameworksStore) Delete(ctx context.Context, frame database.RuntimeFramework) error { + ret := _m.Called(ctx, frame) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.RuntimeFramework) error); ok { + r0 = rf(ctx, frame) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntimeFrameworksStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockRuntimeFrameworksStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - frame database.RuntimeFramework +func (_e *MockRuntimeFrameworksStore_Expecter) Delete(ctx interface{}, frame interface{}) *MockRuntimeFrameworksStore_Delete_Call { + return &MockRuntimeFrameworksStore_Delete_Call{Call: _e.mock.On("Delete", ctx, frame)} +} + +func (_c *MockRuntimeFrameworksStore_Delete_Call) Run(run func(ctx context.Context, frame database.RuntimeFramework)) *MockRuntimeFrameworksStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.RuntimeFramework)) + }) + return _c +} + +func (_c *MockRuntimeFrameworksStore_Delete_Call) Return(_a0 error) *MockRuntimeFrameworksStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntimeFrameworksStore_Delete_Call) RunAndReturn(run func(context.Context, database.RuntimeFramework) error) *MockRuntimeFrameworksStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindByID provides a mock function with given fields: ctx, id +func (_m *MockRuntimeFrameworksStore) FindByID(ctx context.Context, id int64) (*database.RuntimeFramework, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for FindByID") + } + + var r0 *database.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.RuntimeFramework, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.RuntimeFramework); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeFrameworksStore_FindByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByID' +type MockRuntimeFrameworksStore_FindByID_Call struct { + *mock.Call +} + +// FindByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockRuntimeFrameworksStore_Expecter) FindByID(ctx interface{}, id interface{}) *MockRuntimeFrameworksStore_FindByID_Call { + return &MockRuntimeFrameworksStore_FindByID_Call{Call: _e.mock.On("FindByID", ctx, id)} +} + +func (_c *MockRuntimeFrameworksStore_FindByID_Call) Run(run func(ctx context.Context, id int64)) *MockRuntimeFrameworksStore_FindByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRuntimeFrameworksStore_FindByID_Call) Return(_a0 *database.RuntimeFramework, _a1 error) *MockRuntimeFrameworksStore_FindByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeFrameworksStore_FindByID_Call) RunAndReturn(run func(context.Context, int64) (*database.RuntimeFramework, error)) *MockRuntimeFrameworksStore_FindByID_Call { + _c.Call.Return(run) + return _c +} + +// FindEnabledByID provides a mock function with given fields: ctx, id +func (_m *MockRuntimeFrameworksStore) FindEnabledByID(ctx context.Context, id int64) (*database.RuntimeFramework, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for FindEnabledByID") + } + + var r0 *database.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.RuntimeFramework, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.RuntimeFramework); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeFrameworksStore_FindEnabledByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindEnabledByID' +type MockRuntimeFrameworksStore_FindEnabledByID_Call struct { + *mock.Call +} + +// FindEnabledByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockRuntimeFrameworksStore_Expecter) FindEnabledByID(ctx interface{}, id interface{}) *MockRuntimeFrameworksStore_FindEnabledByID_Call { + return &MockRuntimeFrameworksStore_FindEnabledByID_Call{Call: _e.mock.On("FindEnabledByID", ctx, id)} +} + +func (_c *MockRuntimeFrameworksStore_FindEnabledByID_Call) Run(run func(ctx context.Context, id int64)) *MockRuntimeFrameworksStore_FindEnabledByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRuntimeFrameworksStore_FindEnabledByID_Call) Return(_a0 *database.RuntimeFramework, _a1 error) *MockRuntimeFrameworksStore_FindEnabledByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeFrameworksStore_FindEnabledByID_Call) RunAndReturn(run func(context.Context, int64) (*database.RuntimeFramework, error)) *MockRuntimeFrameworksStore_FindEnabledByID_Call { + _c.Call.Return(run) + return _c +} + +// FindEnabledByName provides a mock function with given fields: ctx, name +func (_m *MockRuntimeFrameworksStore) FindEnabledByName(ctx context.Context, name string) (*database.RuntimeFramework, error) { + ret := _m.Called(ctx, name) + + if len(ret) == 0 { + panic("no return value specified for FindEnabledByName") + } + + var r0 *database.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.RuntimeFramework, error)); ok { + return rf(ctx, name) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.RuntimeFramework); ok { + r0 = rf(ctx, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeFrameworksStore_FindEnabledByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindEnabledByName' +type MockRuntimeFrameworksStore_FindEnabledByName_Call struct { + *mock.Call +} + +// FindEnabledByName is a helper method to define mock.On call +// - ctx context.Context +// - name string +func (_e *MockRuntimeFrameworksStore_Expecter) FindEnabledByName(ctx interface{}, name interface{}) *MockRuntimeFrameworksStore_FindEnabledByName_Call { + return &MockRuntimeFrameworksStore_FindEnabledByName_Call{Call: _e.mock.On("FindEnabledByName", ctx, name)} +} + +func (_c *MockRuntimeFrameworksStore_FindEnabledByName_Call) Run(run func(ctx context.Context, name string)) *MockRuntimeFrameworksStore_FindEnabledByName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockRuntimeFrameworksStore_FindEnabledByName_Call) Return(_a0 *database.RuntimeFramework, _a1 error) *MockRuntimeFrameworksStore_FindEnabledByName_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeFrameworksStore_FindEnabledByName_Call) RunAndReturn(run func(context.Context, string) (*database.RuntimeFramework, error)) *MockRuntimeFrameworksStore_FindEnabledByName_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx, deployType +func (_m *MockRuntimeFrameworksStore) List(ctx context.Context, deployType int) ([]database.RuntimeFramework, error) { + ret := _m.Called(ctx, deployType) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []database.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int) ([]database.RuntimeFramework, error)); ok { + return rf(ctx, deployType) + } + if rf, ok := ret.Get(0).(func(context.Context, int) []database.RuntimeFramework); ok { + r0 = rf(ctx, deployType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int) error); ok { + r1 = rf(ctx, deployType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeFrameworksStore_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type MockRuntimeFrameworksStore_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - deployType int +func (_e *MockRuntimeFrameworksStore_Expecter) List(ctx interface{}, deployType interface{}) *MockRuntimeFrameworksStore_List_Call { + return &MockRuntimeFrameworksStore_List_Call{Call: _e.mock.On("List", ctx, deployType)} +} + +func (_c *MockRuntimeFrameworksStore_List_Call) Run(run func(ctx context.Context, deployType int)) *MockRuntimeFrameworksStore_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int)) + }) + return _c +} + +func (_c *MockRuntimeFrameworksStore_List_Call) Return(_a0 []database.RuntimeFramework, _a1 error) *MockRuntimeFrameworksStore_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeFrameworksStore_List_Call) RunAndReturn(run func(context.Context, int) ([]database.RuntimeFramework, error)) *MockRuntimeFrameworksStore_List_Call { + _c.Call.Return(run) + return _c +} + +// ListAll provides a mock function with given fields: ctx +func (_m *MockRuntimeFrameworksStore) ListAll(ctx context.Context) ([]database.RuntimeFramework, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for ListAll") + } + + var r0 []database.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.RuntimeFramework, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.RuntimeFramework); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeFrameworksStore_ListAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAll' +type MockRuntimeFrameworksStore_ListAll_Call struct { + *mock.Call +} + +// ListAll is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockRuntimeFrameworksStore_Expecter) ListAll(ctx interface{}) *MockRuntimeFrameworksStore_ListAll_Call { + return &MockRuntimeFrameworksStore_ListAll_Call{Call: _e.mock.On("ListAll", ctx)} +} + +func (_c *MockRuntimeFrameworksStore_ListAll_Call) Run(run func(ctx context.Context)) *MockRuntimeFrameworksStore_ListAll_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockRuntimeFrameworksStore_ListAll_Call) Return(_a0 []database.RuntimeFramework, _a1 error) *MockRuntimeFrameworksStore_ListAll_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeFrameworksStore_ListAll_Call) RunAndReturn(run func(context.Context) ([]database.RuntimeFramework, error)) *MockRuntimeFrameworksStore_ListAll_Call { + _c.Call.Return(run) + return _c +} + +// ListByIDs provides a mock function with given fields: ctx, ids +func (_m *MockRuntimeFrameworksStore) ListByIDs(ctx context.Context, ids []int64) ([]database.RuntimeFramework, error) { + ret := _m.Called(ctx, ids) + + if len(ret) == 0 { + panic("no return value specified for ListByIDs") + } + + var r0 []database.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []int64) ([]database.RuntimeFramework, error)); ok { + return rf(ctx, ids) + } + if rf, ok := ret.Get(0).(func(context.Context, []int64) []database.RuntimeFramework); ok { + r0 = rf(ctx, ids) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []int64) error); ok { + r1 = rf(ctx, ids) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeFrameworksStore_ListByIDs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByIDs' +type MockRuntimeFrameworksStore_ListByIDs_Call struct { + *mock.Call +} + +// ListByIDs is a helper method to define mock.On call +// - ctx context.Context +// - ids []int64 +func (_e *MockRuntimeFrameworksStore_Expecter) ListByIDs(ctx interface{}, ids interface{}) *MockRuntimeFrameworksStore_ListByIDs_Call { + return &MockRuntimeFrameworksStore_ListByIDs_Call{Call: _e.mock.On("ListByIDs", ctx, ids)} +} + +func (_c *MockRuntimeFrameworksStore_ListByIDs_Call) Run(run func(ctx context.Context, ids []int64)) *MockRuntimeFrameworksStore_ListByIDs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]int64)) + }) + return _c +} + +func (_c *MockRuntimeFrameworksStore_ListByIDs_Call) Return(_a0 []database.RuntimeFramework, _a1 error) *MockRuntimeFrameworksStore_ListByIDs_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeFrameworksStore_ListByIDs_Call) RunAndReturn(run func(context.Context, []int64) ([]database.RuntimeFramework, error)) *MockRuntimeFrameworksStore_ListByIDs_Call { + _c.Call.Return(run) + return _c +} + +// ListByRepoID provides a mock function with given fields: ctx, repoID, deployType +func (_m *MockRuntimeFrameworksStore) ListByRepoID(ctx context.Context, repoID int64, deployType int) ([]database.RepositoriesRuntimeFramework, error) { + ret := _m.Called(ctx, repoID, deployType) + + if len(ret) == 0 { + panic("no return value specified for ListByRepoID") + } + + var r0 []database.RepositoriesRuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int) ([]database.RepositoriesRuntimeFramework, error)); ok { + return rf(ctx, repoID, deployType) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int) []database.RepositoriesRuntimeFramework); ok { + r0 = rf(ctx, repoID, deployType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RepositoriesRuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int) error); ok { + r1 = rf(ctx, repoID, deployType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeFrameworksStore_ListByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByRepoID' +type MockRuntimeFrameworksStore_ListByRepoID_Call struct { + *mock.Call +} + +// ListByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +// - deployType int +func (_e *MockRuntimeFrameworksStore_Expecter) ListByRepoID(ctx interface{}, repoID interface{}, deployType interface{}) *MockRuntimeFrameworksStore_ListByRepoID_Call { + return &MockRuntimeFrameworksStore_ListByRepoID_Call{Call: _e.mock.On("ListByRepoID", ctx, repoID, deployType)} +} + +func (_c *MockRuntimeFrameworksStore_ListByRepoID_Call) Run(run func(ctx context.Context, repoID int64, deployType int)) *MockRuntimeFrameworksStore_ListByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int)) + }) + return _c +} + +func (_c *MockRuntimeFrameworksStore_ListByRepoID_Call) Return(_a0 []database.RepositoriesRuntimeFramework, _a1 error) *MockRuntimeFrameworksStore_ListByRepoID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeFrameworksStore_ListByRepoID_Call) RunAndReturn(run func(context.Context, int64, int) ([]database.RepositoriesRuntimeFramework, error)) *MockRuntimeFrameworksStore_ListByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, frame +func (_m *MockRuntimeFrameworksStore) Update(ctx context.Context, frame database.RuntimeFramework) (*database.RuntimeFramework, error) { + ret := _m.Called(ctx, frame) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 *database.RuntimeFramework + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.RuntimeFramework) (*database.RuntimeFramework, error)); ok { + return rf(ctx, frame) + } + if rf, ok := ret.Get(0).(func(context.Context, database.RuntimeFramework) *database.RuntimeFramework); ok { + r0 = rf(ctx, frame) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.RuntimeFramework) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.RuntimeFramework) error); ok { + r1 = rf(ctx, frame) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeFrameworksStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockRuntimeFrameworksStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - frame database.RuntimeFramework +func (_e *MockRuntimeFrameworksStore_Expecter) Update(ctx interface{}, frame interface{}) *MockRuntimeFrameworksStore_Update_Call { + return &MockRuntimeFrameworksStore_Update_Call{Call: _e.mock.On("Update", ctx, frame)} +} + +func (_c *MockRuntimeFrameworksStore_Update_Call) Run(run func(ctx context.Context, frame database.RuntimeFramework)) *MockRuntimeFrameworksStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.RuntimeFramework)) + }) + return _c +} + +func (_c *MockRuntimeFrameworksStore_Update_Call) Return(_a0 *database.RuntimeFramework, _a1 error) *MockRuntimeFrameworksStore_Update_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeFrameworksStore_Update_Call) RunAndReturn(run func(context.Context, database.RuntimeFramework) (*database.RuntimeFramework, error)) *MockRuntimeFrameworksStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockRuntimeFrameworksStore creates a new instance of MockRuntimeFrameworksStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRuntimeFrameworksStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRuntimeFrameworksStore { + mock := &MockRuntimeFrameworksStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SSHKeyStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SSHKeyStore.go new file mode 100644 index 00000000..4f2b1c24 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SSHKeyStore.go @@ -0,0 +1,557 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockSSHKeyStore is an autogenerated mock type for the SSHKeyStore type +type MockSSHKeyStore struct { + mock.Mock +} + +type MockSSHKeyStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSSHKeyStore) EXPECT() *MockSSHKeyStore_Expecter { + return &MockSSHKeyStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, sshKey +func (_m *MockSSHKeyStore) Create(ctx context.Context, sshKey *database.SSHKey) (*database.SSHKey, error) { + ret := _m.Called(ctx, sshKey) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.SSHKey + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *database.SSHKey) (*database.SSHKey, error)); ok { + return rf(ctx, sshKey) + } + if rf, ok := ret.Get(0).(func(context.Context, *database.SSHKey) *database.SSHKey); ok { + r0 = rf(ctx, sshKey) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SSHKey) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *database.SSHKey) error); ok { + r1 = rf(ctx, sshKey) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSSHKeyStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockSSHKeyStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - sshKey *database.SSHKey +func (_e *MockSSHKeyStore_Expecter) Create(ctx interface{}, sshKey interface{}) *MockSSHKeyStore_Create_Call { + return &MockSSHKeyStore_Create_Call{Call: _e.mock.On("Create", ctx, sshKey)} +} + +func (_c *MockSSHKeyStore_Create_Call) Run(run func(ctx context.Context, sshKey *database.SSHKey)) *MockSSHKeyStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.SSHKey)) + }) + return _c +} + +func (_c *MockSSHKeyStore_Create_Call) Return(_a0 *database.SSHKey, _a1 error) *MockSSHKeyStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSSHKeyStore_Create_Call) RunAndReturn(run func(context.Context, *database.SSHKey) (*database.SSHKey, error)) *MockSSHKeyStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, gid +func (_m *MockSSHKeyStore) Delete(ctx context.Context, gid int64) error { + ret := _m.Called(ctx, gid) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok { + r0 = rf(ctx, gid) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockSSHKeyStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockSSHKeyStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - gid int64 +func (_e *MockSSHKeyStore_Expecter) Delete(ctx interface{}, gid interface{}) *MockSSHKeyStore_Delete_Call { + return &MockSSHKeyStore_Delete_Call{Call: _e.mock.On("Delete", ctx, gid)} +} + +func (_c *MockSSHKeyStore_Delete_Call) Run(run func(ctx context.Context, gid int64)) *MockSSHKeyStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockSSHKeyStore_Delete_Call) Return(err error) *MockSSHKeyStore_Delete_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockSSHKeyStore_Delete_Call) RunAndReturn(run func(context.Context, int64) error) *MockSSHKeyStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindByFingerpringSHA256 provides a mock function with given fields: ctx, fingerprint +func (_m *MockSSHKeyStore) FindByFingerpringSHA256(ctx context.Context, fingerprint string) (*database.SSHKey, error) { + ret := _m.Called(ctx, fingerprint) + + if len(ret) == 0 { + panic("no return value specified for FindByFingerpringSHA256") + } + + var r0 *database.SSHKey + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.SSHKey, error)); ok { + return rf(ctx, fingerprint) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.SSHKey); ok { + r0 = rf(ctx, fingerprint) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SSHKey) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, fingerprint) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSSHKeyStore_FindByFingerpringSHA256_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByFingerpringSHA256' +type MockSSHKeyStore_FindByFingerpringSHA256_Call struct { + *mock.Call +} + +// FindByFingerpringSHA256 is a helper method to define mock.On call +// - ctx context.Context +// - fingerprint string +func (_e *MockSSHKeyStore_Expecter) FindByFingerpringSHA256(ctx interface{}, fingerprint interface{}) *MockSSHKeyStore_FindByFingerpringSHA256_Call { + return &MockSSHKeyStore_FindByFingerpringSHA256_Call{Call: _e.mock.On("FindByFingerpringSHA256", ctx, fingerprint)} +} + +func (_c *MockSSHKeyStore_FindByFingerpringSHA256_Call) Run(run func(ctx context.Context, fingerprint string)) *MockSSHKeyStore_FindByFingerpringSHA256_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockSSHKeyStore_FindByFingerpringSHA256_Call) Return(_a0 *database.SSHKey, _a1 error) *MockSSHKeyStore_FindByFingerpringSHA256_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSSHKeyStore_FindByFingerpringSHA256_Call) RunAndReturn(run func(context.Context, string) (*database.SSHKey, error)) *MockSSHKeyStore_FindByFingerpringSHA256_Call { + _c.Call.Return(run) + return _c +} + +// FindByID provides a mock function with given fields: ctx, id +func (_m *MockSSHKeyStore) FindByID(ctx context.Context, id int64) (*database.SSHKey, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for FindByID") + } + + var r0 *database.SSHKey + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.SSHKey, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.SSHKey); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SSHKey) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSSHKeyStore_FindByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByID' +type MockSSHKeyStore_FindByID_Call struct { + *mock.Call +} + +// FindByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockSSHKeyStore_Expecter) FindByID(ctx interface{}, id interface{}) *MockSSHKeyStore_FindByID_Call { + return &MockSSHKeyStore_FindByID_Call{Call: _e.mock.On("FindByID", ctx, id)} +} + +func (_c *MockSSHKeyStore_FindByID_Call) Run(run func(ctx context.Context, id int64)) *MockSSHKeyStore_FindByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockSSHKeyStore_FindByID_Call) Return(_a0 *database.SSHKey, _a1 error) *MockSSHKeyStore_FindByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSSHKeyStore_FindByID_Call) RunAndReturn(run func(context.Context, int64) (*database.SSHKey, error)) *MockSSHKeyStore_FindByID_Call { + _c.Call.Return(run) + return _c +} + +// FindByKeyContent provides a mock function with given fields: ctx, key +func (_m *MockSSHKeyStore) FindByKeyContent(ctx context.Context, key string) (*database.SSHKey, error) { + ret := _m.Called(ctx, key) + + if len(ret) == 0 { + panic("no return value specified for FindByKeyContent") + } + + var r0 *database.SSHKey + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.SSHKey, error)); ok { + return rf(ctx, key) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.SSHKey); ok { + r0 = rf(ctx, key) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SSHKey) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, key) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSSHKeyStore_FindByKeyContent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByKeyContent' +type MockSSHKeyStore_FindByKeyContent_Call struct { + *mock.Call +} + +// FindByKeyContent is a helper method to define mock.On call +// - ctx context.Context +// - key string +func (_e *MockSSHKeyStore_Expecter) FindByKeyContent(ctx interface{}, key interface{}) *MockSSHKeyStore_FindByKeyContent_Call { + return &MockSSHKeyStore_FindByKeyContent_Call{Call: _e.mock.On("FindByKeyContent", ctx, key)} +} + +func (_c *MockSSHKeyStore_FindByKeyContent_Call) Run(run func(ctx context.Context, key string)) *MockSSHKeyStore_FindByKeyContent_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockSSHKeyStore_FindByKeyContent_Call) Return(_a0 *database.SSHKey, _a1 error) *MockSSHKeyStore_FindByKeyContent_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSSHKeyStore_FindByKeyContent_Call) RunAndReturn(run func(context.Context, string) (*database.SSHKey, error)) *MockSSHKeyStore_FindByKeyContent_Call { + _c.Call.Return(run) + return _c +} + +// FindByNameAndUserID provides a mock function with given fields: ctx, name, userID +func (_m *MockSSHKeyStore) FindByNameAndUserID(ctx context.Context, name string, userID int64) (*database.SSHKey, error) { + ret := _m.Called(ctx, name, userID) + + if len(ret) == 0 { + panic("no return value specified for FindByNameAndUserID") + } + + var r0 *database.SSHKey + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, int64) (*database.SSHKey, error)); ok { + return rf(ctx, name, userID) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int64) *database.SSHKey); ok { + r0 = rf(ctx, name, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SSHKey) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int64) error); ok { + r1 = rf(ctx, name, userID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSSHKeyStore_FindByNameAndUserID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByNameAndUserID' +type MockSSHKeyStore_FindByNameAndUserID_Call struct { + *mock.Call +} + +// FindByNameAndUserID is a helper method to define mock.On call +// - ctx context.Context +// - name string +// - userID int64 +func (_e *MockSSHKeyStore_Expecter) FindByNameAndUserID(ctx interface{}, name interface{}, userID interface{}) *MockSSHKeyStore_FindByNameAndUserID_Call { + return &MockSSHKeyStore_FindByNameAndUserID_Call{Call: _e.mock.On("FindByNameAndUserID", ctx, name, userID)} +} + +func (_c *MockSSHKeyStore_FindByNameAndUserID_Call) Run(run func(ctx context.Context, name string, userID int64)) *MockSSHKeyStore_FindByNameAndUserID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int64)) + }) + return _c +} + +func (_c *MockSSHKeyStore_FindByNameAndUserID_Call) Return(_a0 *database.SSHKey, _a1 error) *MockSSHKeyStore_FindByNameAndUserID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSSHKeyStore_FindByNameAndUserID_Call) RunAndReturn(run func(context.Context, string, int64) (*database.SSHKey, error)) *MockSSHKeyStore_FindByNameAndUserID_Call { + _c.Call.Return(run) + return _c +} + +// FindByUsernameAndName provides a mock function with given fields: ctx, username, keyName +func (_m *MockSSHKeyStore) FindByUsernameAndName(ctx context.Context, username string, keyName string) (database.SSHKey, error) { + ret := _m.Called(ctx, username, keyName) + + if len(ret) == 0 { + panic("no return value specified for FindByUsernameAndName") + } + + var r0 database.SSHKey + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (database.SSHKey, error)); ok { + return rf(ctx, username, keyName) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) database.SSHKey); ok { + r0 = rf(ctx, username, keyName) + } else { + r0 = ret.Get(0).(database.SSHKey) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, username, keyName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSSHKeyStore_FindByUsernameAndName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByUsernameAndName' +type MockSSHKeyStore_FindByUsernameAndName_Call struct { + *mock.Call +} + +// FindByUsernameAndName is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - keyName string +func (_e *MockSSHKeyStore_Expecter) FindByUsernameAndName(ctx interface{}, username interface{}, keyName interface{}) *MockSSHKeyStore_FindByUsernameAndName_Call { + return &MockSSHKeyStore_FindByUsernameAndName_Call{Call: _e.mock.On("FindByUsernameAndName", ctx, username, keyName)} +} + +func (_c *MockSSHKeyStore_FindByUsernameAndName_Call) Run(run func(ctx context.Context, username string, keyName string)) *MockSSHKeyStore_FindByUsernameAndName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockSSHKeyStore_FindByUsernameAndName_Call) Return(sshKey database.SSHKey, err error) *MockSSHKeyStore_FindByUsernameAndName_Call { + _c.Call.Return(sshKey, err) + return _c +} + +func (_c *MockSSHKeyStore_FindByUsernameAndName_Call) RunAndReturn(run func(context.Context, string, string) (database.SSHKey, error)) *MockSSHKeyStore_FindByUsernameAndName_Call { + _c.Call.Return(run) + return _c +} + +// Index provides a mock function with given fields: ctx, username, per, page +func (_m *MockSSHKeyStore) Index(ctx context.Context, username string, per int, page int) ([]database.SSHKey, error) { + ret := _m.Called(ctx, username, per, page) + + if len(ret) == 0 { + panic("no return value specified for Index") + } + + var r0 []database.SSHKey + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int) ([]database.SSHKey, error)); ok { + return rf(ctx, username, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int) []database.SSHKey); ok { + r0 = rf(ctx, username, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.SSHKey) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int) error); ok { + r1 = rf(ctx, username, per, page) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSSHKeyStore_Index_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Index' +type MockSSHKeyStore_Index_Call struct { + *mock.Call +} + +// Index is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - per int +// - page int +func (_e *MockSSHKeyStore_Expecter) Index(ctx interface{}, username interface{}, per interface{}, page interface{}) *MockSSHKeyStore_Index_Call { + return &MockSSHKeyStore_Index_Call{Call: _e.mock.On("Index", ctx, username, per, page)} +} + +func (_c *MockSSHKeyStore_Index_Call) Run(run func(ctx context.Context, username string, per int, page int)) *MockSSHKeyStore_Index_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockSSHKeyStore_Index_Call) Return(sshKeys []database.SSHKey, err error) *MockSSHKeyStore_Index_Call { + _c.Call.Return(sshKeys, err) + return _c +} + +func (_c *MockSSHKeyStore_Index_Call) RunAndReturn(run func(context.Context, string, int, int) ([]database.SSHKey, error)) *MockSSHKeyStore_Index_Call { + _c.Call.Return(run) + return _c +} + +// IsExist provides a mock function with given fields: ctx, username, keyName +func (_m *MockSSHKeyStore) IsExist(ctx context.Context, username string, keyName string) (bool, error) { + ret := _m.Called(ctx, username, keyName) + + if len(ret) == 0 { + panic("no return value specified for IsExist") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (bool, error)); ok { + return rf(ctx, username, keyName) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) bool); ok { + r0 = rf(ctx, username, keyName) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, username, keyName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSSHKeyStore_IsExist_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsExist' +type MockSSHKeyStore_IsExist_Call struct { + *mock.Call +} + +// IsExist is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - keyName string +func (_e *MockSSHKeyStore_Expecter) IsExist(ctx interface{}, username interface{}, keyName interface{}) *MockSSHKeyStore_IsExist_Call { + return &MockSSHKeyStore_IsExist_Call{Call: _e.mock.On("IsExist", ctx, username, keyName)} +} + +func (_c *MockSSHKeyStore_IsExist_Call) Run(run func(ctx context.Context, username string, keyName string)) *MockSSHKeyStore_IsExist_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockSSHKeyStore_IsExist_Call) Return(exists bool, err error) *MockSSHKeyStore_IsExist_Call { + _c.Call.Return(exists, err) + return _c +} + +func (_c *MockSSHKeyStore_IsExist_Call) RunAndReturn(run func(context.Context, string, string) (bool, error)) *MockSSHKeyStore_IsExist_Call { + _c.Call.Return(run) + return _c +} + +// NewMockSSHKeyStore creates a new instance of MockSSHKeyStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSSHKeyStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSSHKeyStore { + mock := &MockSSHKeyStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SelectOption.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SelectOption.go new file mode 100644 index 00000000..da13b8d8 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SelectOption.go @@ -0,0 +1,69 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + bun "github.com/uptrace/bun" + + mock "github.com/stretchr/testify/mock" +) + +// MockSelectOption is an autogenerated mock type for the SelectOption type +type MockSelectOption struct { + mock.Mock +} + +type MockSelectOption_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSelectOption) EXPECT() *MockSelectOption_Expecter { + return &MockSelectOption_Expecter{mock: &_m.Mock} +} + +// Appply provides a mock function with given fields: query +func (_m *MockSelectOption) Appply(query *bun.SelectQuery) { + _m.Called(query) +} + +// MockSelectOption_Appply_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Appply' +type MockSelectOption_Appply_Call struct { + *mock.Call +} + +// Appply is a helper method to define mock.On call +// - query *bun.SelectQuery +func (_e *MockSelectOption_Expecter) Appply(query interface{}) *MockSelectOption_Appply_Call { + return &MockSelectOption_Appply_Call{Call: _e.mock.On("Appply", query)} +} + +func (_c *MockSelectOption_Appply_Call) Run(run func(query *bun.SelectQuery)) *MockSelectOption_Appply_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*bun.SelectQuery)) + }) + return _c +} + +func (_c *MockSelectOption_Appply_Call) Return() *MockSelectOption_Appply_Call { + _c.Call.Return() + return _c +} + +func (_c *MockSelectOption_Appply_Call) RunAndReturn(run func(*bun.SelectQuery)) *MockSelectOption_Appply_Call { + _c.Call.Return(run) + return _c +} + +// NewMockSelectOption creates a new instance of MockSelectOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSelectOption(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSelectOption { + mock := &MockSelectOption{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceResourceStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceResourceStore.go index a1f8b278..6c69b4b4 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceResourceStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceResourceStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceSdkStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceSdkStore.go new file mode 100644 index 00000000..acdb0d48 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceSdkStore.go @@ -0,0 +1,319 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockSpaceSdkStore is an autogenerated mock type for the SpaceSdkStore type +type MockSpaceSdkStore struct { + mock.Mock +} + +type MockSpaceSdkStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSpaceSdkStore) EXPECT() *MockSpaceSdkStore_Expecter { + return &MockSpaceSdkStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, input +func (_m *MockSpaceSdkStore) Create(ctx context.Context, input database.SpaceSdk) (*database.SpaceSdk, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.SpaceSdk + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.SpaceSdk) (*database.SpaceSdk, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.SpaceSdk) *database.SpaceSdk); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SpaceSdk) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.SpaceSdk) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceSdkStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockSpaceSdkStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - input database.SpaceSdk +func (_e *MockSpaceSdkStore_Expecter) Create(ctx interface{}, input interface{}) *MockSpaceSdkStore_Create_Call { + return &MockSpaceSdkStore_Create_Call{Call: _e.mock.On("Create", ctx, input)} +} + +func (_c *MockSpaceSdkStore_Create_Call) Run(run func(ctx context.Context, input database.SpaceSdk)) *MockSpaceSdkStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.SpaceSdk)) + }) + return _c +} + +func (_c *MockSpaceSdkStore_Create_Call) Return(_a0 *database.SpaceSdk, _a1 error) *MockSpaceSdkStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceSdkStore_Create_Call) RunAndReturn(run func(context.Context, database.SpaceSdk) (*database.SpaceSdk, error)) *MockSpaceSdkStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, input +func (_m *MockSpaceSdkStore) Delete(ctx context.Context, input database.SpaceSdk) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.SpaceSdk) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockSpaceSdkStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockSpaceSdkStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - input database.SpaceSdk +func (_e *MockSpaceSdkStore_Expecter) Delete(ctx interface{}, input interface{}) *MockSpaceSdkStore_Delete_Call { + return &MockSpaceSdkStore_Delete_Call{Call: _e.mock.On("Delete", ctx, input)} +} + +func (_c *MockSpaceSdkStore_Delete_Call) Run(run func(ctx context.Context, input database.SpaceSdk)) *MockSpaceSdkStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.SpaceSdk)) + }) + return _c +} + +func (_c *MockSpaceSdkStore_Delete_Call) Return(_a0 error) *MockSpaceSdkStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockSpaceSdkStore_Delete_Call) RunAndReturn(run func(context.Context, database.SpaceSdk) error) *MockSpaceSdkStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindByID provides a mock function with given fields: ctx, id +func (_m *MockSpaceSdkStore) FindByID(ctx context.Context, id int64) (*database.SpaceSdk, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for FindByID") + } + + var r0 *database.SpaceSdk + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.SpaceSdk, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.SpaceSdk); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SpaceSdk) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceSdkStore_FindByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByID' +type MockSpaceSdkStore_FindByID_Call struct { + *mock.Call +} + +// FindByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockSpaceSdkStore_Expecter) FindByID(ctx interface{}, id interface{}) *MockSpaceSdkStore_FindByID_Call { + return &MockSpaceSdkStore_FindByID_Call{Call: _e.mock.On("FindByID", ctx, id)} +} + +func (_c *MockSpaceSdkStore_FindByID_Call) Run(run func(ctx context.Context, id int64)) *MockSpaceSdkStore_FindByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockSpaceSdkStore_FindByID_Call) Return(_a0 *database.SpaceSdk, _a1 error) *MockSpaceSdkStore_FindByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceSdkStore_FindByID_Call) RunAndReturn(run func(context.Context, int64) (*database.SpaceSdk, error)) *MockSpaceSdkStore_FindByID_Call { + _c.Call.Return(run) + return _c +} + +// Index provides a mock function with given fields: ctx +func (_m *MockSpaceSdkStore) Index(ctx context.Context) ([]database.SpaceSdk, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Index") + } + + var r0 []database.SpaceSdk + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.SpaceSdk, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.SpaceSdk); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.SpaceSdk) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceSdkStore_Index_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Index' +type MockSpaceSdkStore_Index_Call struct { + *mock.Call +} + +// Index is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockSpaceSdkStore_Expecter) Index(ctx interface{}) *MockSpaceSdkStore_Index_Call { + return &MockSpaceSdkStore_Index_Call{Call: _e.mock.On("Index", ctx)} +} + +func (_c *MockSpaceSdkStore_Index_Call) Run(run func(ctx context.Context)) *MockSpaceSdkStore_Index_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockSpaceSdkStore_Index_Call) Return(_a0 []database.SpaceSdk, _a1 error) *MockSpaceSdkStore_Index_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceSdkStore_Index_Call) RunAndReturn(run func(context.Context) ([]database.SpaceSdk, error)) *MockSpaceSdkStore_Index_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, input +func (_m *MockSpaceSdkStore) Update(ctx context.Context, input database.SpaceSdk) (*database.SpaceSdk, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 *database.SpaceSdk + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.SpaceSdk) (*database.SpaceSdk, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.SpaceSdk) *database.SpaceSdk); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SpaceSdk) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.SpaceSdk) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceSdkStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockSpaceSdkStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - input database.SpaceSdk +func (_e *MockSpaceSdkStore_Expecter) Update(ctx interface{}, input interface{}) *MockSpaceSdkStore_Update_Call { + return &MockSpaceSdkStore_Update_Call{Call: _e.mock.On("Update", ctx, input)} +} + +func (_c *MockSpaceSdkStore_Update_Call) Run(run func(ctx context.Context, input database.SpaceSdk)) *MockSpaceSdkStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.SpaceSdk)) + }) + return _c +} + +func (_c *MockSpaceSdkStore_Update_Call) Return(_a0 *database.SpaceSdk, _a1 error) *MockSpaceSdkStore_Update_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceSdkStore_Update_Call) RunAndReturn(run func(context.Context, database.SpaceSdk) (*database.SpaceSdk, error)) *MockSpaceSdkStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockSpaceSdkStore creates a new instance of MockSpaceSdkStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSpaceSdkStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSpaceSdkStore { + mock := &MockSpaceSdkStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceStore.go new file mode 100644 index 00000000..ff8cb3f1 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SpaceStore.go @@ -0,0 +1,692 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockSpaceStore is an autogenerated mock type for the SpaceStore type +type MockSpaceStore struct { + mock.Mock +} + +type MockSpaceStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSpaceStore) EXPECT() *MockSpaceStore_Expecter { + return &MockSpaceStore_Expecter{mock: &_m.Mock} +} + +// ByID provides a mock function with given fields: ctx, id +func (_m *MockSpaceStore) ByID(ctx context.Context, id int64) (*database.Space, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for ByID") + } + + var r0 *database.Space + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Space, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Space); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceStore_ByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByID' +type MockSpaceStore_ByID_Call struct { + *mock.Call +} + +// ByID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockSpaceStore_Expecter) ByID(ctx interface{}, id interface{}) *MockSpaceStore_ByID_Call { + return &MockSpaceStore_ByID_Call{Call: _e.mock.On("ByID", ctx, id)} +} + +func (_c *MockSpaceStore_ByID_Call) Run(run func(ctx context.Context, id int64)) *MockSpaceStore_ByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockSpaceStore_ByID_Call) Return(_a0 *database.Space, _a1 error) *MockSpaceStore_ByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceStore_ByID_Call) RunAndReturn(run func(context.Context, int64) (*database.Space, error)) *MockSpaceStore_ByID_Call { + _c.Call.Return(run) + return _c +} + +// ByOrgPath provides a mock function with given fields: ctx, namespace, per, page, onlyPublic +func (_m *MockSpaceStore) ByOrgPath(ctx context.Context, namespace string, per int, page int, onlyPublic bool) ([]database.Space, int, error) { + ret := _m.Called(ctx, namespace, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByOrgPath") + } + + var r0 []database.Space + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Space, int, error)); ok { + return rf(ctx, namespace, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Space); ok { + r0 = rf(ctx, namespace, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, namespace, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockSpaceStore_ByOrgPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByOrgPath' +type MockSpaceStore_ByOrgPath_Call struct { + *mock.Call +} + +// ByOrgPath is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockSpaceStore_Expecter) ByOrgPath(ctx interface{}, namespace interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockSpaceStore_ByOrgPath_Call { + return &MockSpaceStore_ByOrgPath_Call{Call: _e.mock.On("ByOrgPath", ctx, namespace, per, page, onlyPublic)} +} + +func (_c *MockSpaceStore_ByOrgPath_Call) Run(run func(ctx context.Context, namespace string, per int, page int, onlyPublic bool)) *MockSpaceStore_ByOrgPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockSpaceStore_ByOrgPath_Call) Return(spaces []database.Space, total int, err error) *MockSpaceStore_ByOrgPath_Call { + _c.Call.Return(spaces, total, err) + return _c +} + +func (_c *MockSpaceStore_ByOrgPath_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Space, int, error)) *MockSpaceStore_ByOrgPath_Call { + _c.Call.Return(run) + return _c +} + +// ByRepoID provides a mock function with given fields: ctx, repoID +func (_m *MockSpaceStore) ByRepoID(ctx context.Context, repoID int64) (*database.Space, error) { + ret := _m.Called(ctx, repoID) + + if len(ret) == 0 { + panic("no return value specified for ByRepoID") + } + + var r0 *database.Space + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*database.Space, error)); ok { + return rf(ctx, repoID) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *database.Space); ok { + r0 = rf(ctx, repoID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, repoID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceStore_ByRepoID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByRepoID' +type MockSpaceStore_ByRepoID_Call struct { + *mock.Call +} + +// ByRepoID is a helper method to define mock.On call +// - ctx context.Context +// - repoID int64 +func (_e *MockSpaceStore_Expecter) ByRepoID(ctx interface{}, repoID interface{}) *MockSpaceStore_ByRepoID_Call { + return &MockSpaceStore_ByRepoID_Call{Call: _e.mock.On("ByRepoID", ctx, repoID)} +} + +func (_c *MockSpaceStore_ByRepoID_Call) Run(run func(ctx context.Context, repoID int64)) *MockSpaceStore_ByRepoID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockSpaceStore_ByRepoID_Call) Return(_a0 *database.Space, _a1 error) *MockSpaceStore_ByRepoID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceStore_ByRepoID_Call) RunAndReturn(run func(context.Context, int64) (*database.Space, error)) *MockSpaceStore_ByRepoID_Call { + _c.Call.Return(run) + return _c +} + +// ByRepoIDs provides a mock function with given fields: ctx, repoIDs +func (_m *MockSpaceStore) ByRepoIDs(ctx context.Context, repoIDs []int64) ([]database.Space, error) { + ret := _m.Called(ctx, repoIDs) + + if len(ret) == 0 { + panic("no return value specified for ByRepoIDs") + } + + var r0 []database.Space + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []int64) ([]database.Space, error)); ok { + return rf(ctx, repoIDs) + } + if rf, ok := ret.Get(0).(func(context.Context, []int64) []database.Space); ok { + r0 = rf(ctx, repoIDs) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []int64) error); ok { + r1 = rf(ctx, repoIDs) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceStore_ByRepoIDs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByRepoIDs' +type MockSpaceStore_ByRepoIDs_Call struct { + *mock.Call +} + +// ByRepoIDs is a helper method to define mock.On call +// - ctx context.Context +// - repoIDs []int64 +func (_e *MockSpaceStore_Expecter) ByRepoIDs(ctx interface{}, repoIDs interface{}) *MockSpaceStore_ByRepoIDs_Call { + return &MockSpaceStore_ByRepoIDs_Call{Call: _e.mock.On("ByRepoIDs", ctx, repoIDs)} +} + +func (_c *MockSpaceStore_ByRepoIDs_Call) Run(run func(ctx context.Context, repoIDs []int64)) *MockSpaceStore_ByRepoIDs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]int64)) + }) + return _c +} + +func (_c *MockSpaceStore_ByRepoIDs_Call) Return(spaces []database.Space, err error) *MockSpaceStore_ByRepoIDs_Call { + _c.Call.Return(spaces, err) + return _c +} + +func (_c *MockSpaceStore_ByRepoIDs_Call) RunAndReturn(run func(context.Context, []int64) ([]database.Space, error)) *MockSpaceStore_ByRepoIDs_Call { + _c.Call.Return(run) + return _c +} + +// ByUserLikes provides a mock function with given fields: ctx, userID, per, page +func (_m *MockSpaceStore) ByUserLikes(ctx context.Context, userID int64, per int, page int) ([]database.Space, int, error) { + ret := _m.Called(ctx, userID, per, page) + + if len(ret) == 0 { + panic("no return value specified for ByUserLikes") + } + + var r0 []database.Space + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) ([]database.Space, int, error)); ok { + return rf(ctx, userID, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, int, int) []database.Space); ok { + r0 = rf(ctx, userID, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, int, int) int); ok { + r1 = rf(ctx, userID, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, int64, int, int) error); ok { + r2 = rf(ctx, userID, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockSpaceStore_ByUserLikes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByUserLikes' +type MockSpaceStore_ByUserLikes_Call struct { + *mock.Call +} + +// ByUserLikes is a helper method to define mock.On call +// - ctx context.Context +// - userID int64 +// - per int +// - page int +func (_e *MockSpaceStore_Expecter) ByUserLikes(ctx interface{}, userID interface{}, per interface{}, page interface{}) *MockSpaceStore_ByUserLikes_Call { + return &MockSpaceStore_ByUserLikes_Call{Call: _e.mock.On("ByUserLikes", ctx, userID, per, page)} +} + +func (_c *MockSpaceStore_ByUserLikes_Call) Run(run func(ctx context.Context, userID int64, per int, page int)) *MockSpaceStore_ByUserLikes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockSpaceStore_ByUserLikes_Call) Return(spaces []database.Space, total int, err error) *MockSpaceStore_ByUserLikes_Call { + _c.Call.Return(spaces, total, err) + return _c +} + +func (_c *MockSpaceStore_ByUserLikes_Call) RunAndReturn(run func(context.Context, int64, int, int) ([]database.Space, int, error)) *MockSpaceStore_ByUserLikes_Call { + _c.Call.Return(run) + return _c +} + +// ByUsername provides a mock function with given fields: ctx, username, per, page, onlyPublic +func (_m *MockSpaceStore) ByUsername(ctx context.Context, username string, per int, page int, onlyPublic bool) ([]database.Space, int, error) { + ret := _m.Called(ctx, username, per, page, onlyPublic) + + if len(ret) == 0 { + panic("no return value specified for ByUsername") + } + + var r0 []database.Space + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) ([]database.Space, int, error)); ok { + return rf(ctx, username, per, page, onlyPublic) + } + if rf, ok := ret.Get(0).(func(context.Context, string, int, int, bool) []database.Space); ok { + r0 = rf(ctx, username, per, page, onlyPublic) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, int, int, bool) int); ok { + r1 = rf(ctx, username, per, page, onlyPublic) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, int, int, bool) error); ok { + r2 = rf(ctx, username, per, page, onlyPublic) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockSpaceStore_ByUsername_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ByUsername' +type MockSpaceStore_ByUsername_Call struct { + *mock.Call +} + +// ByUsername is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - per int +// - page int +// - onlyPublic bool +func (_e *MockSpaceStore_Expecter) ByUsername(ctx interface{}, username interface{}, per interface{}, page interface{}, onlyPublic interface{}) *MockSpaceStore_ByUsername_Call { + return &MockSpaceStore_ByUsername_Call{Call: _e.mock.On("ByUsername", ctx, username, per, page, onlyPublic)} +} + +func (_c *MockSpaceStore_ByUsername_Call) Run(run func(ctx context.Context, username string, per int, page int, onlyPublic bool)) *MockSpaceStore_ByUsername_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(int), args[3].(int), args[4].(bool)) + }) + return _c +} + +func (_c *MockSpaceStore_ByUsername_Call) Return(spaces []database.Space, total int, err error) *MockSpaceStore_ByUsername_Call { + _c.Call.Return(spaces, total, err) + return _c +} + +func (_c *MockSpaceStore_ByUsername_Call) RunAndReturn(run func(context.Context, string, int, int, bool) ([]database.Space, int, error)) *MockSpaceStore_ByUsername_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, input +func (_m *MockSpaceStore) Create(ctx context.Context, input database.Space) (*database.Space, error) { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.Space + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.Space) (*database.Space, error)); ok { + return rf(ctx, input) + } + if rf, ok := ret.Get(0).(func(context.Context, database.Space) *database.Space); ok { + r0 = rf(ctx, input) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.Space) error); ok { + r1 = rf(ctx, input) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockSpaceStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - input database.Space +func (_e *MockSpaceStore_Expecter) Create(ctx interface{}, input interface{}) *MockSpaceStore_Create_Call { + return &MockSpaceStore_Create_Call{Call: _e.mock.On("Create", ctx, input)} +} + +func (_c *MockSpaceStore_Create_Call) Run(run func(ctx context.Context, input database.Space)) *MockSpaceStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Space)) + }) + return _c +} + +func (_c *MockSpaceStore_Create_Call) Return(_a0 *database.Space, _a1 error) *MockSpaceStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceStore_Create_Call) RunAndReturn(run func(context.Context, database.Space) (*database.Space, error)) *MockSpaceStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, input +func (_m *MockSpaceStore) Delete(ctx context.Context, input database.Space) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.Space) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockSpaceStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockSpaceStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - input database.Space +func (_e *MockSpaceStore_Expecter) Delete(ctx interface{}, input interface{}) *MockSpaceStore_Delete_Call { + return &MockSpaceStore_Delete_Call{Call: _e.mock.On("Delete", ctx, input)} +} + +func (_c *MockSpaceStore_Delete_Call) Run(run func(ctx context.Context, input database.Space)) *MockSpaceStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Space)) + }) + return _c +} + +func (_c *MockSpaceStore_Delete_Call) Return(_a0 error) *MockSpaceStore_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockSpaceStore_Delete_Call) RunAndReturn(run func(context.Context, database.Space) error) *MockSpaceStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// FindByPath provides a mock function with given fields: ctx, namespace, name +func (_m *MockSpaceStore) FindByPath(ctx context.Context, namespace string, name string) (*database.Space, error) { + ret := _m.Called(ctx, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for FindByPath") + } + + var r0 *database.Space + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*database.Space, error)); ok { + return rf(ctx, namespace, name) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) *database.Space); ok { + r0 = rf(ctx, namespace, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, namespace, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceStore_FindByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByPath' +type MockSpaceStore_FindByPath_Call struct { + *mock.Call +} + +// FindByPath is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +func (_e *MockSpaceStore_Expecter) FindByPath(ctx interface{}, namespace interface{}, name interface{}) *MockSpaceStore_FindByPath_Call { + return &MockSpaceStore_FindByPath_Call{Call: _e.mock.On("FindByPath", ctx, namespace, name)} +} + +func (_c *MockSpaceStore_FindByPath_Call) Run(run func(ctx context.Context, namespace string, name string)) *MockSpaceStore_FindByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockSpaceStore_FindByPath_Call) Return(_a0 *database.Space, _a1 error) *MockSpaceStore_FindByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceStore_FindByPath_Call) RunAndReturn(run func(context.Context, string, string) (*database.Space, error)) *MockSpaceStore_FindByPath_Call { + _c.Call.Return(run) + return _c +} + +// ListByPath provides a mock function with given fields: ctx, paths +func (_m *MockSpaceStore) ListByPath(ctx context.Context, paths []string) ([]database.Space, error) { + ret := _m.Called(ctx, paths) + + if len(ret) == 0 { + panic("no return value specified for ListByPath") + } + + var r0 []database.Space + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []string) ([]database.Space, error)); ok { + return rf(ctx, paths) + } + if rf, ok := ret.Get(0).(func(context.Context, []string) []database.Space); ok { + r0 = rf(ctx, paths) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok { + r1 = rf(ctx, paths) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceStore_ListByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByPath' +type MockSpaceStore_ListByPath_Call struct { + *mock.Call +} + +// ListByPath is a helper method to define mock.On call +// - ctx context.Context +// - paths []string +func (_e *MockSpaceStore_Expecter) ListByPath(ctx interface{}, paths interface{}) *MockSpaceStore_ListByPath_Call { + return &MockSpaceStore_ListByPath_Call{Call: _e.mock.On("ListByPath", ctx, paths)} +} + +func (_c *MockSpaceStore_ListByPath_Call) Run(run func(ctx context.Context, paths []string)) *MockSpaceStore_ListByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]string)) + }) + return _c +} + +func (_c *MockSpaceStore_ListByPath_Call) Return(_a0 []database.Space, _a1 error) *MockSpaceStore_ListByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceStore_ListByPath_Call) RunAndReturn(run func(context.Context, []string) ([]database.Space, error)) *MockSpaceStore_ListByPath_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, input +func (_m *MockSpaceStore) Update(ctx context.Context, input database.Space) error { + ret := _m.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.Space) error); ok { + r0 = rf(ctx, input) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockSpaceStore_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockSpaceStore_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - input database.Space +func (_e *MockSpaceStore_Expecter) Update(ctx interface{}, input interface{}) *MockSpaceStore_Update_Call { + return &MockSpaceStore_Update_Call{Call: _e.mock.On("Update", ctx, input)} +} + +func (_c *MockSpaceStore_Update_Call) Run(run func(ctx context.Context, input database.Space)) *MockSpaceStore_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.Space)) + }) + return _c +} + +func (_c *MockSpaceStore_Update_Call) Return(err error) *MockSpaceStore_Update_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockSpaceStore_Update_Call) RunAndReturn(run func(context.Context, database.Space) error) *MockSpaceStore_Update_Call { + _c.Call.Return(run) + return _c +} + +// NewMockSpaceStore creates a new instance of MockSpaceStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSpaceStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSpaceStore { + mock := &MockSpaceStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SyncClientSettingStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SyncClientSettingStore.go new file mode 100644 index 00000000..1218e6c0 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SyncClientSettingStore.go @@ -0,0 +1,256 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockSyncClientSettingStore is an autogenerated mock type for the SyncClientSettingStore type +type MockSyncClientSettingStore struct { + mock.Mock +} + +type MockSyncClientSettingStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSyncClientSettingStore) EXPECT() *MockSyncClientSettingStore_Expecter { + return &MockSyncClientSettingStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: ctx, setting +func (_m *MockSyncClientSettingStore) Create(ctx context.Context, setting *database.SyncClientSetting) (*database.SyncClientSetting, error) { + ret := _m.Called(ctx, setting) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *database.SyncClientSetting + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *database.SyncClientSetting) (*database.SyncClientSetting, error)); ok { + return rf(ctx, setting) + } + if rf, ok := ret.Get(0).(func(context.Context, *database.SyncClientSetting) *database.SyncClientSetting); ok { + r0 = rf(ctx, setting) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SyncClientSetting) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *database.SyncClientSetting) error); ok { + r1 = rf(ctx, setting) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSyncClientSettingStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockSyncClientSettingStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - setting *database.SyncClientSetting +func (_e *MockSyncClientSettingStore_Expecter) Create(ctx interface{}, setting interface{}) *MockSyncClientSettingStore_Create_Call { + return &MockSyncClientSettingStore_Create_Call{Call: _e.mock.On("Create", ctx, setting)} +} + +func (_c *MockSyncClientSettingStore_Create_Call) Run(run func(ctx context.Context, setting *database.SyncClientSetting)) *MockSyncClientSettingStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.SyncClientSetting)) + }) + return _c +} + +func (_c *MockSyncClientSettingStore_Create_Call) Return(_a0 *database.SyncClientSetting, _a1 error) *MockSyncClientSettingStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSyncClientSettingStore_Create_Call) RunAndReturn(run func(context.Context, *database.SyncClientSetting) (*database.SyncClientSetting, error)) *MockSyncClientSettingStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// DeleteAll provides a mock function with given fields: ctx +func (_m *MockSyncClientSettingStore) DeleteAll(ctx context.Context) error { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for DeleteAll") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(ctx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockSyncClientSettingStore_DeleteAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteAll' +type MockSyncClientSettingStore_DeleteAll_Call struct { + *mock.Call +} + +// DeleteAll is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockSyncClientSettingStore_Expecter) DeleteAll(ctx interface{}) *MockSyncClientSettingStore_DeleteAll_Call { + return &MockSyncClientSettingStore_DeleteAll_Call{Call: _e.mock.On("DeleteAll", ctx)} +} + +func (_c *MockSyncClientSettingStore_DeleteAll_Call) Run(run func(ctx context.Context)) *MockSyncClientSettingStore_DeleteAll_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockSyncClientSettingStore_DeleteAll_Call) Return(_a0 error) *MockSyncClientSettingStore_DeleteAll_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockSyncClientSettingStore_DeleteAll_Call) RunAndReturn(run func(context.Context) error) *MockSyncClientSettingStore_DeleteAll_Call { + _c.Call.Return(run) + return _c +} + +// First provides a mock function with given fields: ctx +func (_m *MockSyncClientSettingStore) First(ctx context.Context) (*database.SyncClientSetting, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for First") + } + + var r0 *database.SyncClientSetting + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*database.SyncClientSetting, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *database.SyncClientSetting); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SyncClientSetting) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSyncClientSettingStore_First_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'First' +type MockSyncClientSettingStore_First_Call struct { + *mock.Call +} + +// First is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockSyncClientSettingStore_Expecter) First(ctx interface{}) *MockSyncClientSettingStore_First_Call { + return &MockSyncClientSettingStore_First_Call{Call: _e.mock.On("First", ctx)} +} + +func (_c *MockSyncClientSettingStore_First_Call) Run(run func(ctx context.Context)) *MockSyncClientSettingStore_First_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockSyncClientSettingStore_First_Call) Return(_a0 *database.SyncClientSetting, _a1 error) *MockSyncClientSettingStore_First_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSyncClientSettingStore_First_Call) RunAndReturn(run func(context.Context) (*database.SyncClientSetting, error)) *MockSyncClientSettingStore_First_Call { + _c.Call.Return(run) + return _c +} + +// SyncClientSettingExists provides a mock function with given fields: ctx +func (_m *MockSyncClientSettingStore) SyncClientSettingExists(ctx context.Context) (bool, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for SyncClientSettingExists") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (bool, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) bool); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSyncClientSettingStore_SyncClientSettingExists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SyncClientSettingExists' +type MockSyncClientSettingStore_SyncClientSettingExists_Call struct { + *mock.Call +} + +// SyncClientSettingExists is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockSyncClientSettingStore_Expecter) SyncClientSettingExists(ctx interface{}) *MockSyncClientSettingStore_SyncClientSettingExists_Call { + return &MockSyncClientSettingStore_SyncClientSettingExists_Call{Call: _e.mock.On("SyncClientSettingExists", ctx)} +} + +func (_c *MockSyncClientSettingStore_SyncClientSettingExists_Call) Run(run func(ctx context.Context)) *MockSyncClientSettingStore_SyncClientSettingExists_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockSyncClientSettingStore_SyncClientSettingExists_Call) Return(_a0 bool, _a1 error) *MockSyncClientSettingStore_SyncClientSettingExists_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSyncClientSettingStore_SyncClientSettingExists_Call) RunAndReturn(run func(context.Context) (bool, error)) *MockSyncClientSettingStore_SyncClientSettingExists_Call { + _c.Call.Return(run) + return _c +} + +// NewMockSyncClientSettingStore creates a new instance of MockSyncClientSettingStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSyncClientSettingStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSyncClientSettingStore { + mock := &MockSyncClientSettingStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SyncVersionStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SyncVersionStore.go new file mode 100644 index 00000000..c2e791e3 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_SyncVersionStore.go @@ -0,0 +1,252 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" + + types "opencsg.com/csghub-server/common/types" +) + +// MockSyncVersionStore is an autogenerated mock type for the SyncVersionStore type +type MockSyncVersionStore struct { + mock.Mock +} + +type MockSyncVersionStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSyncVersionStore) EXPECT() *MockSyncVersionStore_Expecter { + return &MockSyncVersionStore_Expecter{mock: &_m.Mock} +} + +// BatchCreate provides a mock function with given fields: ctx, versions +func (_m *MockSyncVersionStore) BatchCreate(ctx context.Context, versions []database.SyncVersion) error { + ret := _m.Called(ctx, versions) + + if len(ret) == 0 { + panic("no return value specified for BatchCreate") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []database.SyncVersion) error); ok { + r0 = rf(ctx, versions) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockSyncVersionStore_BatchCreate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchCreate' +type MockSyncVersionStore_BatchCreate_Call struct { + *mock.Call +} + +// BatchCreate is a helper method to define mock.On call +// - ctx context.Context +// - versions []database.SyncVersion +func (_e *MockSyncVersionStore_Expecter) BatchCreate(ctx interface{}, versions interface{}) *MockSyncVersionStore_BatchCreate_Call { + return &MockSyncVersionStore_BatchCreate_Call{Call: _e.mock.On("BatchCreate", ctx, versions)} +} + +func (_c *MockSyncVersionStore_BatchCreate_Call) Run(run func(ctx context.Context, versions []database.SyncVersion)) *MockSyncVersionStore_BatchCreate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]database.SyncVersion)) + }) + return _c +} + +func (_c *MockSyncVersionStore_BatchCreate_Call) Return(_a0 error) *MockSyncVersionStore_BatchCreate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockSyncVersionStore_BatchCreate_Call) RunAndReturn(run func(context.Context, []database.SyncVersion) error) *MockSyncVersionStore_BatchCreate_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, version +func (_m *MockSyncVersionStore) Create(ctx context.Context, version *database.SyncVersion) error { + ret := _m.Called(ctx, version) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.SyncVersion) error); ok { + r0 = rf(ctx, version) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockSyncVersionStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockSyncVersionStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - version *database.SyncVersion +func (_e *MockSyncVersionStore_Expecter) Create(ctx interface{}, version interface{}) *MockSyncVersionStore_Create_Call { + return &MockSyncVersionStore_Create_Call{Call: _e.mock.On("Create", ctx, version)} +} + +func (_c *MockSyncVersionStore_Create_Call) Run(run func(ctx context.Context, version *database.SyncVersion)) *MockSyncVersionStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.SyncVersion)) + }) + return _c +} + +func (_c *MockSyncVersionStore_Create_Call) Return(err error) *MockSyncVersionStore_Create_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockSyncVersionStore_Create_Call) RunAndReturn(run func(context.Context, *database.SyncVersion) error) *MockSyncVersionStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// FindByPath provides a mock function with given fields: ctx, path +func (_m *MockSyncVersionStore) FindByPath(ctx context.Context, path string) (*database.SyncVersion, error) { + ret := _m.Called(ctx, path) + + if len(ret) == 0 { + panic("no return value specified for FindByPath") + } + + var r0 *database.SyncVersion + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (*database.SyncVersion, error)); ok { + return rf(ctx, path) + } + if rf, ok := ret.Get(0).(func(context.Context, string) *database.SyncVersion); ok { + r0 = rf(ctx, path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SyncVersion) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSyncVersionStore_FindByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByPath' +type MockSyncVersionStore_FindByPath_Call struct { + *mock.Call +} + +// FindByPath is a helper method to define mock.On call +// - ctx context.Context +// - path string +func (_e *MockSyncVersionStore_Expecter) FindByPath(ctx interface{}, path interface{}) *MockSyncVersionStore_FindByPath_Call { + return &MockSyncVersionStore_FindByPath_Call{Call: _e.mock.On("FindByPath", ctx, path)} +} + +func (_c *MockSyncVersionStore_FindByPath_Call) Run(run func(ctx context.Context, path string)) *MockSyncVersionStore_FindByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *MockSyncVersionStore_FindByPath_Call) Return(_a0 *database.SyncVersion, _a1 error) *MockSyncVersionStore_FindByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSyncVersionStore_FindByPath_Call) RunAndReturn(run func(context.Context, string) (*database.SyncVersion, error)) *MockSyncVersionStore_FindByPath_Call { + _c.Call.Return(run) + return _c +} + +// FindByRepoTypeAndPath provides a mock function with given fields: ctx, path, repoType +func (_m *MockSyncVersionStore) FindByRepoTypeAndPath(ctx context.Context, path string, repoType types.RepositoryType) (*database.SyncVersion, error) { + ret := _m.Called(ctx, path, repoType) + + if len(ret) == 0 { + panic("no return value specified for FindByRepoTypeAndPath") + } + + var r0 *database.SyncVersion + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, types.RepositoryType) (*database.SyncVersion, error)); ok { + return rf(ctx, path, repoType) + } + if rf, ok := ret.Get(0).(func(context.Context, string, types.RepositoryType) *database.SyncVersion); ok { + r0 = rf(ctx, path, repoType) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.SyncVersion) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, types.RepositoryType) error); ok { + r1 = rf(ctx, path, repoType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSyncVersionStore_FindByRepoTypeAndPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FindByRepoTypeAndPath' +type MockSyncVersionStore_FindByRepoTypeAndPath_Call struct { + *mock.Call +} + +// FindByRepoTypeAndPath is a helper method to define mock.On call +// - ctx context.Context +// - path string +// - repoType types.RepositoryType +func (_e *MockSyncVersionStore_Expecter) FindByRepoTypeAndPath(ctx interface{}, path interface{}, repoType interface{}) *MockSyncVersionStore_FindByRepoTypeAndPath_Call { + return &MockSyncVersionStore_FindByRepoTypeAndPath_Call{Call: _e.mock.On("FindByRepoTypeAndPath", ctx, path, repoType)} +} + +func (_c *MockSyncVersionStore_FindByRepoTypeAndPath_Call) Run(run func(ctx context.Context, path string, repoType types.RepositoryType)) *MockSyncVersionStore_FindByRepoTypeAndPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(types.RepositoryType)) + }) + return _c +} + +func (_c *MockSyncVersionStore_FindByRepoTypeAndPath_Call) Return(_a0 *database.SyncVersion, _a1 error) *MockSyncVersionStore_FindByRepoTypeAndPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSyncVersionStore_FindByRepoTypeAndPath_Call) RunAndReturn(run func(context.Context, string, types.RepositoryType) (*database.SyncVersion, error)) *MockSyncVersionStore_FindByRepoTypeAndPath_Call { + _c.Call.Return(run) + return _c +} + +// NewMockSyncVersionStore creates a new instance of MockSyncVersionStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSyncVersionStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSyncVersionStore { + mock := &MockSyncVersionStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_TagStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_TagStore.go index d5a592d9..862b878d 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_TagStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_TagStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_TelemetryStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_TelemetryStore.go new file mode 100644 index 00000000..0cbec396 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_TelemetryStore.go @@ -0,0 +1,84 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package database + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockTelemetryStore is an autogenerated mock type for the TelemetryStore type +type MockTelemetryStore struct { + mock.Mock +} + +type MockTelemetryStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockTelemetryStore) EXPECT() *MockTelemetryStore_Expecter { + return &MockTelemetryStore_Expecter{mock: &_m.Mock} +} + +// Save provides a mock function with given fields: ctx, telemetry +func (_m *MockTelemetryStore) Save(ctx context.Context, telemetry *database.Telemetry) error { + ret := _m.Called(ctx, telemetry) + + if len(ret) == 0 { + panic("no return value specified for Save") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *database.Telemetry) error); ok { + r0 = rf(ctx, telemetry) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockTelemetryStore_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' +type MockTelemetryStore_Save_Call struct { + *mock.Call +} + +// Save is a helper method to define mock.On call +// - ctx context.Context +// - telemetry *database.Telemetry +func (_e *MockTelemetryStore_Expecter) Save(ctx interface{}, telemetry interface{}) *MockTelemetryStore_Save_Call { + return &MockTelemetryStore_Save_Call{Call: _e.mock.On("Save", ctx, telemetry)} +} + +func (_c *MockTelemetryStore_Save_Call) Run(run func(ctx context.Context, telemetry *database.Telemetry)) *MockTelemetryStore_Save_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Telemetry)) + }) + return _c +} + +func (_c *MockTelemetryStore_Save_Call) Return(_a0 error) *MockTelemetryStore_Save_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockTelemetryStore_Save_Call) RunAndReturn(run func(context.Context, *database.Telemetry) error) *MockTelemetryStore_Save_Call { + _c.Call.Return(run) + return _c +} + +// NewMockTelemetryStore creates a new instance of MockTelemetryStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockTelemetryStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockTelemetryStore { + mock := &MockTelemetryStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserLikesStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserLikesStore.go index 69d933d9..a7d022de 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserLikesStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserLikesStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserStore.go b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserStore.go index 3ef0f7e7..1429dd8c 100644 --- a/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserStore.go +++ b/_mocks/opencsg.com/csghub-server/builder/store/database/mock_UserStore.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package database diff --git a/_mocks/opencsg.com/csghub-server/builder/store/s3/mock_Client.go b/_mocks/opencsg.com/csghub-server/builder/store/s3/mock_Client.go new file mode 100644 index 00000000..5955010a --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/builder/store/s3/mock_Client.go @@ -0,0 +1,335 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package s3 + +import ( + context "context" + io "io" + + minio "github.com/minio/minio-go/v7" + + mock "github.com/stretchr/testify/mock" + + time "time" + + url "net/url" +) + +// MockClient is an autogenerated mock type for the Client type +type MockClient struct { + mock.Mock +} + +type MockClient_Expecter struct { + mock *mock.Mock +} + +func (_m *MockClient) EXPECT() *MockClient_Expecter { + return &MockClient_Expecter{mock: &_m.Mock} +} + +// PresignedGetObject provides a mock function with given fields: ctx, bucketName, objectName, expires, reqParams +func (_m *MockClient) PresignedGetObject(ctx context.Context, bucketName string, objectName string, expires time.Duration, reqParams url.Values) (*url.URL, error) { + ret := _m.Called(ctx, bucketName, objectName, expires, reqParams) + + if len(ret) == 0 { + panic("no return value specified for PresignedGetObject") + } + + var r0 *url.URL + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, time.Duration, url.Values) (*url.URL, error)); ok { + return rf(ctx, bucketName, objectName, expires, reqParams) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, time.Duration, url.Values) *url.URL); ok { + r0 = rf(ctx, bucketName, objectName, expires, reqParams) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*url.URL) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, time.Duration, url.Values) error); ok { + r1 = rf(ctx, bucketName, objectName, expires, reqParams) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockClient_PresignedGetObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PresignedGetObject' +type MockClient_PresignedGetObject_Call struct { + *mock.Call +} + +// PresignedGetObject is a helper method to define mock.On call +// - ctx context.Context +// - bucketName string +// - objectName string +// - expires time.Duration +// - reqParams url.Values +func (_e *MockClient_Expecter) PresignedGetObject(ctx interface{}, bucketName interface{}, objectName interface{}, expires interface{}, reqParams interface{}) *MockClient_PresignedGetObject_Call { + return &MockClient_PresignedGetObject_Call{Call: _e.mock.On("PresignedGetObject", ctx, bucketName, objectName, expires, reqParams)} +} + +func (_c *MockClient_PresignedGetObject_Call) Run(run func(ctx context.Context, bucketName string, objectName string, expires time.Duration, reqParams url.Values)) *MockClient_PresignedGetObject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(time.Duration), args[4].(url.Values)) + }) + return _c +} + +func (_c *MockClient_PresignedGetObject_Call) Return(_a0 *url.URL, _a1 error) *MockClient_PresignedGetObject_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockClient_PresignedGetObject_Call) RunAndReturn(run func(context.Context, string, string, time.Duration, url.Values) (*url.URL, error)) *MockClient_PresignedGetObject_Call { + _c.Call.Return(run) + return _c +} + +// PresignedPutObject provides a mock function with given fields: ctx, bucketName, objectName, expires +func (_m *MockClient) PresignedPutObject(ctx context.Context, bucketName string, objectName string, expires time.Duration) (*url.URL, error) { + ret := _m.Called(ctx, bucketName, objectName, expires) + + if len(ret) == 0 { + panic("no return value specified for PresignedPutObject") + } + + var r0 *url.URL + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, time.Duration) (*url.URL, error)); ok { + return rf(ctx, bucketName, objectName, expires) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, time.Duration) *url.URL); ok { + r0 = rf(ctx, bucketName, objectName, expires) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*url.URL) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, time.Duration) error); ok { + r1 = rf(ctx, bucketName, objectName, expires) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockClient_PresignedPutObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PresignedPutObject' +type MockClient_PresignedPutObject_Call struct { + *mock.Call +} + +// PresignedPutObject is a helper method to define mock.On call +// - ctx context.Context +// - bucketName string +// - objectName string +// - expires time.Duration +func (_e *MockClient_Expecter) PresignedPutObject(ctx interface{}, bucketName interface{}, objectName interface{}, expires interface{}) *MockClient_PresignedPutObject_Call { + return &MockClient_PresignedPutObject_Call{Call: _e.mock.On("PresignedPutObject", ctx, bucketName, objectName, expires)} +} + +func (_c *MockClient_PresignedPutObject_Call) Run(run func(ctx context.Context, bucketName string, objectName string, expires time.Duration)) *MockClient_PresignedPutObject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(time.Duration)) + }) + return _c +} + +func (_c *MockClient_PresignedPutObject_Call) Return(u *url.URL, err error) *MockClient_PresignedPutObject_Call { + _c.Call.Return(u, err) + return _c +} + +func (_c *MockClient_PresignedPutObject_Call) RunAndReturn(run func(context.Context, string, string, time.Duration) (*url.URL, error)) *MockClient_PresignedPutObject_Call { + _c.Call.Return(run) + return _c +} + +// PutObject provides a mock function with given fields: ctx, bucketName, objectName, reader, objectSize, opts +func (_m *MockClient) PutObject(ctx context.Context, bucketName string, objectName string, reader io.Reader, objectSize int64, opts minio.PutObjectOptions) (minio.UploadInfo, error) { + ret := _m.Called(ctx, bucketName, objectName, reader, objectSize, opts) + + if len(ret) == 0 { + panic("no return value specified for PutObject") + } + + var r0 minio.UploadInfo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, io.Reader, int64, minio.PutObjectOptions) (minio.UploadInfo, error)); ok { + return rf(ctx, bucketName, objectName, reader, objectSize, opts) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, io.Reader, int64, minio.PutObjectOptions) minio.UploadInfo); ok { + r0 = rf(ctx, bucketName, objectName, reader, objectSize, opts) + } else { + r0 = ret.Get(0).(minio.UploadInfo) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, io.Reader, int64, minio.PutObjectOptions) error); ok { + r1 = rf(ctx, bucketName, objectName, reader, objectSize, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockClient_PutObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PutObject' +type MockClient_PutObject_Call struct { + *mock.Call +} + +// PutObject is a helper method to define mock.On call +// - ctx context.Context +// - bucketName string +// - objectName string +// - reader io.Reader +// - objectSize int64 +// - opts minio.PutObjectOptions +func (_e *MockClient_Expecter) PutObject(ctx interface{}, bucketName interface{}, objectName interface{}, reader interface{}, objectSize interface{}, opts interface{}) *MockClient_PutObject_Call { + return &MockClient_PutObject_Call{Call: _e.mock.On("PutObject", ctx, bucketName, objectName, reader, objectSize, opts)} +} + +func (_c *MockClient_PutObject_Call) Run(run func(ctx context.Context, bucketName string, objectName string, reader io.Reader, objectSize int64, opts minio.PutObjectOptions)) *MockClient_PutObject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(io.Reader), args[4].(int64), args[5].(minio.PutObjectOptions)) + }) + return _c +} + +func (_c *MockClient_PutObject_Call) Return(info minio.UploadInfo, err error) *MockClient_PutObject_Call { + _c.Call.Return(info, err) + return _c +} + +func (_c *MockClient_PutObject_Call) RunAndReturn(run func(context.Context, string, string, io.Reader, int64, minio.PutObjectOptions) (minio.UploadInfo, error)) *MockClient_PutObject_Call { + _c.Call.Return(run) + return _c +} + +// RemoveObject provides a mock function with given fields: ctx, bucketName, objectName, opts +func (_m *MockClient) RemoveObject(ctx context.Context, bucketName string, objectName string, opts minio.RemoveObjectOptions) error { + ret := _m.Called(ctx, bucketName, objectName, opts) + + if len(ret) == 0 { + panic("no return value specified for RemoveObject") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, minio.RemoveObjectOptions) error); ok { + r0 = rf(ctx, bucketName, objectName, opts) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockClient_RemoveObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveObject' +type MockClient_RemoveObject_Call struct { + *mock.Call +} + +// RemoveObject is a helper method to define mock.On call +// - ctx context.Context +// - bucketName string +// - objectName string +// - opts minio.RemoveObjectOptions +func (_e *MockClient_Expecter) RemoveObject(ctx interface{}, bucketName interface{}, objectName interface{}, opts interface{}) *MockClient_RemoveObject_Call { + return &MockClient_RemoveObject_Call{Call: _e.mock.On("RemoveObject", ctx, bucketName, objectName, opts)} +} + +func (_c *MockClient_RemoveObject_Call) Run(run func(ctx context.Context, bucketName string, objectName string, opts minio.RemoveObjectOptions)) *MockClient_RemoveObject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(minio.RemoveObjectOptions)) + }) + return _c +} + +func (_c *MockClient_RemoveObject_Call) Return(_a0 error) *MockClient_RemoveObject_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockClient_RemoveObject_Call) RunAndReturn(run func(context.Context, string, string, minio.RemoveObjectOptions) error) *MockClient_RemoveObject_Call { + _c.Call.Return(run) + return _c +} + +// StatObject provides a mock function with given fields: ctx, bucketName, objectName, opts +func (_m *MockClient) StatObject(ctx context.Context, bucketName string, objectName string, opts minio.StatObjectOptions) (minio.ObjectInfo, error) { + ret := _m.Called(ctx, bucketName, objectName, opts) + + if len(ret) == 0 { + panic("no return value specified for StatObject") + } + + var r0 minio.ObjectInfo + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, minio.StatObjectOptions) (minio.ObjectInfo, error)); ok { + return rf(ctx, bucketName, objectName, opts) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, minio.StatObjectOptions) minio.ObjectInfo); ok { + r0 = rf(ctx, bucketName, objectName, opts) + } else { + r0 = ret.Get(0).(minio.ObjectInfo) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, minio.StatObjectOptions) error); ok { + r1 = rf(ctx, bucketName, objectName, opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockClient_StatObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'StatObject' +type MockClient_StatObject_Call struct { + *mock.Call +} + +// StatObject is a helper method to define mock.On call +// - ctx context.Context +// - bucketName string +// - objectName string +// - opts minio.StatObjectOptions +func (_e *MockClient_Expecter) StatObject(ctx interface{}, bucketName interface{}, objectName interface{}, opts interface{}) *MockClient_StatObject_Call { + return &MockClient_StatObject_Call{Call: _e.mock.On("StatObject", ctx, bucketName, objectName, opts)} +} + +func (_c *MockClient_StatObject_Call) Run(run func(ctx context.Context, bucketName string, objectName string, opts minio.StatObjectOptions)) *MockClient_StatObject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(minio.StatObjectOptions)) + }) + return _c +} + +func (_c *MockClient_StatObject_Call) Return(_a0 minio.ObjectInfo, _a1 error) *MockClient_StatObject_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockClient_StatObject_Call) RunAndReturn(run func(context.Context, string, string, minio.StatObjectOptions) (minio.ObjectInfo, error)) *MockClient_StatObject_Call { + _c.Call.Return(run) + return _c +} + +// NewMockClient creates a new instance of MockClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockClient(t interface { + mock.TestingT + Cleanup(func()) +}) *MockClient { + mock := &MockClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/common/types/mock_SensitiveRequestV2.go b/_mocks/opencsg.com/csghub-server/common/types/mock_SensitiveRequestV2.go new file mode 100644 index 00000000..62d93f40 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/common/types/mock_SensitiveRequestV2.go @@ -0,0 +1,82 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package types + +import ( + mock "github.com/stretchr/testify/mock" + types "opencsg.com/csghub-server/common/types" +) + +// MockSensitiveRequestV2 is an autogenerated mock type for the SensitiveRequestV2 type +type MockSensitiveRequestV2 struct { + mock.Mock +} + +type MockSensitiveRequestV2_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSensitiveRequestV2) EXPECT() *MockSensitiveRequestV2_Expecter { + return &MockSensitiveRequestV2_Expecter{mock: &_m.Mock} +} + +// GetSensitiveFields provides a mock function with given fields: +func (_m *MockSensitiveRequestV2) GetSensitiveFields() []types.SensitiveField { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetSensitiveFields") + } + + var r0 []types.SensitiveField + if rf, ok := ret.Get(0).(func() []types.SensitiveField); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.SensitiveField) + } + } + + return r0 +} + +// MockSensitiveRequestV2_GetSensitiveFields_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSensitiveFields' +type MockSensitiveRequestV2_GetSensitiveFields_Call struct { + *mock.Call +} + +// GetSensitiveFields is a helper method to define mock.On call +func (_e *MockSensitiveRequestV2_Expecter) GetSensitiveFields() *MockSensitiveRequestV2_GetSensitiveFields_Call { + return &MockSensitiveRequestV2_GetSensitiveFields_Call{Call: _e.mock.On("GetSensitiveFields")} +} + +func (_c *MockSensitiveRequestV2_GetSensitiveFields_Call) Run(run func()) *MockSensitiveRequestV2_GetSensitiveFields_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockSensitiveRequestV2_GetSensitiveFields_Call) Return(_a0 []types.SensitiveField) *MockSensitiveRequestV2_GetSensitiveFields_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockSensitiveRequestV2_GetSensitiveFields_Call) RunAndReturn(run func() []types.SensitiveField) *MockSensitiveRequestV2_GetSensitiveFields_Call { + _c.Call.Return(run) + return _c +} + +// NewMockSensitiveRequestV2 creates a new instance of MockSensitiveRequestV2. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSensitiveRequestV2(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSensitiveRequestV2 { + mock := &MockSensitiveRequestV2{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/component/mock_AccountingComponent.go b/_mocks/opencsg.com/csghub-server/component/mock_AccountingComponent.go new file mode 100644 index 00000000..ab2dc196 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/component/mock_AccountingComponent.go @@ -0,0 +1,96 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package component + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + types "opencsg.com/csghub-server/common/types" +) + +// MockAccountingComponent is an autogenerated mock type for the AccountingComponent type +type MockAccountingComponent struct { + mock.Mock +} + +type MockAccountingComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *MockAccountingComponent) EXPECT() *MockAccountingComponent_Expecter { + return &MockAccountingComponent_Expecter{mock: &_m.Mock} +} + +// ListMeteringsByUserIDAndTime provides a mock function with given fields: ctx, req +func (_m *MockAccountingComponent) ListMeteringsByUserIDAndTime(ctx context.Context, req types.ACCT_STATEMENTS_REQ) (interface{}, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for ListMeteringsByUserIDAndTime") + } + + var r0 interface{} + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.ACCT_STATEMENTS_REQ) (interface{}, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.ACCT_STATEMENTS_REQ) interface{}); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(interface{}) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.ACCT_STATEMENTS_REQ) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockAccountingComponent_ListMeteringsByUserIDAndTime_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListMeteringsByUserIDAndTime' +type MockAccountingComponent_ListMeteringsByUserIDAndTime_Call struct { + *mock.Call +} + +// ListMeteringsByUserIDAndTime is a helper method to define mock.On call +// - ctx context.Context +// - req types.ACCT_STATEMENTS_REQ +func (_e *MockAccountingComponent_Expecter) ListMeteringsByUserIDAndTime(ctx interface{}, req interface{}) *MockAccountingComponent_ListMeteringsByUserIDAndTime_Call { + return &MockAccountingComponent_ListMeteringsByUserIDAndTime_Call{Call: _e.mock.On("ListMeteringsByUserIDAndTime", ctx, req)} +} + +func (_c *MockAccountingComponent_ListMeteringsByUserIDAndTime_Call) Run(run func(ctx context.Context, req types.ACCT_STATEMENTS_REQ)) *MockAccountingComponent_ListMeteringsByUserIDAndTime_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.ACCT_STATEMENTS_REQ)) + }) + return _c +} + +func (_c *MockAccountingComponent_ListMeteringsByUserIDAndTime_Call) Return(_a0 interface{}, _a1 error) *MockAccountingComponent_ListMeteringsByUserIDAndTime_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockAccountingComponent_ListMeteringsByUserIDAndTime_Call) RunAndReturn(run func(context.Context, types.ACCT_STATEMENTS_REQ) (interface{}, error)) *MockAccountingComponent_ListMeteringsByUserIDAndTime_Call { + _c.Call.Return(run) + return _c +} + +// NewMockAccountingComponent creates a new instance of MockAccountingComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockAccountingComponent(t interface { + mock.TestingT + Cleanup(func()) +}) *MockAccountingComponent { + mock := &MockAccountingComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/component/mock_RepoComponent.go b/_mocks/opencsg.com/csghub-server/component/mock_RepoComponent.go index 11296f06..1dc8413e 100644 --- a/_mocks/opencsg.com/csghub-server/component/mock_RepoComponent.go +++ b/_mocks/opencsg.com/csghub-server/component/mock_RepoComponent.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package component @@ -1779,6 +1779,63 @@ func (_c *MockRepoComponent_FileRaw_Call) RunAndReturn(run func(context.Context, return _c } +// GenerateEndpoint provides a mock function with given fields: ctx, _a1 +func (_m *MockRepoComponent) GenerateEndpoint(ctx context.Context, _a1 *database.Deploy) (string, string) { + ret := _m.Called(ctx, _a1) + + if len(ret) == 0 { + panic("no return value specified for GenerateEndpoint") + } + + var r0 string + var r1 string + if rf, ok := ret.Get(0).(func(context.Context, *database.Deploy) (string, string)); ok { + return rf(ctx, _a1) + } + if rf, ok := ret.Get(0).(func(context.Context, *database.Deploy) string); ok { + r0 = rf(ctx, _a1) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, *database.Deploy) string); ok { + r1 = rf(ctx, _a1) + } else { + r1 = ret.Get(1).(string) + } + + return r0, r1 +} + +// MockRepoComponent_GenerateEndpoint_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GenerateEndpoint' +type MockRepoComponent_GenerateEndpoint_Call struct { + *mock.Call +} + +// GenerateEndpoint is a helper method to define mock.On call +// - ctx context.Context +// - _a1 *database.Deploy +func (_e *MockRepoComponent_Expecter) GenerateEndpoint(ctx interface{}, _a1 interface{}) *MockRepoComponent_GenerateEndpoint_Call { + return &MockRepoComponent_GenerateEndpoint_Call{Call: _e.mock.On("GenerateEndpoint", ctx, _a1)} +} + +func (_c *MockRepoComponent_GenerateEndpoint_Call) Run(run func(ctx context.Context, _a1 *database.Deploy)) *MockRepoComponent_GenerateEndpoint_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Deploy)) + }) + return _c +} + +func (_c *MockRepoComponent_GenerateEndpoint_Call) Return(_a0 string, _a1 string) *MockRepoComponent_GenerateEndpoint_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_GenerateEndpoint_Call) RunAndReturn(run func(context.Context, *database.Deploy) (string, string)) *MockRepoComponent_GenerateEndpoint_Call { + _c.Call.Return(run) + return _c +} + // GetCommitWithDiff provides a mock function with given fields: ctx, req func (_m *MockRepoComponent) GetCommitWithDiff(ctx context.Context, req *types.GetCommitsReq) (*types.CommitResponse, error) { ret := _m.Called(ctx, req) @@ -2184,6 +2241,52 @@ func (_c *MockRepoComponent_IncrDownloads_Call) RunAndReturn(run func(context.Co return _c } +// IsAdminRole provides a mock function with given fields: user +func (_m *MockRepoComponent) IsAdminRole(user database.User) bool { + ret := _m.Called(user) + + if len(ret) == 0 { + panic("no return value specified for IsAdminRole") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(database.User) bool); ok { + r0 = rf(user) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// MockRepoComponent_IsAdminRole_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsAdminRole' +type MockRepoComponent_IsAdminRole_Call struct { + *mock.Call +} + +// IsAdminRole is a helper method to define mock.On call +// - user database.User +func (_e *MockRepoComponent_Expecter) IsAdminRole(user interface{}) *MockRepoComponent_IsAdminRole_Call { + return &MockRepoComponent_IsAdminRole_Call{Call: _e.mock.On("IsAdminRole", user)} +} + +func (_c *MockRepoComponent_IsAdminRole_Call) Run(run func(user database.User)) *MockRepoComponent_IsAdminRole_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(database.User)) + }) + return _c +} + +func (_c *MockRepoComponent_IsAdminRole_Call) Return(_a0 bool) *MockRepoComponent_IsAdminRole_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRepoComponent_IsAdminRole_Call) RunAndReturn(run func(database.User) bool) *MockRepoComponent_IsAdminRole_Call { + _c.Call.Return(run) + return _c +} + // IsLfs provides a mock function with given fields: ctx, req func (_m *MockRepoComponent) IsLfs(ctx context.Context, req *types.GetFileReq) (bool, int64, error) { ret := _m.Called(ctx, req) @@ -3358,6 +3461,66 @@ func (_c *MockRepoComponent_UploadFile_Call) RunAndReturn(run func(context.Conte return _c } +// VisiableToUser provides a mock function with given fields: ctx, repos, currentUser +func (_m *MockRepoComponent) VisiableToUser(ctx context.Context, repos []*database.Repository, currentUser string) ([]*database.Repository, error) { + ret := _m.Called(ctx, repos, currentUser) + + if len(ret) == 0 { + panic("no return value specified for VisiableToUser") + } + + var r0 []*database.Repository + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []*database.Repository, string) ([]*database.Repository, error)); ok { + return rf(ctx, repos, currentUser) + } + if rf, ok := ret.Get(0).(func(context.Context, []*database.Repository, string) []*database.Repository); ok { + r0 = rf(ctx, repos, currentUser) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.Repository) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []*database.Repository, string) error); ok { + r1 = rf(ctx, repos, currentUser) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRepoComponent_VisiableToUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VisiableToUser' +type MockRepoComponent_VisiableToUser_Call struct { + *mock.Call +} + +// VisiableToUser is a helper method to define mock.On call +// - ctx context.Context +// - repos []*database.Repository +// - currentUser string +func (_e *MockRepoComponent_Expecter) VisiableToUser(ctx interface{}, repos interface{}, currentUser interface{}) *MockRepoComponent_VisiableToUser_Call { + return &MockRepoComponent_VisiableToUser_Call{Call: _e.mock.On("VisiableToUser", ctx, repos, currentUser)} +} + +func (_c *MockRepoComponent_VisiableToUser_Call) Run(run func(ctx context.Context, repos []*database.Repository, currentUser string)) *MockRepoComponent_VisiableToUser_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]*database.Repository), args[2].(string)) + }) + return _c +} + +func (_c *MockRepoComponent_VisiableToUser_Call) Return(_a0 []*database.Repository, _a1 error) *MockRepoComponent_VisiableToUser_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRepoComponent_VisiableToUser_Call) RunAndReturn(run func(context.Context, []*database.Repository, string) ([]*database.Repository, error)) *MockRepoComponent_VisiableToUser_Call { + _c.Call.Return(run) + return _c +} + // NewMockRepoComponent creates a new instance of MockRepoComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewMockRepoComponent(t interface { diff --git a/_mocks/opencsg.com/csghub-server/component/mock_RuntimeArchitectureComponent.go b/_mocks/opencsg.com/csghub-server/component/mock_RuntimeArchitectureComponent.go new file mode 100644 index 00000000..41eff85e --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/component/mock_RuntimeArchitectureComponent.go @@ -0,0 +1,516 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package component + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" +) + +// MockRuntimeArchitectureComponent is an autogenerated mock type for the RuntimeArchitectureComponent type +type MockRuntimeArchitectureComponent struct { + mock.Mock +} + +type MockRuntimeArchitectureComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRuntimeArchitectureComponent) EXPECT() *MockRuntimeArchitectureComponent_Expecter { + return &MockRuntimeArchitectureComponent_Expecter{mock: &_m.Mock} +} + +// AddResourceTag provides a mock function with given fields: ctx, rstags, modelname, repoId +func (_m *MockRuntimeArchitectureComponent) AddResourceTag(ctx context.Context, rstags []*database.Tag, modelname string, repoId int64) error { + ret := _m.Called(ctx, rstags, modelname, repoId) + + if len(ret) == 0 { + panic("no return value specified for AddResourceTag") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []*database.Tag, string, int64) error); ok { + r0 = rf(ctx, rstags, modelname, repoId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntimeArchitectureComponent_AddResourceTag_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddResourceTag' +type MockRuntimeArchitectureComponent_AddResourceTag_Call struct { + *mock.Call +} + +// AddResourceTag is a helper method to define mock.On call +// - ctx context.Context +// - rstags []*database.Tag +// - modelname string +// - repoId int64 +func (_e *MockRuntimeArchitectureComponent_Expecter) AddResourceTag(ctx interface{}, rstags interface{}, modelname interface{}, repoId interface{}) *MockRuntimeArchitectureComponent_AddResourceTag_Call { + return &MockRuntimeArchitectureComponent_AddResourceTag_Call{Call: _e.mock.On("AddResourceTag", ctx, rstags, modelname, repoId)} +} + +func (_c *MockRuntimeArchitectureComponent_AddResourceTag_Call) Run(run func(ctx context.Context, rstags []*database.Tag, modelname string, repoId int64)) *MockRuntimeArchitectureComponent_AddResourceTag_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]*database.Tag), args[2].(string), args[3].(int64)) + }) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_AddResourceTag_Call) Return(_a0 error) *MockRuntimeArchitectureComponent_AddResourceTag_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_AddResourceTag_Call) RunAndReturn(run func(context.Context, []*database.Tag, string, int64) error) *MockRuntimeArchitectureComponent_AddResourceTag_Call { + _c.Call.Return(run) + return _c +} + +// AddRuntimeFrameworkTag provides a mock function with given fields: ctx, rftags, repoId, rfId +func (_m *MockRuntimeArchitectureComponent) AddRuntimeFrameworkTag(ctx context.Context, rftags []*database.Tag, repoId int64, rfId int64) error { + ret := _m.Called(ctx, rftags, repoId, rfId) + + if len(ret) == 0 { + panic("no return value specified for AddRuntimeFrameworkTag") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []*database.Tag, int64, int64) error); ok { + r0 = rf(ctx, rftags, repoId, rfId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntimeArchitectureComponent_AddRuntimeFrameworkTag_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddRuntimeFrameworkTag' +type MockRuntimeArchitectureComponent_AddRuntimeFrameworkTag_Call struct { + *mock.Call +} + +// AddRuntimeFrameworkTag is a helper method to define mock.On call +// - ctx context.Context +// - rftags []*database.Tag +// - repoId int64 +// - rfId int64 +func (_e *MockRuntimeArchitectureComponent_Expecter) AddRuntimeFrameworkTag(ctx interface{}, rftags interface{}, repoId interface{}, rfId interface{}) *MockRuntimeArchitectureComponent_AddRuntimeFrameworkTag_Call { + return &MockRuntimeArchitectureComponent_AddRuntimeFrameworkTag_Call{Call: _e.mock.On("AddRuntimeFrameworkTag", ctx, rftags, repoId, rfId)} +} + +func (_c *MockRuntimeArchitectureComponent_AddRuntimeFrameworkTag_Call) Run(run func(ctx context.Context, rftags []*database.Tag, repoId int64, rfId int64)) *MockRuntimeArchitectureComponent_AddRuntimeFrameworkTag_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]*database.Tag), args[2].(int64), args[3].(int64)) + }) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_AddRuntimeFrameworkTag_Call) Return(_a0 error) *MockRuntimeArchitectureComponent_AddRuntimeFrameworkTag_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_AddRuntimeFrameworkTag_Call) RunAndReturn(run func(context.Context, []*database.Tag, int64, int64) error) *MockRuntimeArchitectureComponent_AddRuntimeFrameworkTag_Call { + _c.Call.Return(run) + return _c +} + +// DeleteArchitectures provides a mock function with given fields: ctx, id, architectures +func (_m *MockRuntimeArchitectureComponent) DeleteArchitectures(ctx context.Context, id int64, architectures []string) ([]string, error) { + ret := _m.Called(ctx, id, architectures) + + if len(ret) == 0 { + panic("no return value specified for DeleteArchitectures") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, []string) ([]string, error)); ok { + return rf(ctx, id, architectures) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, []string) []string); ok { + r0 = rf(ctx, id, architectures) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, []string) error); ok { + r1 = rf(ctx, id, architectures) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeArchitectureComponent_DeleteArchitectures_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteArchitectures' +type MockRuntimeArchitectureComponent_DeleteArchitectures_Call struct { + *mock.Call +} + +// DeleteArchitectures is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +// - architectures []string +func (_e *MockRuntimeArchitectureComponent_Expecter) DeleteArchitectures(ctx interface{}, id interface{}, architectures interface{}) *MockRuntimeArchitectureComponent_DeleteArchitectures_Call { + return &MockRuntimeArchitectureComponent_DeleteArchitectures_Call{Call: _e.mock.On("DeleteArchitectures", ctx, id, architectures)} +} + +func (_c *MockRuntimeArchitectureComponent_DeleteArchitectures_Call) Run(run func(ctx context.Context, id int64, architectures []string)) *MockRuntimeArchitectureComponent_DeleteArchitectures_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].([]string)) + }) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_DeleteArchitectures_Call) Return(_a0 []string, _a1 error) *MockRuntimeArchitectureComponent_DeleteArchitectures_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_DeleteArchitectures_Call) RunAndReturn(run func(context.Context, int64, []string) ([]string, error)) *MockRuntimeArchitectureComponent_DeleteArchitectures_Call { + _c.Call.Return(run) + return _c +} + +// GetArchitectureFromConfig provides a mock function with given fields: ctx, namespace, name +func (_m *MockRuntimeArchitectureComponent) GetArchitectureFromConfig(ctx context.Context, namespace string, name string) (string, error) { + ret := _m.Called(ctx, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for GetArchitectureFromConfig") + } + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (string, error)); ok { + return rf(ctx, namespace, name) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) string); ok { + r0 = rf(ctx, namespace, name) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, namespace, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeArchitectureComponent_GetArchitectureFromConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetArchitectureFromConfig' +type MockRuntimeArchitectureComponent_GetArchitectureFromConfig_Call struct { + *mock.Call +} + +// GetArchitectureFromConfig is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +func (_e *MockRuntimeArchitectureComponent_Expecter) GetArchitectureFromConfig(ctx interface{}, namespace interface{}, name interface{}) *MockRuntimeArchitectureComponent_GetArchitectureFromConfig_Call { + return &MockRuntimeArchitectureComponent_GetArchitectureFromConfig_Call{Call: _e.mock.On("GetArchitectureFromConfig", ctx, namespace, name)} +} + +func (_c *MockRuntimeArchitectureComponent_GetArchitectureFromConfig_Call) Run(run func(ctx context.Context, namespace string, name string)) *MockRuntimeArchitectureComponent_GetArchitectureFromConfig_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_GetArchitectureFromConfig_Call) Return(_a0 string, _a1 error) *MockRuntimeArchitectureComponent_GetArchitectureFromConfig_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_GetArchitectureFromConfig_Call) RunAndReturn(run func(context.Context, string, string) (string, error)) *MockRuntimeArchitectureComponent_GetArchitectureFromConfig_Call { + _c.Call.Return(run) + return _c +} + +// IsSupportedModelResource provides a mock function with given fields: ctx, modelName, rfm, id +func (_m *MockRuntimeArchitectureComponent) IsSupportedModelResource(ctx context.Context, modelName string, rfm *database.RuntimeFramework, id int64) (bool, error) { + ret := _m.Called(ctx, modelName, rfm, id) + + if len(ret) == 0 { + panic("no return value specified for IsSupportedModelResource") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, *database.RuntimeFramework, int64) (bool, error)); ok { + return rf(ctx, modelName, rfm, id) + } + if rf, ok := ret.Get(0).(func(context.Context, string, *database.RuntimeFramework, int64) bool); ok { + r0 = rf(ctx, modelName, rfm, id) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, *database.RuntimeFramework, int64) error); ok { + r1 = rf(ctx, modelName, rfm, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeArchitectureComponent_IsSupportedModelResource_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsSupportedModelResource' +type MockRuntimeArchitectureComponent_IsSupportedModelResource_Call struct { + *mock.Call +} + +// IsSupportedModelResource is a helper method to define mock.On call +// - ctx context.Context +// - modelName string +// - rfm *database.RuntimeFramework +// - id int64 +func (_e *MockRuntimeArchitectureComponent_Expecter) IsSupportedModelResource(ctx interface{}, modelName interface{}, rfm interface{}, id interface{}) *MockRuntimeArchitectureComponent_IsSupportedModelResource_Call { + return &MockRuntimeArchitectureComponent_IsSupportedModelResource_Call{Call: _e.mock.On("IsSupportedModelResource", ctx, modelName, rfm, id)} +} + +func (_c *MockRuntimeArchitectureComponent_IsSupportedModelResource_Call) Run(run func(ctx context.Context, modelName string, rfm *database.RuntimeFramework, id int64)) *MockRuntimeArchitectureComponent_IsSupportedModelResource_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(*database.RuntimeFramework), args[3].(int64)) + }) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_IsSupportedModelResource_Call) Return(_a0 bool, _a1 error) *MockRuntimeArchitectureComponent_IsSupportedModelResource_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_IsSupportedModelResource_Call) RunAndReturn(run func(context.Context, string, *database.RuntimeFramework, int64) (bool, error)) *MockRuntimeArchitectureComponent_IsSupportedModelResource_Call { + _c.Call.Return(run) + return _c +} + +// ListByRuntimeFrameworkID provides a mock function with given fields: ctx, id +func (_m *MockRuntimeArchitectureComponent) ListByRuntimeFrameworkID(ctx context.Context, id int64) ([]database.RuntimeArchitecture, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for ListByRuntimeFrameworkID") + } + + var r0 []database.RuntimeArchitecture + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64) ([]database.RuntimeArchitecture, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) []database.RuntimeArchitecture); ok { + r0 = rf(ctx, id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.RuntimeArchitecture) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeArchitectureComponent_ListByRuntimeFrameworkID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByRuntimeFrameworkID' +type MockRuntimeArchitectureComponent_ListByRuntimeFrameworkID_Call struct { + *mock.Call +} + +// ListByRuntimeFrameworkID is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +func (_e *MockRuntimeArchitectureComponent_Expecter) ListByRuntimeFrameworkID(ctx interface{}, id interface{}) *MockRuntimeArchitectureComponent_ListByRuntimeFrameworkID_Call { + return &MockRuntimeArchitectureComponent_ListByRuntimeFrameworkID_Call{Call: _e.mock.On("ListByRuntimeFrameworkID", ctx, id)} +} + +func (_c *MockRuntimeArchitectureComponent_ListByRuntimeFrameworkID_Call) Run(run func(ctx context.Context, id int64)) *MockRuntimeArchitectureComponent_ListByRuntimeFrameworkID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64)) + }) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_ListByRuntimeFrameworkID_Call) Return(_a0 []database.RuntimeArchitecture, _a1 error) *MockRuntimeArchitectureComponent_ListByRuntimeFrameworkID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_ListByRuntimeFrameworkID_Call) RunAndReturn(run func(context.Context, int64) ([]database.RuntimeArchitecture, error)) *MockRuntimeArchitectureComponent_ListByRuntimeFrameworkID_Call { + _c.Call.Return(run) + return _c +} + +// RemoveRuntimeFrameworkTag provides a mock function with given fields: ctx, rftags, repoId, rfId +func (_m *MockRuntimeArchitectureComponent) RemoveRuntimeFrameworkTag(ctx context.Context, rftags []*database.Tag, repoId int64, rfId int64) { + _m.Called(ctx, rftags, repoId, rfId) +} + +// MockRuntimeArchitectureComponent_RemoveRuntimeFrameworkTag_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveRuntimeFrameworkTag' +type MockRuntimeArchitectureComponent_RemoveRuntimeFrameworkTag_Call struct { + *mock.Call +} + +// RemoveRuntimeFrameworkTag is a helper method to define mock.On call +// - ctx context.Context +// - rftags []*database.Tag +// - repoId int64 +// - rfId int64 +func (_e *MockRuntimeArchitectureComponent_Expecter) RemoveRuntimeFrameworkTag(ctx interface{}, rftags interface{}, repoId interface{}, rfId interface{}) *MockRuntimeArchitectureComponent_RemoveRuntimeFrameworkTag_Call { + return &MockRuntimeArchitectureComponent_RemoveRuntimeFrameworkTag_Call{Call: _e.mock.On("RemoveRuntimeFrameworkTag", ctx, rftags, repoId, rfId)} +} + +func (_c *MockRuntimeArchitectureComponent_RemoveRuntimeFrameworkTag_Call) Run(run func(ctx context.Context, rftags []*database.Tag, repoId int64, rfId int64)) *MockRuntimeArchitectureComponent_RemoveRuntimeFrameworkTag_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]*database.Tag), args[2].(int64), args[3].(int64)) + }) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_RemoveRuntimeFrameworkTag_Call) Return() *MockRuntimeArchitectureComponent_RemoveRuntimeFrameworkTag_Call { + _c.Call.Return() + return _c +} + +func (_c *MockRuntimeArchitectureComponent_RemoveRuntimeFrameworkTag_Call) RunAndReturn(run func(context.Context, []*database.Tag, int64, int64)) *MockRuntimeArchitectureComponent_RemoveRuntimeFrameworkTag_Call { + _c.Call.Return(run) + return _c +} + +// ScanArchitecture provides a mock function with given fields: ctx, id, scanType, models +func (_m *MockRuntimeArchitectureComponent) ScanArchitecture(ctx context.Context, id int64, scanType int, models []string) error { + ret := _m.Called(ctx, id, scanType, models) + + if len(ret) == 0 { + panic("no return value specified for ScanArchitecture") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, int64, int, []string) error); ok { + r0 = rf(ctx, id, scanType, models) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockRuntimeArchitectureComponent_ScanArchitecture_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ScanArchitecture' +type MockRuntimeArchitectureComponent_ScanArchitecture_Call struct { + *mock.Call +} + +// ScanArchitecture is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +// - scanType int +// - models []string +func (_e *MockRuntimeArchitectureComponent_Expecter) ScanArchitecture(ctx interface{}, id interface{}, scanType interface{}, models interface{}) *MockRuntimeArchitectureComponent_ScanArchitecture_Call { + return &MockRuntimeArchitectureComponent_ScanArchitecture_Call{Call: _e.mock.On("ScanArchitecture", ctx, id, scanType, models)} +} + +func (_c *MockRuntimeArchitectureComponent_ScanArchitecture_Call) Run(run func(ctx context.Context, id int64, scanType int, models []string)) *MockRuntimeArchitectureComponent_ScanArchitecture_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(int), args[3].([]string)) + }) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_ScanArchitecture_Call) Return(_a0 error) *MockRuntimeArchitectureComponent_ScanArchitecture_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_ScanArchitecture_Call) RunAndReturn(run func(context.Context, int64, int, []string) error) *MockRuntimeArchitectureComponent_ScanArchitecture_Call { + _c.Call.Return(run) + return _c +} + +// SetArchitectures provides a mock function with given fields: ctx, id, architectures +func (_m *MockRuntimeArchitectureComponent) SetArchitectures(ctx context.Context, id int64, architectures []string) ([]string, error) { + ret := _m.Called(ctx, id, architectures) + + if len(ret) == 0 { + panic("no return value specified for SetArchitectures") + } + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, []string) ([]string, error)); ok { + return rf(ctx, id, architectures) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, []string) []string); ok { + r0 = rf(ctx, id, architectures) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, []string) error); ok { + r1 = rf(ctx, id, architectures) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockRuntimeArchitectureComponent_SetArchitectures_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetArchitectures' +type MockRuntimeArchitectureComponent_SetArchitectures_Call struct { + *mock.Call +} + +// SetArchitectures is a helper method to define mock.On call +// - ctx context.Context +// - id int64 +// - architectures []string +func (_e *MockRuntimeArchitectureComponent_Expecter) SetArchitectures(ctx interface{}, id interface{}, architectures interface{}) *MockRuntimeArchitectureComponent_SetArchitectures_Call { + return &MockRuntimeArchitectureComponent_SetArchitectures_Call{Call: _e.mock.On("SetArchitectures", ctx, id, architectures)} +} + +func (_c *MockRuntimeArchitectureComponent_SetArchitectures_Call) Run(run func(ctx context.Context, id int64, architectures []string)) *MockRuntimeArchitectureComponent_SetArchitectures_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].([]string)) + }) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_SetArchitectures_Call) Return(_a0 []string, _a1 error) *MockRuntimeArchitectureComponent_SetArchitectures_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockRuntimeArchitectureComponent_SetArchitectures_Call) RunAndReturn(run func(context.Context, int64, []string) ([]string, error)) *MockRuntimeArchitectureComponent_SetArchitectures_Call { + _c.Call.Return(run) + return _c +} + +// NewMockRuntimeArchitectureComponent creates a new instance of MockRuntimeArchitectureComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRuntimeArchitectureComponent(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRuntimeArchitectureComponent { + mock := &MockRuntimeArchitectureComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/component/mock_SpaceComponent.go b/_mocks/opencsg.com/csghub-server/component/mock_SpaceComponent.go new file mode 100644 index 00000000..026277cb --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/component/mock_SpaceComponent.go @@ -0,0 +1,1029 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package component + +import ( + context "context" + + deploy "opencsg.com/csghub-server/builder/deploy" + database "opencsg.com/csghub-server/builder/store/database" + + mock "github.com/stretchr/testify/mock" + + types "opencsg.com/csghub-server/common/types" +) + +// MockSpaceComponent is an autogenerated mock type for the SpaceComponent type +type MockSpaceComponent struct { + mock.Mock +} + +type MockSpaceComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSpaceComponent) EXPECT() *MockSpaceComponent_Expecter { + return &MockSpaceComponent_Expecter{mock: &_m.Mock} +} + +// AllowCallApi provides a mock function with given fields: ctx, spaceID, username +func (_m *MockSpaceComponent) AllowCallApi(ctx context.Context, spaceID int64, username string) (bool, error) { + ret := _m.Called(ctx, spaceID, username) + + if len(ret) == 0 { + panic("no return value specified for AllowCallApi") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, int64, string) (bool, error)); ok { + return rf(ctx, spaceID, username) + } + if rf, ok := ret.Get(0).(func(context.Context, int64, string) bool); ok { + r0 = rf(ctx, spaceID, username) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(context.Context, int64, string) error); ok { + r1 = rf(ctx, spaceID, username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceComponent_AllowCallApi_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllowCallApi' +type MockSpaceComponent_AllowCallApi_Call struct { + *mock.Call +} + +// AllowCallApi is a helper method to define mock.On call +// - ctx context.Context +// - spaceID int64 +// - username string +func (_e *MockSpaceComponent_Expecter) AllowCallApi(ctx interface{}, spaceID interface{}, username interface{}) *MockSpaceComponent_AllowCallApi_Call { + return &MockSpaceComponent_AllowCallApi_Call{Call: _e.mock.On("AllowCallApi", ctx, spaceID, username)} +} + +func (_c *MockSpaceComponent_AllowCallApi_Call) Run(run func(ctx context.Context, spaceID int64, username string)) *MockSpaceComponent_AllowCallApi_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(int64), args[2].(string)) + }) + return _c +} + +func (_c *MockSpaceComponent_AllowCallApi_Call) Return(_a0 bool, _a1 error) *MockSpaceComponent_AllowCallApi_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceComponent_AllowCallApi_Call) RunAndReturn(run func(context.Context, int64, string) (bool, error)) *MockSpaceComponent_AllowCallApi_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, req +func (_m *MockSpaceComponent) Create(ctx context.Context, req types.CreateSpaceReq) (*types.Space, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *types.Space + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, types.CreateSpaceReq) (*types.Space, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, types.CreateSpaceReq) *types.Space); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, types.CreateSpaceReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceComponent_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockSpaceComponent_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - req types.CreateSpaceReq +func (_e *MockSpaceComponent_Expecter) Create(ctx interface{}, req interface{}) *MockSpaceComponent_Create_Call { + return &MockSpaceComponent_Create_Call{Call: _e.mock.On("Create", ctx, req)} +} + +func (_c *MockSpaceComponent_Create_Call) Run(run func(ctx context.Context, req types.CreateSpaceReq)) *MockSpaceComponent_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.CreateSpaceReq)) + }) + return _c +} + +func (_c *MockSpaceComponent_Create_Call) Return(_a0 *types.Space, _a1 error) *MockSpaceComponent_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceComponent_Create_Call) RunAndReturn(run func(context.Context, types.CreateSpaceReq) (*types.Space, error)) *MockSpaceComponent_Create_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function with given fields: ctx, namespace, name, currentUser +func (_m *MockSpaceComponent) Delete(ctx context.Context, namespace string, name string, currentUser string) error { + ret := _m.Called(ctx, namespace, name, currentUser) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) error); ok { + r0 = rf(ctx, namespace, name, currentUser) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockSpaceComponent_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockSpaceComponent_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +// - currentUser string +func (_e *MockSpaceComponent_Expecter) Delete(ctx interface{}, namespace interface{}, name interface{}, currentUser interface{}) *MockSpaceComponent_Delete_Call { + return &MockSpaceComponent_Delete_Call{Call: _e.mock.On("Delete", ctx, namespace, name, currentUser)} +} + +func (_c *MockSpaceComponent_Delete_Call) Run(run func(ctx context.Context, namespace string, name string, currentUser string)) *MockSpaceComponent_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockSpaceComponent_Delete_Call) Return(_a0 error) *MockSpaceComponent_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockSpaceComponent_Delete_Call) RunAndReturn(run func(context.Context, string, string, string) error) *MockSpaceComponent_Delete_Call { + _c.Call.Return(run) + return _c +} + +// Deploy provides a mock function with given fields: ctx, namespace, name, currentUser +func (_m *MockSpaceComponent) Deploy(ctx context.Context, namespace string, name string, currentUser string) (int64, error) { + ret := _m.Called(ctx, namespace, name, currentUser) + + if len(ret) == 0 { + panic("no return value specified for Deploy") + } + + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) (int64, error)); ok { + return rf(ctx, namespace, name, currentUser) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) int64); ok { + r0 = rf(ctx, namespace, name, currentUser) + } else { + r0 = ret.Get(0).(int64) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { + r1 = rf(ctx, namespace, name, currentUser) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceComponent_Deploy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Deploy' +type MockSpaceComponent_Deploy_Call struct { + *mock.Call +} + +// Deploy is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +// - currentUser string +func (_e *MockSpaceComponent_Expecter) Deploy(ctx interface{}, namespace interface{}, name interface{}, currentUser interface{}) *MockSpaceComponent_Deploy_Call { + return &MockSpaceComponent_Deploy_Call{Call: _e.mock.On("Deploy", ctx, namespace, name, currentUser)} +} + +func (_c *MockSpaceComponent_Deploy_Call) Run(run func(ctx context.Context, namespace string, name string, currentUser string)) *MockSpaceComponent_Deploy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockSpaceComponent_Deploy_Call) Return(_a0 int64, _a1 error) *MockSpaceComponent_Deploy_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceComponent_Deploy_Call) RunAndReturn(run func(context.Context, string, string, string) (int64, error)) *MockSpaceComponent_Deploy_Call { + _c.Call.Return(run) + return _c +} + +// FixHasEntryFile provides a mock function with given fields: ctx, s +func (_m *MockSpaceComponent) FixHasEntryFile(ctx context.Context, s *database.Space) *database.Space { + ret := _m.Called(ctx, s) + + if len(ret) == 0 { + panic("no return value specified for FixHasEntryFile") + } + + var r0 *database.Space + if rf, ok := ret.Get(0).(func(context.Context, *database.Space) *database.Space); ok { + r0 = rf(ctx, s) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*database.Space) + } + } + + return r0 +} + +// MockSpaceComponent_FixHasEntryFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FixHasEntryFile' +type MockSpaceComponent_FixHasEntryFile_Call struct { + *mock.Call +} + +// FixHasEntryFile is a helper method to define mock.On call +// - ctx context.Context +// - s *database.Space +func (_e *MockSpaceComponent_Expecter) FixHasEntryFile(ctx interface{}, s interface{}) *MockSpaceComponent_FixHasEntryFile_Call { + return &MockSpaceComponent_FixHasEntryFile_Call{Call: _e.mock.On("FixHasEntryFile", ctx, s)} +} + +func (_c *MockSpaceComponent_FixHasEntryFile_Call) Run(run func(ctx context.Context, s *database.Space)) *MockSpaceComponent_FixHasEntryFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Space)) + }) + return _c +} + +func (_c *MockSpaceComponent_FixHasEntryFile_Call) Return(_a0 *database.Space) *MockSpaceComponent_FixHasEntryFile_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockSpaceComponent_FixHasEntryFile_Call) RunAndReturn(run func(context.Context, *database.Space) *database.Space) *MockSpaceComponent_FixHasEntryFile_Call { + _c.Call.Return(run) + return _c +} + +// HasEntryFile provides a mock function with given fields: ctx, space +func (_m *MockSpaceComponent) HasEntryFile(ctx context.Context, space *database.Space) bool { + ret := _m.Called(ctx, space) + + if len(ret) == 0 { + panic("no return value specified for HasEntryFile") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(context.Context, *database.Space) bool); ok { + r0 = rf(ctx, space) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// MockSpaceComponent_HasEntryFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HasEntryFile' +type MockSpaceComponent_HasEntryFile_Call struct { + *mock.Call +} + +// HasEntryFile is a helper method to define mock.On call +// - ctx context.Context +// - space *database.Space +func (_e *MockSpaceComponent_Expecter) HasEntryFile(ctx interface{}, space interface{}) *MockSpaceComponent_HasEntryFile_Call { + return &MockSpaceComponent_HasEntryFile_Call{Call: _e.mock.On("HasEntryFile", ctx, space)} +} + +func (_c *MockSpaceComponent_HasEntryFile_Call) Run(run func(ctx context.Context, space *database.Space)) *MockSpaceComponent_HasEntryFile_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*database.Space)) + }) + return _c +} + +func (_c *MockSpaceComponent_HasEntryFile_Call) Return(_a0 bool) *MockSpaceComponent_HasEntryFile_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockSpaceComponent_HasEntryFile_Call) RunAndReturn(run func(context.Context, *database.Space) bool) *MockSpaceComponent_HasEntryFile_Call { + _c.Call.Return(run) + return _c +} + +// Index provides a mock function with given fields: ctx, filter, per, page +func (_m *MockSpaceComponent) Index(ctx context.Context, filter *types.RepoFilter, per int, page int) ([]types.Space, int, error) { + ret := _m.Called(ctx, filter, per, page) + + if len(ret) == 0 { + panic("no return value specified for Index") + } + + var r0 []types.Space + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.RepoFilter, int, int) ([]types.Space, int, error)); ok { + return rf(ctx, filter, per, page) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.RepoFilter, int, int) []types.Space); ok { + r0 = rf(ctx, filter, per, page) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.RepoFilter, int, int) int); ok { + r1 = rf(ctx, filter, per, page) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.RepoFilter, int, int) error); ok { + r2 = rf(ctx, filter, per, page) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockSpaceComponent_Index_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Index' +type MockSpaceComponent_Index_Call struct { + *mock.Call +} + +// Index is a helper method to define mock.On call +// - ctx context.Context +// - filter *types.RepoFilter +// - per int +// - page int +func (_e *MockSpaceComponent_Expecter) Index(ctx interface{}, filter interface{}, per interface{}, page interface{}) *MockSpaceComponent_Index_Call { + return &MockSpaceComponent_Index_Call{Call: _e.mock.On("Index", ctx, filter, per, page)} +} + +func (_c *MockSpaceComponent_Index_Call) Run(run func(ctx context.Context, filter *types.RepoFilter, per int, page int)) *MockSpaceComponent_Index_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.RepoFilter), args[2].(int), args[3].(int)) + }) + return _c +} + +func (_c *MockSpaceComponent_Index_Call) Return(_a0 []types.Space, _a1 int, _a2 error) *MockSpaceComponent_Index_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockSpaceComponent_Index_Call) RunAndReturn(run func(context.Context, *types.RepoFilter, int, int) ([]types.Space, int, error)) *MockSpaceComponent_Index_Call { + _c.Call.Return(run) + return _c +} + +// ListByPath provides a mock function with given fields: ctx, paths +func (_m *MockSpaceComponent) ListByPath(ctx context.Context, paths []string) ([]*types.Space, error) { + ret := _m.Called(ctx, paths) + + if len(ret) == 0 { + panic("no return value specified for ListByPath") + } + + var r0 []*types.Space + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []string) ([]*types.Space, error)); ok { + return rf(ctx, paths) + } + if rf, ok := ret.Get(0).(func(context.Context, []string) []*types.Space); ok { + r0 = rf(ctx, paths) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*types.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok { + r1 = rf(ctx, paths) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceComponent_ListByPath_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByPath' +type MockSpaceComponent_ListByPath_Call struct { + *mock.Call +} + +// ListByPath is a helper method to define mock.On call +// - ctx context.Context +// - paths []string +func (_e *MockSpaceComponent_Expecter) ListByPath(ctx interface{}, paths interface{}) *MockSpaceComponent_ListByPath_Call { + return &MockSpaceComponent_ListByPath_Call{Call: _e.mock.On("ListByPath", ctx, paths)} +} + +func (_c *MockSpaceComponent_ListByPath_Call) Run(run func(ctx context.Context, paths []string)) *MockSpaceComponent_ListByPath_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]string)) + }) + return _c +} + +func (_c *MockSpaceComponent_ListByPath_Call) Return(_a0 []*types.Space, _a1 error) *MockSpaceComponent_ListByPath_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceComponent_ListByPath_Call) RunAndReturn(run func(context.Context, []string) ([]*types.Space, error)) *MockSpaceComponent_ListByPath_Call { + _c.Call.Return(run) + return _c +} + +// Logs provides a mock function with given fields: ctx, namespace, name +func (_m *MockSpaceComponent) Logs(ctx context.Context, namespace string, name string) (*deploy.MultiLogReader, error) { + ret := _m.Called(ctx, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for Logs") + } + + var r0 *deploy.MultiLogReader + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (*deploy.MultiLogReader, error)); ok { + return rf(ctx, namespace, name) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) *deploy.MultiLogReader); ok { + r0 = rf(ctx, namespace, name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*deploy.MultiLogReader) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = rf(ctx, namespace, name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceComponent_Logs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Logs' +type MockSpaceComponent_Logs_Call struct { + *mock.Call +} + +// Logs is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +func (_e *MockSpaceComponent_Expecter) Logs(ctx interface{}, namespace interface{}, name interface{}) *MockSpaceComponent_Logs_Call { + return &MockSpaceComponent_Logs_Call{Call: _e.mock.On("Logs", ctx, namespace, name)} +} + +func (_c *MockSpaceComponent_Logs_Call) Run(run func(ctx context.Context, namespace string, name string)) *MockSpaceComponent_Logs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockSpaceComponent_Logs_Call) Return(_a0 *deploy.MultiLogReader, _a1 error) *MockSpaceComponent_Logs_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceComponent_Logs_Call) RunAndReturn(run func(context.Context, string, string) (*deploy.MultiLogReader, error)) *MockSpaceComponent_Logs_Call { + _c.Call.Return(run) + return _c +} + +// OrgSpaces provides a mock function with given fields: ctx, req +func (_m *MockSpaceComponent) OrgSpaces(ctx context.Context, req *types.OrgSpacesReq) ([]types.Space, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for OrgSpaces") + } + + var r0 []types.Space + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.OrgSpacesReq) ([]types.Space, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.OrgSpacesReq) []types.Space); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.OrgSpacesReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.OrgSpacesReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockSpaceComponent_OrgSpaces_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OrgSpaces' +type MockSpaceComponent_OrgSpaces_Call struct { + *mock.Call +} + +// OrgSpaces is a helper method to define mock.On call +// - ctx context.Context +// - req *types.OrgSpacesReq +func (_e *MockSpaceComponent_Expecter) OrgSpaces(ctx interface{}, req interface{}) *MockSpaceComponent_OrgSpaces_Call { + return &MockSpaceComponent_OrgSpaces_Call{Call: _e.mock.On("OrgSpaces", ctx, req)} +} + +func (_c *MockSpaceComponent_OrgSpaces_Call) Run(run func(ctx context.Context, req *types.OrgSpacesReq)) *MockSpaceComponent_OrgSpaces_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.OrgSpacesReq)) + }) + return _c +} + +func (_c *MockSpaceComponent_OrgSpaces_Call) Return(_a0 []types.Space, _a1 int, _a2 error) *MockSpaceComponent_OrgSpaces_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockSpaceComponent_OrgSpaces_Call) RunAndReturn(run func(context.Context, *types.OrgSpacesReq) ([]types.Space, int, error)) *MockSpaceComponent_OrgSpaces_Call { + _c.Call.Return(run) + return _c +} + +// Show provides a mock function with given fields: ctx, namespace, name, currentUser +func (_m *MockSpaceComponent) Show(ctx context.Context, namespace string, name string, currentUser string) (*types.Space, error) { + ret := _m.Called(ctx, namespace, name, currentUser) + + if len(ret) == 0 { + panic("no return value specified for Show") + } + + var r0 *types.Space + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) (*types.Space, error)); ok { + return rf(ctx, namespace, name, currentUser) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, string) *types.Space); ok { + r0 = rf(ctx, namespace, name, currentUser) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, string) error); ok { + r1 = rf(ctx, namespace, name, currentUser) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceComponent_Show_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Show' +type MockSpaceComponent_Show_Call struct { + *mock.Call +} + +// Show is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +// - currentUser string +func (_e *MockSpaceComponent_Expecter) Show(ctx interface{}, namespace interface{}, name interface{}, currentUser interface{}) *MockSpaceComponent_Show_Call { + return &MockSpaceComponent_Show_Call{Call: _e.mock.On("Show", ctx, namespace, name, currentUser)} +} + +func (_c *MockSpaceComponent_Show_Call) Run(run func(ctx context.Context, namespace string, name string, currentUser string)) *MockSpaceComponent_Show_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockSpaceComponent_Show_Call) Return(_a0 *types.Space, _a1 error) *MockSpaceComponent_Show_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceComponent_Show_Call) RunAndReturn(run func(context.Context, string, string, string) (*types.Space, error)) *MockSpaceComponent_Show_Call { + _c.Call.Return(run) + return _c +} + +// Status provides a mock function with given fields: ctx, namespace, name +func (_m *MockSpaceComponent) Status(ctx context.Context, namespace string, name string) (string, string, error) { + ret := _m.Called(ctx, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for Status") + } + + var r0 string + var r1 string + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) (string, string, error)); ok { + return rf(ctx, namespace, name) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string) string); ok { + r0 = rf(ctx, namespace, name) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string) string); ok { + r1 = rf(ctx, namespace, name) + } else { + r1 = ret.Get(1).(string) + } + + if rf, ok := ret.Get(2).(func(context.Context, string, string) error); ok { + r2 = rf(ctx, namespace, name) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockSpaceComponent_Status_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Status' +type MockSpaceComponent_Status_Call struct { + *mock.Call +} + +// Status is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +func (_e *MockSpaceComponent_Expecter) Status(ctx interface{}, namespace interface{}, name interface{}) *MockSpaceComponent_Status_Call { + return &MockSpaceComponent_Status_Call{Call: _e.mock.On("Status", ctx, namespace, name)} +} + +func (_c *MockSpaceComponent_Status_Call) Run(run func(ctx context.Context, namespace string, name string)) *MockSpaceComponent_Status_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockSpaceComponent_Status_Call) Return(_a0 string, _a1 string, _a2 error) *MockSpaceComponent_Status_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockSpaceComponent_Status_Call) RunAndReturn(run func(context.Context, string, string) (string, string, error)) *MockSpaceComponent_Status_Call { + _c.Call.Return(run) + return _c +} + +// Stop provides a mock function with given fields: ctx, namespace, name +func (_m *MockSpaceComponent) Stop(ctx context.Context, namespace string, name string) error { + ret := _m.Called(ctx, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for Stop") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { + r0 = rf(ctx, namespace, name) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockSpaceComponent_Stop_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Stop' +type MockSpaceComponent_Stop_Call struct { + *mock.Call +} + +// Stop is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +func (_e *MockSpaceComponent_Expecter) Stop(ctx interface{}, namespace interface{}, name interface{}) *MockSpaceComponent_Stop_Call { + return &MockSpaceComponent_Stop_Call{Call: _e.mock.On("Stop", ctx, namespace, name)} +} + +func (_c *MockSpaceComponent_Stop_Call) Run(run func(ctx context.Context, namespace string, name string)) *MockSpaceComponent_Stop_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockSpaceComponent_Stop_Call) Return(_a0 error) *MockSpaceComponent_Stop_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockSpaceComponent_Stop_Call) RunAndReturn(run func(context.Context, string, string) error) *MockSpaceComponent_Stop_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, req +func (_m *MockSpaceComponent) Update(ctx context.Context, req *types.UpdateSpaceReq) (*types.Space, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 *types.Space + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UpdateSpaceReq) (*types.Space, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UpdateSpaceReq) *types.Space); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UpdateSpaceReq) error); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockSpaceComponent_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type MockSpaceComponent_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UpdateSpaceReq +func (_e *MockSpaceComponent_Expecter) Update(ctx interface{}, req interface{}) *MockSpaceComponent_Update_Call { + return &MockSpaceComponent_Update_Call{Call: _e.mock.On("Update", ctx, req)} +} + +func (_c *MockSpaceComponent_Update_Call) Run(run func(ctx context.Context, req *types.UpdateSpaceReq)) *MockSpaceComponent_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UpdateSpaceReq)) + }) + return _c +} + +func (_c *MockSpaceComponent_Update_Call) Return(_a0 *types.Space, _a1 error) *MockSpaceComponent_Update_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockSpaceComponent_Update_Call) RunAndReturn(run func(context.Context, *types.UpdateSpaceReq) (*types.Space, error)) *MockSpaceComponent_Update_Call { + _c.Call.Return(run) + return _c +} + +// UserLikesSpaces provides a mock function with given fields: ctx, req, userID +func (_m *MockSpaceComponent) UserLikesSpaces(ctx context.Context, req *types.UserSpacesReq, userID int64) ([]types.Space, int, error) { + ret := _m.Called(ctx, req, userID) + + if len(ret) == 0 { + panic("no return value specified for UserLikesSpaces") + } + + var r0 []types.Space + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserSpacesReq, int64) ([]types.Space, int, error)); ok { + return rf(ctx, req, userID) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserSpacesReq, int64) []types.Space); ok { + r0 = rf(ctx, req, userID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserSpacesReq, int64) int); ok { + r1 = rf(ctx, req, userID) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserSpacesReq, int64) error); ok { + r2 = rf(ctx, req, userID) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockSpaceComponent_UserLikesSpaces_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UserLikesSpaces' +type MockSpaceComponent_UserLikesSpaces_Call struct { + *mock.Call +} + +// UserLikesSpaces is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserSpacesReq +// - userID int64 +func (_e *MockSpaceComponent_Expecter) UserLikesSpaces(ctx interface{}, req interface{}, userID interface{}) *MockSpaceComponent_UserLikesSpaces_Call { + return &MockSpaceComponent_UserLikesSpaces_Call{Call: _e.mock.On("UserLikesSpaces", ctx, req, userID)} +} + +func (_c *MockSpaceComponent_UserLikesSpaces_Call) Run(run func(ctx context.Context, req *types.UserSpacesReq, userID int64)) *MockSpaceComponent_UserLikesSpaces_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserSpacesReq), args[2].(int64)) + }) + return _c +} + +func (_c *MockSpaceComponent_UserLikesSpaces_Call) Return(_a0 []types.Space, _a1 int, _a2 error) *MockSpaceComponent_UserLikesSpaces_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockSpaceComponent_UserLikesSpaces_Call) RunAndReturn(run func(context.Context, *types.UserSpacesReq, int64) ([]types.Space, int, error)) *MockSpaceComponent_UserLikesSpaces_Call { + _c.Call.Return(run) + return _c +} + +// UserSpaces provides a mock function with given fields: ctx, req +func (_m *MockSpaceComponent) UserSpaces(ctx context.Context, req *types.UserSpacesReq) ([]types.Space, int, error) { + ret := _m.Called(ctx, req) + + if len(ret) == 0 { + panic("no return value specified for UserSpaces") + } + + var r0 []types.Space + var r1 int + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, *types.UserSpacesReq) ([]types.Space, int, error)); ok { + return rf(ctx, req) + } + if rf, ok := ret.Get(0).(func(context.Context, *types.UserSpacesReq) []types.Space); ok { + r0 = rf(ctx, req) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Space) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *types.UserSpacesReq) int); ok { + r1 = rf(ctx, req) + } else { + r1 = ret.Get(1).(int) + } + + if rf, ok := ret.Get(2).(func(context.Context, *types.UserSpacesReq) error); ok { + r2 = rf(ctx, req) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockSpaceComponent_UserSpaces_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UserSpaces' +type MockSpaceComponent_UserSpaces_Call struct { + *mock.Call +} + +// UserSpaces is a helper method to define mock.On call +// - ctx context.Context +// - req *types.UserSpacesReq +func (_e *MockSpaceComponent_Expecter) UserSpaces(ctx interface{}, req interface{}) *MockSpaceComponent_UserSpaces_Call { + return &MockSpaceComponent_UserSpaces_Call{Call: _e.mock.On("UserSpaces", ctx, req)} +} + +func (_c *MockSpaceComponent_UserSpaces_Call) Run(run func(ctx context.Context, req *types.UserSpacesReq)) *MockSpaceComponent_UserSpaces_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*types.UserSpacesReq)) + }) + return _c +} + +func (_c *MockSpaceComponent_UserSpaces_Call) Return(_a0 []types.Space, _a1 int, _a2 error) *MockSpaceComponent_UserSpaces_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MockSpaceComponent_UserSpaces_Call) RunAndReturn(run func(context.Context, *types.UserSpacesReq) ([]types.Space, int, error)) *MockSpaceComponent_UserSpaces_Call { + _c.Call.Return(run) + return _c +} + +// Wakeup provides a mock function with given fields: ctx, namespace, name +func (_m *MockSpaceComponent) Wakeup(ctx context.Context, namespace string, name string) error { + ret := _m.Called(ctx, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for Wakeup") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { + r0 = rf(ctx, namespace, name) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockSpaceComponent_Wakeup_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Wakeup' +type MockSpaceComponent_Wakeup_Call struct { + *mock.Call +} + +// Wakeup is a helper method to define mock.On call +// - ctx context.Context +// - namespace string +// - name string +func (_e *MockSpaceComponent_Expecter) Wakeup(ctx interface{}, namespace interface{}, name interface{}) *MockSpaceComponent_Wakeup_Call { + return &MockSpaceComponent_Wakeup_Call{Call: _e.mock.On("Wakeup", ctx, namespace, name)} +} + +func (_c *MockSpaceComponent_Wakeup_Call) Run(run func(ctx context.Context, namespace string, name string)) *MockSpaceComponent_Wakeup_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *MockSpaceComponent_Wakeup_Call) Return(_a0 error) *MockSpaceComponent_Wakeup_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockSpaceComponent_Wakeup_Call) RunAndReturn(run func(context.Context, string, string) error) *MockSpaceComponent_Wakeup_Call { + _c.Call.Return(run) + return _c +} + +// NewMockSpaceComponent creates a new instance of MockSpaceComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSpaceComponent(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSpaceComponent { + mock := &MockSpaceComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/component/mock_TagComponent.go b/_mocks/opencsg.com/csghub-server/component/mock_TagComponent.go new file mode 100644 index 00000000..76b73284 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/component/mock_TagComponent.go @@ -0,0 +1,309 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package component + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + database "opencsg.com/csghub-server/builder/store/database" + + types "opencsg.com/csghub-server/common/types" +) + +// MockTagComponent is an autogenerated mock type for the TagComponent type +type MockTagComponent struct { + mock.Mock +} + +type MockTagComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *MockTagComponent) EXPECT() *MockTagComponent_Expecter { + return &MockTagComponent_Expecter{mock: &_m.Mock} +} + +// AllTags provides a mock function with given fields: ctx +func (_m *MockTagComponent) AllTags(ctx context.Context) ([]database.Tag, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AllTags") + } + + var r0 []database.Tag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]database.Tag, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) []database.Tag); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]database.Tag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagComponent_AllTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllTags' +type MockTagComponent_AllTags_Call struct { + *mock.Call +} + +// AllTags is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockTagComponent_Expecter) AllTags(ctx interface{}) *MockTagComponent_AllTags_Call { + return &MockTagComponent_AllTags_Call{Call: _e.mock.On("AllTags", ctx)} +} + +func (_c *MockTagComponent_AllTags_Call) Run(run func(ctx context.Context)) *MockTagComponent_AllTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *MockTagComponent_AllTags_Call) Return(_a0 []database.Tag, _a1 error) *MockTagComponent_AllTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagComponent_AllTags_Call) RunAndReturn(run func(context.Context) ([]database.Tag, error)) *MockTagComponent_AllTags_Call { + _c.Call.Return(run) + return _c +} + +// ClearMetaTags provides a mock function with given fields: ctx, repoType, namespace, name +func (_m *MockTagComponent) ClearMetaTags(ctx context.Context, repoType types.RepositoryType, namespace string, name string) error { + ret := _m.Called(ctx, repoType, namespace, name) + + if len(ret) == 0 { + panic("no return value specified for ClearMetaTags") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, types.RepositoryType, string, string) error); ok { + r0 = rf(ctx, repoType, namespace, name) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockTagComponent_ClearMetaTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ClearMetaTags' +type MockTagComponent_ClearMetaTags_Call struct { + *mock.Call +} + +// ClearMetaTags is a helper method to define mock.On call +// - ctx context.Context +// - repoType types.RepositoryType +// - namespace string +// - name string +func (_e *MockTagComponent_Expecter) ClearMetaTags(ctx interface{}, repoType interface{}, namespace interface{}, name interface{}) *MockTagComponent_ClearMetaTags_Call { + return &MockTagComponent_ClearMetaTags_Call{Call: _e.mock.On("ClearMetaTags", ctx, repoType, namespace, name)} +} + +func (_c *MockTagComponent_ClearMetaTags_Call) Run(run func(ctx context.Context, repoType types.RepositoryType, namespace string, name string)) *MockTagComponent_ClearMetaTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(types.RepositoryType), args[2].(string), args[3].(string)) + }) + return _c +} + +func (_c *MockTagComponent_ClearMetaTags_Call) Return(_a0 error) *MockTagComponent_ClearMetaTags_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockTagComponent_ClearMetaTags_Call) RunAndReturn(run func(context.Context, types.RepositoryType, string, string) error) *MockTagComponent_ClearMetaTags_Call { + _c.Call.Return(run) + return _c +} + +// UpdateLibraryTags provides a mock function with given fields: ctx, tagScope, namespace, name, oldFilePath, newFilePath +func (_m *MockTagComponent) UpdateLibraryTags(ctx context.Context, tagScope database.TagScope, namespace string, name string, oldFilePath string, newFilePath string) error { + ret := _m.Called(ctx, tagScope, namespace, name, oldFilePath, newFilePath) + + if len(ret) == 0 { + panic("no return value specified for UpdateLibraryTags") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.TagScope, string, string, string, string) error); ok { + r0 = rf(ctx, tagScope, namespace, name, oldFilePath, newFilePath) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockTagComponent_UpdateLibraryTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateLibraryTags' +type MockTagComponent_UpdateLibraryTags_Call struct { + *mock.Call +} + +// UpdateLibraryTags is a helper method to define mock.On call +// - ctx context.Context +// - tagScope database.TagScope +// - namespace string +// - name string +// - oldFilePath string +// - newFilePath string +func (_e *MockTagComponent_Expecter) UpdateLibraryTags(ctx interface{}, tagScope interface{}, namespace interface{}, name interface{}, oldFilePath interface{}, newFilePath interface{}) *MockTagComponent_UpdateLibraryTags_Call { + return &MockTagComponent_UpdateLibraryTags_Call{Call: _e.mock.On("UpdateLibraryTags", ctx, tagScope, namespace, name, oldFilePath, newFilePath)} +} + +func (_c *MockTagComponent_UpdateLibraryTags_Call) Run(run func(ctx context.Context, tagScope database.TagScope, namespace string, name string, oldFilePath string, newFilePath string)) *MockTagComponent_UpdateLibraryTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.TagScope), args[2].(string), args[3].(string), args[4].(string), args[5].(string)) + }) + return _c +} + +func (_c *MockTagComponent_UpdateLibraryTags_Call) Return(_a0 error) *MockTagComponent_UpdateLibraryTags_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockTagComponent_UpdateLibraryTags_Call) RunAndReturn(run func(context.Context, database.TagScope, string, string, string, string) error) *MockTagComponent_UpdateLibraryTags_Call { + _c.Call.Return(run) + return _c +} + +// UpdateMetaTags provides a mock function with given fields: ctx, tagScope, namespace, name, content +func (_m *MockTagComponent) UpdateMetaTags(ctx context.Context, tagScope database.TagScope, namespace string, name string, content string) ([]*database.RepositoryTag, error) { + ret := _m.Called(ctx, tagScope, namespace, name, content) + + if len(ret) == 0 { + panic("no return value specified for UpdateMetaTags") + } + + var r0 []*database.RepositoryTag + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, database.TagScope, string, string, string) ([]*database.RepositoryTag, error)); ok { + return rf(ctx, tagScope, namespace, name, content) + } + if rf, ok := ret.Get(0).(func(context.Context, database.TagScope, string, string, string) []*database.RepositoryTag); ok { + r0 = rf(ctx, tagScope, namespace, name, content) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*database.RepositoryTag) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, database.TagScope, string, string, string) error); ok { + r1 = rf(ctx, tagScope, namespace, name, content) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockTagComponent_UpdateMetaTags_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateMetaTags' +type MockTagComponent_UpdateMetaTags_Call struct { + *mock.Call +} + +// UpdateMetaTags is a helper method to define mock.On call +// - ctx context.Context +// - tagScope database.TagScope +// - namespace string +// - name string +// - content string +func (_e *MockTagComponent_Expecter) UpdateMetaTags(ctx interface{}, tagScope interface{}, namespace interface{}, name interface{}, content interface{}) *MockTagComponent_UpdateMetaTags_Call { + return &MockTagComponent_UpdateMetaTags_Call{Call: _e.mock.On("UpdateMetaTags", ctx, tagScope, namespace, name, content)} +} + +func (_c *MockTagComponent_UpdateMetaTags_Call) Run(run func(ctx context.Context, tagScope database.TagScope, namespace string, name string, content string)) *MockTagComponent_UpdateMetaTags_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.TagScope), args[2].(string), args[3].(string), args[4].(string)) + }) + return _c +} + +func (_c *MockTagComponent_UpdateMetaTags_Call) Return(_a0 []*database.RepositoryTag, _a1 error) *MockTagComponent_UpdateMetaTags_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockTagComponent_UpdateMetaTags_Call) RunAndReturn(run func(context.Context, database.TagScope, string, string, string) ([]*database.RepositoryTag, error)) *MockTagComponent_UpdateMetaTags_Call { + _c.Call.Return(run) + return _c +} + +// UpdateRepoTagsByCategory provides a mock function with given fields: ctx, tagScope, repoID, category, tagNames +func (_m *MockTagComponent) UpdateRepoTagsByCategory(ctx context.Context, tagScope database.TagScope, repoID int64, category string, tagNames []string) error { + ret := _m.Called(ctx, tagScope, repoID, category, tagNames) + + if len(ret) == 0 { + panic("no return value specified for UpdateRepoTagsByCategory") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, database.TagScope, int64, string, []string) error); ok { + r0 = rf(ctx, tagScope, repoID, category, tagNames) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockTagComponent_UpdateRepoTagsByCategory_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateRepoTagsByCategory' +type MockTagComponent_UpdateRepoTagsByCategory_Call struct { + *mock.Call +} + +// UpdateRepoTagsByCategory is a helper method to define mock.On call +// - ctx context.Context +// - tagScope database.TagScope +// - repoID int64 +// - category string +// - tagNames []string +func (_e *MockTagComponent_Expecter) UpdateRepoTagsByCategory(ctx interface{}, tagScope interface{}, repoID interface{}, category interface{}, tagNames interface{}) *MockTagComponent_UpdateRepoTagsByCategory_Call { + return &MockTagComponent_UpdateRepoTagsByCategory_Call{Call: _e.mock.On("UpdateRepoTagsByCategory", ctx, tagScope, repoID, category, tagNames)} +} + +func (_c *MockTagComponent_UpdateRepoTagsByCategory_Call) Run(run func(ctx context.Context, tagScope database.TagScope, repoID int64, category string, tagNames []string)) *MockTagComponent_UpdateRepoTagsByCategory_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(database.TagScope), args[2].(int64), args[3].(string), args[4].([]string)) + }) + return _c +} + +func (_c *MockTagComponent_UpdateRepoTagsByCategory_Call) Return(_a0 error) *MockTagComponent_UpdateRepoTagsByCategory_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockTagComponent_UpdateRepoTagsByCategory_Call) RunAndReturn(run func(context.Context, database.TagScope, int64, string, []string) error) *MockTagComponent_UpdateRepoTagsByCategory_Call { + _c.Call.Return(run) + return _c +} + +// NewMockTagComponent creates a new instance of MockTagComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockTagComponent(t interface { + mock.TestingT + Cleanup(func()) +}) *MockTagComponent { + mock := &MockTagComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/mirror/queue/mock_PriorityQueue.go b/_mocks/opencsg.com/csghub-server/mirror/queue/mock_PriorityQueue.go new file mode 100644 index 00000000..28bacbec --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/mirror/queue/mock_PriorityQueue.go @@ -0,0 +1,195 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package queue + +import ( + mock "github.com/stretchr/testify/mock" + queue "opencsg.com/csghub-server/mirror/queue" +) + +// MockPriorityQueue is an autogenerated mock type for the PriorityQueue type +type MockPriorityQueue struct { + mock.Mock +} + +type MockPriorityQueue_Expecter struct { + mock *mock.Mock +} + +func (_m *MockPriorityQueue) EXPECT() *MockPriorityQueue_Expecter { + return &MockPriorityQueue_Expecter{mock: &_m.Mock} +} + +// PopLfsMirror provides a mock function with given fields: +func (_m *MockPriorityQueue) PopLfsMirror() *queue.MirrorTask { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for PopLfsMirror") + } + + var r0 *queue.MirrorTask + if rf, ok := ret.Get(0).(func() *queue.MirrorTask); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*queue.MirrorTask) + } + } + + return r0 +} + +// MockPriorityQueue_PopLfsMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PopLfsMirror' +type MockPriorityQueue_PopLfsMirror_Call struct { + *mock.Call +} + +// PopLfsMirror is a helper method to define mock.On call +func (_e *MockPriorityQueue_Expecter) PopLfsMirror() *MockPriorityQueue_PopLfsMirror_Call { + return &MockPriorityQueue_PopLfsMirror_Call{Call: _e.mock.On("PopLfsMirror")} +} + +func (_c *MockPriorityQueue_PopLfsMirror_Call) Run(run func()) *MockPriorityQueue_PopLfsMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockPriorityQueue_PopLfsMirror_Call) Return(_a0 *queue.MirrorTask) *MockPriorityQueue_PopLfsMirror_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPriorityQueue_PopLfsMirror_Call) RunAndReturn(run func() *queue.MirrorTask) *MockPriorityQueue_PopLfsMirror_Call { + _c.Call.Return(run) + return _c +} + +// PopRepoMirror provides a mock function with given fields: +func (_m *MockPriorityQueue) PopRepoMirror() *queue.MirrorTask { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for PopRepoMirror") + } + + var r0 *queue.MirrorTask + if rf, ok := ret.Get(0).(func() *queue.MirrorTask); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*queue.MirrorTask) + } + } + + return r0 +} + +// MockPriorityQueue_PopRepoMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PopRepoMirror' +type MockPriorityQueue_PopRepoMirror_Call struct { + *mock.Call +} + +// PopRepoMirror is a helper method to define mock.On call +func (_e *MockPriorityQueue_Expecter) PopRepoMirror() *MockPriorityQueue_PopRepoMirror_Call { + return &MockPriorityQueue_PopRepoMirror_Call{Call: _e.mock.On("PopRepoMirror")} +} + +func (_c *MockPriorityQueue_PopRepoMirror_Call) Run(run func()) *MockPriorityQueue_PopRepoMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockPriorityQueue_PopRepoMirror_Call) Return(_a0 *queue.MirrorTask) *MockPriorityQueue_PopRepoMirror_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockPriorityQueue_PopRepoMirror_Call) RunAndReturn(run func() *queue.MirrorTask) *MockPriorityQueue_PopRepoMirror_Call { + _c.Call.Return(run) + return _c +} + +// PushLfsMirror provides a mock function with given fields: mt +func (_m *MockPriorityQueue) PushLfsMirror(mt *queue.MirrorTask) { + _m.Called(mt) +} + +// MockPriorityQueue_PushLfsMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PushLfsMirror' +type MockPriorityQueue_PushLfsMirror_Call struct { + *mock.Call +} + +// PushLfsMirror is a helper method to define mock.On call +// - mt *queue.MirrorTask +func (_e *MockPriorityQueue_Expecter) PushLfsMirror(mt interface{}) *MockPriorityQueue_PushLfsMirror_Call { + return &MockPriorityQueue_PushLfsMirror_Call{Call: _e.mock.On("PushLfsMirror", mt)} +} + +func (_c *MockPriorityQueue_PushLfsMirror_Call) Run(run func(mt *queue.MirrorTask)) *MockPriorityQueue_PushLfsMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*queue.MirrorTask)) + }) + return _c +} + +func (_c *MockPriorityQueue_PushLfsMirror_Call) Return() *MockPriorityQueue_PushLfsMirror_Call { + _c.Call.Return() + return _c +} + +func (_c *MockPriorityQueue_PushLfsMirror_Call) RunAndReturn(run func(*queue.MirrorTask)) *MockPriorityQueue_PushLfsMirror_Call { + _c.Call.Return(run) + return _c +} + +// PushRepoMirror provides a mock function with given fields: mt +func (_m *MockPriorityQueue) PushRepoMirror(mt *queue.MirrorTask) { + _m.Called(mt) +} + +// MockPriorityQueue_PushRepoMirror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PushRepoMirror' +type MockPriorityQueue_PushRepoMirror_Call struct { + *mock.Call +} + +// PushRepoMirror is a helper method to define mock.On call +// - mt *queue.MirrorTask +func (_e *MockPriorityQueue_Expecter) PushRepoMirror(mt interface{}) *MockPriorityQueue_PushRepoMirror_Call { + return &MockPriorityQueue_PushRepoMirror_Call{Call: _e.mock.On("PushRepoMirror", mt)} +} + +func (_c *MockPriorityQueue_PushRepoMirror_Call) Run(run func(mt *queue.MirrorTask)) *MockPriorityQueue_PushRepoMirror_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*queue.MirrorTask)) + }) + return _c +} + +func (_c *MockPriorityQueue_PushRepoMirror_Call) Return() *MockPriorityQueue_PushRepoMirror_Call { + _c.Call.Return() + return _c +} + +func (_c *MockPriorityQueue_PushRepoMirror_Call) RunAndReturn(run func(*queue.MirrorTask)) *MockPriorityQueue_PushRepoMirror_Call { + _c.Call.Return(run) + return _c +} + +// NewMockPriorityQueue creates a new instance of MockPriorityQueue. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockPriorityQueue(t interface { + mock.TestingT + Cleanup(func()) +}) *MockPriorityQueue { + mock := &MockPriorityQueue{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/mq/mock_MessageQueue.go b/_mocks/opencsg.com/csghub-server/mq/mock_MessageQueue.go new file mode 100644 index 00000000..855c7fc9 --- /dev/null +++ b/_mocks/opencsg.com/csghub-server/mq/mock_MessageQueue.go @@ -0,0 +1,618 @@ +// Code generated by mockery v2.49.1. DO NOT EDIT. + +package mq + +import ( + context "context" + + jetstream "github.com/nats-io/nats.go/jetstream" + mock "github.com/stretchr/testify/mock" + + mq "opencsg.com/csghub-server/mq" + + nats "github.com/nats-io/nats.go" +) + +// MockMessageQueue is an autogenerated mock type for the MessageQueue type +type MockMessageQueue struct { + mock.Mock +} + +type MockMessageQueue_Expecter struct { + mock *mock.Mock +} + +func (_m *MockMessageQueue) EXPECT() *MockMessageQueue_Expecter { + return &MockMessageQueue_Expecter{mock: &_m.Mock} +} + +// BuildDLQStream provides a mock function with given fields: +func (_m *MockMessageQueue) BuildDLQStream() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for BuildDLQStream") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMessageQueue_BuildDLQStream_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BuildDLQStream' +type MockMessageQueue_BuildDLQStream_Call struct { + *mock.Call +} + +// BuildDLQStream is a helper method to define mock.On call +func (_e *MockMessageQueue_Expecter) BuildDLQStream() *MockMessageQueue_BuildDLQStream_Call { + return &MockMessageQueue_BuildDLQStream_Call{Call: _e.mock.On("BuildDLQStream")} +} + +func (_c *MockMessageQueue_BuildDLQStream_Call) Run(run func()) *MockMessageQueue_BuildDLQStream_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockMessageQueue_BuildDLQStream_Call) Return(_a0 error) *MockMessageQueue_BuildDLQStream_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMessageQueue_BuildDLQStream_Call) RunAndReturn(run func() error) *MockMessageQueue_BuildDLQStream_Call { + _c.Call.Return(run) + return _c +} + +// BuildEventStreamAndConsumer provides a mock function with given fields: cfg, streamCfg, consumerCfg +func (_m *MockMessageQueue) BuildEventStreamAndConsumer(cfg mq.EventConfig, streamCfg jetstream.StreamConfig, consumerCfg jetstream.ConsumerConfig) (jetstream.Consumer, error) { + ret := _m.Called(cfg, streamCfg, consumerCfg) + + if len(ret) == 0 { + panic("no return value specified for BuildEventStreamAndConsumer") + } + + var r0 jetstream.Consumer + var r1 error + if rf, ok := ret.Get(0).(func(mq.EventConfig, jetstream.StreamConfig, jetstream.ConsumerConfig) (jetstream.Consumer, error)); ok { + return rf(cfg, streamCfg, consumerCfg) + } + if rf, ok := ret.Get(0).(func(mq.EventConfig, jetstream.StreamConfig, jetstream.ConsumerConfig) jetstream.Consumer); ok { + r0 = rf(cfg, streamCfg, consumerCfg) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(jetstream.Consumer) + } + } + + if rf, ok := ret.Get(1).(func(mq.EventConfig, jetstream.StreamConfig, jetstream.ConsumerConfig) error); ok { + r1 = rf(cfg, streamCfg, consumerCfg) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMessageQueue_BuildEventStreamAndConsumer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BuildEventStreamAndConsumer' +type MockMessageQueue_BuildEventStreamAndConsumer_Call struct { + *mock.Call +} + +// BuildEventStreamAndConsumer is a helper method to define mock.On call +// - cfg mq.EventConfig +// - streamCfg jetstream.StreamConfig +// - consumerCfg jetstream.ConsumerConfig +func (_e *MockMessageQueue_Expecter) BuildEventStreamAndConsumer(cfg interface{}, streamCfg interface{}, consumerCfg interface{}) *MockMessageQueue_BuildEventStreamAndConsumer_Call { + return &MockMessageQueue_BuildEventStreamAndConsumer_Call{Call: _e.mock.On("BuildEventStreamAndConsumer", cfg, streamCfg, consumerCfg)} +} + +func (_c *MockMessageQueue_BuildEventStreamAndConsumer_Call) Run(run func(cfg mq.EventConfig, streamCfg jetstream.StreamConfig, consumerCfg jetstream.ConsumerConfig)) *MockMessageQueue_BuildEventStreamAndConsumer_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(mq.EventConfig), args[1].(jetstream.StreamConfig), args[2].(jetstream.ConsumerConfig)) + }) + return _c +} + +func (_c *MockMessageQueue_BuildEventStreamAndConsumer_Call) Return(_a0 jetstream.Consumer, _a1 error) *MockMessageQueue_BuildEventStreamAndConsumer_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMessageQueue_BuildEventStreamAndConsumer_Call) RunAndReturn(run func(mq.EventConfig, jetstream.StreamConfig, jetstream.ConsumerConfig) (jetstream.Consumer, error)) *MockMessageQueue_BuildEventStreamAndConsumer_Call { + _c.Call.Return(run) + return _c +} + +// BuildMeterEventStream provides a mock function with given fields: +func (_m *MockMessageQueue) BuildMeterEventStream() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for BuildMeterEventStream") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMessageQueue_BuildMeterEventStream_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BuildMeterEventStream' +type MockMessageQueue_BuildMeterEventStream_Call struct { + *mock.Call +} + +// BuildMeterEventStream is a helper method to define mock.On call +func (_e *MockMessageQueue_Expecter) BuildMeterEventStream() *MockMessageQueue_BuildMeterEventStream_Call { + return &MockMessageQueue_BuildMeterEventStream_Call{Call: _e.mock.On("BuildMeterEventStream")} +} + +func (_c *MockMessageQueue_BuildMeterEventStream_Call) Run(run func()) *MockMessageQueue_BuildMeterEventStream_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockMessageQueue_BuildMeterEventStream_Call) Return(_a0 error) *MockMessageQueue_BuildMeterEventStream_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMessageQueue_BuildMeterEventStream_Call) RunAndReturn(run func() error) *MockMessageQueue_BuildMeterEventStream_Call { + _c.Call.Return(run) + return _c +} + +// CreateOrUpdateStream provides a mock function with given fields: ctx, streamName, streamCfg +func (_m *MockMessageQueue) CreateOrUpdateStream(ctx context.Context, streamName string, streamCfg jetstream.StreamConfig) (jetstream.Stream, error) { + ret := _m.Called(ctx, streamName, streamCfg) + + if len(ret) == 0 { + panic("no return value specified for CreateOrUpdateStream") + } + + var r0 jetstream.Stream + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, jetstream.StreamConfig) (jetstream.Stream, error)); ok { + return rf(ctx, streamName, streamCfg) + } + if rf, ok := ret.Get(0).(func(context.Context, string, jetstream.StreamConfig) jetstream.Stream); ok { + r0 = rf(ctx, streamName, streamCfg) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(jetstream.Stream) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, jetstream.StreamConfig) error); ok { + r1 = rf(ctx, streamName, streamCfg) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockMessageQueue_CreateOrUpdateStream_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateOrUpdateStream' +type MockMessageQueue_CreateOrUpdateStream_Call struct { + *mock.Call +} + +// CreateOrUpdateStream is a helper method to define mock.On call +// - ctx context.Context +// - streamName string +// - streamCfg jetstream.StreamConfig +func (_e *MockMessageQueue_Expecter) CreateOrUpdateStream(ctx interface{}, streamName interface{}, streamCfg interface{}) *MockMessageQueue_CreateOrUpdateStream_Call { + return &MockMessageQueue_CreateOrUpdateStream_Call{Call: _e.mock.On("CreateOrUpdateStream", ctx, streamName, streamCfg)} +} + +func (_c *MockMessageQueue_CreateOrUpdateStream_Call) Run(run func(ctx context.Context, streamName string, streamCfg jetstream.StreamConfig)) *MockMessageQueue_CreateOrUpdateStream_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(jetstream.StreamConfig)) + }) + return _c +} + +func (_c *MockMessageQueue_CreateOrUpdateStream_Call) Return(_a0 jetstream.Stream, _a1 error) *MockMessageQueue_CreateOrUpdateStream_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockMessageQueue_CreateOrUpdateStream_Call) RunAndReturn(run func(context.Context, string, jetstream.StreamConfig) (jetstream.Stream, error)) *MockMessageQueue_CreateOrUpdateStream_Call { + _c.Call.Return(run) + return _c +} + +// GetConn provides a mock function with given fields: +func (_m *MockMessageQueue) GetConn() *nats.Conn { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetConn") + } + + var r0 *nats.Conn + if rf, ok := ret.Get(0).(func() *nats.Conn); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*nats.Conn) + } + } + + return r0 +} + +// MockMessageQueue_GetConn_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetConn' +type MockMessageQueue_GetConn_Call struct { + *mock.Call +} + +// GetConn is a helper method to define mock.On call +func (_e *MockMessageQueue_Expecter) GetConn() *MockMessageQueue_GetConn_Call { + return &MockMessageQueue_GetConn_Call{Call: _e.mock.On("GetConn")} +} + +func (_c *MockMessageQueue_GetConn_Call) Run(run func()) *MockMessageQueue_GetConn_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockMessageQueue_GetConn_Call) Return(_a0 *nats.Conn) *MockMessageQueue_GetConn_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMessageQueue_GetConn_Call) RunAndReturn(run func() *nats.Conn) *MockMessageQueue_GetConn_Call { + _c.Call.Return(run) + return _c +} + +// GetJetStream provides a mock function with given fields: +func (_m *MockMessageQueue) GetJetStream() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetJetStream") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMessageQueue_GetJetStream_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetJetStream' +type MockMessageQueue_GetJetStream_Call struct { + *mock.Call +} + +// GetJetStream is a helper method to define mock.On call +func (_e *MockMessageQueue_Expecter) GetJetStream() *MockMessageQueue_GetJetStream_Call { + return &MockMessageQueue_GetJetStream_Call{Call: _e.mock.On("GetJetStream")} +} + +func (_c *MockMessageQueue_GetJetStream_Call) Run(run func()) *MockMessageQueue_GetJetStream_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockMessageQueue_GetJetStream_Call) Return(_a0 error) *MockMessageQueue_GetJetStream_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMessageQueue_GetJetStream_Call) RunAndReturn(run func() error) *MockMessageQueue_GetJetStream_Call { + _c.Call.Return(run) + return _c +} + +// PublishData provides a mock function with given fields: subject, data +func (_m *MockMessageQueue) PublishData(subject string, data []byte) error { + ret := _m.Called(subject, data) + + if len(ret) == 0 { + panic("no return value specified for PublishData") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string, []byte) error); ok { + r0 = rf(subject, data) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMessageQueue_PublishData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishData' +type MockMessageQueue_PublishData_Call struct { + *mock.Call +} + +// PublishData is a helper method to define mock.On call +// - subject string +// - data []byte +func (_e *MockMessageQueue_Expecter) PublishData(subject interface{}, data interface{}) *MockMessageQueue_PublishData_Call { + return &MockMessageQueue_PublishData_Call{Call: _e.mock.On("PublishData", subject, data)} +} + +func (_c *MockMessageQueue_PublishData_Call) Run(run func(subject string, data []byte)) *MockMessageQueue_PublishData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].([]byte)) + }) + return _c +} + +func (_c *MockMessageQueue_PublishData_Call) Return(_a0 error) *MockMessageQueue_PublishData_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMessageQueue_PublishData_Call) RunAndReturn(run func(string, []byte) error) *MockMessageQueue_PublishData_Call { + _c.Call.Return(run) + return _c +} + +// PublishMeterDataToDLQ provides a mock function with given fields: data +func (_m *MockMessageQueue) PublishMeterDataToDLQ(data []byte) error { + ret := _m.Called(data) + + if len(ret) == 0 { + panic("no return value specified for PublishMeterDataToDLQ") + } + + var r0 error + if rf, ok := ret.Get(0).(func([]byte) error); ok { + r0 = rf(data) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMessageQueue_PublishMeterDataToDLQ_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishMeterDataToDLQ' +type MockMessageQueue_PublishMeterDataToDLQ_Call struct { + *mock.Call +} + +// PublishMeterDataToDLQ is a helper method to define mock.On call +// - data []byte +func (_e *MockMessageQueue_Expecter) PublishMeterDataToDLQ(data interface{}) *MockMessageQueue_PublishMeterDataToDLQ_Call { + return &MockMessageQueue_PublishMeterDataToDLQ_Call{Call: _e.mock.On("PublishMeterDataToDLQ", data)} +} + +func (_c *MockMessageQueue_PublishMeterDataToDLQ_Call) Run(run func(data []byte)) *MockMessageQueue_PublishMeterDataToDLQ_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]byte)) + }) + return _c +} + +func (_c *MockMessageQueue_PublishMeterDataToDLQ_Call) Return(_a0 error) *MockMessageQueue_PublishMeterDataToDLQ_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMessageQueue_PublishMeterDataToDLQ_Call) RunAndReturn(run func([]byte) error) *MockMessageQueue_PublishMeterDataToDLQ_Call { + _c.Call.Return(run) + return _c +} + +// PublishMeterDurationData provides a mock function with given fields: data +func (_m *MockMessageQueue) PublishMeterDurationData(data []byte) error { + ret := _m.Called(data) + + if len(ret) == 0 { + panic("no return value specified for PublishMeterDurationData") + } + + var r0 error + if rf, ok := ret.Get(0).(func([]byte) error); ok { + r0 = rf(data) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMessageQueue_PublishMeterDurationData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishMeterDurationData' +type MockMessageQueue_PublishMeterDurationData_Call struct { + *mock.Call +} + +// PublishMeterDurationData is a helper method to define mock.On call +// - data []byte +func (_e *MockMessageQueue_Expecter) PublishMeterDurationData(data interface{}) *MockMessageQueue_PublishMeterDurationData_Call { + return &MockMessageQueue_PublishMeterDurationData_Call{Call: _e.mock.On("PublishMeterDurationData", data)} +} + +func (_c *MockMessageQueue_PublishMeterDurationData_Call) Run(run func(data []byte)) *MockMessageQueue_PublishMeterDurationData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]byte)) + }) + return _c +} + +func (_c *MockMessageQueue_PublishMeterDurationData_Call) Return(_a0 error) *MockMessageQueue_PublishMeterDurationData_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMessageQueue_PublishMeterDurationData_Call) RunAndReturn(run func([]byte) error) *MockMessageQueue_PublishMeterDurationData_Call { + _c.Call.Return(run) + return _c +} + +// VerifyDLQStream provides a mock function with given fields: +func (_m *MockMessageQueue) VerifyDLQStream() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for VerifyDLQStream") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMessageQueue_VerifyDLQStream_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VerifyDLQStream' +type MockMessageQueue_VerifyDLQStream_Call struct { + *mock.Call +} + +// VerifyDLQStream is a helper method to define mock.On call +func (_e *MockMessageQueue_Expecter) VerifyDLQStream() *MockMessageQueue_VerifyDLQStream_Call { + return &MockMessageQueue_VerifyDLQStream_Call{Call: _e.mock.On("VerifyDLQStream")} +} + +func (_c *MockMessageQueue_VerifyDLQStream_Call) Run(run func()) *MockMessageQueue_VerifyDLQStream_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockMessageQueue_VerifyDLQStream_Call) Return(_a0 error) *MockMessageQueue_VerifyDLQStream_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMessageQueue_VerifyDLQStream_Call) RunAndReturn(run func() error) *MockMessageQueue_VerifyDLQStream_Call { + _c.Call.Return(run) + return _c +} + +// VerifyMeteringStream provides a mock function with given fields: +func (_m *MockMessageQueue) VerifyMeteringStream() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for VerifyMeteringStream") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMessageQueue_VerifyMeteringStream_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VerifyMeteringStream' +type MockMessageQueue_VerifyMeteringStream_Call struct { + *mock.Call +} + +// VerifyMeteringStream is a helper method to define mock.On call +func (_e *MockMessageQueue_Expecter) VerifyMeteringStream() *MockMessageQueue_VerifyMeteringStream_Call { + return &MockMessageQueue_VerifyMeteringStream_Call{Call: _e.mock.On("VerifyMeteringStream")} +} + +func (_c *MockMessageQueue_VerifyMeteringStream_Call) Run(run func()) *MockMessageQueue_VerifyMeteringStream_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockMessageQueue_VerifyMeteringStream_Call) Return(_a0 error) *MockMessageQueue_VerifyMeteringStream_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMessageQueue_VerifyMeteringStream_Call) RunAndReturn(run func() error) *MockMessageQueue_VerifyMeteringStream_Call { + _c.Call.Return(run) + return _c +} + +// VerifyStreamByName provides a mock function with given fields: streamName +func (_m *MockMessageQueue) VerifyStreamByName(streamName string) error { + ret := _m.Called(streamName) + + if len(ret) == 0 { + panic("no return value specified for VerifyStreamByName") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { + r0 = rf(streamName) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockMessageQueue_VerifyStreamByName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VerifyStreamByName' +type MockMessageQueue_VerifyStreamByName_Call struct { + *mock.Call +} + +// VerifyStreamByName is a helper method to define mock.On call +// - streamName string +func (_e *MockMessageQueue_Expecter) VerifyStreamByName(streamName interface{}) *MockMessageQueue_VerifyStreamByName_Call { + return &MockMessageQueue_VerifyStreamByName_Call{Call: _e.mock.On("VerifyStreamByName", streamName)} +} + +func (_c *MockMessageQueue_VerifyStreamByName_Call) Run(run func(streamName string)) *MockMessageQueue_VerifyStreamByName_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *MockMessageQueue_VerifyStreamByName_Call) Return(_a0 error) *MockMessageQueue_VerifyStreamByName_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockMessageQueue_VerifyStreamByName_Call) RunAndReturn(run func(string) error) *MockMessageQueue_VerifyStreamByName_Call { + _c.Call.Return(run) + return _c +} + +// NewMockMessageQueue creates a new instance of MockMessageQueue. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockMessageQueue(t interface { + mock.TestingT + Cleanup(func()) +}) *MockMessageQueue { + mock := &MockMessageQueue{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/_mocks/opencsg.com/csghub-server/user/component/mock_MemberComponent.go b/_mocks/opencsg.com/csghub-server/user/component/mock_MemberComponent.go index ba3423f0..923aca3f 100644 --- a/_mocks/opencsg.com/csghub-server/user/component/mock_MemberComponent.go +++ b/_mocks/opencsg.com/csghub-server/user/component/mock_MemberComponent.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.48.0. DO NOT EDIT. +// Code generated by mockery v2.49.1. DO NOT EDIT. package component diff --git a/api/router/api.go b/api/router/api.go index f234ed1b..670b6f19 100644 --- a/api/router/api.go +++ b/api/router/api.go @@ -704,13 +704,13 @@ func createHFRoutes(r *gin.Engine, hfdsHandler *handler.HFDatasetHandler, repoCo hfAPIGroup.GET("/whoami-v2", userHandler.UserPermission) hfModelAPIGroup := hfAPIGroup.Group("/models") { - // compitable with HF model info api, used for sdk like this: huggingface_hub.model_info(repo_id, revision) + // compatible with HF model info api, used for sdk like this: huggingface_hub.model_info(repo_id, revision) hfModelAPIGroup.GET("/:namespace/:name/revision/:ref", middleware.RepoMapping(types.ModelRepo), modelHandler.SDKModelInfo) hfModelAPIGroup.GET("/:namespace/:name", middleware.RepoMapping(types.ModelRepo), modelHandler.SDKModelInfo) } hfDSAPIGroup := hfAPIGroup.Group("/datasets") { - // compitable with HF dataset info api, used for sdk like this: huggingface_hub.dataset_info(repo_id, revision) + // compatible with HF dataset info api, used for sdk like this: huggingface_hub.dataset_info(repo_id, revision) hfDSAPIGroup.GET("/:namespace/:name/revision/:ref", middleware.RepoMapping(types.DatasetRepo), repoCommonHandler.SDKListFiles) hfDSAPIGroup.GET("/:namespace/:name", middleware.RepoMapping(types.DatasetRepo), repoCommonHandler.SDKListFiles) hfDSAPIGroup.POST("/:namespace/:name/paths-info/:ref", hfdsHandler.DatasetPathsInfo) diff --git a/builder/accounting/client.go b/builder/accounting/client.go index fd621a8b..508a410f 100644 --- a/builder/accounting/client.go +++ b/builder/accounting/client.go @@ -12,32 +12,35 @@ import ( "opencsg.com/csghub-server/common/types" ) -type AccountingClient struct { +type AccountingClient interface { + ListMeteringsByUserIDAndTime(req types.ACCT_STATEMENTS_REQ) (any, error) +} +type accountingClientImpl struct { remote *url.URL client *http.Client authToken string } -func NewAccountingClient(config *config.Config) (*AccountingClient, error) { +func NewAccountingClient(config *config.Config) (*accountingClientImpl, error) { remoteURL := fmt.Sprintf("%s:%d", config.Accounting.Host, config.Accounting.Port) parsedURL, err := url.Parse(remoteURL) if err != nil { return nil, err } - return &AccountingClient{ + return &accountingClientImpl{ remote: parsedURL, client: http.DefaultClient, authToken: config.APIToken, }, nil } -func (ac *AccountingClient) ListMeteringsByUserIDAndTime(req types.ACCT_STATEMENTS_REQ) (interface{}, error) { +func (ac *accountingClientImpl) ListMeteringsByUserIDAndTime(req types.ACCT_STATEMENTS_REQ) (any, error) { subUrlPath := fmt.Sprintf("/metering/%s/statements?current_user=%s&scene=%d&instance_name=%s&start_time=%s&end_time=%s&per=%d&page=%d", req.UserUUID, req.CurrentUser, req.Scene, req.InstanceName, url.QueryEscape(req.StartTime), url.QueryEscape(req.EndTime), req.Per, req.Page) return ac.handleResponse(ac.doRequest(http.MethodGet, subUrlPath, nil)) } // Helper method to execute the actual HTTP request and read the response. -func (ac *AccountingClient) doRequest(method, subPath string, data interface{}) (*http.Response, error) { +func (ac *accountingClientImpl) doRequest(method, subPath string, data any) (*http.Response, error) { urlPath := fmt.Sprintf("%s%s%s", ac.remote, "/api/v1/accounting", subPath) // slog.Info("call", slog.Any("urlPath", urlPath)) var buf io.Reader @@ -61,7 +64,7 @@ func (ac *AccountingClient) doRequest(method, subPath string, data interface{}) return nil, err } if resp.StatusCode < 200 || resp.StatusCode >= 300 { - var errData interface{} + var errData any err := json.NewDecoder(resp.Body).Decode(&errData) if err != nil { return nil, fmt.Errorf("unexpected http status code: %d, %w", resp.StatusCode, err) @@ -73,7 +76,7 @@ func (ac *AccountingClient) doRequest(method, subPath string, data interface{}) return resp, nil } -func (ac *AccountingClient) handleResponse(response *http.Response, err error) (interface{}, error) { +func (ac *accountingClientImpl) handleResponse(response *http.Response, err error) (any, error) { if err != nil { return nil, err } @@ -81,8 +84,8 @@ func (ac *AccountingClient) handleResponse(response *http.Response, err error) ( defer response.Body.Close() } var res struct { - Msg string `json:"msg"` - Data interface{} `json:"data"` + Msg string `json:"msg"` + Data any `json:"data"` } err = json.NewDecoder(response.Body).Decode(&res) if err != nil { diff --git a/builder/deploy/scheduler/builder_runner.go b/builder/deploy/scheduler/builder_runner.go index 55cad33f..05ed2af4 100644 --- a/builder/deploy/scheduler/builder_runner.go +++ b/builder/deploy/scheduler/builder_runner.go @@ -138,7 +138,7 @@ func (t *BuilderRunner) Run(ctx context.Context) error { func (t *BuilderRunner) buildInProgress() { t.task.Status = buildInProgress t.task.Message = "build in progress" - // change to buidling status + // change to building status t.task.Deploy.Status = common.Building ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -150,7 +150,7 @@ func (t *BuilderRunner) buildInProgress() { func (t *BuilderRunner) buildSuccess(resp imagebuilder.StatusResponse) { t.task.Status = buildSucceed t.task.Message = "build succeeded" - // change to buidling status + // change to building status t.task.Deploy.Status = common.BuildSuccess t.task.Deploy.ImageID = resp.ImageID ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) @@ -163,7 +163,7 @@ func (t *BuilderRunner) buildSuccess(resp imagebuilder.StatusResponse) { func (t *BuilderRunner) buildFailed() { t.task.Status = buildFailed t.task.Message = "build failed" - // change to buidling status + // change to building status t.task.Deploy.Status = common.BuildFailed ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() diff --git a/builder/deploy/scheduler/deploy_runner.go b/builder/deploy/scheduler/deploy_runner.go index be12529d..839fcb29 100644 --- a/builder/deploy/scheduler/deploy_runner.go +++ b/builder/deploy/scheduler/deploy_runner.go @@ -145,7 +145,7 @@ func (t *DeployRunner) WatchID() int64 { return t.task.ID } func (t *DeployRunner) deployInProgress(svcName string) { t.task.Status = deploying t.task.Message = "deploy in progress" - // change to buidling status + // change to building status t.task.Deploy.Status = common.Deploying if len(svcName) > 0 { t.task.Deploy.SvcName = svcName @@ -160,7 +160,7 @@ func (t *DeployRunner) deployInProgress(svcName string) { func (t *DeployRunner) deploySuccess() { t.task.Status = deployStartUp t.task.Message = "deploy succeeded, wati for startup" - // change to buidling status + // change to building status t.task.Deploy.Status = common.Startup ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -172,7 +172,7 @@ func (t *DeployRunner) deploySuccess() { func (t *DeployRunner) deployFailed(msg string) { t.task.Status = deployFailed t.task.Message = msg - // change to buidling status + // change to building status t.task.Deploy.Status = common.DeployFailed ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -184,7 +184,7 @@ func (t *DeployRunner) deployFailed(msg string) { func (t *DeployRunner) running(endpoint string) { t.task.Status = deployRunning t.task.Message = "running" - // change to buidling status + // change to building status t.task.Deploy.Status = common.Running t.task.Deploy.Endpoint = endpoint ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) @@ -197,7 +197,7 @@ func (t *DeployRunner) running(endpoint string) { func (t *DeployRunner) runtimeError(msg string) { t.task.Status = deployRunTimeError t.task.Message = msg - // change to buidling status + // change to building status t.task.Deploy.Status = common.RunTimeError ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() diff --git a/builder/git/membership/gitea/member.go b/builder/git/membership/gitea/member.go index f642d1f2..268502d5 100644 --- a/builder/git/membership/gitea/member.go +++ b/builder/git/membership/gitea/member.go @@ -86,7 +86,7 @@ func (c *Client) addMember(ctx context.Context, org, member string, role members } return err } - // unkown server error happend + // unknown server error happened slog.ErrorContext(ctx, "fail to get team member from gitea", slog.Any("err", err)) return err } diff --git a/builder/inference/llm_infer.go b/builder/inference/llm_infer.go index 3047b5a1..ba01774d 100644 --- a/builder/inference/llm_infer.go +++ b/builder/inference/llm_infer.go @@ -102,6 +102,7 @@ func (c *llmInferClient) ListServing() (map[uint64]ModelInfo, error) { slog.Error("fail to call list serving api", slog.Any("err", err)) return c.modelInfos, fmt.Errorf("fail to call list serving api,%w", err) } + defer resp.Body.Close() llmInfos := make(map[string]LlmModelInfo) err = json.NewDecoder(resp.Body).Decode(&llmInfos) if err != nil { diff --git a/builder/multisync/client.go b/builder/multisync/client.go index 8bec9cc4..f16093cf 100644 --- a/builder/multisync/client.go +++ b/builder/multisync/client.go @@ -42,6 +42,7 @@ func (c *commonClient) Latest(ctx context.Context, currentVersion int64) (types. return types.SyncVersionResponse{}, fmt.Errorf("failed to get latest version from endpoint %s, param cur:%d, cause: %w", c.endpoint, currentVersion, err) } + defer resp.Body.Close() if resp.StatusCode != http.StatusOK { var data bytes.Buffer @@ -67,6 +68,7 @@ func (c *commonClient) ModelInfo(ctx context.Context, v types.SyncVersion) (*typ return nil, fmt.Errorf("failed to get model info from endpoint %s, repo path:%s, cause: %w", c.endpoint, v.RepoPath, err) } + defer resp.Body.Close() if resp.StatusCode != 200 { return nil, fmt.Errorf("failed to get model info from endpoint %s, repo path:%s, status code: %d", c.endpoint, v.RepoPath, resp.StatusCode) @@ -89,6 +91,7 @@ func (c *commonClient) DatasetInfo(ctx context.Context, v types.SyncVersion) (*t return nil, fmt.Errorf("failed to get dataset info from endpoint %s, repo path:%s, cause: %w", c.endpoint, v.RepoPath, err) } + defer resp.Body.Close() if resp.StatusCode != 200 { return nil, fmt.Errorf("failed to get dataset info from endpoint %s, repo path:%s, status code: %d", c.endpoint, v.RepoPath, resp.StatusCode) @@ -111,6 +114,7 @@ func (c *commonClient) ReadMeData(ctx context.Context, v types.SyncVersion) (str return "", fmt.Errorf("failed to get readme data endpoint %s, repo path:%s, cause: %w", c.endpoint, v.RepoPath, err) } + defer resp.Body.Close() if resp.StatusCode != 200 { return "", fmt.Errorf("failed to get readme data from endpoint %s, repo path:%s, status code: %d", c.endpoint, v.RepoPath, resp.StatusCode) @@ -133,6 +137,7 @@ func (c *commonClient) FileList(ctx context.Context, v types.SyncVersion) ([]typ return nil, fmt.Errorf("failed to get readme data endpoint %s, repo path:%s, cause: %w", c.endpoint, v.RepoPath, err) } + defer resp.Body.Close() if resp.StatusCode != 200 { return nil, fmt.Errorf("failed to get readme data from endpoint %s, repo path:%s, status code: %d", c.endpoint, v.RepoPath, resp.StatusCode) diff --git a/builder/rpc/http_client.go b/builder/rpc/http_client.go index 3d40e4cd..52acc53a 100644 --- a/builder/rpc/http_client.go +++ b/builder/rpc/http_client.go @@ -35,6 +35,7 @@ func (c *HttpClient) Get(ctx context.Context, path string, outObj interface{}) e if err != nil { return fmt.Errorf("failed to do http request, path:%s, err:%w", path, err) } + defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return fmt.Errorf("failed to get response, path:%s, status:%d", path, resp.StatusCode) } @@ -59,6 +60,7 @@ func (c *HttpClient) Post(ctx context.Context, path string, data interface{}, ou if err != nil { return fmt.Errorf("failed to do http request, path:%s, err:%w", path, err) } + defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return fmt.Errorf("failed to get response, path:%s, status:%d", path, resp.StatusCode) } diff --git a/builder/store/database/common.go b/builder/store/database/common.go index 7d1a0d29..923d3256 100644 --- a/builder/store/database/common.go +++ b/builder/store/database/common.go @@ -53,7 +53,7 @@ func assertAffectedXRows(X int64, result sql.Result, err error) error { affected, err := result.RowsAffected() if err != nil { - err = fmt.Errorf("retriving affected row count: %w", err) + err = fmt.Errorf("retrieving affected row count: %w", err) return err } if affected != X { diff --git a/builder/store/database/lfs.go b/builder/store/database/lfs.go index 5b2aedc4..09590d28 100644 --- a/builder/store/database/lfs.go +++ b/builder/store/database/lfs.go @@ -4,6 +4,6 @@ type LfsFile struct { ID int64 `bun:",pk,autoincrement" json:"id"` RepositoryID int64 `bun:",notnull" json:"repository_id"` Repository *Repository `bun:"rel:belongs-to,join:repository_id=id"` - OriginPath string `bun:",notnull" json:"orgin_path"` + OriginPath string `bun:",notnull" json:"origin_path"` times } diff --git a/builder/store/database/runtime_architecture.go b/builder/store/database/runtime_architecture.go index 535e7901..b082a978 100644 --- a/builder/store/database/runtime_architecture.go +++ b/builder/store/database/runtime_architecture.go @@ -61,7 +61,7 @@ func (ra *runtimeArchitecturesStoreImpl) DeleteByRuntimeIDAndArchName(ctx contex var arch RuntimeArchitecture _, err := ra.db.Core.NewDelete().Model(&arch).Where("runtime_framework_id = ? and architecture_name = ?", id, archName).Exec(ctx) if err != nil { - return fmt.Errorf("deleteing runtime architecture in the db failed, error:%w", err) + return fmt.Errorf("deleting runtime architecture in the db failed, error:%w", err) } return nil } diff --git a/builder/store/s3/minio.go b/builder/store/s3/minio.go index a630bffd..265649cf 100644 --- a/builder/store/s3/minio.go +++ b/builder/store/s3/minio.go @@ -3,6 +3,7 @@ package s3 import ( "context" "fmt" + "io" "log/slog" "net/url" "time" @@ -12,8 +13,8 @@ import ( "opencsg.com/csghub-server/common/config" ) -func NewMinio(cfg *config.Config) (*Client, error) { - minioClient, err := minio.New(cfg.S3.Endpoint, &minio.Options{ +func NewMinio(cfg *config.Config) (Client, error) { + mClient, err := minio.New(cfg.S3.Endpoint, &minio.Options{ Creds: credentials.NewStaticV4(cfg.S3.AccessKeyID, cfg.S3.AccessKeySecret, ""), Secure: cfg.S3.EnableSSL, BucketLookup: minio.BucketLookupAuto, @@ -22,8 +23,8 @@ func NewMinio(cfg *config.Config) (*Client, error) { if err != nil { return nil, fmt.Errorf("failed to init s3 client, error:%w", err) } - client := &Client{ - Client: minioClient, + client := &minioClient{ + Client: mClient, } if len(cfg.S3.InternalEndpoint) > 0 { minioClientInternal, err := minio.New(cfg.S3.InternalEndpoint, &minio.Options{ @@ -40,13 +41,23 @@ func NewMinio(cfg *config.Config) (*Client, error) { return client, nil } -type Client struct { +type Client interface { + PresignedGetObject(ctx context.Context, bucketName, objectName string, expires time.Duration, reqParams url.Values) (*url.URL, error) + PutObject(ctx context.Context, bucketName, objectName string, reader io.Reader, objectSize int64, + opts minio.PutObjectOptions, + ) (info minio.UploadInfo, err error) + StatObject(ctx context.Context, bucketName, objectName string, opts minio.StatObjectOptions) (minio.ObjectInfo, error) + RemoveObject(ctx context.Context, bucketName, objectName string, opts minio.RemoveObjectOptions) error + PresignedPutObject(ctx context.Context, bucketName, objectName string, expires time.Duration) (u *url.URL, err error) +} + +type minioClient struct { *minio.Client internalClient *minio.Client } // PresignedGetObject is a wrapper around minio.Client.PresignedGetObject that adds some extra customization. -func (c *Client) PresignedGetObject(ctx context.Context, bucketName, objectName string, expires time.Duration, reqParams url.Values) (*url.URL, error) { +func (c *minioClient) PresignedGetObject(ctx context.Context, bucketName, objectName string, expires time.Duration, reqParams url.Values) (*url.URL, error) { if c.useInternalClient(ctx) && c.internalClient != nil { slog.Info("use internal s3 client for presigned get object", slog.String("bucket_name", bucketName), slog.String("object_name", objectName)) return c.internalClient.PresignedGetObject(ctx, bucketName, objectName, expires, reqParams) @@ -54,7 +65,7 @@ func (c *Client) PresignedGetObject(ctx context.Context, bucketName, objectName return c.Client.PresignedGetObject(ctx, bucketName, objectName, expires, reqParams) } -func (c *Client) useInternalClient(ctx context.Context) bool { +func (c *minioClient) useInternalClient(ctx context.Context) bool { v, success := ctx.Value("X-OPENCSG-S3-Internal").(bool) if !success { return false diff --git a/builder/store/s3/minio_test.go b/builder/store/s3/minio_test.go index 9be3f3cc..bb24a5d9 100644 --- a/builder/store/s3/minio_test.go +++ b/builder/store/s3/minio_test.go @@ -7,7 +7,7 @@ import ( // test for useInternalClient func Test_useInternalClient(t *testing.T) { - c := &Client{} + c := &minioClient{} ctx := context.Background() if c.useInternalClient(ctx) != false { t.Errorf("should not use internal s3 client if context not defined") diff --git a/cmd/csghub-server/cmd/cron/gen_telemetry.go b/cmd/csghub-server/cmd/cron/gen_telemetry.go index 52ba9b45..f75243b7 100644 --- a/cmd/csghub-server/cmd/cron/gen_telemetry.go +++ b/cmd/csghub-server/cmd/cron/gen_telemetry.go @@ -108,6 +108,7 @@ func genTelemetry(config *config.Config) func(ctx context.Context) error { if err != nil { return fmt.Errorf("failed to report usage data, %w", err) } + defer resp.Body.Close() if resp.StatusCode != http.StatusOK { var respData bytes.Buffer _, err = io.Copy(&respData, resp.Body) diff --git a/cmd/csghub-server/cmd/git/generate_lfs_meta_objects.go b/cmd/csghub-server/cmd/git/generate_lfs_meta_objects.go index f5b7b5ff..d57e4c82 100644 --- a/cmd/csghub-server/cmd/git/generate_lfs_meta_objects.go +++ b/cmd/csghub-server/cmd/git/generate_lfs_meta_objects.go @@ -93,7 +93,7 @@ var generateLfsMetaObjectsCmd = &cobra.Command{ }, } -func fetchAllPointersForRepo(config *config.Config, gitServer gitserver.GitServer, s3Client *s3.Client, lfsMetaObjectStore database.LfsMetaObjectStore, repo database.Repository) error { +func fetchAllPointersForRepo(config *config.Config, gitServer gitserver.GitServer, s3Client s3.Client, lfsMetaObjectStore database.LfsMetaObjectStore, repo database.Repository) error { namespace := strings.Split(repo.Path, "/")[0] name := strings.Split(repo.Path, "/")[1] ref := repo.DefaultBranch @@ -123,7 +123,7 @@ func fetchAllPointersForRepo(config *config.Config, gitServer gitserver.GitServe return nil } -func checkAndUpdateLfsMetaObjects(config *config.Config, s3Client *s3.Client, lfsMetaObjectStore database.LfsMetaObjectStore, repo database.Repository, pointer *types.Pointer) { +func checkAndUpdateLfsMetaObjects(config *config.Config, s3Client s3.Client, lfsMetaObjectStore database.LfsMetaObjectStore, repo database.Repository, pointer *types.Pointer) { var exists bool ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() diff --git a/common/tests/stores.go b/common/tests/stores.go index c445d1a8..46380274 100644 --- a/common/tests/stores.go +++ b/common/tests/stores.go @@ -1,41 +1,75 @@ package tests import ( - "testing" - + "github.com/stretchr/testify/mock" mockdb "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/store/database" "opencsg.com/csghub-server/builder/store/database" ) type MockStores struct { - User database.UserStore - UserLikes database.UserLikesStore - Repo database.RepoStore - Model database.ModelStore - SpaceResource database.SpaceResourceStore - Tag database.TagStore - Dataset database.DatasetStore - PromptConversation database.PromptConversationStore - PromptPrefix database.PromptPrefixStore - LLMConfig database.LLMConfigStore - Prompt database.PromptStore - Namespace database.NamespaceStore -} - -func NewMockStores(t *testing.T) *MockStores { + User database.UserStore + UserLikes database.UserLikesStore + Repo database.RepoStore + RepoRelation database.RepoRelationsStore + Model database.ModelStore + SpaceResource database.SpaceResourceStore + Tag database.TagStore + Dataset database.DatasetStore + PromptConversation database.PromptConversationStore + PromptPrefix database.PromptPrefixStore + LLMConfig database.LLMConfigStore + Prompt database.PromptStore + Namespace database.NamespaceStore + LfsMetaObject database.LfsMetaObjectStore + Mirror database.MirrorStore + MirrorSource database.MirrorSourceStore + AccessToken database.AccessTokenStore + SyncVersion database.SyncVersionStore + SyncClientSetting database.SyncClientSettingStore + RuntimeFramework database.RuntimeFrameworksStore + DeployTask database.DeployTaskStore + ClusterInfo database.ClusterInfoStore + Code database.CodeStore + Collection database.CollectionStore + Space database.SpaceStore + SpaceSdk database.SpaceSdkStore + Recom database.RecomStore + RepoRuntimeFramework database.RepositoriesRuntimeFrameworkStore +} + +func NewMockStores(t interface { + Cleanup(func()) + mock.TestingT +}) *MockStores { return &MockStores{ - User: mockdb.NewMockUserStore(t), - UserLikes: mockdb.NewMockUserLikesStore(t), - Repo: mockdb.NewMockRepoStore(t), - Model: mockdb.NewMockModelStore(t), - SpaceResource: mockdb.NewMockSpaceResourceStore(t), - Tag: mockdb.NewMockTagStore(t), - Dataset: mockdb.NewMockDatasetStore(t), - PromptConversation: mockdb.NewMockPromptConversationStore(t), - PromptPrefix: mockdb.NewMockPromptPrefixStore(t), - LLMConfig: mockdb.NewMockLLMConfigStore(t), - Prompt: mockdb.NewMockPromptStore(t), - Namespace: mockdb.NewMockNamespaceStore(t), + User: mockdb.NewMockUserStore(t), + UserLikes: mockdb.NewMockUserLikesStore(t), + Repo: mockdb.NewMockRepoStore(t), + RepoRelation: mockdb.NewMockRepoRelationsStore(t), + Model: mockdb.NewMockModelStore(t), + SpaceResource: mockdb.NewMockSpaceResourceStore(t), + Tag: mockdb.NewMockTagStore(t), + Dataset: mockdb.NewMockDatasetStore(t), + PromptConversation: mockdb.NewMockPromptConversationStore(t), + PromptPrefix: mockdb.NewMockPromptPrefixStore(t), + LLMConfig: mockdb.NewMockLLMConfigStore(t), + Prompt: mockdb.NewMockPromptStore(t), + Namespace: mockdb.NewMockNamespaceStore(t), + LfsMetaObject: mockdb.NewMockLfsMetaObjectStore(t), + Mirror: mockdb.NewMockMirrorStore(t), + MirrorSource: mockdb.NewMockMirrorSourceStore(t), + AccessToken: mockdb.NewMockAccessTokenStore(t), + SyncVersion: mockdb.NewMockSyncVersionStore(t), + SyncClientSetting: mockdb.NewMockSyncClientSettingStore(t), + RuntimeFramework: mockdb.NewMockRuntimeFrameworksStore(t), + DeployTask: mockdb.NewMockDeployTaskStore(t), + ClusterInfo: mockdb.NewMockClusterInfoStore(t), + Code: mockdb.NewMockCodeStore(t), + Collection: mockdb.NewMockCollectionStore(t), + Space: mockdb.NewMockSpaceStore(t), + SpaceSdk: mockdb.NewMockSpaceSdkStore(t), + Recom: mockdb.NewMockRecomStore(t), + RepoRuntimeFramework: mockdb.NewMockRepositoriesRuntimeFrameworkStore(t), } } @@ -51,6 +85,10 @@ func (s *MockStores) RepoMock() *mockdb.MockRepoStore { return s.Repo.(*mockdb.MockRepoStore) } +func (s *MockStores) RepoRelationMock() *mockdb.MockRepoRelationsStore { + return s.RepoRelation.(*mockdb.MockRepoRelationsStore) +} + func (s *MockStores) ModelMock() *mockdb.MockModelStore { return s.Model.(*mockdb.MockModelStore) } @@ -86,3 +124,63 @@ func (s *MockStores) PromptMock() *mockdb.MockPromptStore { func (s *MockStores) NamespaceMock() *mockdb.MockNamespaceStore { return s.Namespace.(*mockdb.MockNamespaceStore) } + +func (s *MockStores) LfsMetaObjectMock() *mockdb.MockLfsMetaObjectStore { + return s.LfsMetaObject.(*mockdb.MockLfsMetaObjectStore) +} + +func (s *MockStores) MirrorMock() *mockdb.MockMirrorStore { + return s.Mirror.(*mockdb.MockMirrorStore) +} + +func (s *MockStores) MirrorSourceMock() *mockdb.MockMirrorSourceStore { + return s.MirrorSource.(*mockdb.MockMirrorSourceStore) +} + +func (s *MockStores) AccessTokenMock() *mockdb.MockAccessTokenStore { + return s.AccessToken.(*mockdb.MockAccessTokenStore) +} + +func (s *MockStores) SyncVersionMock() *mockdb.MockSyncVersionStore { + return s.SyncVersion.(*mockdb.MockSyncVersionStore) +} + +func (s *MockStores) SyncClientSettingMock() *mockdb.MockSyncClientSettingStore { + return s.SyncClientSetting.(*mockdb.MockSyncClientSettingStore) +} + +func (s *MockStores) RuntimeFrameworkMock() *mockdb.MockRuntimeFrameworksStore { + return s.RuntimeFramework.(*mockdb.MockRuntimeFrameworksStore) +} + +func (s *MockStores) DeployTaskMock() *mockdb.MockDeployTaskStore { + return s.DeployTask.(*mockdb.MockDeployTaskStore) +} + +func (s *MockStores) ClusterInfoMock() *mockdb.MockClusterInfoStore { + return s.ClusterInfo.(*mockdb.MockClusterInfoStore) +} + +func (s *MockStores) CodeMock() *mockdb.MockCodeStore { + return s.Code.(*mockdb.MockCodeStore) +} + +func (s *MockStores) CollectionMock() *mockdb.MockCollectionStore { + return s.Collection.(*mockdb.MockCollectionStore) +} + +func (s *MockStores) SpaceMock() *mockdb.MockSpaceStore { + return s.Space.(*mockdb.MockSpaceStore) +} + +func (s *MockStores) SpaceSdkMock() *mockdb.MockSpaceSdkStore { + return s.SpaceSdk.(*mockdb.MockSpaceSdkStore) +} + +func (s *MockStores) RecomMock() *mockdb.MockRecomStore { + return s.Recom.(*mockdb.MockRecomStore) +} + +func (s *MockStores) RepoRuntimeFrameworkMock() *mockdb.MockRepositoriesRuntimeFrameworkStore { + return s.RepoRuntimeFramework.(*mockdb.MockRepositoriesRuntimeFrameworkStore) +} diff --git a/common/types/user.go b/common/types/user.go index d2b3d903..5c4b8b0f 100644 --- a/common/types/user.go +++ b/common/types/user.go @@ -171,7 +171,7 @@ type UserLikesRequest struct { CurrentUser string `json:"current_user"` } -/* for HF compitable apis */ +/* for HF compatible apis */ type WhoamiResponse struct { Name string `json:"name"` Email string `json:"email"` diff --git a/component/accounting.go b/component/accounting.go index e03d2c46..172393d5 100644 --- a/component/accounting.go +++ b/component/accounting.go @@ -12,9 +12,9 @@ import ( ) type accountingComponentImpl struct { - acctClient *accounting.AccountingClient - user database.UserStore - deploy database.DeployTaskStore + acctountingClient accounting.AccountingClient + userStore database.UserStore + deployTaskStore database.DeployTaskStore } type AccountingComponent interface { @@ -27,19 +27,19 @@ func NewAccountingComponent(config *config.Config) (AccountingComponent, error) return nil, err } return &accountingComponentImpl{ - acctClient: c, - user: database.NewUserStore(), - deploy: database.NewDeployTaskStore(), + acctountingClient: c, + userStore: database.NewUserStore(), + deployTaskStore: database.NewDeployTaskStore(), }, nil } func (ac *accountingComponentImpl) ListMeteringsByUserIDAndTime(ctx context.Context, req types.ACCT_STATEMENTS_REQ) (interface{}, error) { - user, err := ac.user.FindByUsername(ctx, req.CurrentUser) + user, err := ac.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return nil, fmt.Errorf("user does not exist, %w", err) } if user.UUID != req.UserUUID { return nil, errors.New("invalid user") } - return ac.acctClient.ListMeteringsByUserIDAndTime(req) + return ac.acctountingClient.ListMeteringsByUserIDAndTime(req) } diff --git a/component/accounting_test.go b/component/accounting_test.go new file mode 100644 index 00000000..043e3712 --- /dev/null +++ b/component/accounting_test.go @@ -0,0 +1,29 @@ +package component + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/types" +) + +func TestAccountingComponent_ListMeteringsByUserIDAndTime(t *testing.T) { + ctx := context.TODO() + ac := initializeTestAccountingComponent(ctx, t) + + req := types.ACCT_STATEMENTS_REQ{ + CurrentUser: "user", + UserUUID: "uuid", + } + ac.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ + UUID: "uuid", + }, nil) + ac.mocks.accountingClient.EXPECT().ListMeteringsByUserIDAndTime(req).Return( + "", nil, + ) + resp, err := ac.ListMeteringsByUserIDAndTime(ctx, req) + require.Nil(t, err) + require.Equal(t, "", resp) +} diff --git a/component/code.go b/component/code.go index 653d4faf..d2cf14af 100644 --- a/component/code.go +++ b/component/code.go @@ -299,7 +299,7 @@ func (c *codeComponentImpl) Show(ctx context.Context, namespace, name, currentUs }) } - likeExists, err := c.uls.IsExist(ctx, currentUser, code.Repository.ID) + likeExists, err := c.userLikesStore.IsExist(ctx, currentUser, code.Repository.ID) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user likes,error:%w", err) return nil, newError @@ -379,7 +379,7 @@ func (c *codeComponentImpl) OrgCodes(ctx context.Context, req *types.OrgCodesReq r := membership.RoleUnknown if req.CurrentUser != "" { r, err = c.userSvcClient.GetMemberRole(ctx, req.Namespace, req.CurrentUser) - // log error, and treat user as unkown role in org + // log error, and treat user as unknown role in org if err != nil { slog.Error("faild to get member role", slog.String("org", req.Namespace), slog.String("user", req.CurrentUser), diff --git a/component/collection.go b/component/collection.go index 47259288..f48d48dc 100644 --- a/component/collection.go +++ b/component/collection.go @@ -282,7 +282,7 @@ func (c *collectionComponentImpl) OrgCollections(ctx context.Context, req *types r := membership.RoleUnknown if req.CurrentUser != "" { r, err = c.userSvcClient.GetMemberRole(ctx, req.Namespace, req.CurrentUser) - // log error, and treat user as unkown role in org + // log error, and treat user as unknown role in org if err != nil { slog.Error("faild to get member role", slog.String("org", req.Namespace), slog.String("user", req.CurrentUser), diff --git a/component/dataset.go b/component/dataset.go index a8e7753d..44b224ed 100644 --- a/component/dataset.go +++ b/component/dataset.go @@ -120,12 +120,12 @@ func (c *datasetComponentImpl) Create(ctx context.Context, req *types.CreateData tags []types.RepoTag ) - namespace, err := c.namespace.FindByPath(ctx, req.Namespace) + namespace, err := c.namespaceStore.FindByPath(ctx, req.Namespace) if err != nil { return nil, errors.New("namespace does not exist") } - user, err := c.user.FindByUsername(ctx, req.Username) + user, err := c.userStore.FindByUsername(ctx, req.Username) if err != nil { return nil, errors.New("user does not exist") } @@ -417,7 +417,7 @@ func (c *datasetComponentImpl) Show(ctx context.Context, namespace, name, curren }) } - likeExists, err := c.uls.IsExist(ctx, currentUser, dataset.Repository.ID) + likeExists, err := c.userLikesStore.IsExist(ctx, currentUser, dataset.Repository.ID) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user likes,error:%w", err) return nil, newError @@ -499,7 +499,7 @@ func (c *datasetComponentImpl) OrgDatasets(ctx context.Context, req *types.OrgDa r := membership.RoleUnknown if req.CurrentUser != "" { r, err = c.userSvcClient.GetMemberRole(ctx, req.Namespace, req.CurrentUser) - // log error, and treat user as unkown role in org + // log error, and treat user as unknown role in org if err != nil { slog.Error("faild to get member role", slog.String("org", req.Namespace), slog.String("user", req.CurrentUser), diff --git a/component/git_http.go b/component/git_http.go index b8dbc112..d1eb5305 100644 --- a/component/git_http.go +++ b/component/git_http.go @@ -28,7 +28,7 @@ import ( type gitHTTPComponentImpl struct { git gitserver.GitServer config *config.Config - s3Client *s3.Client + s3Client s3.Client lfsMetaObjectStore database.LfsMetaObjectStore lfsLockStore database.LfsLockStore repo database.RepoStore @@ -145,7 +145,7 @@ func (c *gitHTTPComponentImpl) GitReceivePack(ctx context.Context, req types.Git return fmt.Errorf("failed to find repo, error: %w", err) } - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return ErrUnauthorized } @@ -456,7 +456,7 @@ func (c *gitHTTPComponentImpl) CreateLock(ctx context.Context, req types.LfsLock return nil, fmt.Errorf("failed to find repo, error: %w", err) } - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return nil, ErrUnauthorized } @@ -497,7 +497,7 @@ func (c *gitHTTPComponentImpl) ListLocks(ctx context.Context, req types.ListLFSL return nil, fmt.Errorf("failed to find repo, error: %w", err) } - _, err = c.user.FindByUsername(ctx, req.CurrentUser) + _, err = c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return nil, ErrUnauthorized } @@ -562,7 +562,7 @@ func (c *gitHTTPComponentImpl) UnLock(ctx context.Context, req types.UnlockLFSRe return nil, fmt.Errorf("failed to find repo, error: %w", err) } - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return nil, ErrUnauthorized } @@ -607,7 +607,7 @@ func (c *gitHTTPComponentImpl) VerifyLock(ctx context.Context, req types.VerifyL return nil, fmt.Errorf("failed to find repo, error: %w", err) } - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return nil, ErrUnauthorized } diff --git a/component/internal.go b/component/internal.go index 2ca87b97..d23f28ec 100644 --- a/component/internal.go +++ b/component/internal.go @@ -50,7 +50,7 @@ func (c *internalComponentImpl) Allowed(ctx context.Context) (bool, error) { } func (c *internalComponentImpl) SSHAllowed(ctx context.Context, req types.SSHAllowedReq) (*types.SSHAllowedResp, error) { - namespace, err := c.namespace.FindByPath(ctx, req.Namespace) + namespace, err := c.namespaceStore.FindByPath(ctx, req.Namespace) if err != nil { return nil, fmt.Errorf("failed to find namespace %s: %v", req.Namespace, err) } diff --git a/component/mirror.go b/component/mirror.go index 399d2f43..04f1cec6 100644 --- a/component/mirror.go +++ b/component/mirror.go @@ -27,7 +27,7 @@ type mirrorComponentImpl struct { saas bool repoComp RepoComponent git gitserver.GitServer - s3Client *s3.Client + s3Client s3.Client lfsBucket string modelStore database.ModelStore datasetStore database.DatasetStore @@ -39,7 +39,7 @@ type mirrorComponentImpl struct { lfsMetaObjectStore database.LfsMetaObjectStore userStore database.UserStore config *config.Config - mq *queue.PriorityQueue + mq queue.PriorityQueue } type MirrorComponent interface { @@ -149,13 +149,13 @@ func (c *mirrorComponentImpl) CreateMirrorRepo(ctx context.Context, req types.Cr } repo, err := c.repoStore.FindByPath(ctx, req.RepoType, namespace, name) if err != nil && !errors.Is(err, sql.ErrNoRows) { - return nil, fmt.Errorf("failed to check repo existance, error: %w", err) + return nil, fmt.Errorf("failed to check repo existence, error: %w", err) } if repo != nil { name = fmt.Sprintf("%s_%s", req.SourceNamespace, req.SourceName) repo, err = c.repoStore.FindByPath(ctx, req.RepoType, namespace, name) if err != nil && !errors.Is(err, sql.ErrNoRows) { - return nil, fmt.Errorf("failed to check repo existance, error: %w", err) + return nil, fmt.Errorf("failed to check repo existence, error: %w", err) } if repo != nil { return nil, fmt.Errorf("repo already exists,repo type:%s, source namespace: %s, source name: %s, target namespace: %s, target name: %s", diff --git a/component/model.go b/component/model.go index 1d8a738a..f62bf97e 100644 --- a/component/model.go +++ b/component/model.go @@ -10,9 +10,11 @@ import ( "strconv" "opencsg.com/csghub-server/builder/deploy" + "opencsg.com/csghub-server/builder/git" "opencsg.com/csghub-server/builder/git/gitserver" "opencsg.com/csghub-server/builder/git/membership" "opencsg.com/csghub-server/builder/inference" + "opencsg.com/csghub-server/builder/rpc" "opencsg.com/csghub-server/builder/store/database" "opencsg.com/csghub-server/common/config" "opencsg.com/csghub-server/common/types" @@ -85,45 +87,64 @@ type ModelComponent interface { } func NewModelComponent(config *config.Config) (ModelComponent, error) { - c := &modelComponentImpl{} + c := &modelComponentImpl{config: config} var err error - c.repoComponentImpl, err = NewRepoComponentImpl(config) + c.repoComponent, err = NewRepoComponent(config) if err != nil { return nil, err } - c.spaceComonent, _ = NewSpaceComponent(config) - c.ms = database.NewModelStore() - c.rs = database.NewRepoStore() - c.SS = database.NewSpaceResourceStore() - c.infer = inference.NewInferClient(config.Inference.ServerAddr) - c.us = database.NewUserStore() + c.spaceComponent, _ = NewSpaceComponent(config) + c.modelStore = database.NewModelStore() + c.repoStore = database.NewRepoStore() + c.spaceResourceStore = database.NewSpaceResourceStore() + c.inferClient = inference.NewInferClient(config.Inference.ServerAddr) + c.userStore = database.NewUserStore() + c.userLikesStore = database.NewUserLikesStore() c.deployer = deploy.NewDeployer() - c.ts = database.NewTagStore() - c.rac, err = NewRuntimeArchitectureComponent(config) + c.tagStore = database.NewTagStore() + c.runtimeArchComponent, err = NewRuntimeArchitectureComponent(config) if err != nil { return nil, err } - c.ac, err = NewAccountingComponent(config) - c.ds = database.NewDatasetStore() + c.accountingComponent, err = NewAccountingComponent(config) if err != nil { return nil, err } + c.datasetStore = database.NewDatasetStore() + c.repoRuntimeFrameworkStore = database.NewRepositoriesRuntimeFramework() + c.runtimeFrameworksStore = database.NewRuntimeFrameworksStore() + c.deployTaskStore = database.NewDeployTaskStore() + c.gitServer, err = git.NewGitServer(config) + if err != nil { + return nil, err + } + c.userSvcClient = rpc.NewUserSvcHttpClient(fmt.Sprintf("%s:%d", config.User.Host, config.User.Port), + rpc.AuthWithApiKey(config.APIToken)) + c.recomStore = database.NewRecomStore() return c, nil } type modelComponentImpl struct { - *repoComponentImpl - spaceComonent SpaceComponent - ms database.ModelStore - rs database.RepoStore - SS database.SpaceResourceStore - infer inference.Client - us database.UserStore - deployer deploy.Deployer - ac AccountingComponent - ts database.TagStore - rac RuntimeArchitectureComponent - ds database.DatasetStore + config *config.Config + repoComponent RepoComponent + spaceComponent SpaceComponent + modelStore database.ModelStore + repoStore database.RepoStore + spaceResourceStore database.SpaceResourceStore + inferClient inference.Client + userStore database.UserStore + deployer deploy.Deployer + accountingComponent AccountingComponent + tagStore database.TagStore + runtimeArchComponent RuntimeArchitectureComponent + datasetStore database.DatasetStore + recomStore database.RecomStore + gitServer gitserver.GitServer + userLikesStore database.UserLikesStore + repoRuntimeFrameworkStore database.RepositoriesRuntimeFrameworkStore + deployTaskStore database.DeployTaskStore + runtimeFrameworksStore database.RuntimeFrameworksStore + userSvcClient rpc.UserSvcClient } func (c *modelComponentImpl) Index(ctx context.Context, filter *types.RepoFilter, per, page int) ([]types.Model, int, error) { @@ -131,7 +152,7 @@ func (c *modelComponentImpl) Index(ctx context.Context, filter *types.RepoFilter err error resModels []types.Model ) - repos, total, err := c.PublicToUser(ctx, types.ModelRepo, filter.Username, filter, per, page) + repos, total, err := c.repoComponent.PublicToUser(ctx, types.ModelRepo, filter.Username, filter, per, page) if err != nil { newError := fmt.Errorf("failed to get public model repos,error:%w", err) return nil, 0, newError @@ -140,7 +161,7 @@ func (c *modelComponentImpl) Index(ctx context.Context, filter *types.RepoFilter for _, repo := range repos { repoIDs = append(repoIDs, repo.ID) } - models, err := c.ms.ByRepoIDs(ctx, repoIDs) + models, err := c.modelStore.ByRepoIDs(ctx, repoIDs) if err != nil { newError := fmt.Errorf("failed to get models by repo ids,error:%w", err) return nil, 0, newError @@ -197,7 +218,7 @@ func (c *modelComponentImpl) Create(ctx context.Context, req *types.CreateModelR nickname string tags []types.RepoTag ) - user, err := c.user.FindByUsername(ctx, req.Username) + user, err := c.userStore.FindByUsername(ctx, req.Username) if err != nil { return nil, errors.New("user does not exist") } @@ -214,7 +235,7 @@ func (c *modelComponentImpl) Create(ctx context.Context, req *types.CreateModelR req.Nickname = nickname req.RepoType = types.ModelRepo req.Readme = generateReadmeData(req.License) - _, dbRepo, err := c.CreateRepo(ctx, req.CreateRepoReq) + _, dbRepo, err := c.repoComponent.CreateRepo(ctx, req.CreateRepoReq) if err != nil { return nil, err } @@ -225,13 +246,13 @@ func (c *modelComponentImpl) Create(ctx context.Context, req *types.CreateModelR BaseModel: req.BaseModel, } - model, err := c.ms.Create(ctx, dbModel) + model, err := c.modelStore.Create(ctx, dbModel) if err != nil { return nil, fmt.Errorf("failed to create database model, cause: %w", err) } // Create README.md file - err = c.git.CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ + err = c.gitServer.CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ Username: user.Username, Email: user.Email, Message: initCommitMessage, @@ -247,7 +268,7 @@ func (c *modelComponentImpl) Create(ctx context.Context, req *types.CreateModelR } // Create .gitattributes file - err = c.git.CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ + err = c.gitServer.CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ Username: user.Username, Email: user.Email, Message: initCommitMessage, @@ -317,12 +338,12 @@ func buildCreateFileReq(p *types.CreateFileParams, repoType types.RepositoryType func (c *modelComponentImpl) Update(ctx context.Context, req *types.UpdateModelReq) (*types.Model, error) { req.RepoType = types.ModelRepo - dbRepo, err := c.UpdateRepo(ctx, req.UpdateRepoReq) + dbRepo, err := c.repoComponent.UpdateRepo(ctx, req.UpdateRepoReq) if err != nil { return nil, err } - model, err := c.ms.ByRepoID(ctx, dbRepo.ID) + model, err := c.modelStore.ByRepoID(ctx, dbRepo.ID) if err != nil { return nil, fmt.Errorf("failed to find model, error: %w", err) } @@ -330,7 +351,7 @@ func (c *modelComponentImpl) Update(ctx context.Context, req *types.UpdateModelR if req.BaseModel != nil { model.BaseModel = *req.BaseModel } - model, err = c.ms.Update(ctx, *model) + model, err = c.modelStore.Update(ctx, *model) if err != nil { return nil, fmt.Errorf("failed to update database model, error: %w", err) } @@ -353,7 +374,7 @@ func (c *modelComponentImpl) Update(ctx context.Context, req *types.UpdateModelR } func (c *modelComponentImpl) Delete(ctx context.Context, namespace, name, currentUser string) error { - model, err := c.ms.FindByPath(ctx, namespace, name) + model, err := c.modelStore.FindByPath(ctx, namespace, name) if err != nil { return fmt.Errorf("failed to find model, error: %w", err) } @@ -364,12 +385,12 @@ func (c *modelComponentImpl) Delete(ctx context.Context, namespace, name, curren Name: name, RepoType: types.ModelRepo, } - _, err = c.DeleteRepo(ctx, deleteDatabaseRepoReq) + _, err = c.repoComponent.DeleteRepo(ctx, deleteDatabaseRepoReq) if err != nil { return fmt.Errorf("failed to delete repo of model, error: %w", err) } - err = c.ms.Delete(ctx, *model) + err = c.modelStore.Delete(ctx, *model) if err != nil { return fmt.Errorf("failed to delete database model, error: %w", err) } @@ -378,12 +399,12 @@ func (c *modelComponentImpl) Delete(ctx context.Context, namespace, name, curren func (c *modelComponentImpl) Show(ctx context.Context, namespace, name, currentUser string) (*types.Model, error) { var tags []types.RepoTag - model, err := c.ms.FindByPath(ctx, namespace, name) + model, err := c.modelStore.FindByPath(ctx, namespace, name) if err != nil { return nil, fmt.Errorf("failed to find model, error: %w", err) } - permission, err := c.GetUserRepoPermission(ctx, currentUser, model.Repository) + permission, err := c.repoComponent.GetUserRepoPermission(ctx, currentUser, model.Repository) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -391,7 +412,7 @@ func (c *modelComponentImpl) Show(ctx context.Context, namespace, name, currentU return nil, ErrUnauthorized } - ns, err := c.GetNameSpaceInfo(ctx, namespace) + ns, err := c.repoComponent.GetNameSpaceInfo(ctx, namespace) if err != nil { return nil, fmt.Errorf("failed to get namespace info for model, error: %w", err) } @@ -408,7 +429,7 @@ func (c *modelComponentImpl) Show(ctx context.Context, namespace, name, currentU }) } - likeExists, err := c.uls.IsExist(ctx, currentUser, model.Repository.ID) + likeExists, err := c.userLikesStore.IsExist(ctx, currentUser, model.Repository.ID) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user likes,error:%w", err) return nil, newError @@ -447,11 +468,11 @@ func (c *modelComponentImpl) Show(ctx context.Context, namespace, name, currentU CanManage: permission.CanAdmin, Namespace: ns, } - inferences, _ := c.rrtfms.GetByRepoIDsAndType(ctx, model.Repository.ID, types.InferenceType) + inferences, _ := c.repoRuntimeFrameworkStore.GetByRepoIDsAndType(ctx, model.Repository.ID, types.InferenceType) if len(inferences) > 0 { resModel.EnableInference = true } - finetunes, _ := c.rrtfms.GetByRepoIDsAndType(ctx, model.Repository.ID, types.FinetuneType) + finetunes, _ := c.repoRuntimeFrameworkStore.GetByRepoIDsAndType(ctx, model.Repository.ID, types.FinetuneType) if len(finetunes) > 0 { resModel.EnableFinetune = true } @@ -459,22 +480,22 @@ func (c *modelComponentImpl) Show(ctx context.Context, namespace, name, currentU } func (c *modelComponentImpl) GetServerless(ctx context.Context, namespace, name, currentUser string) (*types.DeployRepo, error) { - model, err := c.ms.FindByPath(ctx, namespace, name) + model, err := c.modelStore.FindByPath(ctx, namespace, name) if err != nil { return nil, fmt.Errorf("failed to find model, error: %w", err) } - allow, _ := c.AllowReadAccessRepo(ctx, model.Repository, currentUser) + allow, _ := c.repoComponent.AllowReadAccessRepo(ctx, model.Repository, currentUser) if !allow { return nil, ErrUnauthorized } - deploy, err := c.deploy.GetServerlessDeployByRepID(ctx, model.Repository.ID) + deploy, err := c.deployTaskStore.GetServerlessDeployByRepID(ctx, model.Repository.ID) if err != nil { return nil, fmt.Errorf("failed to get serverless deployment, error: %w", err) } if deploy == nil { return nil, nil } - endpoint, _ := c.generateEndpoint(ctx, deploy) + endpoint, _ := c.repoComponent.GenerateEndpoint(ctx, deploy) resDeploy := types.DeployRepo{ DeployID: deploy.ID, @@ -498,12 +519,12 @@ func (c *modelComponentImpl) GetServerless(ctx context.Context, namespace, name, } func (c *modelComponentImpl) SDKModelInfo(ctx context.Context, namespace, name, ref, currentUser string) (*types.SDKModelInfo, error) { - model, err := c.ms.FindByPath(ctx, namespace, name) + model, err := c.modelStore.FindByPath(ctx, namespace, name) if err != nil { return nil, fmt.Errorf("failed to find model, error: %w", err) } - allow, _ := c.AllowReadAccessRepo(ctx, model.Repository, currentUser) + allow, _ := c.repoComponent.AllowReadAccessRepo(ctx, model.Repository, currentUser) if !allow { return nil, ErrUnauthorized } @@ -520,7 +541,7 @@ func (c *modelComponentImpl) SDKModelInfo(ctx context.Context, namespace, name, } } - filePaths, err := getFilePaths(namespace, name, "", types.ModelRepo, ref, c.git.GetRepoFileTree) + filePaths, err := getFilePaths(namespace, name, "", types.ModelRepo, ref, c.gitServer.GetRepoFileTree) if err != nil { return nil, fmt.Errorf("failed to get all %s files, error: %w", types.ModelRepo, err) } @@ -539,13 +560,13 @@ func (c *modelComponentImpl) SDKModelInfo(ctx context.Context, namespace, name, Ref: ref, RepoType: types.ModelRepo, } - lastCommit, err := c.git.GetRepoLastCommit(ctx, getLastCommitReq) + lastCommit, err := c.gitServer.GetRepoLastCommit(ctx, getLastCommitReq) if err != nil { slog.Error("failed to get last commit", slog.String("namespace", namespace), slog.String("name", name), slog.String("ref", ref), slog.Any("error", err)) return nil, fmt.Errorf("failed to get last commit, error: %w", err) } - relatedRepos, _ := c.RelatedRepos(ctx, model.RepositoryID, currentUser) + relatedRepos, _ := c.repoComponent.RelatedRepos(ctx, model.RepositoryID, currentUser) relatedSpaces := relatedRepos[types.SpaceRepo] spaceNames := make([]string, len(relatedSpaces)) for idx, s := range relatedSpaces { @@ -585,12 +606,12 @@ func (c *modelComponentImpl) SDKModelInfo(ctx context.Context, namespace, name, } func (c *modelComponentImpl) Relations(ctx context.Context, namespace, name, currentUser string) (*types.Relations, error) { - model, err := c.ms.FindByPath(ctx, namespace, name) + model, err := c.modelStore.FindByPath(ctx, namespace, name) if err != nil { return nil, fmt.Errorf("failed to find model, error: %w", err) } - allow, _ := c.AllowReadAccessRepo(ctx, model.Repository, currentUser) + allow, _ := c.repoComponent.AllowReadAccessRepo(ctx, model.Repository, currentUser) if !allow { return nil, ErrUnauthorized } @@ -599,7 +620,7 @@ func (c *modelComponentImpl) Relations(ctx context.Context, namespace, name, cur } func (c *modelComponentImpl) SetRelationDatasets(ctx context.Context, req types.RelationDatasets) error { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return fmt.Errorf("user does not exist, %w", err) } @@ -608,7 +629,7 @@ func (c *modelComponentImpl) SetRelationDatasets(ctx context.Context, req types. return fmt.Errorf("only admin is allowed to set dataset for model") } - _, err = c.repo.FindByPath(ctx, types.ModelRepo, req.Namespace, req.Name) + _, err = c.repoStore.FindByPath(ctx, types.ModelRepo, req.Namespace, req.Name) if err != nil { return fmt.Errorf("failed to find model, error: %w", err) } @@ -621,7 +642,7 @@ func (c *modelComponentImpl) SetRelationDatasets(ctx context.Context, req types. RepoType: types.ModelRepo, } - metaMap, splits, err := GetMetaMapFromReadMe(c.git, getFileContentReq) + metaMap, splits, err := GetMetaMapFromReadMe(c.gitServer, getFileContentReq) if err != nil { return fmt.Errorf("failed parse meta from readme, cause: %w", err) } @@ -642,7 +663,7 @@ func (c *modelComponentImpl) SetRelationDatasets(ctx context.Context, req types. readmeReq.Email = user.Email readmeReq.Content = base64.StdEncoding.EncodeToString([]byte(output)) - err = c.git.UpdateRepoFile(&readmeReq) + err = c.gitServer.UpdateRepoFile(&readmeReq) if err != nil { return fmt.Errorf("failed to set dataset tag to %s file, cause: %w", readmeReq.FilePath, err) } @@ -651,7 +672,7 @@ func (c *modelComponentImpl) SetRelationDatasets(ctx context.Context, req types. } func (c *modelComponentImpl) AddRelationDataset(ctx context.Context, req types.RelationDataset) error { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return fmt.Errorf("user does not exist, %w", err) } @@ -660,7 +681,7 @@ func (c *modelComponentImpl) AddRelationDataset(ctx context.Context, req types.R return fmt.Errorf("only admin was allowed to set dataset for model") } - _, err = c.repo.FindByPath(ctx, types.ModelRepo, req.Namespace, req.Name) + _, err = c.repoStore.FindByPath(ctx, types.ModelRepo, req.Namespace, req.Name) if err != nil { return fmt.Errorf("failed to find model, error: %w", err) } @@ -672,7 +693,7 @@ func (c *modelComponentImpl) AddRelationDataset(ctx context.Context, req types.R Path: REPOCARD_FILENAME, RepoType: types.ModelRepo, } - metaMap, splits, err := GetMetaMapFromReadMe(c.git, getFileContentReq) + metaMap, splits, err := GetMetaMapFromReadMe(c.gitServer, getFileContentReq) if err != nil { return fmt.Errorf("failed parse meta from readme, cause: %w", err) } @@ -699,7 +720,7 @@ func (c *modelComponentImpl) AddRelationDataset(ctx context.Context, req types.R readmeReq.Email = user.Email readmeReq.Content = base64.StdEncoding.EncodeToString([]byte(output)) - err = c.git.UpdateRepoFile(&readmeReq) + err = c.gitServer.UpdateRepoFile(&readmeReq) if err != nil { return fmt.Errorf("failed to add dataset tag to %s file, cause: %w", readmeReq.FilePath, err) } @@ -708,7 +729,7 @@ func (c *modelComponentImpl) AddRelationDataset(ctx context.Context, req types.R } func (c *modelComponentImpl) DelRelationDataset(ctx context.Context, req types.RelationDataset) error { - user, err := c.user.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { return fmt.Errorf("user does not exist, %w", err) } @@ -717,7 +738,7 @@ func (c *modelComponentImpl) DelRelationDataset(ctx context.Context, req types.R return fmt.Errorf("only admin was allowed to delete dataset for model") } - _, err = c.repo.FindByPath(ctx, types.ModelRepo, req.Namespace, req.Name) + _, err = c.repoStore.FindByPath(ctx, types.ModelRepo, req.Namespace, req.Name) if err != nil { return fmt.Errorf("failed to find model, error: %w", err) } @@ -729,7 +750,7 @@ func (c *modelComponentImpl) DelRelationDataset(ctx context.Context, req types.R Path: REPOCARD_FILENAME, RepoType: types.ModelRepo, } - metaMap, splits, err := GetMetaMapFromReadMe(c.git, getFileContentReq) + metaMap, splits, err := GetMetaMapFromReadMe(c.gitServer, getFileContentReq) if err != nil { return fmt.Errorf("failed parse meta from readme, cause: %w", err) } @@ -761,7 +782,8 @@ func (c *modelComponentImpl) DelRelationDataset(ctx context.Context, req types.R readmeReq.Email = user.Email readmeReq.Content = base64.StdEncoding.EncodeToString([]byte(output)) - err = c.git.UpdateRepoFile(&readmeReq) + fmt.Println("===== zzzzz") + err = c.gitServer.UpdateRepoFile(&readmeReq) if err != nil { return fmt.Errorf("failed to delete dataset tag to %s file, cause: %w", readmeReq.FilePath, err) } @@ -770,7 +792,7 @@ func (c *modelComponentImpl) DelRelationDataset(ctx context.Context, req types.R } func (c *modelComponentImpl) getRelations(ctx context.Context, fromRepoID int64, currentUser string) (*types.Relations, error) { - res, err := c.RelatedRepos(ctx, fromRepoID, currentUser) + res, err := c.repoComponent.RelatedRepos(ctx, fromRepoID, currentUser) if err != nil { return nil, err } @@ -804,7 +826,7 @@ func (c *modelComponentImpl) getRelations(ctx context.Context, fromRepoID int64, for _, repo := range spaceRepos { spacePaths = append(spacePaths, repo.Path) } - spaces, err := c.spaceComonent.ListByPath(ctx, spacePaths) + spaces, err := c.spaceComponent.ListByPath(ctx, spacePaths) if err != nil { return nil, fmt.Errorf("failed to get space info by paths, error: %w", err) } @@ -854,7 +876,7 @@ func (c *modelComponentImpl) Predict(ctx context.Context, req *types.ModelPredic inferReq := &inference.PredictRequest{ Prompt: req.Input, } - inferResp, err := c.infer.Predict(mid, inferReq) + inferResp, err := c.inferClient.Predict(mid, inferReq) if err != nil { slog.Error("failed to predict", slog.Any("req", *inferReq), slog.Any("model", mid), slog.String("error", err.Error())) return nil, err @@ -867,13 +889,13 @@ func (c *modelComponentImpl) Predict(ctx context.Context, req *types.ModelPredic // create model deploy as inference/serverless func (c *modelComponentImpl) Deploy(ctx context.Context, deployReq types.DeployActReq, req types.ModelRunReq) (int64, error) { - m, err := c.ms.FindByPath(ctx, deployReq.Namespace, deployReq.Name) + m, err := c.modelStore.FindByPath(ctx, deployReq.Namespace, deployReq.Name) if err != nil { return -1, fmt.Errorf("cannot find model, %w", err) } if deployReq.DeployType == types.ServerlessType { // only one service deploy was allowed - d, err := c.deploy.GetServerlessDeployByRepID(ctx, m.Repository.ID) + d, err := c.deployTaskStore.GetServerlessDeployByRepID(ctx, m.Repository.ID) if err != nil { return -1, fmt.Errorf("fail to get deploy, %w", err) } @@ -882,20 +904,20 @@ func (c *modelComponentImpl) Deploy(ctx context.Context, deployReq types.DeployA } } // found user id - user, err := c.us.FindByUsername(ctx, deployReq.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, deployReq.CurrentUser) if err != nil { return -1, fmt.Errorf("cannot find user for deploy model, %w", err) } if deployReq.DeployType == types.ServerlessType { // Check if the user is an admin - isAdmin := c.isAdminRole(user) + isAdmin := c.repoComponent.IsAdminRole(user) if !isAdmin { return -1, fmt.Errorf("need admin permission for Serverless deploy") } } - frame, err := c.rtfm.FindEnabledByID(ctx, req.RuntimeFrameworkID) + frame, err := c.runtimeFrameworksStore.FindEnabledByID(ctx, req.RuntimeFrameworkID) if err != nil { return -1, fmt.Errorf("cannot find available runtime framework, %w", err) } @@ -909,7 +931,7 @@ func (c *modelComponentImpl) Deploy(ctx context.Context, deployReq types.DeployA return -1, fmt.Errorf("fail to create annotations for deploy model, %w", err) } - resource, err := c.SS.FindByID(ctx, req.ResourceID) + resource, err := c.spaceResourceStore.FindByID(ctx, req.ResourceID) if err != nil { return -1, fmt.Errorf("cannot find resource, %w", err) } @@ -965,13 +987,13 @@ func (c *modelComponentImpl) ListModelsByRuntimeFrameworkID(ctx context.Context, resModels []types.Model ) if currentUser != "" { - user, err = c.user.FindByUsername(ctx, currentUser) + user, err = c.userStore.FindByUsername(ctx, currentUser) if err != nil { return nil, 0, fmt.Errorf("failed to get current user,error:%w", err) } } - runtimeRepos, err := c.rrtfms.ListByRuntimeFrameworkID(ctx, id, deployType) + runtimeRepos, err := c.repoRuntimeFrameworkStore.ListByRuntimeFrameworkID(ctx, id, deployType) if err != nil { return nil, 0, fmt.Errorf("failed to get repo by runtime,error:%w", err) } @@ -985,7 +1007,7 @@ func (c *modelComponentImpl) ListModelsByRuntimeFrameworkID(ctx context.Context, repoIDs = append(repoIDs, repo.RepoID) } - repos, total, err := c.rs.ListRepoPublicToUserByRepoIDs(ctx, types.ModelRepo, user.ID, "", "", per, page, repoIDs) + repos, total, err := c.repoStore.ListRepoPublicToUserByRepoIDs(ctx, types.ModelRepo, user.ID, "", "", per, page, repoIDs) if err != nil { newError := fmt.Errorf("failed to get public model repos,error:%w", err) return nil, 0, newError @@ -1005,7 +1027,7 @@ func (c *modelComponentImpl) ListModelsByRuntimeFrameworkID(ctx context.Context, } func (c *modelComponentImpl) ListAllByRuntimeFramework(ctx context.Context, currentUser string) ([]database.RuntimeFramework, error) { - runtimes, err := c.runFrame.ListAll(ctx) + runtimes, err := c.runtimeFrameworksStore.ListAll(ctx) if err != nil { newError := fmt.Errorf("failed to get public model repos,error:%w", err) return nil, newError @@ -1015,7 +1037,7 @@ func (c *modelComponentImpl) ListAllByRuntimeFramework(ctx context.Context, curr } func (c *modelComponentImpl) SetRuntimeFrameworkModes(ctx context.Context, deployType int, id int64, paths []string) ([]string, error) { - runtimeRepos, err := c.rtfm.FindByID(ctx, id) + runtimeRepos, err := c.runtimeFrameworksStore.FindByID(ctx, id) if err != nil { return nil, err } @@ -1024,30 +1046,30 @@ func (c *modelComponentImpl) SetRuntimeFrameworkModes(ctx context.Context, deplo return nil, fmt.Errorf("failed to get runtime framework") } - models, err := c.ms.ListByPath(ctx, paths) + models, err := c.modelStore.ListByPath(ctx, paths) if err != nil { return nil, err } - runtime_framework_tags, _ := c.ts.GetTagsByScopeAndCategories(ctx, "model", []string{"runtime_framework", "resource"}) + runtime_framework_tags, _ := c.tagStore.GetTagsByScopeAndCategories(ctx, "model", []string{"runtime_framework", "resource"}) var failedModels []string for _, model := range models { - relations, err := c.rrtfms.GetByIDsAndType(ctx, id, model.Repository.ID, deployType) + relations, err := c.repoRuntimeFrameworkStore.GetByIDsAndType(ctx, id, model.Repository.ID, deployType) if err != nil { return nil, err } if relations == nil || len(relations) < 1 { - err = c.rrtfms.Add(ctx, id, model.Repository.ID, deployType) + err = c.repoRuntimeFrameworkStore.Add(ctx, id, model.Repository.ID, deployType) if err != nil { failedModels = append(failedModels, model.Repository.Path) } _, modelName := model.Repository.NamespaceAndName() - err = c.rac.AddRuntimeFrameworkTag(ctx, runtime_framework_tags, model.Repository.ID, id) + err = c.runtimeArchComponent.AddRuntimeFrameworkTag(ctx, runtime_framework_tags, model.Repository.ID, id) if err != nil { return nil, err } - err = c.rac.AddResourceTag(ctx, runtime_framework_tags, modelName, model.Repository.ID) + err = c.runtimeArchComponent.AddResourceTag(ctx, runtime_framework_tags, modelName, model.Repository.ID) if err != nil { return nil, err } @@ -1058,14 +1080,14 @@ func (c *modelComponentImpl) SetRuntimeFrameworkModes(ctx context.Context, deplo } func (c *modelComponentImpl) DeleteRuntimeFrameworkModes(ctx context.Context, deployType int, id int64, paths []string) ([]string, error) { - models, err := c.ms.ListByPath(ctx, paths) + models, err := c.modelStore.ListByPath(ctx, paths) if err != nil { return nil, err } var failedModels []string for _, model := range models { - err = c.rrtfms.Delete(ctx, id, model.Repository.ID, deployType) + err = c.repoRuntimeFrameworkStore.Delete(ctx, id, model.Repository.ID, deployType) if err != nil { failedModels = append(failedModels, model.Repository.Path) } @@ -1081,12 +1103,12 @@ func (c *modelComponentImpl) ListModelsOfRuntimeFrameworks(ctx context.Context, resModels []types.Model ) - user, err = c.user.FindByUsername(ctx, currentUser) + user, err = c.userStore.FindByUsername(ctx, currentUser) if err != nil { return nil, 0, fmt.Errorf("failed to get current user %s, error:%w", currentUser, err) } - runtimeRepos, err := c.rrtfms.ListRepoIDsByType(ctx, deployType) + runtimeRepos, err := c.repoRuntimeFrameworkStore.ListRepoIDsByType(ctx, deployType) if err != nil { return nil, 0, fmt.Errorf("failed to get repo by deploy type, error:%w", err) } @@ -1100,7 +1122,7 @@ func (c *modelComponentImpl) ListModelsOfRuntimeFrameworks(ctx context.Context, repoIDs = append(repoIDs, repo.RepoID) } - repos, total, err := c.rs.ListRepoPublicToUserByRepoIDs(ctx, types.ModelRepo, user.ID, search, sort, per, page, repoIDs) + repos, total, err := c.repoStore.ListRepoPublicToUserByRepoIDs(ctx, types.ModelRepo, user.ID, search, sort, per, page, repoIDs) if err != nil { newError := fmt.Errorf("failed to get public model repos, error:%w", err) return nil, 0, newError @@ -1130,7 +1152,7 @@ func (c *modelComponentImpl) OrgModels(ctx context.Context, req *types.OrgModels r := membership.RoleUnknown if req.CurrentUser != "" { r, err = c.userSvcClient.GetMemberRole(ctx, req.Namespace, req.CurrentUser) - // log error, and treat user as unkown role in org + // log error, and treat user as unknown role in org if err != nil { slog.Error("faild to get member role", slog.String("org", req.Namespace), slog.String("user", req.CurrentUser), @@ -1138,7 +1160,7 @@ func (c *modelComponentImpl) OrgModels(ctx context.Context, req *types.OrgModels } } onlyPublic := !r.CanRead() - ms, total, err := c.ms.ByOrgPath(ctx, req.Namespace, req.PageSize, req.Page, onlyPublic) + ms, total, err := c.modelStore.ByOrgPath(ctx, req.Namespace, req.PageSize, req.Page, onlyPublic) if err != nil { newError := fmt.Errorf("failed to get user datasets,error:%w", err) slog.Error(newError.Error()) diff --git a/component/model_test.go b/component/model_test.go index dcf01bf2..f90bc1d5 100644 --- a/component/model_test.go +++ b/component/model_test.go @@ -4,96 +4,673 @@ import ( "context" "testing" + "github.com/alibabacloud-go/tea/tea" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - gsmock "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/git/gitserver" "opencsg.com/csghub-server/builder/git/gitserver" + "opencsg.com/csghub-server/builder/git/membership" + "opencsg.com/csghub-server/builder/inference" "opencsg.com/csghub-server/builder/store/database" - "opencsg.com/csghub-server/common/tests" "opencsg.com/csghub-server/common/types" ) -func NewTestModelComponent(stores *tests.MockStores, git gitserver.GitServer) (ModelComponent, error) { - c := &modelComponentImpl{} - c.ms = stores.Model - c.rs = stores.Repo - c.SS = stores.SpaceResource - c.us = stores.User - c.ts = stores.Tag - c.ds = stores.Dataset - c.repoComponentImpl = &repoComponentImpl{ - git: git, - user: stores.User, - repo: stores.Repo, +// func TestModelComponent_Index(t *testing.T) { +// ctx := context.TODO() +// mc := initializeTestModelComponent(ctx, t) + +// filter := &types.RepoFilter{Username: "user"} +// mc.mocks.components.repo.EXPECT().PublicToUser(ctx, types.ModelRepo, "user", filter, 10, 1).Return( +// []*database.Repository{ +// {ID: 1, Name: "r1", Tags: []database.Tag{{Name: "t1"}}}, +// {ID: 2, Name: "r2", Tags: []database.Tag{{Name: "t2"}}}, +// }, 100, nil, +// ) + +// mc.mocks.stores.ModelMock().EXPECT().ByRepoIDs(ctx, []int64{1, 2}).Return([]database.Model{ +// {RepositoryID: 1, ID: 11, Repository: &database.Repository{}}, +// {RepositoryID: 2, ID: 12, Repository: &database.Repository{}}, +// }, nil) + +// data, total, err := mc.Index(ctx, filter, 10, 1) +// require.Nil(t, err) +// require.Equal(t, 100, total) + +// require.Equal(t, []*types.Model{ +// { +// ID: 11, Name: "r1", Tags: []types.RepoTag{{Name: "t1"}}, RepositoryID: 1, +// Repository: types.Repository{ +// HTTPCloneURL: "https://foo.com/s/.git", +// SSHCloneURL: "test@127.0.0.1:s/.git", +// }, +// }, +// { +// ID: 12, Name: "r2", Tags: []types.RepoTag{{Name: "t2"}}, RepositoryID: 2, +// Repository: types.Repository{ +// HTTPCloneURL: "https://foo.com/s/.git", +// SSHCloneURL: "test@127.0.0.1:s/.git", +// }, +// }, +// }, data) + +// } + +func TestModelComponent_Create(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + user := database.User{ + Username: "user", + Email: "foo@bar.com", + } + mc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(user, nil) + + dbrepo := &database.Repository{ + ID: 321, + User: user, + Tags: []database.Tag{{Name: "t1"}}, + Name: "n", + License: "MIT", } - return c, nil + mc.mocks.components.repo.EXPECT().CreateRepo(ctx, types.CreateRepoReq{ + DefaultBranch: "main", + Readme: generateReadmeData("MIT"), + License: "MIT", + Namespace: "ns", + Name: "n", + Nickname: "n", + RepoType: types.ModelRepo, + Username: "user", + }).Return(nil, dbrepo, nil) + + mc.mocks.stores.ModelMock().EXPECT().Create(ctx, database.Model{ + Repository: dbrepo, + RepositoryID: dbrepo.ID, + BaseModel: "base", + }).Return(&database.Model{ + Repository: dbrepo, + }, nil) + mc.mocks.gitServer.EXPECT().CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ + Username: "user", + Email: "foo@bar.com", + Message: initCommitMessage, + Branch: "main", + Content: generateReadmeData("MIT"), + NewBranch: "main", + Namespace: "ns", + Name: "n", + FilePath: readmeFileName, + }, types.ModelRepo)).Return(nil) + mc.mocks.gitServer.EXPECT().CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ + Username: "user", + Email: "foo@bar.com", + Message: initCommitMessage, + Branch: "main", + Content: spaceGitattributesContent, + NewBranch: "main", + Namespace: "ns", + Name: "n", + FilePath: gitattributesFileName, + }, types.ModelRepo)).Return(nil) + + model, err := mc.Create(ctx, &types.CreateModelReq{ + BaseModel: "base", + CreateRepoReq: types.CreateRepoReq{ + DefaultBranch: "main", + Readme: "readme", + Namespace: "ns", + Name: "n", + License: "MIT", + Username: "user", + }, + }) + require.Nil(t, err) + + require.Equal(t, &types.Model{ + License: "MIT", + Name: "n", + User: &types.User{ + Username: "user", + Email: "foo@bar.com", + }, + Tags: []types.RepoTag{{Name: "t1"}}, + Repository: types.Repository{ + HTTPCloneURL: "https://foo.com/s/.git", + SSHCloneURL: "test@127.0.0.1:s/.git", + }, + }, model) + } -func TestModelComponent_SetRelationDatasetsAndPrompts(t *testing.T) { +func TestModelComponent_Update(t *testing.T) { ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + req := &types.UpdateModelReq{ + BaseModel: tea.String("base2"), + UpdateRepoReq: types.UpdateRepoReq{RepoType: types.ModelRepo}, + } + mc.mocks.components.repo.EXPECT().UpdateRepo(ctx, req.UpdateRepoReq).Return(&database.Repository{ + Name: "n", + ID: 1, + }, nil) + mc.mocks.stores.ModelMock().EXPECT().ByRepoID(ctx, int64(1)).Return(&database.Model{ + ID: 2, + BaseModel: "base", + }, nil) - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - model, err := NewTestModelComponent(stores, gitServer) + mc.mocks.stores.ModelMock().EXPECT().Update(ctx, database.Model{ + ID: 2, + BaseModel: "base2", + }).Return(&database.Model{ + ID: 2, + BaseModel: "base2", + }, nil) + + m, err := mc.Update(ctx, req) require.Nil(t, err) + require.Equal(t, &types.Model{ + ID: 2, + BaseModel: "base2", + Name: "n", + RepositoryID: 1, + }, m) +} - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ - Email: "foo@bar.com", - RoleMask: "foo", - }, nil).Once() - err = model.SetRelationDatasets(ctx, types.RelationDatasets{ +func TestModelComponent_Delete(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + mc.mocks.stores.ModelMock().EXPECT().FindByPath(ctx, "ns", "n").Return(&database.Model{ID: 1}, nil) + mc.mocks.components.repo.EXPECT().DeleteRepo(ctx, types.DeleteRepoReq{ + Username: "user", + Namespace: "ns", + Name: "n", + RepoType: types.ModelRepo, + }).Return(nil, nil) + mc.mocks.stores.ModelMock().EXPECT().Delete(ctx, database.Model{ID: 1}).Return(nil) + + err := mc.Delete(ctx, "ns", "n", "user") + require.Nil(t, err) + +} + +func TestModelComponent_Show(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + mc.mocks.stores.ModelMock().EXPECT().FindByPath(ctx, "ns", "n").Return(&database.Model{ + ID: 1, + RepositoryID: 123, + Repository: &database.Repository{ID: 123, Name: "n", Path: "foo/bar"}, + }, nil) + mc.mocks.components.repo.EXPECT().GetUserRepoPermission(ctx, "user", &database.Repository{ + ID: 123, + Name: "n", + Path: "foo/bar", + }).Return( + &types.UserRepoPermission{CanRead: true, CanAdmin: true}, nil, + ) + mc.mocks.components.repo.EXPECT().GetNameSpaceInfo(ctx, "ns").Return(&types.Namespace{Path: "ns"}, nil) + + mc.mocks.stores.UserLikesMock().EXPECT().IsExist(ctx, "user", int64(123)).Return(true, nil) + mc.mocks.stores.RepoRuntimeFrameworkMock().EXPECT().GetByRepoIDsAndType( + ctx, int64(123), mock.Anything, + ).Return([]database.RepositoriesRuntimeFramework{{}}, nil) + + model, err := mc.Show(ctx, "ns", "n", "user") + require.Nil(t, err) + require.Equal(t, &types.Model{ + ID: 1, + Name: "n", + Namespace: &types.Namespace{Path: "ns"}, + UserLikes: true, + RepositoryID: 123, + CanManage: true, + User: &types.User{}, + Path: "foo/bar", + Repository: types.Repository{ + HTTPCloneURL: "https://foo.com/s/foo/bar.git", + SSHCloneURL: "test@127.0.0.1:s/foo/bar.git", + }, + EnableInference: true, + EnableFinetune: true, + WidgetType: types.ModelWidgetTypeGeneration, + }, model) +} + +func TestModelComponent_GetServerless(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + mc.mocks.stores.ModelMock().EXPECT().FindByPath(ctx, "ns", "n").Return(&database.Model{ + ID: 1, + RepositoryID: 123, + Repository: &database.Repository{ID: 123, Name: "n"}, + }, nil) + + mc.mocks.components.repo.EXPECT().AllowReadAccessRepo( + ctx, &database.Repository{ID: 123, Name: "n"}, "user", + ).Return(true, nil) + + deploy := &database.Deploy{ID: 1} + mc.mocks.stores.DeployTaskMock().EXPECT().GetServerlessDeployByRepID(ctx, int64(123)).Return( + deploy, nil, + ) + + mc.mocks.components.repo.EXPECT().GenerateEndpoint(ctx, deploy).Return("ep", "") + + dr, err := mc.GetServerless(ctx, "ns", "n", "user") + require.Nil(t, err) + require.Equal(t, &types.DeployRepo{ + DeployID: 1, + ProxyEndpoint: "ep", + Status: "Stopped", + }, dr) + +} + +func TestModelComponent_SDKModelInfo(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + repo := &database.Repository{ + ID: 123, Name: "n", Path: "p/p", + User: database.User{Username: "user"}, + Tags: []database.Tag{{Name: "t1"}}, + } + mc.mocks.stores.ModelMock().EXPECT().FindByPath(ctx, "ns", "n").Return(&database.Model{ + ID: 1, + RepositoryID: 123, + Repository: repo}, nil) + mc.mocks.components.repo.EXPECT().AllowReadAccessRepo( + ctx, repo, "user", + ).Return(true, nil) + mc.mocks.gitServer.EXPECT().GetRepoLastCommit(ctx, gitserver.GetRepoLastCommitReq{ + Namespace: "ns", + Name: "n", + Ref: "main", + RepoType: types.ModelRepo, + }).Return(&types.Commit{ID: "zzz"}, nil) + file := types.File{Path: "file1.txt", Type: "file", Size: 100, SHA: "sha1"} + repoFiles := []*types.File{&file} + mc.mocks.gitServer.EXPECT().GetRepoFileTree(mock.Anything, mock.Anything).Return(repoFiles, nil) + mc.mocks.components.repo.EXPECT().RelatedRepos(ctx, int64(123), "user").Return( + map[types.RepositoryType][]*database.Repository{ + types.SpaceRepo: { + {Name: "sp"}, + }, + }, nil, + ) + + info, err := mc.SDKModelInfo(ctx, "ns", "n", "main", "user") + require.Nil(t, err) + require.Equal(t, &types.SDKModelInfo{ + ID: "p/p", + Spaces: []string{"sp"}, + Author: "user", + Sha: "zzz", + Siblings: []types.SDKFile{{Filename: "file1.txt"}}, + Tags: []string{"t1"}, + }, info) + +} + +func TestModelComponent_Relations(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + repo := &database.Repository{} + mc.mocks.stores.ModelMock().EXPECT().FindByPath(ctx, "ns", "n").Return(&database.Model{ + RepositoryID: 123, + Repository: repo, + }, nil) + mc.mocks.components.repo.EXPECT().AllowReadAccessRepo(ctx, repo, "user").Return(true, nil) + mc.mocks.components.repo.EXPECT().RelatedRepos(ctx, int64(123), "user").Return( + map[types.RepositoryType][]*database.Repository{ + types.DatasetRepo: {{Name: "d1"}}, + types.CodeRepo: {{Name: "c1"}}, + types.PromptRepo: {{Name: "p1"}}, + types.SpaceRepo: {{Path: "sp"}}, + }, nil, + ) + mc.mocks.components.space.EXPECT().ListByPath(ctx, []string{"sp"}).Return([]*types.Space{ + {Name: "s1"}, + }, nil) + + rels, err := mc.Relations(ctx, "ns", "n", "user") + require.Nil(t, err) + require.Equal(t, &types.Relations{ + Datasets: []*types.Dataset{{Name: "d1"}}, + Codes: []*types.Code{{Name: "c1"}}, + Prompts: []*types.PromptRes{{Name: "p1"}}, + Spaces: []*types.Space{{Name: "s1"}}, + }, rels) +} + +func TestModelComponent_SetRelationDatasets(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + mc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ + RoleMask: "admin", + }, nil) + mc.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( + &database.Repository{}, nil, + ) + mc.mocks.gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: "main", + Path: REPOCARD_FILENAME, + RepoType: types.ModelRepo, + }).Return(&types.File{}, nil) + mc.mocks.gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ + Username: "user", + Message: "update dataset tags", + Branch: "main", + Content: "LS0tCmRhdGFzZXRzOgogICAgLSBkMQoKLS0tCg==", + Namespace: "ns", + Name: "n", + FilePath: "README.md", + RepoType: types.ModelRepo, + }).Return(nil) + err := mc.SetRelationDatasets(ctx, types.RelationDatasets{ + Datasets: []string{"d1"}, Namespace: "ns", Name: "n", - CurrentUser: "foo", + CurrentUser: "user", }) - require.NotNil(t, err) - require.Contains(t, err.Error(), "only admin") + require.Nil(t, err) +} - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ - Email: "foo@bar.com", - RoleMask: "foo-admin", - }, nil).Once() - - stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(&database.Repository{}, nil).Once() - // --- - // foo: "foo" - // bar: "bar" - gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ +func TestModelComponent_AddRelationDataset(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + mc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ + RoleMask: "admin", + }, nil) + mc.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( + &database.Repository{}, nil, + ) + mc.mocks.gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", - Ref: types.MainBranch, + Ref: "main", Path: REPOCARD_FILENAME, RepoType: types.ModelRepo, - }).Return(&types.File{ - Content: "LS0tCiBmb286ICJmb28iCiBiYXI6ICJiYXIi", - }, nil).Once() - - // --- - // bar: bar - // datasets: - // - a - // - b - // foo: foo - - // --- - gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ - Branch: types.MainBranch, - Message: "update dataset tags", - FilePath: REPOCARD_FILENAME, + }).Return(&types.File{}, nil) + mc.mocks.gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ + Username: "user", + Message: "add relation dataset", + Branch: "main", + Content: "LS0tCmRhdGFzZXRzOgogICAgLSBkMQoKLS0tCg==", + Namespace: "ns", + Name: "n", + FilePath: "README.md", RepoType: types.ModelRepo, + }).Return(nil) + err := mc.AddRelationDataset(ctx, types.RelationDataset{ + Dataset: "d1", + Namespace: "ns", + Name: "n", + CurrentUser: "user", + }) + require.Nil(t, err) +} + +func TestModelComponent_DeleteRelationDataset(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + mc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ + RoleMask: "admin", + }, nil) + mc.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( + &database.Repository{}, nil, + ) + mc.mocks.gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", - Username: "foo", - Email: "foo@bar.com", - Content: "LS0tCmJhcjogYmFyCmRhdGFzZXRzOgogICAgLSBhCiAgICAtIGIKZm9vOiBmb28KCi0tLQ==", - }).Return(nil).Once() + Ref: "main", + Path: REPOCARD_FILENAME, + RepoType: types.ModelRepo, + }).Return(&types.File{ + Content: "LS0tCiBkYXRhc2V0czoKICAgLSBkczE=", + }, nil) + mc.mocks.gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ + Username: "user", + Message: "delete relation dataset", + Branch: "main", + Content: "LS0tCmRhdGFzZXRzOgogICAgLSBkczEKCi0tLQ==", + Namespace: "ns", + Name: "n", + FilePath: "README.md", + RepoType: types.ModelRepo, + }).Return(nil) + err := mc.DelRelationDataset(ctx, types.RelationDataset{ + Dataset: "d1", + Namespace: "ns", + Name: "n", + CurrentUser: "user", + }) + require.Nil(t, err) +} + +func TestModelComponent_Predict(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) - err = model.SetRelationDatasets(ctx, types.RelationDatasets{ + mc.mocks.inferenceClient.EXPECT().Predict(inference.ModelID{ + Owner: "ns", + Name: "n", + }, &inference.PredictRequest{ + Prompt: "foo", + }).Return(&inference.PredictResponse{ + GeneratedText: "abcd", + }, nil) + + resp, err := mc.Predict(ctx, &types.ModelPredictReq{ Namespace: "ns", Name: "n", - CurrentUser: "foo", - Datasets: []string{"a", "b"}, + Input: "foo", + CurrentUser: "user", + }) + require.Nil(t, err) + require.Equal(t, &types.ModelPredictResp{ + Content: "abcd", + }, resp) + +} + +// func TestModelComponent_Deploy(t *testing.T) { +// ctx := context.TODO() +// mc := initializeTestModelComponent(ctx, t) + +// mc.mocks.stores.ModelMock().EXPECT().FindByPath(ctx, "ns", "n").Return(&database.Model{ +// RepositoryID: int64(123), +// Repository: &database.Repository{ +// ID: 1, +// Path: "foo", +// }, +// }, nil) +// mc.mocks.stores.DeployTaskMock().EXPECT().GetServerlessDeployByRepID(ctx, int64(1)).Return( +// nil, nil, +// ) +// mc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ +// RoleMask: "admin", +// }, nil) +// mc.mocks.stores.RuntimeFrameworkMock().EXPECT().FindEnabledByID(ctx, int64(11)).Return( +// &database.RuntimeFramework{}, nil, +// ) +// mc.mocks.components.repo.EXPECT().IsAdminRole(database.User{ +// RoleMask: "admin", +// }).Return(true) +// mc.mocks.stores.SpaceResourceMock().EXPECT().FindByID(ctx, int64(123)).Return( +// &database.SpaceResource{ +// ID: 123, +// Resources: `{"memory": "foo"}`, +// }, nil, +// ) + +// mc.mocks.deployer.EXPECT().CheckResourceAvailable(ctx, int64(0), &types.HardWare{ +// Memory: "foo", +// }).Return(true, nil) +// mc.mocks.deployer.EXPECT().Deploy(ctx, types.DeployRepo{ +// DeployName: "dp", +// Path: "foo", +// Hardware: "{\"memory\": \"foo\"}", +// Annotation: "{\"hub-res-name\":\"ns/n\",\"hub-res-type\":\"model\"}", +// ClusterID: "cluster", +// RepoID: 1, +// SKU: "123", +// Type: types.ServerlessType, +// }).Return(111, nil) + +// id, err := mc.Deploy(ctx, types.DeployActReq{ +// Namespace: "ns", +// Name: "n", +// CurrentUser: "user", +// DeployType: types.ServerlessType, +// }, types.ModelRunReq{ +// RuntimeFrameworkID: 11, +// ResourceID: 123, +// ClusterID: "cluster", +// DeployName: "dp", +// }) +// require.Nil(t, err) +// require.Equal(t, int64(111), id) + +// } + +func TestModelComponent_ListModelsByRuntimeFrameworkID(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + mc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) + mc.mocks.stores.RepoRuntimeFrameworkMock().EXPECT().ListByRuntimeFrameworkID(ctx, int64(123), 1).Return( + []database.RepositoriesRuntimeFramework{ + {RepoID: 1}, {RepoID: 2}, + }, nil, + ) + mc.mocks.stores.RepoMock().EXPECT().ListRepoPublicToUserByRepoIDs(ctx, types.ModelRepo, int64(1), "", "", 10, 1, []int64{1, 2}).Return([]*database.Repository{ + {ID: 1, Name: "r1"}, + }, 100, nil) + + models, total, err := mc.ListModelsByRuntimeFrameworkID(ctx, "user", 10, 1, 123, 1) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Model{ + {Name: "r1", RepositoryID: 1}, + }, models) + +} + +func TestModelComponent_SetRuntimeFrameworkModes(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + mc.mocks.stores.RuntimeFrameworkMock().EXPECT().FindByID(ctx, int64(1)).Return( + &database.RuntimeFramework{}, nil, + ) + mc.mocks.stores.ModelMock().EXPECT().ListByPath(ctx, []string{"a", "b"}).Return( + []database.Model{ + {RepositoryID: 1, Repository: &database.Repository{ID: 1, Path: "m1/foo"}}, + {RepositoryID: 2, Repository: &database.Repository{ID: 2, Path: "m2/foo"}}, + }, nil, + ) + rftags := []*database.Tag{{Name: "t1"}, {Name: "t2"}} + mc.mocks.stores.TagMock().EXPECT().GetTagsByScopeAndCategories( + ctx, database.TagScope("model"), []string{"runtime_framework", "resource"}, + ).Return(rftags, nil) + + mc.mocks.stores.RepoRuntimeFrameworkMock().EXPECT().GetByIDsAndType( + ctx, int64(1), int64(1), 1, + ).Return([]database.RepositoriesRuntimeFramework{}, nil) + mc.mocks.stores.RepoRuntimeFrameworkMock().EXPECT().GetByIDsAndType( + ctx, int64(1), int64(2), 1, + ).Return([]database.RepositoriesRuntimeFramework{{}}, nil) + + mc.mocks.stores.RepoRuntimeFrameworkMock().EXPECT().Add(ctx, int64(1), int64(1), 1).Return(nil) + mc.mocks.components.runtimeArchitecture.EXPECT().AddRuntimeFrameworkTag( + ctx, rftags, int64(1), int64(1), + ).Return(nil) + mc.mocks.components.runtimeArchitecture.EXPECT().AddResourceTag(ctx, rftags, "foo", int64(1)).Return(nil) + f, err := mc.SetRuntimeFrameworkModes(ctx, 1, 1, []string{"a", "b"}) + require.Nil(t, err) + require.Empty(t, f) + +} + +func TestModelComponent_DeleteRuntimeFrameworkModes(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + mc.mocks.stores.ModelMock().EXPECT().ListByPath(ctx, []string{"a", "b"}).Return( + []database.Model{ + {RepositoryID: 1, Repository: &database.Repository{ID: 1, Path: "m1/foo"}}, + {RepositoryID: 2, Repository: &database.Repository{ID: 2, Path: "m2/foo"}}, + }, nil, + ) + + mc.mocks.stores.RepoRuntimeFrameworkMock().EXPECT().Delete(ctx, int64(123), int64(1), 1).Return(nil) + mc.mocks.stores.RepoRuntimeFrameworkMock().EXPECT().Delete(ctx, int64(123), int64(2), 1).Return(nil) + + f, err := mc.DeleteRuntimeFrameworkModes(ctx, 1, 123, []string{"a", "b"}) + require.Nil(t, err) + require.Empty(t, f) +} + +func TestModelComponent_ListModelsOfRuntimeFrameworks(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + mc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) + mc.mocks.stores.RepoRuntimeFrameworkMock().EXPECT().ListRepoIDsByType(ctx, 1).Return( + []database.RepositoriesRuntimeFramework{ + {RepoID: 123}, + }, nil, + ) + mc.mocks.stores.RepoMock().EXPECT().ListRepoPublicToUserByRepoIDs(ctx, types.ModelRepo, int64(1), "s", "ss", 10, 1, []int64{123}).Return([]*database.Repository{ + {Name: "r1", Path: "foo"}, + }, 100, nil) + data, total, err := mc.ListModelsOfRuntimeFrameworks(ctx, "user", "s", "ss", 10, 1, 1) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Model{ + { + Name: "r1", + Path: "foo", + EnableInference: true, + }, + }, data) + +} + +func TestModelComponent_OrgModels(t *testing.T) { + ctx := context.TODO() + mc := initializeTestModelComponent(ctx, t) + + mc.mocks.userSvcClient.EXPECT().GetMemberRole(ctx, "ns", "user").Return(membership.RoleAdmin, nil) + mc.mocks.stores.ModelMock().EXPECT().ByOrgPath(ctx, "ns", 10, 1, false).Return([]database.Model{ + {RepositoryID: 1, Repository: &database.Repository{ID: 1, Path: "foo", Name: "r1"}}, + }, 100, nil) + data, total, err := mc.OrgModels(ctx, &types.OrgModelsReq{ + Namespace: "ns", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, }) require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Model{ + { + Name: "r1", + Path: "foo", + RepositoryID: 1, + }, + }, data) } diff --git a/component/prompt.go b/component/prompt.go index b8381637..6fdadcb2 100644 --- a/component/prompt.go +++ b/component/prompt.go @@ -87,6 +87,7 @@ func NewPromptComponent(cfg *config.Config) (PromptComponent, error) { usc := rpc.NewUserSvcHttpClient(fmt.Sprintf("%s:%d", cfg.User.Host, cfg.User.Port), rpc.AuthWithApiKey(cfg.APIToken)) return &promptComponentImpl{ + config: cfg, userStore: database.NewUserStore(), userLikeStore: database.NewUserLikesStore(), userSvcClient: usc, @@ -99,6 +100,7 @@ func NewPromptComponent(cfg *config.Config) (PromptComponent, error) { repoComponent: r, gitServer: gs, maxPromptFS: cfg.Dataset.PromptMaxJsonlFileSize, + namespaceStore: database.NewNamespaceStore(), }, nil } @@ -1223,7 +1225,7 @@ func (c *promptComponentImpl) OrgPrompts(ctx context.Context, req *types.OrgProm r := membership.RoleUnknown if req.CurrentUser != "" { r, err = c.userSvcClient.GetMemberRole(ctx, req.Namespace, req.CurrentUser) - // log error, and treat user as unkown role in org + // log error, and treat user as unknown role in org if err != nil { slog.Error("faild to get member role", slog.String("org", req.Namespace), slog.String("user", req.CurrentUser), diff --git a/component/prompt_test.go b/component/prompt_test.go index e043d725..30ce73ce 100644 --- a/component/prompt_test.go +++ b/component/prompt_test.go @@ -14,47 +14,15 @@ import ( "github.com/spf13/cast" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - gsmock "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/git/gitserver" - urpc_mock "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/rpc" - component_mock "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/component" "opencsg.com/csghub-server/builder/git/gitserver" "opencsg.com/csghub-server/builder/git/membership" - "opencsg.com/csghub-server/builder/llm" - "opencsg.com/csghub-server/builder/rpc" "opencsg.com/csghub-server/builder/store/database" - "opencsg.com/csghub-server/common/config" - "opencsg.com/csghub-server/common/tests" "opencsg.com/csghub-server/common/types" ) -func NewTestPromptComponent(stores *tests.MockStores, rpcUser rpc.UserSvcClient, gitServer gitserver.GitServer) *promptComponentImpl { - cfg := &config.Config{} - cfg.APIServer.PublicDomain = "https://foo.com" - cfg.APIServer.SSHDomain = "ssh://test@127.0.0.1" - return &promptComponentImpl{ - userStore: stores.User, - userLikeStore: stores.UserLikes, - promptConvStore: stores.PromptConversation, - promptPrefixStore: stores.PromptPrefix, - llmConfigStore: stores.LLMConfig, - promptStore: stores.Prompt, - namespaceStore: stores.Namespace, - userSvcClient: rpcUser, - gitServer: gitServer, - repoStore: stores.Repo, - llmClient: llm.NewClient(), - config: cfg, - } -} - func TestPromptComponent_CheckPermission(t *testing.T) { - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - rpcUser := urpc_mock.NewMockUserSvcClient(t) - pc := NewTestPromptComponent(stores, rpcUser, gitServer) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) req := types.PromptReq{ Path: "p", @@ -63,101 +31,96 @@ func TestPromptComponent_CheckPermission(t *testing.T) { CurrentUser: "foo", } - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, errors.New("")).Once() + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, errors.New("")).Once() _, err := pc.checkPromptRepoPermission(ctx, req) require.Contains(t, err.Error(), "namespace does not exist") - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil).Once() - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{}, errors.New("")).Once() + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil).Once() + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{}, errors.New("")).Once() _, err = pc.checkPromptRepoPermission(ctx, req) require.Contains(t, err.Error(), "user does not exist") - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ NamespaceType: database.UserNamespace, Path: "zzz", }, nil).Once() - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ RoleMask: "foo", Username: "zzz", }, nil).Once() _, err = pc.checkPromptRepoPermission(ctx, req) require.Nil(t, err) - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ NamespaceType: database.UserNamespace, Path: "uuu", }, nil).Once() - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ RoleMask: "foo", Username: "vvv", }, nil).Once() _, err = pc.checkPromptRepoPermission(ctx, req) require.Contains(t, err.Error(), "user do not have permission") - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ NamespaceType: database.UserNamespace, Path: "uuu", }, nil).Once() - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ RoleMask: "foo", Username: "uuu", }, nil).Once() _, err = pc.checkPromptRepoPermission(ctx, req) require.Nil(t, err) - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ NamespaceType: database.OrgNamespace, }, nil).Once() - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ RoleMask: "super-admin", }, nil).Once() _, err = pc.checkPromptRepoPermission(ctx, req) require.Nil(t, err) // no write role - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ NamespaceType: database.OrgNamespace, }, nil).Once() - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ RoleMask: "person", }, nil).Once() - mockedRepoComponent.EXPECT().CheckCurrentUserPermission(ctx, "foo", "ns", membership.RoleWrite).Return(false, nil).Once() + pc.mocks.components.repo.EXPECT().CheckCurrentUserPermission(ctx, "foo", "ns", membership.RoleWrite).Return(false, nil).Once() _, err = pc.checkPromptRepoPermission(ctx, req) require.Contains(t, err.Error(), "user do not have permission") // has write role - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ NamespaceType: database.OrgNamespace, }, nil).Once() - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ RoleMask: "person", }, nil).Once() - mockedRepoComponent.EXPECT().CheckCurrentUserPermission(ctx, "foo", "ns", membership.RoleWrite).Return(true, nil).Once() + pc.mocks.components.repo.EXPECT().CheckCurrentUserPermission(ctx, "foo", "ns", membership.RoleWrite).Return(true, nil).Once() _, err = pc.checkPromptRepoPermission(ctx, req) require.Nil(t, err) } func TestPromptComponent_CreatePrompt(t *testing.T) { - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - rpcUser := urpc_mock.NewMockUserSvcClient(t) - pc := NewTestPromptComponent(stores, rpcUser, gitServer) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) for _, exist := range []bool{true, false} { t.Run(fmt.Sprintf("file exist: %v", exist), func(t *testing.T) { - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ NamespaceType: database.OrgNamespace, }, nil).Once() - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ RoleMask: "foo-admin", Email: "foo@bar.com", }, nil).Once() if exist { - gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ + pc.mocks.gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", Ref: types.MainBranch, @@ -176,7 +139,7 @@ func TestPromptComponent_CreatePrompt(t *testing.T) { require.NotNil(t, err) return } else { - gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ + pc.mocks.gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", Ref: types.MainBranch, @@ -185,7 +148,7 @@ func TestPromptComponent_CreatePrompt(t *testing.T) { }).Return("", errors.New("")).Once() } - mockedRepoComponent.EXPECT().CreateFile(ctx, &types.CreateFileReq{ + pc.mocks.components.repo.EXPECT().CreateFile(ctx, &types.CreateFileReq{ Namespace: "ns", Name: "n", Branch: types.MainBranch, @@ -214,26 +177,21 @@ func TestPromptComponent_CreatePrompt(t *testing.T) { } func TestPromptComponent_UpdatePrompt(t *testing.T) { - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - rpcUser := urpc_mock.NewMockUserSvcClient(t) - pc := NewTestPromptComponent(stores, rpcUser, gitServer) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) for _, exist := range []bool{true, false} { t.Run(fmt.Sprintf("file exist: %v", exist), func(t *testing.T) { - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ NamespaceType: database.OrgNamespace, }, nil).Once() - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ RoleMask: "foo-admin", Email: "foo@bar.com", }, nil).Once() if !exist { - gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ + pc.mocks.gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", Ref: types.MainBranch, @@ -252,7 +210,7 @@ func TestPromptComponent_UpdatePrompt(t *testing.T) { require.NotNil(t, err) return } else { - gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ + pc.mocks.gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", Ref: types.MainBranch, @@ -261,7 +219,7 @@ func TestPromptComponent_UpdatePrompt(t *testing.T) { }).Return("", nil).Once() } - mockedRepoComponent.EXPECT().UpdateFile(ctx, &types.UpdateFileReq{ + pc.mocks.components.repo.EXPECT().UpdateFile(ctx, &types.UpdateFileReq{ Namespace: "ns", Name: "n", Branch: types.MainBranch, @@ -290,23 +248,18 @@ func TestPromptComponent_UpdatePrompt(t *testing.T) { } func TestPromptComponent_DeletePrompt(t *testing.T) { - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - rpcUser := urpc_mock.NewMockUserSvcClient(t) - pc := NewTestPromptComponent(stores, rpcUser, gitServer) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{ NamespaceType: database.OrgNamespace, }, nil).Once() - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ RoleMask: "foo-admin", Email: "foo@bar.com", }, nil).Once() - mockedRepoComponent.EXPECT().DeleteFile(ctx, &types.DeleteFileReq{ + pc.mocks.components.repo.EXPECT().DeleteFile(ctx, &types.DeleteFileReq{ Namespace: "ns", Name: "n", Branch: types.MainBranch, @@ -330,19 +283,14 @@ func TestPromptComponent_DeletePrompt(t *testing.T) { } func TestPromptComponent_ListPrompt(t *testing.T) { - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - rpcUser := urpc_mock.NewMockUserSvcClient(t) - pc := NewTestPromptComponent(stores, rpcUser, gitServer) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) repo := &database.Repository{} - stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() - mockedRepoComponent.EXPECT().AllowReadAccessRepo(ctx, repo, "foo").Return(true, nil).Once() + pc.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() + pc.mocks.components.repo.EXPECT().AllowReadAccessRepo(ctx, repo, "foo").Return(true, nil).Once() - gitServer.EXPECT().GetRepoFileTree(context.Background(), gitserver.GetRepoInfoByPathReq{ + pc.mocks.gitServer.EXPECT().GetRepoFileTree(context.Background(), gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", RepoType: types.PromptRepo, @@ -354,7 +302,7 @@ func TestPromptComponent_ListPrompt(t *testing.T) { }, nil) for _, name := range []string{"foo.jsonl", "bar.jsonl"} { - gitServer.EXPECT().GetRepoFileContents(ctx, gitserver.GetRepoInfoByPathReq{ + pc.mocks.gitServer.EXPECT().GetRepoFileContents(ctx, gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", Ref: "main", @@ -383,21 +331,16 @@ func TestPromptComponent_ListPrompt(t *testing.T) { } func TestPromptComponent_GetPrompt(t *testing.T) { - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - rpcUser := urpc_mock.NewMockUserSvcClient(t) - pc := NewTestPromptComponent(stores, rpcUser, gitServer) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) repo := &database.Repository{} - stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() - mockedRepoComponent.EXPECT().GetUserRepoPermission(ctx, "foo", repo).Return(&types.UserRepoPermission{ + pc.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() + pc.mocks.components.repo.EXPECT().GetUserRepoPermission(ctx, "foo", repo).Return(&types.UserRepoPermission{ CanRead: true, }, nil).Once() - gitServer.EXPECT().GetRepoFileContents(ctx, gitserver.GetRepoInfoByPathReq{ + pc.mocks.gitServer.EXPECT().GetRepoFileContents(ctx, gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", Ref: "main", @@ -419,12 +362,11 @@ func TestPromptComponent_GetPrompt(t *testing.T) { } func TestPromptComponent_NewConversation(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() - stores.PromptConversationMock().EXPECT().CreateConversation(ctx, database.PromptConversation{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + pc.mocks.stores.PromptConversationMock().EXPECT().CreateConversation(ctx, database.PromptConversation{ UserID: 123, ConversationID: "zzz", Title: "test", @@ -443,16 +385,15 @@ func TestPromptComponent_NewConversation(t *testing.T) { } func TestPromptComponent_ListConversationByUserID(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() mockedResults := []database.PromptConversation{ {Title: "foo"}, {Title: "bar"}, } - stores.PromptConversationMock().EXPECT().FindConversationsByUserID(ctx, int64(123)).Return(mockedResults, nil).Once() + pc.mocks.stores.PromptConversationMock().EXPECT().FindConversationsByUserID(ctx, int64(123)).Return(mockedResults, nil).Once() results, err := pc.ListConversationsByUserID(ctx, "foo") require.Nil(t, err) @@ -461,13 +402,12 @@ func TestPromptComponent_ListConversationByUserID(t *testing.T) { } func TestPromptComponent_GetConversation(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() mocked := &database.PromptConversation{} - stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", true).Return(mocked, nil).Once() + pc.mocks.stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", true).Return(mocked, nil).Once() cv, err := pc.GetConversation(ctx, types.ConversationReq{ CurrentUser: "foo", @@ -481,32 +421,31 @@ func TestPromptComponent_GetConversation(t *testing.T) { } func TestPromptComponent_SubmitMessage(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) for _, lang := range []string{"en", "zh"} { t.Run(lang, func(t *testing.T) { - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() - stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(&database.PromptConversation{}, nil).Once() + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + pc.mocks.stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(&database.PromptConversation{}, nil).Once() content := "go" if lang == "zh" { content = "围棋" } - stores.PromptConversationMock().EXPECT().SaveConversationMessage( + pc.mocks.stores.PromptConversationMock().EXPECT().SaveConversationMessage( ctx, database.PromptConversationMessage{ ConversationID: "uuid", Role: UserRole, Content: content, }, ).Return(&database.PromptConversationMessage{}, nil) - stores.LLMConfigMock().EXPECT().GetOptimization(ctx).Return(&database.LLMConfig{ + pc.mocks.stores.LLMConfigMock().EXPECT().GetOptimization(ctx).Return(&database.LLMConfig{ ApiEndpoint: "https://llm.com", AuthHeader: `{"token": "foobar"}`, }, nil).Once() - stores.PromptPrefixMock().EXPECT().Get(ctx).Return(&database.PromptPrefix{ + pc.mocks.stores.PromptPrefixMock().EXPECT().Get(ctx).Return(&database.PromptPrefix{ ZH: "use Chinese", EN: "use English", }, nil).Once() @@ -556,12 +495,11 @@ func TestPromptComponent_SubmitMessage(t *testing.T) { } func TestPromptComponent_SaveGeneratedText(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) mocked := &database.PromptConversationMessage{} - stores.PromptConversationMock().EXPECT().SaveConversationMessage(ctx, database.PromptConversationMessage{ + pc.mocks.stores.PromptConversationMock().EXPECT().SaveConversationMessage(ctx, database.PromptConversationMessage{ ConversationID: "uuid", Role: AssistantRole, Content: "m", @@ -577,12 +515,11 @@ func TestPromptComponent_SaveGeneratedText(t *testing.T) { } func TestPromptComponent_RemoveConversation(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() - stores.PromptConversationMock().EXPECT().DeleteConversationsByID(ctx, int64(123), "uuid").Return(nil).Once() + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + pc.mocks.stores.PromptConversationMock().EXPECT().DeleteConversationsByID(ctx, int64(123), "uuid").Return(nil).Once() err := pc.RemoveConversation(ctx, types.ConversationReq{ CurrentUser: "foo", @@ -594,18 +531,17 @@ func TestPromptComponent_RemoveConversation(t *testing.T) { } func TestPromptComponent_UpdateConversation(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() - stores.PromptConversationMock().EXPECT().UpdateConversation(ctx, database.PromptConversation{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + pc.mocks.stores.PromptConversationMock().EXPECT().UpdateConversation(ctx, database.PromptConversation{ UserID: 123, ConversationID: "uuid", Title: "title", }).Return(nil).Once() mocked := &database.PromptConversation{} - stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(mocked, nil) + pc.mocks.stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(mocked, nil) cv, err := pc.UpdateConversation(ctx, types.ConversationTitleReq{ CurrentUser: "foo", @@ -619,13 +555,12 @@ func TestPromptComponent_UpdateConversation(t *testing.T) { } func TestPromptComponent_LikeConversationMessage(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() - stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(&database.PromptConversation{}, nil).Once() - stores.PromptConversationMock().EXPECT().LikeMessageByID(ctx, int64(123)).Return(nil).Once() + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + pc.mocks.stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(&database.PromptConversation{}, nil).Once() + pc.mocks.stores.PromptConversationMock().EXPECT().LikeMessageByID(ctx, int64(123)).Return(nil).Once() err := pc.LikeConversationMessage(ctx, types.ConversationMessageReq{ Uuid: "uuid", @@ -636,13 +571,12 @@ func TestPromptComponent_LikeConversationMessage(t *testing.T) { } func TestPromptComponent_HateConversationMessage(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() - stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(&database.PromptConversation{}, nil).Once() - stores.PromptConversationMock().EXPECT().HateMessageByID(ctx, int64(123)).Return(nil).Once() + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ID: 123}, nil).Once() + pc.mocks.stores.PromptConversationMock().EXPECT().GetConversationByID(ctx, int64(123), "uuid", false).Return(&database.PromptConversation{}, nil).Once() + pc.mocks.stores.PromptConversationMock().EXPECT().HateMessageByID(ctx, int64(123)).Return(nil).Once() err := pc.HateConversationMessage(ctx, types.ConversationMessageReq{ Uuid: "uuid", @@ -653,23 +587,19 @@ func TestPromptComponent_HateConversationMessage(t *testing.T) { } func TestPromptComponent_SetRelationModels(t *testing.T) { - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - pc := NewTestPromptComponent(stores, nil, gitServer) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ ID: 123, Email: "foo@bar.com", }, nil).Once() repo := &database.Repository{} - stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() - mockedRepoComponent.EXPECT().GetUserRepoPermission(ctx, "foo", repo).Return(&types.UserRepoPermission{ + pc.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() + pc.mocks.components.repo.EXPECT().GetUserRepoPermission(ctx, "foo", repo).Return(&types.UserRepoPermission{ CanWrite: true, }, nil).Once() - gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ + pc.mocks.gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", Ref: "main", @@ -678,7 +608,7 @@ func TestPromptComponent_SetRelationModels(t *testing.T) { }).Return(&types.File{ Content: "LS0tCiB0aXRsZTogImFpIg==", }, nil).Once() - gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ + pc.mocks.gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ Branch: types.MainBranch, Message: "update model relation tags", FilePath: REPOCARD_FILENAME, @@ -701,21 +631,17 @@ func TestPromptComponent_SetRelationModels(t *testing.T) { } func TestPromptComponent_AddRelationModel(t *testing.T) { - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - pc := NewTestPromptComponent(stores, nil, gitServer) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ ID: 123, Email: "foo@bar.com", RoleMask: "foo-admin", }, nil).Once() repo := &database.Repository{} - stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() - gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ + pc.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() + pc.mocks.gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", Ref: "main", @@ -724,7 +650,7 @@ func TestPromptComponent_AddRelationModel(t *testing.T) { }).Return(&types.File{ Content: "LS0tCiB0aXRsZTogImFpIg==", }, nil).Once() - gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ + pc.mocks.gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ Branch: types.MainBranch, Message: "add relation model", FilePath: REPOCARD_FILENAME, @@ -747,21 +673,17 @@ func TestPromptComponent_AddRelationModel(t *testing.T) { } func TestPromptComponent_DelRelationModel(t *testing.T) { - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - pc := NewTestPromptComponent(stores, nil, gitServer) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ ID: 123, Email: "foo@bar.com", RoleMask: "foo-admin", }, nil).Once() repo := &database.Repository{} - stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() - gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ + pc.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.PromptRepo, "ns", "n").Return(repo, nil).Once() + pc.mocks.gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ Namespace: "ns", Name: "n", Ref: "main", @@ -770,7 +692,7 @@ func TestPromptComponent_DelRelationModel(t *testing.T) { }).Return(&types.File{ Content: "LS0tCm1vZGVsczoKICAgIC0gbWEKdGl0bGU6IGFpCgotLS0=", }, nil).Once() - gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ + pc.mocks.gitServer.EXPECT().UpdateRepoFile(&types.UpdateFileReq{ Branch: types.MainBranch, Message: "delete relation model", FilePath: REPOCARD_FILENAME, @@ -793,14 +715,10 @@ func TestPromptComponent_DelRelationModel(t *testing.T) { } func TestPromptComponent_CreatePromptRepo(t *testing.T) { - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - pc := NewTestPromptComponent(stores, nil, gitServer) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) - stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ + pc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "foo").Return(database.User{ ID: 123, Email: "foo@bar.com", RoleMask: "foo-admin", @@ -817,14 +735,14 @@ func TestPromptComponent_CreatePromptRepo(t *testing.T) { DefaultBranch: "main", RepoType: types.PromptRepo, } - stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil).Once() + pc.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil).Once() dbRepo := &database.Repository{} - mockedRepoComponent.EXPECT().CreateRepo(ctx, req).Return(&gitserver.CreateRepoResp{}, dbRepo, nil) + pc.mocks.components.repo.EXPECT().CreateRepo(ctx, req).Return(&gitserver.CreateRepoResp{}, dbRepo, nil) dbPrompt := database.Prompt{ Repository: dbRepo, RepositoryID: dbRepo.ID, } - stores.PromptMock().EXPECT().Create(ctx, dbPrompt).Return(&database.Prompt{ + pc.mocks.stores.PromptMock().EXPECT().Create(ctx, dbPrompt).Return(&database.Prompt{ Repository: &database.Repository{ Name: "r1", Tags: []database.Tag{ @@ -834,7 +752,7 @@ func TestPromptComponent_CreatePromptRepo(t *testing.T) { }, }, nil) // create readme - gitServer.EXPECT().CreateRepoFile(&types.CreateFileReq{ + pc.mocks.gitServer.EXPECT().CreateRepoFile(&types.CreateFileReq{ Email: "foo@bar.com", Message: "initial commit", Branch: "main", @@ -846,7 +764,7 @@ func TestPromptComponent_CreatePromptRepo(t *testing.T) { RepoType: types.PromptRepo, }).Return(nil).Once() // create .gitattributes - gitServer.EXPECT().CreateRepoFile(&types.CreateFileReq{ + pc.mocks.gitServer.EXPECT().CreateRepoFile(&types.CreateFileReq{ Email: "foo@bar.com", Message: "initial commit", Branch: "main", @@ -886,19 +804,15 @@ func TestPromptComponent_CreatePromptRepo(t *testing.T) { } func TestPromptComponent_IndexPromptRepo(t *testing.T) { - stores := tests.NewMockStores(t) - gitServer := gsmock.NewMockGitServer(t) - pc := NewTestPromptComponent(stores, nil, gitServer) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) filter := &types.RepoFilter{Username: "foo"} - mockedRepoComponent.EXPECT().PublicToUser(ctx, types.PromptRepo, "foo", filter, 1, 1).Return([]*database.Repository{ + pc.mocks.components.repo.EXPECT().PublicToUser(ctx, types.PromptRepo, "foo", filter, 1, 1).Return([]*database.Repository{ {ID: 1, Name: "rp1"}, {ID: 2, Name: "rp2"}, {ID: 3, Name: "rp3", Tags: []database.Tag{{Name: "t1"}, {Name: "t2"}}}, }, 30, nil).Once() - stores.PromptMock().EXPECT().ByRepoIDs(ctx, []int64{1, 2, 3}).Return([]database.Prompt{ + pc.mocks.stores.PromptMock().EXPECT().ByRepoIDs(ctx, []int64{1, 2, 3}).Return([]database.Prompt{ {ID: 6, RepositoryID: 2, Repository: &database.Repository{}}, {ID: 5, RepositoryID: 1, Repository: &database.Repository{}}, {ID: 4, RepositoryID: 3, Repository: &database.Repository{}}, @@ -932,20 +846,17 @@ func TestPromptComponent_IndexPromptRepo(t *testing.T) { } func TestPromptComponent_UpdatePromptRepo(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) req := &types.UpdatePromptRepoReq{ UpdateRepoReq: types.UpdateRepoReq{RepoType: types.PromptRepo}, } mockedRepo := &database.Repository{Name: "rp1", ID: 123} - mockedRepoComponent.EXPECT().UpdateRepo(ctx, req.UpdateRepoReq).Return(mockedRepo, nil).Once() + pc.mocks.components.repo.EXPECT().UpdateRepo(ctx, req.UpdateRepoReq).Return(mockedRepo, nil).Once() mockedPrompt := &database.Prompt{ID: 3} - stores.PromptMock().EXPECT().ByRepoID(ctx, int64(123)).Return(mockedPrompt, nil).Once() - stores.PromptMock().EXPECT().Update(ctx, *mockedPrompt).Return(nil).Once() + pc.mocks.stores.PromptMock().EXPECT().ByRepoID(ctx, int64(123)).Return(mockedPrompt, nil).Once() + pc.mocks.stores.PromptMock().EXPECT().Update(ctx, *mockedPrompt).Return(nil).Once() res, err := pc.UpdatePromptRepo(ctx, req) require.Nil(t, err) @@ -958,21 +869,18 @@ func TestPromptComponent_UpdatePromptRepo(t *testing.T) { } func TestPromptComponent_RemovetRepo(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) mockedPrompt := &database.Prompt{} - stores.PromptMock().EXPECT().FindByPath(ctx, "ns", "n").Return(mockedPrompt, nil).Once() - mockedRepoComponent.EXPECT().DeleteRepo(ctx, types.DeleteRepoReq{ + pc.mocks.stores.PromptMock().EXPECT().FindByPath(ctx, "ns", "n").Return(mockedPrompt, nil).Once() + pc.mocks.components.repo.EXPECT().DeleteRepo(ctx, types.DeleteRepoReq{ Username: "foo", Namespace: "ns", Name: "n", RepoType: types.PromptRepo, }).Return(nil, nil).Once() - stores.PromptMock().EXPECT().Delete(ctx, *mockedPrompt).Return(nil).Once() + pc.mocks.stores.PromptMock().EXPECT().Delete(ctx, *mockedPrompt).Return(nil).Once() err := pc.RemoveRepo(ctx, "ns", "n", "foo") require.Nil(t, err) @@ -980,11 +888,8 @@ func TestPromptComponent_RemovetRepo(t *testing.T) { } func TestPromptComponent_Show(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) mockedPrompt := &database.Prompt{ Repository: &database.Repository{ @@ -992,12 +897,12 @@ func TestPromptComponent_Show(t *testing.T) { Tags: []database.Tag{{Name: "t1"}}, }, } - stores.PromptMock().EXPECT().FindByPath(ctx, "ns", "n").Return(mockedPrompt, nil).Once() - mockedRepoComponent.EXPECT().GetUserRepoPermission(ctx, "foo", mockedPrompt.Repository).Return(&types.UserRepoPermission{ + pc.mocks.stores.PromptMock().EXPECT().FindByPath(ctx, "ns", "n").Return(mockedPrompt, nil).Once() + pc.mocks.components.repo.EXPECT().GetUserRepoPermission(ctx, "foo", mockedPrompt.Repository).Return(&types.UserRepoPermission{ CanRead: true, }, nil).Once() - mockedRepoComponent.EXPECT().GetNameSpaceInfo(ctx, "ns").Return(&types.Namespace{}, nil).Once() - stores.UserLikesMock().EXPECT().IsExist(ctx, "foo", int64(123)).Return(true, nil).Once() + pc.mocks.components.repo.EXPECT().GetNameSpaceInfo(ctx, "ns").Return(&types.Namespace{}, nil).Once() + pc.mocks.stores.UserLikesMock().EXPECT().IsExist(ctx, "foo", int64(123)).Return(true, nil).Once() res, err := pc.Show(ctx, "ns", "n", "foo") require.Nil(t, err) @@ -1015,11 +920,8 @@ func TestPromptComponent_Show(t *testing.T) { } func TestPromptComponent_Relations(t *testing.T) { - stores := tests.NewMockStores(t) - pc := NewTestPromptComponent(stores, nil, nil) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) mockedPrompt := &database.Prompt{ RepositoryID: 123, @@ -1028,9 +930,9 @@ func TestPromptComponent_Relations(t *testing.T) { Tags: []database.Tag{{Name: "t1"}}, }, } - stores.PromptMock().EXPECT().FindByPath(ctx, "ns", "n").Return(mockedPrompt, nil).Once() - mockedRepoComponent.EXPECT().AllowReadAccessRepo(ctx, mockedPrompt.Repository, "foo").Return(true, nil).Once() - mockedRepoComponent.EXPECT().RelatedRepos(ctx, int64(123), "foo").Return( + pc.mocks.stores.PromptMock().EXPECT().FindByPath(ctx, "ns", "n").Return(mockedPrompt, nil).Once() + pc.mocks.components.repo.EXPECT().AllowReadAccessRepo(ctx, mockedPrompt.Repository, "foo").Return(true, nil).Once() + pc.mocks.components.repo.EXPECT().RelatedRepos(ctx, int64(123), "foo").Return( map[types.RepositoryType][]*database.Repository{ types.ModelRepo: { {ID: 1, Name: "r1"}, @@ -1055,12 +957,8 @@ func TestPromptComponent_Relations(t *testing.T) { } func TestPromptComponent_OrgPrompts(t *testing.T) { - stores := tests.NewMockStores(t) - rpcUser := urpc_mock.NewMockUserSvcClient(t) - pc := NewTestPromptComponent(stores, rpcUser, nil) - mockedRepoComponent := component_mock.NewMockRepoComponent(t) - pc.repoComponent = mockedRepoComponent ctx := context.TODO() + pc := initializeTestPromptComponent(ctx, t) cases := []struct { role membership.Role @@ -1072,8 +970,8 @@ func TestPromptComponent_OrgPrompts(t *testing.T) { for _, c := range cases { t.Run(string(c.role), func(t *testing.T) { - rpcUser.EXPECT().GetMemberRole(ctx, "ns", "foo").Return(c.role, nil).Once() - stores.PromptMock().EXPECT().ByOrgPath(ctx, "ns", 1, 1, c.publicOnly).Return([]database.Prompt{ + pc.mocks.userSvcClient.EXPECT().GetMemberRole(ctx, "ns", "foo").Return(c.role, nil).Once() + pc.mocks.stores.PromptMock().EXPECT().ByOrgPath(ctx, "ns", 1, 1, c.publicOnly).Return([]database.Prompt{ {ID: 1, Repository: &database.Repository{Name: "r1"}}, {ID: 2, Repository: &database.Repository{Name: "r2"}}, {ID: 3, Repository: &database.Repository{Name: "r3"}}, diff --git a/component/repo.go b/component/repo.go index 48d1ba29..4b6f3e83 100644 --- a/component/repo.go +++ b/component/repo.go @@ -42,39 +42,38 @@ const ( ) type repoComponentImpl struct { - tc TagComponent - user database.UserStore - org database.OrgStore - namespace database.NamespaceStore - repo database.RepoStore - repoFile database.RepoFileStore - rel database.RepoRelationsStore - mirror database.MirrorStore - git gitserver.GitServer - s3Client *s3.Client - userSvcClient rpc.UserSvcClient - lfsBucket string - uls database.UserLikesStore - mirrorServer mirrorserver.MirrorServer - runFrame database.RuntimeFrameworksStore - deploy database.DeployTaskStore - deployer deploy.Deployer - publicRootDomain string - serverBaseUrl string - cluster database.ClusterInfoStore - mirrorSource database.MirrorSourceStore - tokenStore database.AccessTokenStore - rtfm database.RuntimeFrameworksStore - rrtfms database.RepositoriesRuntimeFrameworkStore - syncVersion database.SyncVersionStore - syncClientSetting database.SyncClientSettingStore - file database.FileStore - config *config.Config - ac AccountingComponent - srs database.SpaceResourceStore - lfsMetaObjectStore database.LfsMetaObjectStore - recom database.RecomStore - mq *queue.PriorityQueue + tagComponent TagComponent + userStore database.UserStore + orgStore database.OrgStore + namespaceStore database.NamespaceStore + repoStore database.RepoStore + repoFileStore database.RepoFileStore + repoRelationsStore database.RepoRelationsStore + mirrorStore database.MirrorStore + git gitserver.GitServer + s3Client s3.Client + userSvcClient rpc.UserSvcClient + lfsBucket string + userLikesStore database.UserLikesStore + mirrorServer mirrorserver.MirrorServer + runtimeFrameworksStore database.RuntimeFrameworksStore + deployTaskStore database.DeployTaskStore + deployer deploy.Deployer + publicRootDomain string + serverBaseUrl string + cluster database.ClusterInfoStore + mirrorSourceStore database.MirrorSourceStore + tokenStore database.AccessTokenStore + repoRuntimeFrameworkStore database.RepositoriesRuntimeFrameworkStore + syncVersionStore database.SyncVersionStore + syncClientSettingStore database.SyncClientSettingStore + fileStore database.FileStore + config *config.Config + accountingComponent AccountingComponent + spaceResourceStore database.SpaceResourceStore + lfsMetaObjectStore database.LfsMetaObjectStore + recomStore database.RecomStore + mq queue.PriorityQueue } type RepoComponent interface { @@ -143,6 +142,9 @@ type RepoComponent interface { CheckCurrentUserPermission(ctx context.Context, userName string, namespace string, role membership.Role) (bool, error) GetNameSpaceInfo(ctx context.Context, path string) (*types.Namespace, error) RelatedRepos(ctx context.Context, repoID int64, currentUser string) (map[types.RepositoryType][]*database.Repository, error) + VisiableToUser(ctx context.Context, repos []*database.Repository, currentUser string) ([]*database.Repository, error) + GenerateEndpoint(ctx context.Context, deploy *database.Deploy) (string, string) + IsAdminRole(user database.User) bool } func NewRepoComponentImpl(config *config.Config) (*repoComponentImpl, error) { @@ -155,19 +157,19 @@ func NewRepoComponentImpl(config *config.Config) (*repoComponentImpl, error) { func NewRepoComponent(config *config.Config) (RepoComponent, error) { c := &repoComponentImpl{} - c.namespace = database.NewNamespaceStore() - c.user = database.NewUserStore() - c.org = database.NewOrgStore() - c.repo = database.NewRepoStore() - c.repoFile = database.NewRepoFileStore() - c.rel = database.NewRepoRelationsStore() - c.uls = database.NewUserLikesStore() - c.mirror = database.NewMirrorStore() - c.mirrorSource = database.NewMirrorSourceStore() + c.namespaceStore = database.NewNamespaceStore() + c.userStore = database.NewUserStore() + c.orgStore = database.NewOrgStore() + c.repoStore = database.NewRepoStore() + c.repoFileStore = database.NewRepoFileStore() + c.repoRelationsStore = database.NewRepoRelationsStore() + c.userLikesStore = database.NewUserLikesStore() + c.mirrorStore = database.NewMirrorStore() + c.mirrorSourceStore = database.NewMirrorSourceStore() c.tokenStore = database.NewAccessTokenStore() - c.syncVersion = database.NewSyncVersionStore() - c.syncClientSetting = database.NewSyncClientSettingStore() - c.file = database.NewFileStore() + c.syncVersionStore = database.NewSyncVersionStore() + c.syncClientSettingStore = database.NewSyncClientSettingStore() + c.fileStore = database.NewFileStore() var err error c.git, err = git.NewGitServer(config) if err != nil { @@ -186,7 +188,7 @@ func NewRepoComponent(config *config.Config) (RepoComponent, error) { slog.Error(newError.Error()) return nil, newError } - c.tc, err = NewTagComponent(config) + c.tagComponent, err = NewTagComponent(config) if err != nil { newError := fmt.Errorf("fail to create tag component,error:%w", err) slog.Error(newError.Error()) @@ -201,32 +203,31 @@ func NewRepoComponent(config *config.Config) (RepoComponent, error) { c.lfsBucket = config.S3.Bucket c.userSvcClient = rpc.NewUserSvcHttpClient(fmt.Sprintf("%s:%d", config.User.Host, config.User.Port), rpc.AuthWithApiKey(config.APIToken)) - c.runFrame = database.NewRuntimeFrameworksStore() - c.deploy = database.NewDeployTaskStore() + c.runtimeFrameworksStore = database.NewRuntimeFrameworksStore() + c.deployTaskStore = database.NewDeployTaskStore() c.deployer = deploy.NewDeployer() c.publicRootDomain = config.Space.PublicRootDomain c.serverBaseUrl = config.APIServer.PublicDomain c.cluster = database.NewClusterInfoStore() - c.rtfm = database.NewRuntimeFrameworksStore() - c.rrtfms = database.NewRepositoriesRuntimeFramework() - c.ac, err = NewAccountingComponent(config) + c.repoRuntimeFrameworkStore = database.NewRepositoriesRuntimeFramework() + c.accountingComponent, err = NewAccountingComponent(config) if err != nil { return nil, err } - c.srs = database.NewSpaceResourceStore() + c.spaceResourceStore = database.NewSpaceResourceStore() c.lfsMetaObjectStore = database.NewLfsMetaObjectStore() - c.recom = database.NewRecomStore() + c.recomStore = database.NewRecomStore() c.config = config return c, nil } func (c *repoComponentImpl) CreateRepo(ctx context.Context, req types.CreateRepoReq) (*gitserver.CreateRepoResp, *database.Repository, error) { - namespace, err := c.namespace.FindByPath(ctx, req.Namespace) + namespace, err := c.namespaceStore.FindByPath(ctx, req.Namespace) if err != nil { return nil, nil, errors.New("namespace does not exist") } - user, err := c.user.FindByUsername(ctx, req.Username) + user, err := c.userStore.FindByUsername(ctx, req.Username) if err != nil { return nil, nil, errors.New("user does not exist") } @@ -286,7 +287,7 @@ func (c *repoComponentImpl) CreateRepo(ctx context.Context, req types.CreateRepo HTTPCloneURL: gitRepo.HttpCloneURL, SSHCloneURL: gitRepo.SshCloneURL, } - newDBRepo, err := c.repo.CreateRepo(ctx, dbRepo) + newDBRepo, err := c.repoStore.CreateRepo(ctx, dbRepo) if err != nil { return nil, nil, fmt.Errorf("fail to create database repo, error: %w", err) } @@ -296,17 +297,17 @@ func (c *repoComponentImpl) CreateRepo(ctx context.Context, req types.CreateRepo } func (c *repoComponentImpl) UpdateRepo(ctx context.Context, req types.UpdateRepoReq) (*database.Repository, error) { - repo, err := c.repo.Find(ctx, req.Namespace, string(req.RepoType), req.Name) + repo, err := c.repoStore.Find(ctx, req.Namespace, string(req.RepoType), req.Name) if err != nil { return nil, errors.New("repository does not exist") } - namespace, err := c.namespace.FindByPath(ctx, req.Namespace) + namespace, err := c.namespaceStore.FindByPath(ctx, req.Namespace) if err != nil { return nil, errors.New("namespace does not exist") } - user, err := c.user.FindByUsername(ctx, req.Username) + user, err := c.userStore.FindByUsername(ctx, req.Username) if err != nil { return nil, errors.New("user does not exist") } @@ -352,7 +353,7 @@ func (c *repoComponentImpl) UpdateRepo(ctx context.Context, req types.UpdateRepo return nil, fmt.Errorf("fail to update repo in git, error: %w", err) } - resRepo, err := c.repo.UpdateRepo(ctx, *repo) + resRepo, err := c.repoStore.UpdateRepo(ctx, *repo) if err != nil { slog.Error("fail to update repo in git ", slog.Any("req", req), slog.String("error", err.Error())) return nil, fmt.Errorf("fail to update repo in database, error: %w", err) @@ -362,17 +363,17 @@ func (c *repoComponentImpl) UpdateRepo(ctx context.Context, req types.UpdateRepo } func (c *repoComponentImpl) DeleteRepo(ctx context.Context, req types.DeleteRepoReq) (*database.Repository, error) { - repo, err := c.repo.Find(ctx, req.Namespace, string(req.RepoType), req.Name) + repo, err := c.repoStore.Find(ctx, req.Namespace, string(req.RepoType), req.Name) if err != nil { return nil, errors.New("repository does not exist") } - namespace, err := c.namespace.FindByPath(ctx, req.Namespace) + namespace, err := c.namespaceStore.FindByPath(ctx, req.Namespace) if err != nil { return nil, errors.New("namespace does not exist") } - user, err := c.user.FindByUsername(ctx, req.Username) + user, err := c.userStore.FindByUsername(ctx, req.Username) if err != nil { return nil, errors.New("user does not exist") } @@ -391,7 +392,7 @@ func (c *repoComponentImpl) DeleteRepo(ctx context.Context, req types.DeleteRepo } } - err = c.repo.CleanRelationsByRepoID(ctx, repo.ID) + err = c.repoStore.CleanRelationsByRepoID(ctx, repo.ID) if err != nil { return nil, fmt.Errorf("fail to clean repo relations, %w", err) } @@ -407,7 +408,7 @@ func (c *repoComponentImpl) DeleteRepo(ctx context.Context, req types.DeleteRepo return nil, fmt.Errorf("fail to delete repo in git, error: %w", err) } - err = c.repo.DeleteRepo(ctx, *repo) + err = c.repoStore.DeleteRepo(ctx, *repo) if err != nil { slog.Error("fail to delete repo in git ", slog.Any("req", req), slog.String("error", err.Error())) return nil, fmt.Errorf("fail to delete repo in database, error: %w", err) @@ -432,7 +433,7 @@ func (c *repoComponentImpl) PublicToUser(ctx context.Context, repoType types.Rep repoOwnerIDs = append(repoOwnerIDs, org.UserID) } } - repos, count, err = c.repo.PublicToUser(ctx, repoType, repoOwnerIDs, filter, per, page) + repos, count, err = c.repoStore.PublicToUser(ctx, repoType, repoOwnerIDs, filter, per, page) if err != nil { return nil, 0, fmt.Errorf("failed to get user public repos, error: %w", err) } @@ -442,7 +443,7 @@ func (c *repoComponentImpl) PublicToUser(ctx context.Context, repoType types.Rep // RelatedRepos gets all repos related to the given repo, and return them by repo type func (c *repoComponentImpl) RelatedRepos(ctx context.Context, repoID int64, currentUser string) (map[types.RepositoryType][]*database.Repository, error) { - fromRelations, err := c.rel.From(ctx, repoID) + fromRelations, err := c.repoRelationsStore.From(ctx, repoID) if err != nil { return nil, fmt.Errorf("failed to get repo relation from, error: %w", err) } @@ -451,7 +452,7 @@ func (c *repoComponentImpl) RelatedRepos(ctx context.Context, repoID int64, curr toRepoIDs = append(toRepoIDs, rel.ToRepoID) } - toRelations, err := c.rel.To(ctx, repoID) + toRelations, err := c.repoRelationsStore.To(ctx, repoID) if err != nil { return nil, fmt.Errorf("failed to get repo relation to, error: %w", err) } @@ -471,12 +472,12 @@ func (c *repoComponentImpl) RelatedRepos(ctx context.Context, repoID int64, curr opts = append(opts, database.Columns("id", "repository_type", "path", "user_id", "private", "name", "nickname", "description", "download_count", "updated_at")) - RelatedRepos, err := c.repo.FindByIds(ctx, relatedRepoIDs, opts...) + RelatedRepos, err := c.repoStore.FindByIds(ctx, relatedRepoIDs, opts...) if err != nil { return nil, fmt.Errorf("failed to get relation to repositories by ids, error: %w", err) } - RelatedRepos, err = c.visiableToUser(ctx, RelatedRepos, currentUser) + RelatedRepos, err = c.VisiableToUser(ctx, RelatedRepos, currentUser) if err != nil { return nil, fmt.Errorf("failed to check related repositories visiable to user:%s, %w", currentUser, err) } @@ -487,7 +488,7 @@ func (c *repoComponentImpl) RelatedRepos(ctx context.Context, repoID int64, curr return res, nil } -func (c *repoComponentImpl) visiableToUser(ctx context.Context, repos []*database.Repository, currentUser string) ([]*database.Repository, error) { +func (c *repoComponentImpl) VisiableToUser(ctx context.Context, repos []*database.Repository, currentUser string) ([]*database.Repository, error) { var res []*database.Repository for _, repo := range repos { if repo.Private { @@ -516,7 +517,7 @@ func (c *repoComponentImpl) CreateFile(ctx context.Context, req *types.CreateFil user database.User useLfs bool ) - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } @@ -529,13 +530,13 @@ func (c *repoComponentImpl) CreateFile(ctx context.Context, req *types.CreateFil return nil, ErrUnauthorized } - user, err = c.user.FindByUsername(ctx, req.Username) + user, err = c.userStore.FindByUsername(ctx, req.Username) if err != nil { return nil, fmt.Errorf("fail to check user, cause: %w", err) } req.Email = user.Email - _, err = c.namespace.FindByPath(ctx, req.Namespace) + _, err = c.namespaceStore.FindByPath(ctx, req.Namespace) if err != nil { return nil, fmt.Errorf("fail to check namespace, cause: %w", err) } @@ -579,7 +580,7 @@ func (c *repoComponentImpl) CreateFile(ctx context.Context, req *types.CreateFil } } - err = c.repo.SetUpdateTimeByPath(ctx, req.RepoType, req.Namespace, req.Name, time.Now()) + err = c.repoStore.SetUpdateTimeByPath(ctx, req.RepoType, req.Namespace, req.Name, time.Now()) if err != nil { slog.Error("failed to set repo update time", slog.Any("error", err), slog.String("repo_type", string(req.RepoType)), slog.String("namespace", req.Namespace), slog.String("name", req.Name)) } @@ -591,7 +592,7 @@ func (c *repoComponentImpl) CreateFile(ctx context.Context, req *types.CreateFil func (c *repoComponentImpl) createReadmeFile(ctx context.Context, req *types.CreateFileReq) error { var err error contentDecoded, _ := base64.RawStdEncoding.DecodeString(req.Content) - _, err = c.tc.UpdateMetaTags(ctx, getTagScopeByRepoType(req.RepoType), req.Namespace, req.Name, string(contentDecoded)) + _, err = c.tagComponent.UpdateMetaTags(ctx, getTagScopeByRepoType(req.RepoType), req.Namespace, req.Name, string(contentDecoded)) if err != nil { return fmt.Errorf("failed to update meta tags, cause: %w", err) } @@ -606,7 +607,7 @@ func (c *repoComponentImpl) createReadmeFile(ctx context.Context, req *types.Cre func (c *repoComponentImpl) createLibraryFile(ctx context.Context, req *types.CreateFileReq) error { var err error - err = c.tc.UpdateLibraryTags(ctx, getTagScopeByRepoType(req.RepoType), req.Namespace, req.Name, "", req.FilePath) + err = c.tagComponent.UpdateLibraryTags(ctx, getTagScopeByRepoType(req.RepoType), req.Namespace, req.Name, "", req.FilePath) if err != nil { slog.Error(fmt.Sprintf("failed to set %s's tags", req.RepoType), slog.String("namespace", req.Namespace), slog.String("name", req.Name), slog.Any("error", err)) @@ -629,7 +630,7 @@ func (c *repoComponentImpl) UpdateFile(ctx context.Context, req *types.UpdateFil user database.User useLfs bool ) - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } @@ -642,13 +643,13 @@ func (c *repoComponentImpl) UpdateFile(ctx context.Context, req *types.UpdateFil return nil, ErrUnauthorized } - user, err = c.user.FindByUsername(ctx, req.Username) + user, err = c.userStore.FindByUsername(ctx, req.Username) if err != nil { return nil, fmt.Errorf("fail to check user, cause: %w", err) } req.Email = user.Email - _, err = c.namespace.FindByPath(ctx, req.Namespace) + _, err = c.namespaceStore.FindByPath(ctx, req.Namespace) if err != nil { return nil, fmt.Errorf("fail to check namespace, cause: %w", err) } @@ -698,7 +699,7 @@ func (c *repoComponentImpl) UpdateFile(ctx context.Context, req *types.UpdateFil } } - err = c.repo.SetUpdateTimeByPath(ctx, req.RepoType, req.Namespace, req.Name, time.Now()) + err = c.repoStore.SetUpdateTimeByPath(ctx, req.RepoType, req.Namespace, req.Name, time.Now()) if err != nil { slog.Error("failed to set repo update time", slog.Any("error", err), slog.String("repo_type", string(req.RepoType)), slog.String("namespace", req.Namespace), slog.String("name", req.Name)) } @@ -715,7 +716,7 @@ func (c *repoComponentImpl) DeleteFile(ctx context.Context, req *types.DeleteFil err error user database.User ) - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } @@ -728,13 +729,13 @@ func (c *repoComponentImpl) DeleteFile(ctx context.Context, req *types.DeleteFil return nil, ErrUnauthorized } - user, err = c.user.FindByUsername(ctx, req.Username) + user, err = c.userStore.FindByUsername(ctx, req.Username) if err != nil { return nil, fmt.Errorf("fail to check user, cause: %w", err) } req.Email = user.Email - _, err = c.namespace.FindByPath(ctx, req.Namespace) + _, err = c.namespaceStore.FindByPath(ctx, req.Namespace) if err != nil { return nil, fmt.Errorf("fail to check namespace, cause: %w", err) } @@ -760,7 +761,7 @@ func (c *repoComponentImpl) DeleteFile(ctx context.Context, req *types.DeleteFil slog.Error("failed to delete file", slog.String("file", req.FilePath), slog.Any("error", err), slog.String("namespace", req.Namespace), slog.String("name", req.Name)) } - err = c.repo.SetUpdateTimeByPath(ctx, req.RepoType, req.Namespace, req.Name, time.Now()) + err = c.repoStore.SetUpdateTimeByPath(ctx, req.RepoType, req.Namespace, req.Name, time.Now()) if err != nil { slog.Error("failed to set repo update time", slog.Any("error", err), slog.String("repo_type", string(req.RepoType)), slog.String("namespace", req.Namespace), slog.String("name", req.Name)) } @@ -785,7 +786,7 @@ func (c *repoComponentImpl) changeLibraryFile(ctx context.Context, filePath, ori isFileRenamed := filePath != originPath // need to handle tag change only if file renamed if isFileRenamed { - err = c.tc.UpdateLibraryTags(ctx, getTagScopeByRepoType(repoType), namespace, name, originPath, filePath) + err = c.tagComponent.UpdateLibraryTags(ctx, getTagScopeByRepoType(repoType), namespace, name, originPath, filePath) if err != nil { slog.Error(fmt.Sprintf("failed to set %s's tags", repoType), slog.String("namespace", namespace), slog.String("name", name), slog.Any("error", err)) @@ -815,7 +816,7 @@ func (c *repoComponentImpl) deleteReadmeFile(ctx context.Context, req *types.Del func (c *repoComponentImpl) changeReadmeFile(ctx context.Context, content, namespace, name string, repoType types.RepositoryType) error { contentDecoded, _ := base64.RawStdEncoding.DecodeString(content) - _, err := c.tc.UpdateMetaTags(ctx, getTagScopeByRepoType(repoType), namespace, name, string(contentDecoded)) + _, err := c.tagComponent.UpdateMetaTags(ctx, getTagScopeByRepoType(repoType), namespace, name, string(contentDecoded)) if err != nil { return fmt.Errorf("failed to update meta tags, cause: %w", err) } @@ -823,7 +824,7 @@ func (c *repoComponentImpl) changeReadmeFile(ctx context.Context, content, names } func (c *repoComponentImpl) Commits(ctx context.Context, req *types.GetCommitsReq) ([]types.Commit, *types.RepoPageOpts, error) { - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, nil, fmt.Errorf("failed to find repo, error: %w", err) } @@ -855,7 +856,7 @@ func (c *repoComponentImpl) Commits(ctx context.Context, req *types.GetCommitsRe } func (c *repoComponentImpl) LastCommit(ctx context.Context, req *types.GetCommitsReq) (*types.Commit, error) { - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } @@ -885,7 +886,7 @@ func (c *repoComponentImpl) LastCommit(ctx context.Context, req *types.GetCommit } func (c *repoComponentImpl) FileRaw(ctx context.Context, req *types.GetFileReq) (string, error) { - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil || repo == nil { return "", fmt.Errorf("failed to find repo, error: %w", err) } @@ -899,7 +900,7 @@ func (c *repoComponentImpl) FileRaw(ctx context.Context, req *types.GetFileReq) } if repo.Source != types.LocalSource && strings.ToLower(req.Path) == "readme.md" { - _, err := c.mirror.FindByRepoID(ctx, repo.ID) + _, err := c.mirrorStore.FindByRepoID(ctx, repo.ID) if err != nil { if errors.Is(err, sql.ErrNoRows) { return repo.Readme, nil @@ -929,7 +930,7 @@ func (c *repoComponentImpl) DownloadFile(ctx context.Context, req *types.GetFile downloadUrl string size int64 ) - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, 0, "", fmt.Errorf("failed to find repo, error: %w", err) } @@ -942,7 +943,7 @@ func (c *repoComponentImpl) DownloadFile(ctx context.Context, req *types.GetFile return nil, 0, "", ErrUnauthorized } - err = c.repo.UpdateRepoFileDownloads(ctx, repo, time.Now(), 1) + err = c.repoStore.UpdateRepoFileDownloads(ctx, repo, time.Now(), 1) if err != nil { return nil, 0, "", fmt.Errorf("failed to update %s file download count, error: %w", req.RepoType, err) } @@ -979,7 +980,7 @@ func (c *repoComponentImpl) DownloadFile(ctx context.Context, req *types.GetFile } func (c *repoComponentImpl) Branches(ctx context.Context, req *types.GetBranchesReq) ([]types.Branch, error) { - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } @@ -1010,7 +1011,7 @@ func (c *repoComponentImpl) Branches(ctx context.Context, req *types.GetBranches } func (c *repoComponentImpl) Tags(ctx context.Context, req *types.GetTagsReq) ([]database.Tag, error) { - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find %s, error: %w", req.RepoType, err) } @@ -1023,7 +1024,7 @@ func (c *repoComponentImpl) Tags(ctx context.Context, req *types.GetTagsReq) ([] return nil, ErrUnauthorized } - tags, err := c.repo.Tags(ctx, repo.ID) + tags, err := c.repoStore.Tags(ctx, repo.ID) if err != nil { return nil, fmt.Errorf("failed to get %s tags, error: %w", req.RepoType, err) } @@ -1031,7 +1032,7 @@ func (c *repoComponentImpl) Tags(ctx context.Context, req *types.GetTagsReq) ([] } func (c *repoComponentImpl) UpdateTags(ctx context.Context, namespace, name string, repoType types.RepositoryType, category, currentUser string, tags []string) error { - repo, err := c.repo.FindByPath(ctx, repoType, namespace, name) + repo, err := c.repoStore.FindByPath(ctx, repoType, namespace, name) if err != nil { return fmt.Errorf("failed to find repo, error: %w", err) } @@ -1045,13 +1046,13 @@ func (c *repoComponentImpl) UpdateTags(ctx context.Context, namespace, name stri } tagScope := getTagScopeByRepoType(repoType) - err = c.tc.UpdateRepoTagsByCategory(ctx, tagScope, repo.ID, category, tags) + err = c.tagComponent.UpdateRepoTagsByCategory(ctx, tagScope, repo.ID, category, tags) return err } func (c *repoComponentImpl) Tree(ctx context.Context, req *types.GetFileReq) ([]*types.File, error) { - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } @@ -1069,13 +1070,13 @@ func (c *repoComponentImpl) Tree(ctx context.Context, req *types.GetFileReq) ([] } if repo.Source != types.LocalSource { - _, err := c.mirror.FindByRepoID(ctx, repo.ID) + _, err := c.mirrorStore.FindByRepoID(ctx, repo.ID) if err != nil { if errors.Is(err, sql.ErrNoRows) { if req.Path == "" { req.Path = "/" } - files, err := c.file.FindByParentPath(ctx, repo.ID, req.Path) + files, err := c.fileStore.FindByParentPath(ctx, repo.ID, req.Path) if err != nil { if errors.Is(err, sql.ErrNoRows) { return []*types.File{}, nil @@ -1153,7 +1154,7 @@ func (c *repoComponentImpl) UploadFile(ctx context.Context, req *types.CreateFil func (c *repoComponentImpl) SDKListFiles(ctx context.Context, repoType types.RepositoryType, namespace, name, ref, userName string) (*types.SDKFiles, error) { var sdkFiles []types.SDKFile - repo, err := c.repo.FindByPath(ctx, repoType, namespace, name) + repo, err := c.repoStore.FindByPath(ctx, repoType, namespace, name) if err != nil || repo == nil { return nil, ErrNotFound } @@ -1210,7 +1211,7 @@ func (c *repoComponentImpl) IsLfs(ctx context.Context, req *types.GetFileReq) (b } func (c *repoComponentImpl) HeadDownloadFile(ctx context.Context, req *types.GetFileReq, userName string) (*types.File, error) { - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } @@ -1244,7 +1245,7 @@ func (c *repoComponentImpl) HeadDownloadFile(ctx context.Context, req *types.Get func (c *repoComponentImpl) SDKDownloadFile(ctx context.Context, req *types.GetFileReq, userName string) (io.ReadCloser, int64, string, error) { var downloadUrl string - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, 0, "", fmt.Errorf("failed to find repo, error: %w", err) } @@ -1307,12 +1308,12 @@ func (c *repoComponentImpl) SDKDownloadFile(ctx context.Context, req *types.GetF // UpdateDownloads increase clone download count for repo by given count func (c *repoComponentImpl) UpdateDownloads(ctx context.Context, req *types.UpdateDownloadsReq) error { - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return fmt.Errorf("failed to find %s, error: %w", req.RepoType, err) } - err = c.repo.UpdateRepoCloneDownloads(ctx, repo, req.Date, req.CloneCount) + err = c.repoStore.UpdateRepoCloneDownloads(ctx, repo, req.Date, req.CloneCount) if err != nil { return fmt.Errorf("failed to update %s download count, error: %w", req.RepoType, err) } @@ -1321,12 +1322,12 @@ func (c *repoComponentImpl) UpdateDownloads(ctx context.Context, req *types.Upda // IncrDownloads increase the click download count for repo by 1 func (c *repoComponentImpl) IncrDownloads(ctx context.Context, repoType types.RepositoryType, namespace, name string) error { - repo, err := c.repo.FindByPath(ctx, repoType, namespace, name) + repo, err := c.repoStore.FindByPath(ctx, repoType, namespace, name) if err != nil { return fmt.Errorf("failed to find %s, error: %w", repoType, err) } - err = c.repo.UpdateRepoFileDownloads(ctx, repo, time.Now(), 1) + err = c.repoStore.UpdateRepoFileDownloads(ctx, repo, time.Now(), 1) if err != nil { return fmt.Errorf("failed to incr download count, error: %w", err) } @@ -1334,7 +1335,7 @@ func (c *repoComponentImpl) IncrDownloads(ctx context.Context, repoType types.Re } func (c *repoComponentImpl) FileInfo(ctx context.Context, req *types.GetFileReq) (*types.File, error) { - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } @@ -1352,7 +1353,7 @@ func (c *repoComponentImpl) FileInfo(ctx context.Context, req *types.GetFileReq) } if repo.Source != types.LocalSource && strings.ToLower(req.Path) == "readme.md" { - _, err := c.mirror.FindByRepoID(ctx, repo.ID) + _, err := c.mirrorStore.FindByRepoID(ctx, repo.ID) if err != nil { if errors.Is(err, sql.ErrNoRows) { content := base64.StdEncoding.EncodeToString([]byte(repo.Readme)) @@ -1410,7 +1411,7 @@ func (c *repoComponentImpl) AllowReadAccessRepo(ctx context.Context, repo *datab } func (c *repoComponentImpl) AllowReadAccess(ctx context.Context, repoType types.RepositoryType, namespace, name, username string) (bool, error) { - repo, err := c.repo.FindByPath(ctx, repoType, namespace, name) + repo, err := c.repoStore.FindByPath(ctx, repoType, namespace, name) if err != nil { return false, fmt.Errorf("failed to find repo, error: %w", err) } @@ -1418,7 +1419,7 @@ func (c *repoComponentImpl) AllowReadAccess(ctx context.Context, repoType types. } func (c *repoComponentImpl) AllowWriteAccess(ctx context.Context, repoType types.RepositoryType, namespace, name, username string) (bool, error) { - repo, err := c.repo.FindByPath(ctx, repoType, namespace, name) + repo, err := c.repoStore.FindByPath(ctx, repoType, namespace, name) if err != nil { return false, fmt.Errorf("failed to find repo, error: %w", err) } @@ -1434,7 +1435,7 @@ func (c *repoComponentImpl) AllowWriteAccess(ctx context.Context, repoType types } func (c *repoComponentImpl) AllowAdminAccess(ctx context.Context, repoType types.RepositoryType, namespace, name, username string) (bool, error) { - repo, err := c.repo.FindByPath(ctx, repoType, namespace, name) + repo, err := c.repoStore.FindByPath(ctx, repoType, namespace, name) if err != nil { return false, fmt.Errorf("failed to find repo, error: %w", err) } @@ -1456,7 +1457,7 @@ func (c *repoComponentImpl) GetUserRepoPermission(ctx context.Context, userName } namespace, _ := repo.NamespaceAndName() - ns, err := c.namespace.FindByPath(ctx, namespace) + ns, err := c.namespaceStore.FindByPath(ctx, namespace) if err != nil { return nil, fmt.Errorf("failed to find namespace '%s' when get user repo permission, error: %w", namespace, err) } @@ -1490,7 +1491,7 @@ func (c *repoComponentImpl) GetUserRepoPermission(ctx context.Context, userName } func (c *repoComponentImpl) CheckCurrentUserPermission(ctx context.Context, userName string, namespace string, role membership.Role) (bool, error) { - ns, err := c.namespace.FindByPath(ctx, namespace) + ns, err := c.namespaceStore.FindByPath(ctx, namespace) if err != nil { return false, err } @@ -1520,7 +1521,7 @@ func (c *repoComponentImpl) GetCommitWithDiff(ctx context.Context, req *types.Ge if req.Ref == "" { return nil, fmt.Errorf("failed to find request commit id") } - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } @@ -1560,18 +1561,18 @@ func (c *repoComponentImpl) CreateMirror(ctx context.Context, req types.CreateMi return nil, fmt.Errorf("users do not have permission to create mirror for this repo") } - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } - exists, err := c.mirror.IsExist(ctx, repo.ID) + exists, err := c.mirrorStore.IsExist(ctx, repo.ID) if err != nil { return nil, fmt.Errorf("failed to find mirror, error: %w", err) } if exists { return nil, fmt.Errorf("mirror already exists") } - mirrorSource, err := c.mirrorSource.Get(ctx, req.MirrorSourceID) + mirrorSource, err := c.mirrorSourceStore.Get(ctx, req.MirrorSourceID) if err != nil { return nil, fmt.Errorf("failed to get mirror source, err: %w, id: %d", err, req.MirrorSourceID) } @@ -1623,7 +1624,7 @@ func (c *repoComponentImpl) CreateMirror(ctx context.Context, req types.CreateMi mirror.MirrorTaskID = taskId - reqMirror, err := c.mirror.Create(ctx, &mirror) + reqMirror, err := c.mirrorStore.Create(ctx, &mirror) if err != nil { return nil, fmt.Errorf("failed to create mirror") } @@ -1635,7 +1636,7 @@ func (c *repoComponentImpl) CreateMirror(ctx context.Context, req types.CreateMi CreatedAt: mirror.CreatedAt.Unix(), }) reqMirror.Status = types.MirrorWaiting - err = c.mirror.Update(ctx, reqMirror) + err = c.mirrorStore.Update(ctx, reqMirror) if err != nil { return nil, fmt.Errorf("failed to update mirror status: %v", err) } @@ -1645,11 +1646,11 @@ func (c *repoComponentImpl) CreateMirror(ctx context.Context, req types.CreateMi } func (c *repoComponentImpl) MirrorFromSaas(ctx context.Context, namespace, name, currentUser string, repoType types.RepositoryType) error { - repo, err := c.repo.FindByPath(ctx, repoType, namespace, name) + repo, err := c.repoStore.FindByPath(ctx, repoType, namespace, name) if err != nil { return fmt.Errorf("failed to find repo, error: %w", err) } - m, err := c.mirror.FindByRepoID(ctx, repo.ID) + m, err := c.mirrorStore.FindByRepoID(ctx, repo.ID) if err != nil { if !errors.Is(err, sql.ErrNoRows) { return fmt.Errorf("failed to find mirror, error: %w", err) @@ -1663,7 +1664,7 @@ func (c *repoComponentImpl) MirrorFromSaas(ctx context.Context, namespace, name, return nil } var mirror database.Mirror - syncVersion, err := c.syncVersion.FindByRepoTypeAndPath(ctx, repo.PathWithOutPrefix(), repoType) + syncVersion, err := c.syncVersionStore.FindByRepoTypeAndPath(ctx, repo.PathWithOutPrefix(), repoType) if err != nil { return fmt.Errorf("failed to find sync version, error: %w", err) } @@ -1675,7 +1676,7 @@ func (c *repoComponentImpl) MirrorFromSaas(ctx context.Context, namespace, name, } mirrorSource.SourceName = types.OpenCSGPrefix - syncClientSetting, err := c.syncClientSetting.First(ctx) + syncClientSetting, err := c.syncClientSettingStore.First(ctx) if err != nil { return fmt.Errorf("failed to find sync client setting, error: %w", err) } @@ -1702,7 +1703,7 @@ func (c *repoComponentImpl) MirrorFromSaas(ctx context.Context, namespace, name, mirror.MirrorTaskID = taskId - _, err = c.mirror.Create(ctx, &mirror) + _, err = c.mirrorStore.Create(ctx, &mirror) if err != nil { return fmt.Errorf("failed to create mirror") @@ -1720,7 +1721,7 @@ func (c *repoComponentImpl) MirrorFromSaas(ctx context.Context, namespace, name, repo.SyncStatus = types.SyncStatusInProgress } - _, err = c.repo.UpdateRepo(ctx, *repo) + _, err = c.repoStore.UpdateRepo(ctx, *repo) if err != nil { return fmt.Errorf("failed to update repo sync status: %w", err) } @@ -1729,11 +1730,11 @@ func (c *repoComponentImpl) MirrorFromSaas(ctx context.Context, namespace, name, func (c *repoComponentImpl) mirrorFromSaasSync(ctx context.Context, mirror *database.Mirror, namespace, name string, repoType types.RepositoryType) error { var err error - syncClientSetting, err := c.syncClientSetting.First(ctx) + syncClientSetting, err := c.syncClientSettingStore.First(ctx) if err != nil { return fmt.Errorf("failed to find sync client setting, error: %w", err) } - repo, err := c.repo.FindById(ctx, mirror.RepositoryID) + repo, err := c.repoStore.FindById(ctx, mirror.RepositoryID) if err != nil { return fmt.Errorf("failed to find repo, error: %w", err) } @@ -1758,7 +1759,7 @@ func (c *repoComponentImpl) mirrorFromSaasSync(ctx context.Context, mirror *data repo.SyncStatus = types.SyncStatusPending } - _, err = c.repo.UpdateRepo(ctx, *repo) + _, err = c.repoStore.UpdateRepo(ctx, *repo) if err != nil { return fmt.Errorf("failed to update repo sync status: %w", err) } @@ -1774,11 +1775,11 @@ func (c *repoComponentImpl) GetMirror(ctx context.Context, req types.GetMirrorRe if !admin { return nil, fmt.Errorf("users do not have permission to get mirror for this repo") } - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } - mirror, err := c.mirror.FindByRepoID(ctx, repo.ID) + mirror, err := c.mirrorStore.FindByRepoID(ctx, repo.ID) if err != nil { return nil, fmt.Errorf("failed to find mirror, error: %w", err) } @@ -1794,15 +1795,15 @@ func (c *repoComponentImpl) UpdateMirror(ctx context.Context, req types.UpdateMi if !admin { return nil, fmt.Errorf("users do not have permission to update mirror for this repo") } - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } - mirror, err := c.mirror.FindByRepoID(ctx, repo.ID) + mirror, err := c.mirrorStore.FindByRepoID(ctx, repo.ID) if err != nil { return nil, fmt.Errorf("failed to find mirror, error: %w", err) } - mirrorSource, err := c.mirrorSource.Get(ctx, req.MirrorSourceID) + mirrorSource, err := c.mirrorSourceStore.Get(ctx, req.MirrorSourceID) if err != nil { return nil, fmt.Errorf("failed to get mirror source, err: %w, id: %d", err, req.MirrorSourceID) } @@ -1822,7 +1823,7 @@ func (c *repoComponentImpl) UpdateMirror(ctx context.Context, req types.UpdateMi mirror.PushAccessToken = pushAccessToken.Token mirror.SourceRepoPath = req.SourceRepoPath mirror.LocalRepoPath = fmt.Sprintf("%s_%s_%s_%s", mirrorSource.SourceName, req.RepoType, req.Namespace, req.Name) - err = c.mirror.Update(ctx, mirror) + err = c.mirrorStore.Update(ctx, mirror) if err != nil { return nil, fmt.Errorf("failed to update mirror, error: %w", err) } @@ -1838,15 +1839,15 @@ func (c *repoComponentImpl) DeleteMirror(ctx context.Context, req types.DeleteMi if !admin { return fmt.Errorf("users do not have permission to delete mirror for this repo") } - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return fmt.Errorf("failed to find repo, error: %w", err) } - mirror, err := c.mirror.FindByRepoID(ctx, repo.ID) + mirror, err := c.mirrorStore.FindByRepoID(ctx, repo.ID) if err != nil { return fmt.Errorf("failed to find mirror, error: %w", err) } - err = c.mirror.Delete(ctx, mirror) + err = c.mirrorStore.Delete(ctx, mirror) if err != nil { return fmt.Errorf("failed to delete mirror, error: %w", err) } @@ -1855,7 +1856,7 @@ func (c *repoComponentImpl) DeleteMirror(ctx context.Context, req types.DeleteMi // get runtime framework list with type func (c *repoComponentImpl) ListRuntimeFrameworkWithType(ctx context.Context, deployType int) ([]types.RuntimeFramework, error) { - frames, err := c.runFrame.List(ctx, deployType) + frames, err := c.runtimeFrameworksStore.List(ctx, deployType) if err != nil { return nil, fmt.Errorf("failed to list runtime frameworks, error: %w", err) } @@ -1877,11 +1878,11 @@ func (c *repoComponentImpl) ListRuntimeFrameworkWithType(ctx context.Context, de // get runtime framework list func (c *repoComponentImpl) ListRuntimeFramework(ctx context.Context, repoType types.RepositoryType, namespace, name string, deployType int) ([]types.RuntimeFramework, error) { - repo, err := c.repo.FindByPath(ctx, repoType, namespace, name) + repo, err := c.repoStore.FindByPath(ctx, repoType, namespace, name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } - frames, err := c.runFrame.ListByRepoID(ctx, repo.ID, deployType) + frames, err := c.runtimeFrameworksStore.ListByRepoID(ctx, repo.ID, deployType) if err != nil { return nil, fmt.Errorf("failed to list runtime frameworks, error: %w", err) } @@ -1912,7 +1913,7 @@ func (c *repoComponentImpl) CreateRuntimeFramework(ctx context.Context, req *typ ContainerPort: req.ContainerPort, Type: req.Type, } - err := c.runFrame.Add(ctx, newFrame) + err := c.runtimeFrameworksStore.Add(ctx, newFrame) if err != nil { return nil, fmt.Errorf("failed to create runtime framework, error: %w", err) } @@ -1939,7 +1940,7 @@ func (c *repoComponentImpl) UpdateRuntimeFramework(ctx context.Context, id int64 ContainerPort: req.ContainerPort, Type: req.Type, } - frame, err := c.runFrame.Update(ctx, newFrame) + frame, err := c.runtimeFrameworksStore.Update(ctx, newFrame) if err != nil { return nil, fmt.Errorf("failed to update runtime frameworks, error: %w", err) } @@ -1956,20 +1957,20 @@ func (c *repoComponentImpl) UpdateRuntimeFramework(ctx context.Context, id int64 } func (c *repoComponentImpl) DeleteRuntimeFramework(ctx context.Context, id int64) error { - frame, err := c.runFrame.FindByID(ctx, id) + frame, err := c.runtimeFrameworksStore.FindByID(ctx, id) if err != nil { return fmt.Errorf("failed to find runtime frameworks, error: %w", err) } - err = c.runFrame.Delete(ctx, *frame) + err = c.runtimeFrameworksStore.Delete(ctx, *frame) return err } func (c *repoComponentImpl) ListDeploy(ctx context.Context, repoType types.RepositoryType, namespace, name, currentUser string) ([]types.DeployRepo, error) { - user, err := c.user.FindByUsername(ctx, currentUser) + user, err := c.userStore.FindByUsername(ctx, currentUser) if err != nil { return nil, errors.New("user does not exist") } - repo, err := c.repo.FindByPath(ctx, repoType, namespace, name) + repo, err := c.repoStore.FindByPath(ctx, repoType, namespace, name) if err != nil { slog.Error("Failed to query deploy", slog.Any("error", err), slog.Any("repotype", repoType), slog.Any("namespace", namespace), slog.Any("name", name)) return nil, errors.New("invalid repository for query parameters") @@ -1978,7 +1979,7 @@ func (c *repoComponentImpl) ListDeploy(ctx context.Context, repoType types.Repos slog.Error("nothing found for deploys", slog.Any("repotype", repoType), slog.Any("namespace", namespace), slog.Any("name", name)) return nil, errors.New("nothing found for deploys") } - deploys, err := c.deploy.ListDeploy(ctx, repoType, repo.ID, user.ID) + deploys, err := c.deployTaskStore.ListDeploy(ctx, repoType, repo.ID, user.ID) if err != nil { return nil, errors.New("fail to list user deploys") } @@ -2039,7 +2040,7 @@ func (c *repoComponentImpl) DeleteDeploy(ctx context.Context, delReq types.Deplo } // update database deploy - err = c.deploy.DeleteDeploy(ctx, types.RepositoryType(delReq.RepoType), deploy.RepoID, user.ID, delReq.DeployID) + err = c.deployTaskStore.DeleteDeploy(ctx, types.RepositoryType(delReq.RepoType), deploy.RepoID, user.ID, delReq.DeployID) if err != nil { return fmt.Errorf("fail to remove deploy instance, %w", err) } @@ -2061,7 +2062,7 @@ func (c *repoComponentImpl) DeployDetail(ctx context.Context, detailReq types.De return nil, err } - endpoint, _ := c.generateEndpoint(ctx, deploy) + endpoint, _ := c.GenerateEndpoint(ctx, deploy) req := types.DeployRepo{ DeployID: deploy.ID, @@ -2116,7 +2117,7 @@ func (c *repoComponentImpl) DeployDetail(ctx context.Context, detailReq types.De } // generate endpoint -func (c *repoComponentImpl) generateEndpoint(ctx context.Context, deploy *database.Deploy) (string, string) { +func (c *repoComponentImpl) GenerateEndpoint(ctx context.Context, deploy *database.Deploy) (string, string) { var endpoint string provider := "" cls, err := c.cluster.ByClusterID(ctx, deploy.ClusterID) @@ -2221,7 +2222,7 @@ func (c *repoComponentImpl) DeployInstanceLogs(ctx context.Context, logReq types // check access repo permission by repo id func (c *repoComponentImpl) AllowAccessByRepoID(ctx context.Context, repoID int64, username string) (bool, error) { - r, err := c.repo.FindById(ctx, repoID) + r, err := c.repoStore.FindById(ctx, repoID) if err != nil { return false, fmt.Errorf("failed to get repository by repo_id: %d, %w", repoID, err) } @@ -2243,14 +2244,14 @@ func (c *repoComponentImpl) AllowAccessEndpoint(ctx context.Context, currentUser // check access deploy permission func (c *repoComponentImpl) AllowAccessDeploy(ctx context.Context, req types.DeployActReq) (bool, error) { - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return false, fmt.Errorf("failed to find repo, error: %w", err) } if repo == nil { return false, fmt.Errorf("failed to find %s repo %s/%s", req.RepoType, req.Namespace, req.Name) } - deploy, err := c.deploy.GetDeployByID(ctx, req.DeployID) + deploy, err := c.deployTaskStore.GetDeployByID(ctx, req.DeployID) if err != nil { return false, err } @@ -2266,7 +2267,7 @@ func (c *repoComponentImpl) AllowAccessDeploy(ctx context.Context, req types.Dep // common check function for apiserver and rproxy func (c *repoComponentImpl) checkAccessDeployForUser(ctx context.Context, repoID int64, currentUser string, deploy *database.Deploy) (bool, error) { - user, err := c.user.FindByUsername(ctx, currentUser) + user, err := c.userStore.FindByUsername(ctx, currentUser) if err != nil { return false, errors.New("user does not exist") } @@ -2282,11 +2283,11 @@ func (c *repoComponentImpl) checkAccessDeployForUser(ctx context.Context, repoID } func (c *repoComponentImpl) checkAccessDeployForServerless(ctx context.Context, repoID int64, currentUser string, deploy *database.Deploy) (bool, error) { - user, err := c.user.FindByUsername(ctx, currentUser) + user, err := c.userStore.FindByUsername(ctx, currentUser) if err != nil { return false, fmt.Errorf("user %s does not exist", currentUser) } - isAdmin := c.isAdminRole(user) + isAdmin := c.IsAdminRole(user) if !isAdmin { return false, errors.New("need admin permission to see Serverless deploy instances") } @@ -2339,7 +2340,7 @@ func (c *repoComponentImpl) DeployStop(ctx context.Context, stopReq types.Deploy } // update database deploy to stopped - err = c.deploy.StopDeploy(ctx, stopReq.RepoType, deploy.RepoID, user.ID, stopReq.DeployID) + err = c.deployTaskStore.StopDeploy(ctx, stopReq.RepoType, deploy.RepoID, user.ID, stopReq.DeployID) if err != nil { return fmt.Errorf("fail to stop deploy instance, %w", err) } @@ -2348,15 +2349,15 @@ func (c *repoComponentImpl) DeployStop(ctx context.Context, stopReq types.Deploy } func (c *repoComponentImpl) AllowReadAccessByDeployID(ctx context.Context, repoType types.RepositoryType, namespace, name, currentUser string, deployID int64) (bool, error) { - user, err := c.user.FindByUsername(ctx, currentUser) + user, err := c.userStore.FindByUsername(ctx, currentUser) if err != nil { return false, errors.New("user does not exist") } - repo, err := c.repo.FindByPath(ctx, repoType, namespace, name) + repo, err := c.repoStore.FindByPath(ctx, repoType, namespace, name) if err != nil { return false, fmt.Errorf("failed to find repo, error: %w", err) } - deploy, err := c.deploy.GetDeployByID(ctx, deployID) + deploy, err := c.deployTaskStore.GetDeployByID(ctx, deployID) if err != nil { return false, err } @@ -2373,7 +2374,7 @@ func (c *repoComponentImpl) AllowReadAccessByDeployID(ctx context.Context, repoT } func (c *repoComponentImpl) DeployStatus(ctx context.Context, repoType types.RepositoryType, namespace, name string, deployID int64) (string, string, []types.Instance, error) { - deploy, err := c.deploy.GetDeployByID(ctx, deployID) + deploy, err := c.deployTaskStore.GetDeployByID(ctx, deployID) if err != nil { return "", SpaceStatusStopped, nil, err } @@ -2395,7 +2396,7 @@ func (c *repoComponentImpl) DeployStatus(ctx context.Context, repoType types.Rep } func (c *repoComponentImpl) GetDeployBySvcName(ctx context.Context, svcName string) (*database.Deploy, error) { - d, err := c.deploy.GetDeployBySvcName(ctx, svcName) + d, err := c.deployTaskStore.GetDeployBySvcName(ctx, svcName) if err != nil { return nil, fmt.Errorf("failed to get deploy by svc name:%s, %w", svcName, err) } @@ -2414,11 +2415,11 @@ func (c *repoComponentImpl) SyncMirror(ctx context.Context, repoType types.Repos if !admin { return fmt.Errorf("users do not have permission to delete mirror for this repo") } - repo, err := c.repo.FindByPath(ctx, repoType, namespace, name) + repo, err := c.repoStore.FindByPath(ctx, repoType, namespace, name) if err != nil { return fmt.Errorf("failed to find repo, error: %w", err) } - mirror, err := c.mirror.FindByRepoID(ctx, repo.ID) + mirror, err := c.mirrorStore.FindByRepoID(ctx, repo.ID) if err != nil { return fmt.Errorf("failed to find mirror, error: %w", err) } @@ -2438,7 +2439,7 @@ func (c *repoComponentImpl) SyncMirror(ctx context.Context, repoType types.Repos CreatedAt: mirror.CreatedAt.Unix(), }) mirror.Status = types.MirrorWaiting - err = c.mirror.Update(ctx, mirror) + err = c.mirrorStore.Update(ctx, mirror) if err != nil { return fmt.Errorf("failed to update mirror status: %v", err) } @@ -2448,11 +2449,11 @@ func (c *repoComponentImpl) SyncMirror(ctx context.Context, repoType types.Repos } func (c *repoComponentImpl) checkDeployPermissionForUser(ctx context.Context, deployReq types.DeployActReq) (*database.User, *database.Deploy, error) { - user, err := c.user.FindByUsername(ctx, deployReq.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, deployReq.CurrentUser) if err != nil { return nil, nil, &types.PermissionError{Message: "user does not exist"} } - deploy, err := c.deploy.GetDeployByID(ctx, deployReq.DeployID) + deploy, err := c.deployTaskStore.GetDeployByID(ctx, deployReq.DeployID) if err != nil { return nil, nil, fmt.Errorf("fail to get user deploy %v, %w", deployReq.DeployID, err) } @@ -2466,15 +2467,15 @@ func (c *repoComponentImpl) checkDeployPermissionForUser(ctx context.Context, de } func (c *repoComponentImpl) checkDeployPermissionForServerless(ctx context.Context, deployReq types.DeployActReq) (*database.User, *database.Deploy, error) { - user, err := c.user.FindByUsername(ctx, deployReq.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, deployReq.CurrentUser) if err != nil { return nil, nil, fmt.Errorf("user does not exist, %w", err) } - isAdmin := c.isAdminRole(user) + isAdmin := c.IsAdminRole(user) if !isAdmin { return nil, nil, fmt.Errorf("need admin permission for Serverless deploy") } - deploy, err := c.deploy.GetDeployByID(ctx, deployReq.DeployID) + deploy, err := c.deployTaskStore.GetDeployByID(ctx, deployReq.DeployID) if err != nil { return nil, nil, fmt.Errorf("fail to get serverless deploy:%v, %w", deployReq.DeployID, err) } @@ -2499,7 +2500,7 @@ func (c *repoComponentImpl) DeployUpdate(ctx context.Context, updateReq types.De } // check user balance if resource changed if req.ResourceID != nil { - frame, err := c.rtfm.FindEnabledByName(ctx, deploy.RuntimeFramework) + frame, err := c.runtimeFrameworksStore.FindEnabledByName(ctx, deploy.RuntimeFramework) if err != nil { return fmt.Errorf("cannot find available runtime framework, %w", err) } @@ -2583,7 +2584,7 @@ func (c *repoComponentImpl) DeployStart(ctx context.Context, startReq types.Depl } func (c *repoComponentImpl) AllFiles(ctx context.Context, req types.GetAllFilesReq) ([]*types.File, error) { - repo, err := c.repo.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) + repo, err := c.repoStore.FindByPath(ctx, req.RepoType, req.Namespace, req.Name) if err != nil { return nil, fmt.Errorf("failed to find repo, error: %w", err) } @@ -2608,7 +2609,7 @@ func (c *repoComponentImpl) AllFiles(ctx context.Context, req types.GetAllFilesR return allFiles, nil } -func (c *repoComponentImpl) isAdminRole(user database.User) bool { +func (c *repoComponentImpl) IsAdminRole(user database.User) bool { slog.Debug("Check if user is admin", slog.Any("user", user)) return user.CanAdmin() } diff --git a/component/repo_test.go b/component/repo_test.go new file mode 100644 index 00000000..09551edc --- /dev/null +++ b/component/repo_test.go @@ -0,0 +1,2025 @@ +package component + +import ( + "context" + "errors" + "testing" + + "github.com/alibabacloud-go/tea/tea" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/deploy" + deployStatus "opencsg.com/csghub-server/builder/deploy/common" + "opencsg.com/csghub-server/builder/git/gitserver" + "opencsg.com/csghub-server/builder/rpc" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/common/types" +) + +func TestRepoComponent_CreateRepo(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + repo.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil) + dbuser := database.User{ + ID: 123, + RoleMask: "admin", + Email: "foo@bar.com", + } + repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(dbuser, nil) + gitrepo := &gitserver.CreateRepoResp{ + GitPath: "gp", + DefaultBranch: "main", + HttpCloneURL: "http", + SshCloneURL: "ssh", + } + repo.mocks.gitServer.EXPECT().CreateRepo(ctx, gitserver.CreateRepoReq{ + Username: "user", + Namespace: "ns", + Name: "n", + Nickname: "n", + License: "MIT", + DefaultBranch: "main", + Readme: "rr", + Private: true, + RepoType: types.ModelRepo, + }).Return(gitrepo, nil) + + dbrepo := &database.Repository{ + UserID: 123, + Path: "ns/n", + GitPath: "gp", + Name: "n", + Nickname: "nn", + Description: "desc", + Private: true, + License: "MIT", + DefaultBranch: "main", + RepositoryType: types.ModelRepo, + HTTPCloneURL: "http", + SSHCloneURL: "ssh", + } + repo.mocks.stores.RepoMock().EXPECT().CreateRepo(ctx, *dbrepo).Return(dbrepo, nil) + + r1, r2, err := repo.CreateRepo(ctx, types.CreateRepoReq{ + Username: "user", + Namespace: "ns", + Name: "n", + Nickname: "nn", + License: "MIT", + DefaultBranch: "main", + Readme: "rr", + Private: true, + RepoType: types.ModelRepo, + Description: "desc", + }) + require.Nil(t, err) + require.Equal(t, gitrepo, r1) + dbrepo.User = dbuser + require.Equal(t, dbrepo, r2) + +} + +func TestRepoComponent_UpdateRepo(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + dbrepo := &database.Repository{ + UserID: 123, + Path: "ns/n", + GitPath: "gp", + Name: "n", + Nickname: "nn", + Description: "desc", + Private: true, + License: "MIT", + DefaultBranch: "main", + RepositoryType: types.ModelRepo, + HTTPCloneURL: "http", + SSHCloneURL: "ssh", + } + repo.mocks.stores.RepoMock().EXPECT().Find(ctx, "ns", string(types.ModelRepo), "n").Return(dbrepo, nil) + repo.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil) + dbuser := database.User{ + ID: 123, + RoleMask: "admin", + Email: "foo@bar.com", + } + repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(dbuser, nil) + gitrepo := &gitserver.CreateRepoResp{ + GitPath: "gp", + DefaultBranch: "main", + HttpCloneURL: "http", + SshCloneURL: "ssh", + } + repo.mocks.gitServer.EXPECT().UpdateRepo(ctx, gitserver.UpdateRepoReq{ + Namespace: "ns", + Name: "n", + Nickname: "nn2", + Description: "desc2", + DefaultBranch: "main", + Private: true, + RepoType: types.ModelRepo, + }).Return(gitrepo, nil) + + dbrepo.Nickname = "nn2" + dbrepo.Description = "desc2" + repo.mocks.stores.RepoMock().EXPECT().UpdateRepo(ctx, *dbrepo).Return(dbrepo, nil) + + r1, err := repo.UpdateRepo(ctx, types.UpdateRepoReq{ + Username: "user", + Namespace: "ns", + Name: "n", + RepoType: types.ModelRepo, + Nickname: tea.String("nn2"), + Description: tea.String("desc2"), + Private: tea.Bool(true), + }) + require.Nil(t, err) + require.Equal(t, dbrepo, r1) + +} + +func TestRepoComponent_DeleteRepo(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + dbrepo := &database.Repository{ + ID: 1, + UserID: 123, + Path: "ns/n", + GitPath: "gp", + Name: "n", + Nickname: "nn", + Description: "desc", + Private: true, + License: "MIT", + DefaultBranch: "main", + RepositoryType: types.ModelRepo, + HTTPCloneURL: "http", + SSHCloneURL: "ssh", + } + repo.mocks.stores.RepoMock().EXPECT().Find(ctx, "ns", string(types.ModelRepo), "n").Return(dbrepo, nil) + repo.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil) + dbuser := database.User{ + ID: 123, + RoleMask: "admin", + Email: "foo@bar.com", + } + repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(dbuser, nil) + repo.mocks.stores.RepoMock().EXPECT().CleanRelationsByRepoID(ctx, dbrepo.ID).Return(nil) + + repo.mocks.gitServer.EXPECT().DeleteRepo(ctx, gitserver.DeleteRepoReq{ + Namespace: "ns", + Name: "n", + RepoType: types.ModelRepo, + }).Return(nil) + + repo.mocks.stores.RepoMock().EXPECT().DeleteRepo(ctx, *dbrepo).Return(nil) + + r1, err := repo.DeleteRepo(ctx, types.DeleteRepoReq{ + Username: "user", + Namespace: "ns", + Name: "n", + RepoType: types.ModelRepo, + }) + require.Nil(t, err) + require.Equal(t, dbrepo, r1) + +} + +func TestRepoComponent_PublicToUser(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + repo.mocks.userSvcClient.EXPECT().GetUserInfo(ctx, "user", "user").Return(&rpc.User{ + ID: 1, + Roles: []string{"a", "b"}, + Orgs: []rpc.Organization{ + {UserID: 2}, + {UserID: 3}, + }, + }, nil) + + filter := &types.RepoFilter{} + mrepos := []*database.Repository{ + {Name: "foo"}, + } + repo.mocks.stores.RepoMock().EXPECT().PublicToUser(ctx, types.ModelRepo, []int64{1, 2, 3}, filter, 10, 1).Return(mrepos, 100, nil) + + repos, count, err := repo.PublicToUser(ctx, types.ModelRepo, "user", &types.RepoFilter{}, 10, 1) + require.Equal(t, mrepos, repos) + require.Equal(t, 100, count) + require.Nil(t, err) +} + +func mockUserRepoAdminPermission(ctx context.Context, stores *tests.MockStores, userName string) { + stores.UserMock().EXPECT().FindByUsername(ctx, userName).Return(database.User{ + RoleMask: "admin", + }, nil).Once() + stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return( + database.Namespace{NamespaceType: "user"}, nil, + ).Maybe() + +} + +// func TestRepoComponent_RelatedRepos(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// froms := []*database.RepoRelation{{ToRepoID: 1}, {ToRepoID: 2}} +// repo.mocks.stores.RepoRelationMock().EXPECT().From(ctx, int64(123)).Return(froms, nil) +// tos := []*database.RepoRelation{{FromRepoID: 3}, {FromRepoID: 4}} +// repo.mocks.stores.RepoRelationMock().EXPECT().To(ctx, int64(123)).Return(tos, nil) + +// var opts []interface{} +// opts = append(opts, database.Columns("id", "repository_type", "path", "user_id", "private", "name", +// "nickname", "description", "download_count", "updated_at")) + +// repos := []*database.Repository{ +// {Private: false, RepositoryType: types.ModelRepo, Path: "a/b"}, +// {Private: false, RepositoryType: types.ModelRepo, Path: "a/c"}, +// {Private: true, RepositoryType: types.DatasetRepo, Path: "b/e"}, +// {Private: true, RepositoryType: types.DatasetRepo, Path: "user/f"}, +// } +// repo.mocks.stores.RepoMock().EXPECT().FindByIds(ctx, []int64{1, 2, 3, 4}, opts...).Return(repos, nil) + +// repo.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "b").Return(database.Namespace{ +// NamespaceType: "user", +// }, nil) +// repo.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "user").Return(database.Namespace{ +// NamespaceType: "user", +// }, nil) +// repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{RoleMask: "foo"}, nil) + +// related, err := repo.RelatedRepos(ctx, 123, "user") +// require.Nil(t, err) +// require.Equal(t, map[types.RepositoryType][]*database.Repository{ +// types.ModelRepo: {repos[0], repos[1]}, +// types.DatasetRepo: {repos[3]}, +// }, related) + +// } + +// func TestRepoComponent_CreateFile(t *testing.T) { + +// cases := []struct { +// useLFS bool +// path string +// testUpload bool +// }{ +// {false, "test.go", false}, +// {false, "README.md", false}, +// {true, "test.go", false}, +// {false, "test.go", true}, +// } + +// for _, c := range cases { +// t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// mockedRepo := &database.Repository{ID: 123} +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(mockedRepo, nil) +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") +// repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "un").Return(database.User{ +// Email: "foo@bar.com", +// }, nil) +// repo.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil) +// if c.useLFS { +// repo.config.GitServer.Type = types.GitServerTypeGitaly +// ct := base64.RawStdEncoding.EncodeToString( +// []byte(c.path + " filter=lfs diff=lfs merge=lfs -text"), +// ) +// repo.mocks.gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ +// RepoType: types.ModelRepo, +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Path: GitAttributesFileName, +// }).Return(&types.File{ +// Content: ct, +// }, nil) +// repo.mocks.s3Client.EXPECT().PutObject( +// mock.Anything, repo.config.S3.Bucket, +// "lfs/e3/b0/c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", mock.Anything, int64(0), minio.PutObjectOptions{}).Return(minio.UploadInfo{ +// Size: 0, +// }, nil) +// repo.mocks.stores.LfsMetaObjectMock().EXPECT().UpdateOrCreate(mock.Anything, database.LfsMetaObject{ +// Oid: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", +// Size: 0, +// RepositoryID: 123, +// Existing: true, +// }).Return(nil, nil) +// } + +// repo.mocks.stores.RepoMock().EXPECT().SetUpdateTimeByPath(mock.Anything, types.ModelRepo, "ns", "n", mock.Anything).Return(nil) +// if c.path == "README.md" { +// repo.mocks.components.tag.EXPECT().UpdateMetaTags(mock.Anything, getTagScopeByRepoType(types.ModelRepo), "ns", "n", "").Return(nil, nil) +// } else { +// repo.mocks.components.tag.EXPECT().UpdateLibraryTags(mock.Anything, getTagScopeByRepoType(types.ModelRepo), "ns", "n", "", c.path).Return(nil) +// } +// req := &types.CreateFileReq{ +// RepoType: types.ModelRepo, +// Namespace: "ns", +// Name: "n", +// CurrentUser: "user", +// Username: "un", +// Branch: "main", +// FilePath: c.path, +// OriginalContent: []byte{}, +// } +// repo.mocks.gitServer.EXPECT().CreateRepoFile(req).Return(nil) + +// if c.testUpload { +// // GetRepoFileContents return error, create +// repo.mocks.gitServer.EXPECT().GetRepoFileContents(ctx, gitserver.GetRepoInfoByPathReq{ +// Namespace: req.Namespace, +// Name: req.Name, +// Ref: req.Branch, +// Path: req.FilePath, +// RepoType: req.RepoType, +// }).Return(nil, errors.New("not allowed")).Once() +// err := repo.UploadFile(ctx, req) +// require.Nil(t, err) +// } else { + +// resp, err := repo.CreateFile(ctx, req) +// require.Nil(t, err) +// require.Equal(t, &types.CreateFileResp{}, resp) +// } +// }) +// } +// } + +// func TestRepoComponent_UpdateFile(t *testing.T) { + +// cases := []struct { +// useLFS bool +// path string +// testUpload bool +// }{ +// {false, "test.go", false}, +// {false, "README.md", false}, +// {true, "test.go", false}, +// {false, "test.go", true}, +// } + +// for _, c := range cases { +// t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// mockedRepo := &database.Repository{ID: 123} +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(mockedRepo, nil) +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") +// repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "un").Return(database.User{ +// Email: "foo@bar.com", +// }, nil) +// repo.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil) +// if c.useLFS { +// repo.config.GitServer.Type = types.GitServerTypeGitaly +// ct := base64.RawStdEncoding.EncodeToString( +// []byte(c.path + " filter=lfs diff=lfs merge=lfs -text"), +// ) +// repo.mocks.gitServer.EXPECT().GetRepoFileContents(mock.Anything, gitserver.GetRepoInfoByPathReq{ +// RepoType: types.ModelRepo, +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Path: GitAttributesFileName, +// }).Return(&types.File{ +// Content: ct, +// }, nil) +// repo.mocks.s3Client.EXPECT().PutObject( +// mock.Anything, repo.config.S3.Bucket, +// "lfs/af/a7/518106309c22d325df6d2663249d158d2f36f1976269d6d4104d9198a108", mock.Anything, int64(4), minio.PutObjectOptions{}).Return(minio.UploadInfo{ +// Size: 4, +// }, nil) +// repo.mocks.stores.LfsMetaObjectMock().EXPECT().UpdateOrCreate(mock.Anything, database.LfsMetaObject{ +// Oid: "afa7518106309c22d325df6d2663249d158d2f36f1976269d6d4104d9198a108", +// Size: 4, +// RepositoryID: 123, +// Existing: true, +// }).Return(nil, nil) +// } + +// repo.mocks.stores.RepoMock().EXPECT().SetUpdateTimeByPath(mock.Anything, types.ModelRepo, "ns", "n", mock.Anything).Return(nil) +// if c.path == "README.md" { +// repo.mocks.components.tag.EXPECT().UpdateMetaTags(mock.Anything, getTagScopeByRepoType(types.ModelRepo), "ns", "n", "").Return(nil, nil) +// } else { +// repo.mocks.components.tag.EXPECT().UpdateLibraryTags(mock.Anything, getTagScopeByRepoType(types.ModelRepo), "ns", "n", "", c.path).Return(nil) +// } +// req := &types.UpdateFileReq{ +// RepoType: types.ModelRepo, +// Namespace: "ns", +// Name: "n", +// CurrentUser: "user", +// Username: "un", +// Branch: "main", +// FilePath: c.path, +// OriginalContent: []byte{1, 0, 0, 1}, +// Email: "foo@bar.com", +// } +// repo.mocks.gitServer.EXPECT().UpdateRepoFile(req).Return(nil) + +// if c.testUpload { +// // GetRepoFileContents success, update +// repo.mocks.gitServer.EXPECT().GetRepoFileContents(ctx, gitserver.GetRepoInfoByPathReq{ +// Namespace: req.Namespace, +// Name: req.Name, +// Ref: req.Branch, +// Path: req.FilePath, +// RepoType: req.RepoType, +// }).Return(&types.File{}, nil).Once() +// err := repo.UploadFile(ctx, &types.CreateFileReq{ +// Username: req.Username, +// Branch: req.Branch, +// Namespace: req.Namespace, +// Name: req.Name, +// FilePath: req.FilePath, +// RepoType: req.RepoType, +// CurrentUser: req.CurrentUser, +// OriginalContent: req.OriginalContent, +// }) +// require.Nil(t, err) +// } else { +// resp, err := repo.UpdateFile(ctx, req) +// require.Nil(t, err) +// require.Equal(t, &types.UpdateFileResp{}, resp) +// } +// }) +// } +// } + +// func TestRepoComponent_DeleteFile(t *testing.T) { + +// cases := []struct { +// path string +// }{ +// {"test.go"}, +// {"README.md"}, +// } + +// for _, c := range cases { +// t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// mockedRepo := &database.Repository{ID: 123} +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(mockedRepo, nil) +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") +// repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "un").Return(database.User{ +// Email: "foo@bar.com", +// }, nil) +// repo.mocks.stores.NamespaceMock().EXPECT().FindByPath(ctx, "ns").Return(database.Namespace{}, nil) + +// repo.mocks.stores.RepoMock().EXPECT().SetUpdateTimeByPath(mock.Anything, types.ModelRepo, "ns", "n", mock.Anything).Return(nil) +// if c.path == "README.md" { +// repo.mocks.components.tag.EXPECT().UpdateMetaTags(mock.Anything, getTagScopeByRepoType(types.ModelRepo), "ns", "n", "").Return(nil, nil) +// } else { +// repo.mocks.components.tag.EXPECT().UpdateLibraryTags(mock.Anything, getTagScopeByRepoType(types.ModelRepo), "ns", "n", "", c.path).Return(nil) +// } +// req := &types.DeleteFileReq{ +// RepoType: types.ModelRepo, +// Namespace: "ns", +// Name: "n", +// CurrentUser: "user", +// Username: "un", +// Branch: "main", +// FilePath: c.path, +// OriginalContent: []byte{1, 0, 0, 1}, +// } +// repo.mocks.gitServer.EXPECT().DeleteRepoFile(req).Return(nil) + +// resp, err := repo.DeleteFile(ctx, req) +// require.Nil(t, err) +// require.Equal(t, &types.DeleteFileResp{}, resp) +// }) +// } +// } + +// func TestRepoComponent_Commits(t *testing.T) { + +// for _, user := range []string{"user", ""} { +// t.Run(user, func(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// r := &database.Repository{Private: true} +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(r, nil) +// if user != "" { +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") +// repo.mocks.gitServer.EXPECT().GetRepoCommits(ctx, gitserver.GetRepoCommitsReq{ +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Per: 10, +// Page: 1, +// RepoType: types.ModelRepo, +// }).Return(nil, nil, nil) +// } + +// a, b, err := repo.Commits(ctx, &types.GetCommitsReq{ +// Namespace: "ns", +// Name: "n", +// RepoType: types.ModelRepo, +// Per: 10, +// Page: 1, +// Ref: "main", +// CurrentUser: user, +// }) +// if user == "" { +// require.Equal(t, ErrUnauthorized, err) +// return +// } +// require.Nil(t, err) +// require.Nil(t, a) +// require.Nil(t, b) +// }) +// } + +// } + +// func TestRepoComponent_FileRaw(t *testing.T) { + +// cases := []struct { +// canRead bool +// source types.RepositorySource +// path string +// mirrored bool +// }{ +// {false, types.HuggingfaceSource, "test.go", false}, +// {true, types.HuggingfaceSource, "test.go", false}, +// {true, types.LocalSource, "README.md", false}, +// {true, types.HuggingfaceSource, "README.md", false}, +// {true, types.HuggingfaceSource, "README.md", true}, +// } + +// for _, c := range cases { +// t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// r := &database.Repository{ +// ID: 123, +// Private: true, +// Source: c.source, +// Readme: "readme1", +// } +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(r, nil) +// currentUser := "" +// if !c.canRead { +// _, err := repo.FileRaw(ctx, &types.GetFileReq{ +// Namespace: "ns", +// Name: "n", +// RepoType: types.ModelRepo, +// Ref: "main", +// Path: c.path, +// CurrentUser: currentUser, +// }) +// require.Equal(t, ErrUnauthorized, err) +// return +// } + +// currentUser = "user" +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") +// rawContent := "readme1" +// if c.source != types.LocalSource && c.path == "README.md" { +// if c.mirrored { +// repo.mocks.stores.MirrorMock().EXPECT().FindByRepoID(ctx, int64(123)).Return(nil, nil) +// repo.mocks.gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Path: c.path, +// RepoType: types.ModelRepo, +// }).Return("readme2", nil) +// rawContent = "readme2" +// } else { +// repo.mocks.stores.MirrorMock().EXPECT().FindByRepoID(ctx, int64(123)).Return(nil, sql.ErrNoRows) +// } +// } else { +// repo.mocks.gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Path: c.path, +// RepoType: types.ModelRepo, +// }).Return("readme2", nil) +// rawContent = "readme2" +// } + +// a, err := repo.FileRaw(ctx, &types.GetFileReq{ +// Namespace: "ns", +// Name: "n", +// RepoType: types.ModelRepo, +// Ref: "main", +// Path: c.path, +// CurrentUser: currentUser, +// }) +// require.Nil(t, err) +// require.Equal(t, rawContent, a) +// }) +// } + +// } + +// func TestRepoComponent_DownloadFile(t *testing.T) { +// for _, lfs := range []bool{false, true} { +// t.Run(fmt.Sprintf("is lfs: %v", lfs), func(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") +// mockedRepo := &database.Repository{} +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( +// mockedRepo, nil, +// ) + +// repo.mocks.stores.RepoMock().EXPECT().UpdateRepoFileDownloads(ctx, mockedRepo, mock.Anything, int64(1)).Return(nil) + +// if lfs { +// reqParams := make(url.Values) +// reqParams.Set("response-content-disposition", fmt.Sprintf("attachment;filename=%s", "zzz")) +// repo.mocks.s3Client.EXPECT().PresignedGetObject( +// ctx, repo.lfsBucket, "lfs/path", nil, reqParams, +// ).Return(&url.URL{Path: "foobar"}, nil) +// } else { +// repo.mocks.gitServer.EXPECT().GetRepoFileReader(ctx, gitserver.GetRepoInfoByPathReq{ +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Path: "path", +// RepoType: types.ModelRepo, +// }).Return(nil, 100, nil) +// } + +// a, b, c, err := repo.DownloadFile(ctx, &types.GetFileReq{ +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Path: "path", +// RepoType: types.ModelRepo, +// Lfs: lfs, +// SaveAs: "zzz", +// CurrentUser: "user", +// }, "user") +// require.Nil(t, err) +// if lfs { +// require.Nil(t, a) +// require.Equal(t, int64(0), b) +// require.Equal(t, "foobar", c) +// } else { +// require.Nil(t, a) +// require.Equal(t, int64(100), b) +// require.Equal(t, "", c) +// } +// }) +// } + +// } + +func TestRepoComponent_SDKListFiles(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + mockedRepo := &database.Repository{Source: types.HuggingfaceSource, Private: false} + repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( + mockedRepo, nil, + ) + + files := []*types.File{{Name: "test.go"}} + repo.mocks.gitServer.EXPECT().GetRepoFileTree(mock.Anything, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: "main", + RepoType: types.ModelRepo, + }).Return(files, nil) + + fs, err := repo.SDKListFiles(ctx, types.ModelRepo, "ns", "n", "main", "user") + require.Nil(t, err) + require.Equal(t, &types.SDKFiles{ + Tags: []string{}, + ID: "ns/n", + Siblings: []types.SDKFile{{}}, + }, fs) + +} + +func TestRepoComponent_IsLFS(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + repo.mocks.gitServer.EXPECT().GetRepoFileRaw(ctx, gitserver.GetRepoInfoByPathReq{ + Namespace: "ns", + Name: "n", + Ref: "main", + Path: "p", + RepoType: types.ModelRepo, + }).Return("readme", nil) + + a, b, err := repo.IsLfs(ctx, &types.GetFileReq{ + Namespace: "ns", + Name: "n", + Ref: "main", + Path: "p", + RepoType: types.ModelRepo, + }) + require.Nil(t, err) + require.Equal(t, false, a) + require.Equal(t, int64(6), b) + +} + +// func TestRepoComponent_HeadDownloadFile(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// mockedRepo := &database.Repository{Source: types.HuggingfaceSource, Private: false} +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( +// mockedRepo, nil, +// ) + +// file := &types.File{Name: "zzz"} +// repo.mocks.gitServer.EXPECT().GetRepoFileContents(ctx, gitserver.GetRepoInfoByPathReq{ +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Path: "path", +// RepoType: types.ModelRepo, +// }).Return(file, nil) + +// commit := &types.Commit{Message: "zzz"} +// repo.mocks.gitServer.EXPECT().GetRepoLastCommit(ctx, gitserver.GetRepoLastCommitReq{ +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// RepoType: types.ModelRepo, +// }).Return(commit, nil) + +// f, e := repo.HeadDownloadFile(ctx, &types.GetFileReq{ +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Path: "path", +// RepoType: types.ModelRepo, +// }, "user") +// require.Nil(t, e) +// require.Equal(t, file, f) + +// } + +// func TestRepoComponent_SDKDownloadFile(t *testing.T) { +// for _, lfs := range []bool{false, true} { +// t.Run(fmt.Sprintf("is lfs: %v", lfs), func(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// mockedRepo := &database.Repository{} +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( +// mockedRepo, nil, +// ) + +// if lfs { + +// repo.mocks.gitServer.EXPECT().GetRepoFileContents(ctx, gitserver.GetRepoInfoByPathReq{ +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Path: "path", +// RepoType: types.ModelRepo, +// }).Return(&types.File{LfsRelativePath: "qqq"}, nil) + +// reqParams := make(url.Values) +// reqParams.Set("response-content-disposition", fmt.Sprintf("attachment;filename=%s", "zzz")) +// repo.mocks.s3Client.EXPECT().PresignedGetObject( +// ctx, repo.lfsBucket, "lfs/qqq", nil, reqParams, +// ).Return(&url.URL{Path: "foobar"}, nil) +// } else { +// repo.mocks.gitServer.EXPECT().GetRepoFileReader(ctx, gitserver.GetRepoInfoByPathReq{ +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Path: "path", +// RepoType: types.ModelRepo, +// }).Return(nil, 100, nil) +// } + +// a, b, c, err := repo.SDKDownloadFile(ctx, &types.GetFileReq{ +// Namespace: "ns", +// Name: "n", +// Ref: "main", +// Path: "path", +// RepoType: types.ModelRepo, +// Lfs: lfs, +// SaveAs: "zzz", +// CurrentUser: "user", +// }, "user") +// require.Nil(t, err) +// if lfs { +// require.Nil(t, a) +// require.Equal(t, int64(0), b) +// require.Equal(t, "foobar", c) +// } else { +// require.Nil(t, a) +// require.Equal(t, int64(100), b) +// require.Equal(t, "", c) +// } +// }) +// } + +// } + +// func TestRepoComponent_CreateMirror(t *testing.T) { +// cases := []struct { +// saas bool +// gitea bool +// }{ +// {false, false}, +// {false, true}, +// {true, false}, +// {true, true}, +// } + +// for _, c := range cases { +// t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// if c.gitea { +// repo.config.GitServer.Type = types.GitServerTypeGitea +// } else { +// repo.config.GitServer.Type = types.GitServerTypeGitaly +// } +// repo.config.Saas = c.saas + +// mockedRepo := &database.Repository{ID: 123} +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( +// mockedRepo, nil, +// ) +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") + +// repo.mocks.stores.MirrorMock().EXPECT().IsExist(ctx, int64(123)).Return(false, nil) +// repo.mocks.stores.MirrorSourceMock().EXPECT().Get(ctx, int64(321)).Return(&database.MirrorSource{}, nil) +// repo.mocks.stores.AccessTokenMock().EXPECT().GetUserGitToken(ctx, "user").Return(&database.AccessToken{}, nil) + +// mirror := &database.Mirror{ +// SourceUrl: "su", +// MirrorSourceID: 321, +// Username: "user", +// AccessToken: "ak", +// RepositoryID: 123, +// LocalRepoPath: "_model_ns_n", +// } +// if c.saas { +// if c.gitea { +// repo.mocks.mirrorServer.EXPECT().CreateMirrorRepo(ctx, mirrorserver.CreateMirrorRepoReq{ +// Namespace: "root", +// Name: "_model_ns_n", +// CloneUrl: "su", +// Username: "user", +// AccessToken: "ak", +// Private: false, +// }).Return(0, nil) +// } +// } else { +// if c.gitea { +// repo.mocks.gitServer.EXPECT().MirrorSync(ctx, gitserver.MirrorSyncReq{ +// Namespace: "ns", +// Name: "n", +// CloneUrl: "su", +// Username: "user", +// AccessToken: "ak", +// RepoType: types.ModelRepo, +// }).Return(nil) +// } +// } + +// rmi := *mirror +// rmi.ID = 321 +// rmi.Priority = types.HighMirrorPriority +// if c.saas && c.gitea { +// mirror.PushUsername = "user" +// } +// repo.mocks.stores.MirrorMock().EXPECT().Create(ctx, mirror).Return(&rmi, nil) + +// if !c.gitea { +// repo.mocks.mirrorQueue.EXPECT().PushRepoMirror(&queue.MirrorTask{ +// MirrorID: 321, +// Priority: queue.PriorityMap[types.HighMirrorPriority], +// }).Return() +// repo.mocks.stores.MirrorMock().EXPECT().Update(ctx, &rmi).Return(nil) +// } + +// rm, err := repo.CreateMirror(ctx, types.CreateMirrorReq{ +// SourceUrl: "su", +// Username: "user", +// CurrentUser: "user", +// AccessToken: "ak", +// Namespace: "ns", +// Name: "n", +// RepoType: types.ModelRepo, +// MirrorSourceID: 321, +// }) +// require.Nil(t, err) +// require.Equal(t, rmi, *rm) +// }) +// } +// } + +// func TestRepoComponent_MirrorFromSaas(t *testing.T) { +// cases := []struct { +// gitea bool +// mirror bool +// }{ +// {false, false}, +// {false, true}, +// {true, false}, +// {true, true}, +// } + +// for _, c := range cases { +// t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// if c.gitea { +// repo.config.GitServer.Type = types.GitServerTypeGitea +// } else { +// repo.config.GitServer.Type = types.GitServerTypeGitaly +// } + +// mirror := &database.Mirror{ +// SourceUrl: "/models/ns/n.git", +// Username: "user", +// RepositoryID: 123, +// SourceRepoPath: "ns/n", +// } +// if c.mirror { +// repo.mocks.stores.MirrorMock().EXPECT().FindByRepoID(ctx, int64(123)).Return(&database.Mirror{}, nil) +// } else { +// repo.mocks.stores.MirrorMock().EXPECT().FindByRepoID(ctx, int64(123)).Return(nil, sql.ErrNoRows) +// repo.mocks.stores.SyncVersionMock().EXPECT().FindByRepoTypeAndPath(ctx, "", types.ModelRepo).Return(&database.SyncVersion{SourceID: types.SyncVersionSourceHF}, nil) +// repo.mocks.gitServer.EXPECT().CreateMirrorRepo(ctx, gitserver.CreateMirrorRepoReq{ +// Namespace: "ns", +// Name: "n", +// CloneUrl: "/models/ns/n.git", +// Private: false, +// MirrorToken: "foo", +// RepoType: types.ModelRepo, +// }).Return(0, nil) +// repo.mocks.stores.MirrorMock().EXPECT().Create(ctx, mirror).Return(nil, nil) + +// } + +// mockedRepo := &database.Repository{ID: 123} +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( +// mockedRepo, nil, +// ) +// repo.mocks.stores.SyncClientSettingMock().EXPECT().First(ctx).Return(&database.SyncClientSetting{ +// Token: "foo", +// }, nil) + +// if c.gitea { +// if c.mirror { +// repo.mocks.gitServer.EXPECT().MirrorSync(ctx, gitserver.MirrorSyncReq{ +// Namespace: "ns", +// Name: "n", +// MirrorToken: "foo", +// RepoType: types.ModelRepo, +// }).Return(nil) +// } +// mockedRepo.SyncStatus = types.SyncStatusInProgress +// } else { +// mockedRepo.SyncStatus = types.SyncStatusPending +// } + +// repo.mocks.stores.RepoMock().EXPECT().UpdateRepo(ctx, *mockedRepo).Return(nil, nil) + +// if !c.gitea { +// repo.mocks.mirrorQueue.EXPECT().PushRepoMirror(&queue.MirrorTask{ +// MirrorToken: "foo", +// CreatedAt: mirror.CreatedAt.Unix(), +// }).Return() +// } + +// err := repo.MirrorFromSaas(ctx, "ns", "n", "user", types.ModelRepo) +// require.Nil(t, err) +// }) +// } +// } + +// func TestRepoComponent_GetMirror(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(&database.Repository{ +// ID: 123, +// }, nil) +// m := &database.Mirror{ID: 123} +// repo.mocks.stores.MirrorMock().EXPECT().FindByRepoID(ctx, int64(123)).Return(m, nil) +// mm, err := repo.GetMirror(ctx, types.GetMirrorReq{ +// Namespace: "ns", +// Name: "n", +// RepoType: types.ModelRepo, +// CurrentUser: "user", +// }) +// require.Nil(t, err) +// require.Equal(t, m, mm) +// } + +// func TestRepoComponent_UpdateMirror(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(&database.Repository{ +// ID: 123, +// }, nil) +// m := database.Mirror{ +// ID: 123, +// Username: "user", +// AccessToken: "ak", +// PushUsername: "user", +// PushAccessToken: "foo", +// LocalRepoPath: "a_model_ns_n", +// MirrorSourceID: 111, +// } +// mi := m +// repo.mocks.stores.MirrorMock().EXPECT().FindByRepoID(ctx, int64(123)).Return(&mi, nil) +// repo.mocks.stores.AccessTokenMock().EXPECT().GetUserGitToken(ctx, "user").Return(&database.AccessToken{Token: "foo"}, nil) +// repo.mocks.stores.MirrorSourceMock().EXPECT().Get(ctx, int64(111)).Return(&database.MirrorSource{ +// SourceName: "a", +// }, nil) +// repo.mocks.stores.MirrorMock().EXPECT().Update(ctx, &m).Return(nil) + +// mm, err := repo.UpdateMirror(ctx, types.UpdateMirrorReq{ +// Namespace: "ns", +// CurrentUser: "user", +// Username: "user", +// AccessToken: "ak", +// RepoType: types.ModelRepo, +// Name: "n", +// MirrorSourceID: 111, +// }) +// require.Nil(t, err) +// require.Equal(t, m, *mm) +// } + +// func TestRepoComponent_DeleteMirror(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) + +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(&database.Repository{ +// ID: 123, +// }, nil) +// m := &database.Mirror{ID: 123} +// repo.mocks.stores.MirrorMock().EXPECT().FindByRepoID(ctx, int64(123)).Return(m, nil) +// repo.mocks.stores.MirrorMock().EXPECT().Delete(ctx, m).Return(nil) +// err := repo.DeleteMirror(ctx, types.DeleteMirrorReq{ +// Namespace: "ns", +// Name: "n", +// RepoType: types.ModelRepo, +// CurrentUser: "user", +// }) +// require.Nil(t, err) +// } + +func TestRepoComponent_ListRuntimeFrameworkWithType(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + frames := []database.RuntimeFramework{ + { + ID: 1, FrameName: "foo", FrameVersion: "v1", FrameImage: "i", FrameCpuImage: "c", + Enabled: 1, ContainerPort: 321, Type: 12, + }, + } + repo.mocks.stores.RuntimeFrameworkMock().EXPECT().List(ctx, 1).Return(frames, nil) + + fs, err := repo.ListRuntimeFrameworkWithType(ctx, 1) + require.Nil(t, err) + require.Equal(t, 1, len(fs)) + require.Equal(t, types.RuntimeFramework{ + ID: 1, FrameName: "foo", FrameVersion: "v1", FrameImage: "i", FrameCpuImage: "c", + Enabled: 1, ContainerPort: 321, Type: 12, + }, fs[0]) + +} + +func TestRepoComponent_ListRuntimeFramework(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(&database.Repository{ + ID: 123, + }, nil) + + frames := []database.RepositoriesRuntimeFramework{ + { + RuntimeFramework: &database.RuntimeFramework{ + ID: 1, FrameName: "foo", FrameVersion: "v1", + FrameImage: "i", FrameCpuImage: "c", + Enabled: 1, ContainerPort: 321, Type: 12, + }, + }, + } + repo.mocks.stores.RuntimeFrameworkMock().EXPECT().ListByRepoID(ctx, int64(123), 1).Return(frames, nil) + + fs, err := repo.ListRuntimeFramework(ctx, types.ModelRepo, "ns", "n", 1) + require.Nil(t, err) + require.Equal(t, 1, len(fs)) + require.Equal(t, types.RuntimeFramework{ + ID: 1, FrameName: "foo", FrameVersion: "v1", FrameImage: "i", FrameCpuImage: "c", + Enabled: 1, ContainerPort: 321, + }, fs[0]) + +} + +func TestRepoComponent_CreateRuntimeFramework(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + frame := database.RuntimeFramework{ + FrameName: "fm", + FrameVersion: "v1", + FrameImage: "img", + FrameCpuImage: "cimg", + Enabled: 2, + ContainerPort: 321, + Type: 2, + } + + repo.mocks.stores.RuntimeFrameworkMock().EXPECT().Add(ctx, frame).Return(nil) + + fn, err := repo.CreateRuntimeFramework(ctx, &types.RuntimeFrameworkReq{ + FrameName: "fm", + FrameVersion: "v1", + FrameImage: "img", + FrameCpuImage: "cimg", + Enabled: 2, + ContainerPort: 321, + Type: 2, + }) + require.Nil(t, err) + require.Equal(t, types.RuntimeFramework{ + FrameName: "fm", + FrameVersion: "v1", + FrameImage: "img", + FrameCpuImage: "cimg", + Enabled: 2, + ContainerPort: 321, + Type: 2, + }, *fn) + +} + +func TestRepoComponent_UpdateRuntimeFramework(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + frame := database.RuntimeFramework{ + ID: 123, + FrameName: "fm", + FrameVersion: "v1", + FrameImage: "img", + FrameCpuImage: "cimg", + Enabled: 2, + ContainerPort: 321, + Type: 2, + } + + repo.mocks.stores.RuntimeFrameworkMock().EXPECT().Update(ctx, frame).Return(&frame, nil) + + fn, err := repo.UpdateRuntimeFramework(ctx, 123, &types.RuntimeFrameworkReq{ + FrameName: "fm", + FrameVersion: "v1", + FrameImage: "img", + FrameCpuImage: "cimg", + Enabled: 2, + ContainerPort: 321, + Type: 2, + }) + require.Nil(t, err) + require.Equal(t, types.RuntimeFramework{ + ID: 123, + FrameName: "fm", + FrameVersion: "v1", + FrameImage: "img", + FrameCpuImage: "cimg", + Enabled: 2, + ContainerPort: 321, + Type: 2, + }, *fn) + +} + +func TestRepoComponent_DeleteRuntimeFramework(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + frame := database.RuntimeFramework{ + FrameName: "fm", + FrameVersion: "v1", + FrameImage: "img", + FrameCpuImage: "cimg", + Enabled: 2, + ContainerPort: 321, + Type: 2, + } + + repo.mocks.stores.RuntimeFrameworkMock().EXPECT().FindByID(ctx, int64(123)).Return(&frame, nil) + repo.mocks.stores.RuntimeFrameworkMock().EXPECT().Delete(ctx, frame).Return(nil) + + err := repo.DeleteRuntimeFramework(ctx, 123) + require.Nil(t, err) + +} + +func TestRepoComponent_ListDeploy(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return(&database.Repository{ + ID: 123, + }, nil) + repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 123}, nil) + + deploys := []database.Deploy{ + {ID: 123, DeployName: "foo", RepoID: 123, GitBranch: "main"}, + } + repo.mocks.stores.DeployTaskMock().EXPECT().ListDeploy(ctx, types.ModelRepo, int64(123), int64(123)).Return(deploys, nil) + + ds, err := repo.ListDeploy(ctx, types.ModelRepo, "ns", "n", "user") + require.Nil(t, err) + require.Equal(t, 1, len(ds)) + require.Equal(t, types.DeployRepo{ + DeployID: 123, + DeployName: "foo", + RepoID: 123, + GitBranch: "main", + Status: "Stopped", + }, ds[0]) +} + +func TestRepoComponent_DeleteDeploy(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") + dr := types.DeployRepo{ + SpaceID: 0, + DeployID: 3, + Namespace: "ns", + Name: "n", + ClusterID: "cluster", + } + repo.mocks.deployer.EXPECT().Purge(ctx, dr).Return(nil) + repo.mocks.deployer.EXPECT().Exist(ctx, dr).Return(false, nil) + repo.mocks.stores.DeployTaskMock().EXPECT().GetDeployByID(ctx, int64(3)).Return(&database.Deploy{ + RepoID: 1, + UserUUID: "uuid", + ClusterID: "cluster", + }, nil) + repo.mocks.stores.DeployTaskMock().EXPECT().DeleteDeploy( + ctx, types.ModelRepo, int64(1), int64(0), int64(3), + ).Return(nil) + + err := repo.DeleteDeploy(ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "ns", + Name: "n", + CurrentUser: "user", + DeployID: 3, + }) + require.Nil(t, err) + +} + +// func TestRepoComponent_DeployDetail(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") + +// repo.mocks.stores.ClusterInfoMock().EXPECT().ByClusterID(ctx, "cluster").Return(database.ClusterInfo{ +// Zone: "z", +// Provider: "p", +// }, nil) +// repo.mocks.stores.DeployTaskMock().EXPECT().GetDeployByID(ctx, int64(1)).Return(&database.Deploy{ +// RepoID: 1, +// UserUUID: "uuid", +// ClusterID: "cluster", +// SvcName: "svc", +// Status: deployStatus.Running, +// }, nil) +// repo.mocks.deployer.EXPECT().GetReplica(ctx, types.DeployRepo{ +// Namespace: "ns", +// Name: "n", +// ClusterID: "cluster", +// SvcName: "svc", +// }).Return(1, 2, []types.Instance{{Name: "i1"}}, nil) + +// dp, err := repo.DeployDetail(ctx, types.DeployActReq{ +// RepoType: types.ModelRepo, +// Namespace: "ns", +// Name: "n", +// CurrentUser: "user", +// DeployID: 1, +// DeployType: 2, +// InstanceName: "i1", +// }) +// require.Nil(t, err) +// require.Equal(t, types.DeployRepo{ +// RepoID: 1, +// ActualReplica: 1, +// DesiredReplica: 2, +// Status: "Running", +// ClusterID: "cluster", +// Instances: []types.Instance{{Name: "i1"}}, +// Private: true, +// SvcName: "svc", +// Endpoint: "endpoint/svc", +// }, *dp) + +// } + +func TestRepoComponent_DeployInstanceLogs(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") + repo.mocks.stores.DeployTaskMock().EXPECT().GetDeployByID(ctx, int64(123)).Return(&database.Deploy{ + ID: 123, + RepoID: 1, + UserUUID: "uuid", + ClusterID: "cluster", + SvcName: "svc", + Status: deployStatus.Running, + }, nil) + + m := &deploy.MultiLogReader{} + repo.mocks.deployer.EXPECT().InstanceLogs(ctx, types.DeployRepo{ + DeployID: 123, + Namespace: "ns", + Name: "n", + ClusterID: "cluster", + SvcName: "svc", + InstanceName: "i1", + }).Return(m, nil) + + mr, err := repo.DeployInstanceLogs(ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "ns", + Name: "n", + CurrentUser: "user", + DeployID: 123, + DeployType: 1, + InstanceName: "i1", + }) + require.Nil(t, err) + require.Equal(t, m, mr) +} + +func TestRepoComponent_AllowAccessByRepoID(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + repo.mocks.stores.RepoMock().EXPECT().FindById(ctx, int64(123)).Return(&database.Repository{ + Path: "foo/bar", + RepositoryType: types.ModelRepo, + }, nil) + mockedRepo := &database.Repository{} + repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "foo", "bar").Return( + mockedRepo, nil, + ) + + allow, err := repo.AllowAccessByRepoID(ctx, 123, "user") + require.Nil(t, err) + require.True(t, allow) +} + +func TestRepoComponent_AllowAccessEndpoint(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ + ID: 123, + }, nil) + + allow, err := repo.AllowAccessEndpoint(ctx, "user", &database.Deploy{ + SecureLevel: types.EndpointPrivate, + UserID: 123, + RepoID: 456, + }) + require.Nil(t, err) + require.True(t, allow) +} + +func TestRepoComponent_AllowAccessDeploy(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + repo.mocks.stores.DeployTaskMock().EXPECT().GetDeployByID(ctx, int64(123)).Return(&database.Deploy{ + UserID: 123, + }, nil) + mockedRepo := &database.Repository{} + repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( + mockedRepo, nil, + ) + repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ + ID: 123, + }, nil) + + allow, err := repo.AllowAccessDeploy(ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "ns", + Name: "n", + CurrentUser: "user", + DeployID: 123, + DeployType: 1, + InstanceName: "i1", + }) + require.Nil(t, err) + require.True(t, allow) +} + +func TestRepoComponent_DeployStop(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + dr := types.DeployRepo{DeployID: 3, Namespace: "ns", Name: "n"} + repo.mocks.deployer.EXPECT().Stop(ctx, dr).Return(nil) + repo.mocks.deployer.EXPECT().Exist(ctx, dr).Return(false, nil) + repo.mocks.stores.DeployTaskMock().EXPECT().StopDeploy( + ctx, types.ModelRepo, int64(0), int64(2), int64(3), + ).Return(nil) + repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ + ID: 2, + }, nil) + repo.mocks.stores.DeployTaskMock().EXPECT().GetDeployByID(ctx, int64(3)).Return(&database.Deploy{ + UserID: 2, + }, nil) + + err := repo.DeployStop(ctx, types.DeployActReq{ + RepoType: types.ModelRepo, + Namespace: "ns", + Name: "n", + CurrentUser: "user", + DeployID: 3, + DeployType: 1, + InstanceName: "i1", + }) + require.Nil(t, err) + +} + +func TestRepoComponent_AllowReadAccessByDeployID(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + repo.mocks.stores.DeployTaskMock().EXPECT().GetDeployByID(ctx, int64(123)).Return(&database.Deploy{ + UserID: 123, + }, nil) + mockedRepo := &database.Repository{} + repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( + mockedRepo, nil, + ) + repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ + ID: 123, + }, nil) + + allow, err := repo.AllowReadAccessByDeployID(ctx, types.ModelRepo, "ns", "n", "user", 123) + require.Nil(t, err) + require.True(t, allow) +} + +func TestRepoComponent_DeployStatus(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + + repo.mocks.stores.DeployTaskMock().EXPECT().GetDeployByID(ctx, int64(123)).Return(&database.Deploy{ + ID: 1, + SpaceID: 2, + ModelID: 3, + SvcName: "svc", + ClusterID: "cluster", + }, nil) + repo.mocks.deployer.EXPECT().Status(ctx, types.DeployRepo{ + DeployID: 1, + SpaceID: 2, + ModelID: 3, + Namespace: "ns", + Name: "n", + SvcName: "svc", + ClusterID: "cluster", + }, true).Return("svc", 2, []types.Instance{{Name: "i1"}}, nil) + a, b, c, err := repo.DeployStatus(ctx, types.ModelRepo, "ns", "n", 123) + require.Nil(t, err) + require.Equal(t, a, "svc") + require.Equal(t, "Stopped", b) + require.Equal(t, []types.Instance{{Name: "i1"}}, c) + +} + +// func TestRepoComponent_SyncMirror(t *testing.T) { + +// for _, gitea := range []bool{false, true} { +// t.Run(fmt.Sprintf("gitea %v", gitea), func(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") + +// if gitea { +// repo.config.GitServer.Type = types.GitServerTypeGitea +// } else { +// repo.config.GitServer.Type = types.GitServerTypeGitaly +// } + +// mirror := &database.Mirror{ +// ID: 321, +// SourceUrl: "/models/ns/n.git", +// Username: "user", +// RepositoryID: 123, +// SourceRepoPath: "ns/n", +// } + +// repo.mocks.stores.MirrorMock().EXPECT().FindByRepoID(ctx, int64(123)).Return(mirror, nil) +// mockedRepo := &database.Repository{ID: 123} +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( +// mockedRepo, nil, +// ) + +// if gitea { +// repo.mocks.mirrorServer.EXPECT().MirrorSync(ctx, mirrorserver.MirrorSyncReq{ +// Namespace: "root", +// Name: mirror.LocalRepoPath, +// }).Return(nil) +// } else { +// repo.mocks.mirrorQueue.EXPECT().PushRepoMirror(&queue.MirrorTask{ +// MirrorID: 321, +// Priority: queue.PriorityMap[types.HighMirrorPriority], +// CreatedAt: mirror.CreatedAt.Unix(), +// }).Return() +// repo.mocks.stores.MirrorMock().EXPECT().Update(ctx, mirror).Return(nil) +// } + +// err := repo.SyncMirror(ctx, types.ModelRepo, "ns", "n", "user") +// require.Nil(t, err) + +// }) +// } + +// } + +// func TestRepoComponent_DeployUpdate(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") + +// req := &types.DeployUpdateReq{ +// ResourceID: tea.Int64(111), +// ClusterID: tea.String("cluster"), +// } + +// deploy := &database.Deploy{ +// ID: 1, +// SpaceID: 2, +// ModelID: 3, +// SvcName: "svc", +// ClusterID: "cluster", +// RuntimeFramework: "fm", +// } +// repo.mocks.stores.DeployTaskMock().EXPECT().GetDeployByID(ctx, int64(1)).Return(deploy, nil) + +// repo.mocks.stores.SpaceResourceMock().EXPECT().FindByID(ctx, int64(111)).Return(&database.SpaceResource{ +// ID: 111, +// }, nil) +// repo.mocks.stores.RuntimeFrameworkMock().EXPECT().FindEnabledByName(ctx, "fm").Return(&database.RuntimeFramework{ +// ID: 999, +// }, nil) +// repo.mocks.stores.ClusterInfoMock().EXPECT().ByClusterID(ctx, "cluster").Return(database.ClusterInfo{}, nil) + +// repo.mocks.deployer.EXPECT().Exist(ctx, types.DeployRepo{ +// DeployID: 1, +// Namespace: "ns", +// Name: "n", +// SvcName: "svc", +// ClusterID: "cluster", +// SpaceID: 2, +// ModelID: 3, +// }).Return(false, nil) +// repo.mocks.deployer.EXPECT().UpdateDeploy(ctx, req, deploy).Return(nil) + +// err := repo.DeployUpdate(ctx, types.DeployActReq{ +// RepoType: types.ModelRepo, +// Namespace: "ns", +// Name: "n", +// CurrentUser: "user", +// DeployID: 1, +// DeployType: 1, +// InstanceName: "i1", +// }, req) +// require.Nil(t, err) +// } + +// func TestRepoComponent_DeployStart(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) +// mockUserRepoAdminPermission(ctx, repo.mocks.stores, "user") + +// deploy := &database.Deploy{ +// ID: 1, +// SpaceID: 2, +// ModelID: 3, +// SvcName: "svc", +// ClusterID: "cluster", +// RuntimeFramework: "fm", +// SKU: "123", +// } +// repo.mocks.stores.DeployTaskMock().EXPECT().GetDeployByID(ctx, int64(1)).Return(deploy, nil) + +// repo.mocks.stores.SpaceResourceMock().EXPECT().FindByID(ctx, int64(123)).Return(&database.SpaceResource{ +// ID: 111, +// }, nil) + +// repo.mocks.deployer.EXPECT().Exist(ctx, types.DeployRepo{ +// DeployID: 1, +// Namespace: "ns", +// Name: "n", +// SvcName: "svc", +// ClusterID: "cluster", +// SpaceID: 2, +// ModelID: 3, +// }).Return(false, nil) + +// repo.mocks.deployer.EXPECT().StartDeploy(ctx, deploy).Return(nil) + +// err := repo.DeployStart(ctx, types.DeployActReq{ +// RepoType: types.ModelRepo, +// Namespace: "ns", +// Name: "n", +// CurrentUser: "user", +// DeployID: 1, +// DeployType: 1, +// InstanceName: "i1", +// }) +// require.Nil(t, err) +// } + +func TestRepoComponent_Branches(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + mockedRepo := &database.Repository{Source: types.HuggingfaceSource, Private: false} + repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( + mockedRepo, nil, + ).Once() + expected := []types.Branch{{Name: "foo"}} + req := &types.GetBranchesReq{ + Namespace: "ns", + Name: "n", + Per: 10, + Page: 1, + RepoType: types.ModelRepo, + } + greq := gitserver.GetBranchesReq{ + Namespace: "ns", + Name: "n", + Per: 10, + Page: 1, + RepoType: types.ModelRepo, + } + repo.mocks.gitServer.EXPECT().GetRepoBranches(ctx, greq).Return(expected, nil).Once() + + bs, err := repo.Branches(ctx, req) + require.Nil(t, err) + require.Equal(t, expected, bs) + + // remote repo, err, return empty results + repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( + mockedRepo, nil, + ).Once() + repo.mocks.gitServer.EXPECT().GetRepoBranches(ctx, greq).Return(nil, errors.New("err")).Once() + bs, err = repo.Branches(ctx, req) + require.Nil(t, err) + require.Equal(t, []types.Branch{}, bs) + + // local repo, err, return error + mockedRepo.Source = types.LocalSource + repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( + mockedRepo, nil, + ).Once() + repo.mocks.gitServer.EXPECT().GetRepoBranches(ctx, greq).Return(nil, errors.New("err")).Once() + _, err = repo.Branches(ctx, req) + require.NotNil(t, err) + +} + +func TestRepoComponent_Tags(t *testing.T) { + ctx := context.TODO() + repo := initializeTestRepoComponent(ctx, t) + mockedRepo := &database.Repository{Source: types.HuggingfaceSource, Private: false, ID: 123} + repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( + mockedRepo, nil, + ).Once() + expected := []database.Tag{{Name: "foo"}} + req := &types.GetTagsReq{ + Namespace: "ns", + Name: "n", + RepoType: types.ModelRepo, + } + + repo.mocks.stores.RepoMock().EXPECT().Tags(ctx, int64(123)).Return(expected, nil) + + ts, err := repo.Tags(ctx, req) + require.Nil(t, err) + require.Equal(t, expected, ts) + +} + +// func TestRepoComponent_UpdateTags(t *testing.T) { +// ctx := context.TODO() +// repo := initializeTestRepoComponent(ctx, t) +// mockedRepo := &database.Repository{Source: types.HuggingfaceSource, Private: false, ID: 123} +// repo.mocks.stores.RepoMock().EXPECT().FindByPath(ctx, types.ModelRepo, "ns", "n").Return( +// mockedRepo, nil, +// ).Once() +// repo.mocks.components.tag.EXPECT().UpdateRepoTagsByCategory( +// ctx, database.ModelTagScope, int64(123), "cat", []string{"foo", "bar"}, +// ).Return(nil) +// repo.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ +// RoleMask: "admin", +// }, nil) + +// err := repo.UpdateTags(ctx, "ns", "n", types.ModelRepo, "cat", "user", []string{"foo", "bar"}) +// require.Nil(t, err) + +// } + +// func TestRepoComponent_checkCurrentUserPermission(t *testing.T) { + +// t.Run("can read self-owned", func(t *testing.T) { +// ctx := context.TODO() +// repoComp := initializeTestRepoComponent(ctx, t) + +// ns := database.Namespace{} +// ns.NamespaceType = "user" +// ns.Path = "user_name" +// repoComp.mocks.stores.NamespaceMock().EXPECT().FindByPath(mock.Anything, ns.Path).Return(ns, nil) + +// user := database.User{} +// user.Username = "user_name" +// repoComp.mocks.stores.UserMock().EXPECT().FindByUsername(mock.Anything, user.Username).Return(user, nil) + +// yes, err := repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleRead) +// require.True(t, yes) +// require.NoError(t, err) + +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleWrite) +// require.True(t, yes) +// require.NoError(t, err) + +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleAdmin) +// require.True(t, yes) +// require.NoError(t, err) +// }) + +// t.Run("can not read other's", func(t *testing.T) { +// ctx := context.TODO() +// repoComp := initializeTestRepoComponent(ctx, t) + +// ns := database.Namespace{} +// ns.NamespaceType = "user" +// ns.Path = "user_name_other" +// repoComp.mocks.stores.NamespaceMock().EXPECT().FindByPath(mock.Anything, ns.Path).Return(ns, nil) + +// user := database.User{} +// user.Username = "user_name" +// repoComp.mocks.stores.UserMock().EXPECT().FindByUsername(mock.Anything, user.Username).Return(user, nil) + +// yes, err := repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleRead) +// require.False(t, yes) +// require.NoError(t, err) + +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleWrite) +// require.False(t, yes) +// require.NoError(t, err) + +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleAdmin) +// require.False(t, yes) +// require.NoError(t, err) +// }) + +// t.Run("can not read org's if not org member", func(t *testing.T) { +// ctx := context.TODO() +// repoComp := initializeTestRepoComponent(ctx, t) + +// ns := database.Namespace{} +// ns.NamespaceType = "organization" +// ns.Path = "org_name" +// repoComp.mocks.stores.NamespaceMock().EXPECT().FindByPath(mock.Anything, ns.Path).Return(ns, nil) + +// user := database.User{} +// user.Username = "user_name" +// repoComp.mocks.stores.UserMock().EXPECT().FindByUsername(mock.Anything, user.Username).Return(user, nil) + +// //user not belongs to org +// repoComp.mocks.userSvcClient.EXPECT().GetMemberRole(mock.Anything, ns.Path, user.Username).Return(membership.RoleUnknown, nil) + +// yes, err := repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleRead) +// require.False(t, yes) +// require.NoError(t, err) + +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleWrite) +// require.False(t, yes) +// require.NoError(t, err) + +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleAdmin) +// require.False(t, yes) +// require.NoError(t, err) +// }) + +// t.Run("can read org's as org member", func(t *testing.T) { +// ctx := context.TODO() +// repoComp := initializeTestRepoComponent(ctx, t) + +// ns := database.Namespace{} +// ns.NamespaceType = "organization" +// ns.Path = "org_name" +// repoComp.mocks.stores.NamespaceMock().EXPECT().FindByPath(mock.Anything, ns.Path).Return(ns, nil) + +// user := database.User{} +// user.Username = "user_name" +// repoComp.mocks.stores.UserMock().EXPECT().FindByUsername(mock.Anything, user.Username).Return(user, nil) + +// //user is read-only member of the org +// repoComp.mocks.userSvcClient.EXPECT().GetMemberRole(mock.Anything, ns.Path, user.Username).Return(membership.RoleRead, nil) + +// //can read +// yes, err := repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleRead) +// require.True(t, yes) +// require.NoError(t, err) +// //can't write +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleWrite) +// require.False(t, yes) +// require.NoError(t, err) +// //can't admin +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleAdmin) +// require.False(t, yes) +// require.NoError(t, err) +// }) + +// t.Run("admin read org's", func(t *testing.T) { +// ctx := context.TODO() +// repoComp := initializeTestRepoComponent(ctx, t) + +// ns := database.Namespace{} +// ns.NamespaceType = "organization" +// ns.Path = "org_name" +// repoComp.mocks.stores.NamespaceMock().EXPECT().FindByPath(mock.Anything, ns.Path).Return(ns, nil) + +// user := database.User{} +// user.Username = "user_name_admin" +// user.RoleMask = "admin" +// repoComp.mocks.stores.UserMock().EXPECT().FindByUsername(mock.Anything, user.Username).Return(user, nil) + +// yes, err := repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleRead) +// require.True(t, yes) +// require.NoError(t, err) + +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleWrite) +// require.True(t, yes) +// require.NoError(t, err) + +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleAdmin) +// require.True(t, yes) +// require.NoError(t, err) +// }) + +// t.Run("admin read other's", func(t *testing.T) { +// ctx := context.TODO() +// repoComp := initializeTestRepoComponent(ctx, t) + +// ns := database.Namespace{} +// ns.NamespaceType = "user" +// ns.Path = "user_name" +// repoComp.mocks.stores.NamespaceMock().EXPECT().FindByPath(mock.Anything, ns.Path).Return(ns, nil) + +// user := database.User{} +// user.Username = "user_name_admin" +// user.RoleMask = "admin" +// repoComp.mocks.stores.UserMock().EXPECT().FindByUsername(mock.Anything, user.Username).Return(user, nil) + +// yes, err := repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleRead) +// require.True(t, yes) +// require.NoError(t, err) + +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleWrite) +// require.True(t, yes) +// require.NoError(t, err) + +// yes, err = repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleAdmin) +// require.True(t, yes) +// require.NoError(t, err) +// }) +// } + +// func TestRepoComponent_LastCommit(t *testing.T) { +// t.Run("can read self-owned", func(t *testing.T) { +// ctx := context.TODO() +// repoComp := initializeTestRepoComponent(ctx, t) + +// repoComp.mocks.stores.RepoMock().EXPECT().FindByPath(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&database.Repository{}, nil) + +// ns := database.Namespace{} +// ns.NamespaceType = "user" +// ns.Path = "user_name" +// repoComp.mocks.stores.NamespaceMock().EXPECT().FindByPath(mock.Anything, ns.Path).Return(ns, nil) + +// user := database.User{} +// user.Username = "user_name" +// repoComp.mocks.stores.UserMock().EXPECT().FindByUsername(mock.Anything, user.Username).Return(user, nil) + +// commit := &types.Commit{} +// repoComp.mocks.gitServer.EXPECT().GetRepoLastCommit(mock.Anything, mock.Anything).Return(commit, nil) + +// yes, err := repoComp.CheckCurrentUserPermission(context.Background(), user.Username, ns.Path, membership.RoleRead) +// require.True(t, yes) +// require.NoError(t, err) + +// actualCommit, err := repoComp.LastCommit(context.Background(), &types.GetCommitsReq{}) +// require.NoError(t, err) +// require.Equal(t, commit, actualCommit) + +// }) + +// t.Run("forbidden anonymous user to read private repo", func(t *testing.T) { +// ctx := context.TODO() +// repoComp := initializeTestRepoComponent(ctx, t) + +// repoComp.mocks.stores.RepoMock().EXPECT().FindByPath(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&database.Repository{ +// // private repo don't allow read from other user +// Private: true, +// }, nil) + +// actualCommit, err := repoComp.LastCommit(context.Background(), &types.GetCommitsReq{}) +// require.Nil(t, actualCommit) +// require.Equal(t, err, ErrForbidden) + +// }) +// } + +// func TestRepoComponent_Tree(t *testing.T) { +// { +// t.Run("can read self-owned", func(t *testing.T) { +// ctx := context.TODO() +// repoComp := initializeTestRepoComponent(ctx, t) + +// user := database.User{} +// user.Username = "user_name" +// repoComp.mocks.stores.UserMock().EXPECT().FindByUsername(mock.Anything, user.Username).Return(user, nil) + +// ns := database.Namespace{} +// ns.NamespaceType = "user" +// ns.Path = "user_name" +// repoComp.mocks.stores.NamespaceMock().EXPECT().FindByPath(mock.Anything, ns.Path).Return(ns, nil) + +// repo := &database.Repository{ +// Private: true, +// User: user, +// Path: fmt.Sprintf("%s/%s", ns.Path, "repo_name"), +// Source: types.LocalSource, +// } +// repoComp.mocks.stores.RepoMock().EXPECT().FindByPath(mock.Anything, types.ModelRepo, ns.Path, repo.Name).Return(repo, nil) + +// tree := []*types.File{} +// repoComp.mocks.gitServer.EXPECT().GetRepoFileTree(mock.Anything, mock.Anything).Return(tree, nil) + +// actualTree, err := repoComp.Tree(context.Background(), &types.GetFileReq{ +// Namespace: ns.Path, +// Name: repo.Name, +// Path: "", +// RepoType: types.ModelRepo, +// CurrentUser: user.Username, +// }) +// require.Nil(t, err) +// require.Equal(t, tree, actualTree) + +// }) + +// t.Run("forbidden anoymous user to read private repo", func(t *testing.T) { +// ctx := context.TODO() +// repoComp := initializeTestRepoComponent(ctx, t) + +// repoComp.mocks.stores.RepoMock().EXPECT().FindByPath(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&database.Repository{ +// // private repo don't allow read from other user +// Private: true, +// }, nil) + +// actualTree, err := repoComp.Tree(context.Background(), &types.GetFileReq{}) +// require.Nil(t, actualTree) +// require.Equal(t, err, ErrForbidden) + +// }) +// } + +// } diff --git a/component/runtime_architecture.go b/component/runtime_architecture.go index 50c65dd3..138adce0 100644 --- a/component/runtime_architecture.go +++ b/component/runtime_architecture.go @@ -34,7 +34,7 @@ type RuntimeArchitectureComponent interface { DeleteArchitectures(ctx context.Context, id int64, architectures []string) ([]string, error) ScanArchitecture(ctx context.Context, id int64, scanType int, models []string) error // check if it's supported model resource by name - IsSupportedModelResource(ctx context.Context, modelName string, rf *database.RuntimeFramework, id int64) (bool, error) + IsSupportedModelResource(ctx context.Context, modelName string, rfm *database.RuntimeFramework, id int64) (bool, error) GetArchitectureFromConfig(ctx context.Context, namespace, name string) (string, error) // remove runtime_framework tag from model RemoveRuntimeFrameworkTag(ctx context.Context, rftags []*database.Tag, repoId, rfId int64) @@ -67,7 +67,7 @@ func (c *runtimeArchitectureComponentImpl) ListByRuntimeFrameworkID(ctx context. } func (c *runtimeArchitectureComponentImpl) SetArchitectures(ctx context.Context, id int64, architectures []string) ([]string, error) { - _, err := c.r.rtfm.FindByID(ctx, id) + _, err := c.r.runtimeFrameworksStore.FindByID(ctx, id) if err != nil { return nil, fmt.Errorf("invalid runtime framework id, %w", err) } @@ -88,7 +88,7 @@ func (c *runtimeArchitectureComponentImpl) SetArchitectures(ctx context.Context, } func (c *runtimeArchitectureComponentImpl) DeleteArchitectures(ctx context.Context, id int64, architectures []string) ([]string, error) { - _, err := c.r.rtfm.FindByID(ctx, id) + _, err := c.r.runtimeFrameworksStore.FindByID(ctx, id) if err != nil { return nil, fmt.Errorf("invalid runtime framework id, %w", err) } @@ -106,7 +106,7 @@ func (c *runtimeArchitectureComponentImpl) DeleteArchitectures(ctx context.Conte } func (c *runtimeArchitectureComponentImpl) ScanArchitecture(ctx context.Context, id int64, scanType int, models []string) error { - frame, err := c.r.rtfm.FindByID(ctx, id) + frame, err := c.r.runtimeFrameworksStore.FindByID(ctx, id) if err != nil { return fmt.Errorf("invalid runtime framework id, %w", err) } @@ -155,7 +155,7 @@ func (c *runtimeArchitectureComponentImpl) ScanArchitecture(ctx context.Context, } func (c *runtimeArchitectureComponentImpl) scanNewModels(ctx context.Context, req types.ScanReq) error { - repos, err := c.r.repo.GetRepoWithoutRuntimeByID(ctx, req.FrameID, req.Models) + repos, err := c.r.repoStore.GetRepoWithoutRuntimeByID(ctx, req.FrameID, req.Models) if err != nil { return fmt.Errorf("failed to get repos without runtime by ID, %w", err) } @@ -186,7 +186,7 @@ func (c *runtimeArchitectureComponentImpl) scanNewModels(ctx context.Context, re if !exist && !isSupportedRM { continue } - err = c.r.rrtfms.Add(ctx, req.FrameID, repo.ID, req.FrameType) + err = c.r.repoRuntimeFrameworkStore.Add(ctx, req.FrameID, repo.ID, req.FrameType) if err != nil { slog.Warn("fail to create relation", slog.Any("repo", repo.Path), slog.Any("frameid", req.FrameID), slog.Any("error", err)) } @@ -229,7 +229,7 @@ func (c *runtimeArchitectureComponentImpl) IsSupportedModelResource(ctx context. } func (c *runtimeArchitectureComponentImpl) scanExistModels(ctx context.Context, req types.ScanReq) error { - repos, err := c.r.repo.GetRepoWithRuntimeByID(ctx, req.FrameID, req.Models) + repos, err := c.r.repoStore.GetRepoWithRuntimeByID(ctx, req.FrameID, req.Models) if err != nil { return fmt.Errorf("fail to get repos with runtime by ID, %w", err) } @@ -250,7 +250,7 @@ func (c *runtimeArchitectureComponentImpl) scanExistModels(ctx context.Context, if exist { continue } - err = c.r.rrtfms.Delete(ctx, req.FrameID, repo.ID, req.FrameType) + err = c.r.repoRuntimeFrameworkStore.Delete(ctx, req.FrameID, repo.ID, req.FrameType) if err != nil { slog.Warn("fail to remove relation", slog.Any("repo", repo.Path), slog.Any("frameid", req.FrameID), slog.Any("error", err)) } diff --git a/component/space.go b/component/space.go index 51107b71..d91912a5 100644 --- a/component/space.go +++ b/component/space.go @@ -11,8 +11,10 @@ import ( "opencsg.com/csghub-server/builder/deploy" "opencsg.com/csghub-server/builder/deploy/scheduler" + "opencsg.com/csghub-server/builder/git" "opencsg.com/csghub-server/builder/git/gitserver" "opencsg.com/csghub-server/builder/git/membership" + "opencsg.com/csghub-server/builder/rpc" "opencsg.com/csghub-server/builder/store/database" "opencsg.com/csghub-server/common/config" "opencsg.com/csghub-server/common/types" @@ -54,36 +56,51 @@ type SpaceComponent interface { func NewSpaceComponent(config *config.Config) (SpaceComponent, error) { c := &spaceComponentImpl{} - c.ss = database.NewSpaceStore() + c.spaceStore = database.NewSpaceStore() var err error - c.sss = database.NewSpaceSdkStore() - c.srs = database.NewSpaceResourceStore() - c.rs = database.NewRepoStore() - c.repoComponentImpl, err = NewRepoComponentImpl(config) + c.spaceSdkStore = database.NewSpaceSdkStore() + c.spaceResourceStore = database.NewSpaceResourceStore() + c.repoStore = database.NewRepoStore() + c.repoComponent, err = NewRepoComponentImpl(config) if err != nil { return nil, err } c.deployer = deploy.NewDeployer() c.publicRootDomain = config.Space.PublicRootDomain - c.us = database.NewUserStore() - c.ac, err = NewAccountingComponent(config) + c.userStore = database.NewUserStore() + c.accountingComponent, err = NewAccountingComponent(config) if err != nil { return nil, err } - + c.git, err = git.NewGitServer(config) + if err != nil { + return nil, err + } + c.serverBaseUrl = config.APIServer.PublicDomain + c.deployTaskStore = database.NewDeployTaskStore() + c.userSvcClient = rpc.NewUserSvcHttpClient(fmt.Sprintf("%s:%d", config.User.Host, config.User.Port), + rpc.AuthWithApiKey(config.APIToken)) + c.userLikesStore = database.NewUserLikesStore() + c.config = config return c, nil } type spaceComponentImpl struct { - *repoComponentImpl - ss database.SpaceStore - sss database.SpaceSdkStore - srs database.SpaceResourceStore - rs database.RepoStore - us database.UserStore - deployer deploy.Deployer - publicRootDomain string - ac AccountingComponent + config *config.Config + repoComponent RepoComponent + git gitserver.GitServer + spaceStore database.SpaceStore + spaceSdkStore database.SpaceSdkStore + spaceResourceStore database.SpaceResourceStore + repoStore database.RepoStore + userStore database.UserStore + deployer deploy.Deployer + publicRootDomain string + accountingComponent AccountingComponent + serverBaseUrl string + deployTaskStore database.DeployTaskStore + userSvcClient rpc.UserSvcClient + userLikesStore database.UserLikesStore } func (c *spaceComponentImpl) Create(ctx context.Context, req types.CreateSpaceReq) (*types.Space, error) { @@ -99,7 +116,7 @@ func (c *spaceComponentImpl) Create(ctx context.Context, req types.CreateSpaceRe req.Nickname = nickname req.RepoType = types.SpaceRepo req.Readme = generateReadmeData(req.License) - resource, err := c.srs.FindByID(ctx, req.ResourceID) + resource, err := c.spaceResourceStore.FindByID(ctx, req.ResourceID) if err != nil { return nil, err } @@ -113,7 +130,7 @@ func (c *spaceComponentImpl) Create(ctx context.Context, req types.CreateSpaceRe return nil, fmt.Errorf("fail to check resource, %w", err) } - _, dbRepo, err := c.CreateRepo(ctx, req.CreateRepoReq) + _, dbRepo, err := c.repoComponent.CreateRepo(ctx, req.CreateRepoReq) if err != nil { return nil, err } @@ -129,7 +146,7 @@ func (c *spaceComponentImpl) Create(ctx context.Context, req types.CreateSpaceRe SKU: strconv.FormatInt(resource.ID, 10), } - resSpace, err := c.ss.Create(ctx, dbSpace) + resSpace, err := c.spaceStore.Create(ctx, dbSpace) if err != nil { slog.Error("fail to create space in db", slog.Any("req", req), slog.String("error", err.Error())) return nil, fmt.Errorf("fail to create space in db, error: %w", err) @@ -207,12 +224,12 @@ func (c *spaceComponentImpl) Create(ctx context.Context, req types.CreateSpaceRe func (c *spaceComponentImpl) Show(ctx context.Context, namespace, name, currentUser string) (*types.Space, error) { var tags []types.RepoTag - space, err := c.ss.FindByPath(ctx, namespace, name) + space, err := c.spaceStore.FindByPath(ctx, namespace, name) if err != nil { return nil, fmt.Errorf("failed to find space, error: %w", err) } - permission, err := c.GetUserRepoPermission(ctx, currentUser, space.Repository) + permission, err := c.repoComponent.GetUserRepoPermission(ctx, currentUser, space.Repository) if err != nil { return nil, fmt.Errorf("failed to get user repo permission, error: %w", err) } @@ -220,7 +237,7 @@ func (c *spaceComponentImpl) Show(ctx context.Context, namespace, name, currentU return nil, ErrUnauthorized } - ns, err := c.GetNameSpaceInfo(ctx, namespace) + ns, err := c.repoComponent.GetNameSpaceInfo(ctx, namespace) if err != nil { return nil, fmt.Errorf("failed to get namespace info for model, error: %w", err) } @@ -243,7 +260,7 @@ func (c *spaceComponentImpl) Show(ctx context.Context, namespace, name, currentU } } - likeExists, err := c.uls.IsExist(ctx, currentUser, space.Repository.ID) + likeExists, err := c.userLikesStore.IsExist(ctx, currentUser, space.Repository.ID) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user likes,error:%w", err) return nil, newError @@ -291,12 +308,12 @@ func (c *spaceComponentImpl) Show(ctx context.Context, namespace, name, currentU func (c *spaceComponentImpl) Update(ctx context.Context, req *types.UpdateSpaceReq) (*types.Space, error) { req.RepoType = types.SpaceRepo - dbRepo, err := c.UpdateRepo(ctx, req.UpdateRepoReq) + dbRepo, err := c.repoComponent.UpdateRepo(ctx, req.UpdateRepoReq) if err != nil { return nil, err } - space, err := c.ss.ByRepoID(ctx, dbRepo.ID) + space, err := c.spaceStore.ByRepoID(ctx, dbRepo.ID) if err != nil { return nil, fmt.Errorf("failed to find space, error: %w", err) } @@ -305,7 +322,7 @@ func (c *spaceComponentImpl) Update(ctx context.Context, req *types.UpdateSpaceR return nil, fmt.Errorf("failed to merge update space request, error: %w", err) } - err = c.ss.Update(ctx, *space) + err = c.spaceStore.Update(ctx, *space) if err != nil { return nil, fmt.Errorf("failed to update database space, error: %w", err) } @@ -335,7 +352,7 @@ func (c *spaceComponentImpl) Index(ctx context.Context, filter *types.RepoFilter resSpaces []types.Space err error ) - repos, total, err := c.PublicToUser(ctx, types.SpaceRepo, filter.Username, filter, per, page) + repos, total, err := c.repoComponent.PublicToUser(ctx, types.SpaceRepo, filter.Username, filter, per, page) if err != nil { newError := fmt.Errorf("failed to get public space repos,error:%w", err) return nil, 0, newError @@ -344,7 +361,7 @@ func (c *spaceComponentImpl) Index(ctx context.Context, filter *types.RepoFilter for _, repo := range repos { repoIDs = append(repoIDs, repo.ID) } - spaces, err := c.ss.ByRepoIDs(ctx, repoIDs) + spaces, err := c.spaceStore.ByRepoIDs(ctx, repoIDs) if err != nil { newError := fmt.Errorf("failed to get spaces by repo ids,error:%w", err) return nil, 0, newError @@ -408,7 +425,7 @@ func (c *spaceComponentImpl) OrgSpaces(ctx context.Context, req *types.OrgSpaces r := membership.RoleUnknown if req.CurrentUser != "" { r, err = c.userSvcClient.GetMemberRole(ctx, req.Namespace, req.CurrentUser) - // log error, and treat user as unkown role in org + // log error, and treat user as unknown role in org if err != nil { slog.Error("faild to get member role", slog.String("org", req.Namespace), slog.String("user", req.CurrentUser), @@ -416,7 +433,7 @@ func (c *spaceComponentImpl) OrgSpaces(ctx context.Context, req *types.OrgSpaces } } onlyPublic := !r.CanRead() - spaces, total, err := c.ss.ByOrgPath(ctx, req.Namespace, req.PageSize, req.Page, onlyPublic) + spaces, total, err := c.spaceStore.ByOrgPath(ctx, req.Namespace, req.PageSize, req.Page, onlyPublic) if err != nil { newError := fmt.Errorf("failed to get org spaces,error:%w", err) slog.Error(newError.Error()) @@ -447,7 +464,7 @@ func (c *spaceComponentImpl) OrgSpaces(ctx context.Context, req *types.OrgSpaces // UserSpaces get spaces of owner and visible to current user func (c *spaceComponentImpl) UserSpaces(ctx context.Context, req *types.UserSpacesReq) ([]types.Space, int, error) { onlyPublic := req.Owner != req.CurrentUser - ms, total, err := c.ss.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) + ms, total, err := c.spaceStore.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) if err != nil { newError := fmt.Errorf("failed to get spaces by username,%w", err) return nil, 0, newError @@ -477,7 +494,7 @@ func (c *spaceComponentImpl) UserSpaces(ctx context.Context, req *types.UserSpac } func (c *spaceComponentImpl) UserLikesSpaces(ctx context.Context, req *types.UserSpacesReq, userID int64) ([]types.Space, int, error) { - ms, total, err := c.ss.ByUserLikes(ctx, userID, req.PageSize, req.Page) + ms, total, err := c.spaceStore.ByUserLikes(ctx, userID, req.PageSize, req.Page) if err != nil { newError := fmt.Errorf("failed to get spaces by username,%w", err) return nil, 0, newError @@ -508,7 +525,7 @@ func (c *spaceComponentImpl) UserLikesSpaces(ctx context.Context, req *types.Use func (c *spaceComponentImpl) ListByPath(ctx context.Context, paths []string) ([]*types.Space, error) { var spaces []*types.Space - spacesData, err := c.ss.ListByPath(ctx, paths) + spacesData, err := c.spaceStore.ListByPath(ctx, paths) if err != nil { return nil, fmt.Errorf("list space db failed, %w", err) } @@ -554,16 +571,16 @@ func (c *spaceComponentImpl) AllowCallApi(ctx context.Context, spaceID int64, us if username == "" { return false, ErrUserNotFound } - s, err := c.ss.ByID(ctx, spaceID) + s, err := c.spaceStore.ByID(ctx, spaceID) if err != nil { return false, fmt.Errorf("failed to get space by id:%d, %w", spaceID, err) } fields := strings.Split(s.Repository.Path, "/") - return c.AllowReadAccess(ctx, s.Repository.RepositoryType, fields[0], fields[1], username) + return c.repoComponent.AllowReadAccess(ctx, s.Repository.RepositoryType, fields[0], fields[1], username) } func (c *spaceComponentImpl) Delete(ctx context.Context, namespace, name, currentUser string) error { - space, err := c.ss.FindByPath(ctx, namespace, name) + space, err := c.spaceStore.FindByPath(ctx, namespace, name) if err != nil { return fmt.Errorf("failed to find space, error: %w", err) } @@ -574,12 +591,12 @@ func (c *spaceComponentImpl) Delete(ctx context.Context, namespace, name, curren Name: name, RepoType: types.SpaceRepo, } - _, err = c.DeleteRepo(ctx, deleteDatabaseRepoReq) + _, err = c.repoComponent.DeleteRepo(ctx, deleteDatabaseRepoReq) if err != nil { return fmt.Errorf("failed to delete repo of space, error: %w", err) } - err = c.ss.Delete(ctx, *space) + err = c.spaceStore.Delete(ctx, *space) if err != nil { return fmt.Errorf("failed to delete database space, error: %w", err) } @@ -591,13 +608,13 @@ func (c *spaceComponentImpl) Delete(ctx context.Context, namespace, name, curren } func (c *spaceComponentImpl) Deploy(ctx context.Context, namespace, name, currentUser string) (int64, error) { - s, err := c.ss.FindByPath(ctx, namespace, name) + s, err := c.spaceStore.FindByPath(ctx, namespace, name) if err != nil { slog.Error("can't deploy space", slog.Any("error", err), slog.String("namespace", namespace), slog.String("name", name)) return -1, err } // found user id - user, err := c.us.FindByUsername(ctx, currentUser) + user, err := c.userStore.FindByUsername(ctx, currentUser) if err != nil { slog.Error("can't find user for create deploy space", slog.Any("error", err), slog.String("username", currentUser)) return -1, err @@ -647,13 +664,13 @@ func (c *spaceComponentImpl) Deploy(ctx context.Context, namespace, name, curren } func (c *spaceComponentImpl) Wakeup(ctx context.Context, namespace, name string) error { - s, err := c.ss.FindByPath(ctx, namespace, name) + s, err := c.spaceStore.FindByPath(ctx, namespace, name) if err != nil { slog.Error("can't wakeup space", slog.Any("error", err), slog.String("namespace", namespace), slog.String("name", name)) return err } // get latest Deploy for space - deploy, err := c.deploy.GetLatestDeployBySpaceID(ctx, s.ID) + deploy, err := c.deployTaskStore.GetLatestDeployBySpaceID(ctx, s.ID) if err != nil { return fmt.Errorf("can't get space delopyment,%w", err) } @@ -666,13 +683,13 @@ func (c *spaceComponentImpl) Wakeup(ctx context.Context, namespace, name string) } func (c *spaceComponentImpl) Stop(ctx context.Context, namespace, name string) error { - s, err := c.ss.FindByPath(ctx, namespace, name) + s, err := c.spaceStore.FindByPath(ctx, namespace, name) if err != nil { slog.Error("can't stop space", slog.Any("error", err), slog.String("namespace", namespace), slog.String("name", name)) return err } // get latest Deploy of space - deploy, err := c.deploy.GetLatestDeployBySpaceID(ctx, s.ID) + deploy, err := c.deployTaskStore.GetLatestDeployBySpaceID(ctx, s.ID) if err != nil { slog.Error("can't get space deployment", slog.Any("error", err), slog.Any("space id", s.ID)) return fmt.Errorf("can't get space deployment,%w", err) @@ -691,7 +708,7 @@ func (c *spaceComponentImpl) Stop(ctx context.Context, namespace, name string) e return fmt.Errorf("can't stop space service deploy for service '%s', %w", deploy.SvcName, err) } - err = c.deploy.StopDeploy(ctx, types.SpaceRepo, deploy.RepoID, deploy.UserID, deploy.ID) + err = c.deployTaskStore.StopDeploy(ctx, types.SpaceRepo, deploy.RepoID, deploy.UserID, deploy.ID) if err != nil { return fmt.Errorf("fail to update space deploy status to stopped for deploy ID '%d', %w", deploy.ID, err) } @@ -703,7 +720,7 @@ func (c *spaceComponentImpl) FixHasEntryFile(ctx context.Context, s *database.Sp hasAppFile := c.HasEntryFile(ctx, s) if s.HasAppFile != hasAppFile { s.HasAppFile = hasAppFile - if er := c.ss.Update(ctx, *s); er != nil { + if er := c.spaceStore.Update(ctx, *s); er != nil { slog.Error("update space failed", "error", er) } } @@ -719,7 +736,7 @@ func (c *spaceComponentImpl) status(ctx context.Context, s *database.Space) (str return "", SpaceStatusNoAppFile, nil } // get latest Deploy for space by space id - deploy, err := c.deploy.GetLatestDeployBySpaceID(ctx, s.ID) + deploy, err := c.deployTaskStore.GetLatestDeployBySpaceID(ctx, s.ID) if err != nil || deploy == nil { slog.Error("fail to get latest space deploy by space id", slog.Any("SpaceID", s.ID)) return "", SpaceStatusStopped, fmt.Errorf("can't get space deployment,%w", err) @@ -743,7 +760,7 @@ func (c *spaceComponentImpl) status(ctx context.Context, s *database.Space) (str } func (c *spaceComponentImpl) Status(ctx context.Context, namespace, name string) (string, string, error) { - s, err := c.ss.FindByPath(ctx, namespace, name) + s, err := c.spaceStore.FindByPath(ctx, namespace, name) if err != nil { return "", SpaceStatusStopped, fmt.Errorf("can't find space by path:%w", err) } @@ -751,7 +768,7 @@ func (c *spaceComponentImpl) Status(ctx context.Context, namespace, name string) } func (c *spaceComponentImpl) Logs(ctx context.Context, namespace, name string) (*deploy.MultiLogReader, error) { - s, err := c.ss.FindByPath(ctx, namespace, name) + s, err := c.spaceStore.FindByPath(ctx, namespace, name) if err != nil { return nil, fmt.Errorf("can't find space by path:%w", err) } @@ -817,7 +834,7 @@ func (c *spaceComponentImpl) mergeUpdateSpaceRequest(ctx context.Context, space } if req.ResourceID != nil { - resource, err := c.srs.FindByID(ctx, *req.ResourceID) + resource, err := c.spaceResourceStore.FindByID(ctx, *req.ResourceID) if err != nil { return fmt.Errorf("can't find space resource by id, resource id:%d, error:%w", *req.ResourceID, err) } diff --git a/component/space_test.go b/component/space_test.go new file mode 100644 index 00000000..57d894de --- /dev/null +++ b/component/space_test.go @@ -0,0 +1,519 @@ +package component + +import ( + "context" + "fmt" + "testing" + "time" + + "github.com/alibabacloud-go/tea/tea" + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/deploy" + "opencsg.com/csghub-server/builder/deploy/scheduler" + "opencsg.com/csghub-server/builder/git/gitserver" + "opencsg.com/csghub-server/builder/git/membership" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/types" +) + +// func TestSpaceComponent_Create(t *testing.T) { +// ctx := context.TODO() +// sc := initializeTestSpaceComponent(ctx, t) + +// sc.mocks.stores.SpaceResourceMock().EXPECT().FindByID(ctx, int64(1)).Return(&database.SpaceResource{ +// ID: 1, +// Name: "sp", +// Resources: `{"memory": "foo"}`, +// }, nil) + +// sc.mocks.deployer.EXPECT().CheckResourceAvailable(ctx, int64(0), &types.HardWare{ +// Memory: "foo", +// }).Return(true, nil) + +// sc.mocks.components.repo.EXPECT().CreateRepo(ctx, types.CreateRepoReq{ +// DefaultBranch: "main", +// Readme: generateReadmeData("MIT"), +// License: "MIT", +// Namespace: "ns", +// Name: "n", +// Nickname: "n", +// RepoType: types.SpaceRepo, +// Username: "user", +// }).Return(nil, &database.Repository{ +// ID: 321, +// User: database.User{ +// Username: "user", +// Email: "foo@bar.com", +// }, +// }, nil) + +// sc.mocks.stores.SpaceMock().EXPECT().Create(ctx, database.Space{ +// RepositoryID: 321, +// Sdk: scheduler.STREAMLIT.Name, +// SdkVersion: "v1", +// Env: "env", +// Hardware: `{"memory": "foo"}`, +// Secrets: "sss", +// SKU: "1", +// }).Return(&database.Space{}, nil) +// sc.mocks.gitServer.EXPECT().CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ +// Username: "user", +// Email: "foo@bar.com", +// Message: initCommitMessage, +// Branch: "main", +// Content: generateReadmeData("MIT"), +// NewBranch: "main", +// Namespace: "ns", +// Name: "n", +// FilePath: readmeFileName, +// }, types.SpaceRepo)).Return(nil) +// sc.mocks.gitServer.EXPECT().CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ +// Username: "user", +// Email: "foo@bar.com", +// Message: initCommitMessage, +// Branch: "main", +// Content: spaceGitattributesContent, +// NewBranch: "main", +// Namespace: "ns", +// Name: "n", +// FilePath: gitattributesFileName, +// }, types.SpaceRepo)).Return(nil) +// sc.mocks.gitServer.EXPECT().CreateRepoFile(buildCreateFileReq(&types.CreateFileParams{ +// Username: "user", +// Email: "foo@bar.com", +// Message: initCommitMessage, +// Branch: "main", +// Content: streamlitConfigContent, +// NewBranch: "main", +// Namespace: "ns", +// Name: "n", +// FilePath: streamlitConfig, +// }, types.SpaceRepo)).Return(nil) + +// space, err := sc.Create(ctx, types.CreateSpaceReq{ +// Sdk: scheduler.STREAMLIT.Name, +// SdkVersion: "v1", +// Env: "env", +// Secrets: "sss", +// ResourceID: 1, +// ClusterID: "cluster", +// CreateRepoReq: types.CreateRepoReq{ +// DefaultBranch: "main", +// Readme: "readme", +// Namespace: "ns", +// Name: "n", +// License: "MIT", +// Username: "user", +// }, +// }) +// require.Nil(t, err) + +// require.Equal(t, &types.Space{ +// License: "MIT", +// Name: "n", +// Sdk: "streamlit", +// SdkVersion: "v1", +// Env: "env", +// Secrets: "sss", +// Hardware: `{"memory": "foo"}`, +// Creator: "user", +// }, space) + +// } + +func TestSpaceComponent_Show(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + + sc.mocks.stores.SpaceMock().EXPECT().FindByPath(ctx, "ns", "n").Return(&database.Space{ + ID: 1, + Repository: &database.Repository{ID: 123, Name: "n", Path: "foo/bar"}, + HasAppFile: true, + }, nil) + sc.mocks.components.repo.EXPECT().GetUserRepoPermission(ctx, "user", &database.Repository{ + ID: 123, + Name: "n", + Path: "foo/bar", + }).Return( + &types.UserRepoPermission{CanRead: true, CanAdmin: true}, nil, + ) + sc.mocks.components.repo.EXPECT().GetNameSpaceInfo(ctx, "ns").Return(&types.Namespace{Path: "ns"}, nil) + + sc.mocks.stores.DeployTaskMock().EXPECT().GetLatestDeployBySpaceID(ctx, int64(1)).Return( + &database.Deploy{}, nil, + ) + sc.mocks.deployer.EXPECT().Status(ctx, types.DeployRepo{ + Namespace: "foo", + Name: "bar", + }, true).Return("svc", 1, nil, nil) + + sc.mocks.stores.UserLikesMock().EXPECT().IsExist(ctx, "user", int64(123)).Return(true, nil) + + space, err := sc.Show(ctx, "ns", "n", "user") + require.Nil(t, err) + require.Equal(t, &types.Space{ + ID: 1, + Name: "n", + Namespace: &types.Namespace{Path: "ns"}, + UserLikes: true, + RepositoryID: 123, + Status: "Stopped", + CanManage: true, + User: &types.User{}, + Path: "foo/bar", + Repository: &types.Repository{ + HTTPCloneURL: "/s/foo/bar.git", + SSHCloneURL: ":s/foo/bar.git", + }, + Endpoint: "endpoint/svc", + SvcName: "svc", + }, space) +} + +func TestSpaceComponent_Update(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + + sc.mocks.stores.SpaceResourceMock().EXPECT().FindByID(ctx, int64(12)).Return(&database.SpaceResource{ + ID: 12, + Name: "sp", + Resources: `{"memory": "foo"}`, + }, nil) + + sc.mocks.components.repo.EXPECT().UpdateRepo(ctx, types.UpdateRepoReq{ + Username: "user", + Namespace: "ns", + Name: "n", + RepoType: types.SpaceRepo, + }).Return( + &database.Repository{ + ID: 123, + Name: "repo", + }, nil, + ) + sc.mocks.stores.SpaceMock().EXPECT().ByRepoID(ctx, int64(123)).Return(&database.Space{ + ID: 321, + }, nil) + sc.mocks.stores.SpaceMock().EXPECT().Update(ctx, database.Space{ + ID: 321, + Hardware: `{"memory": "foo"}`, + SKU: "12", + }).Return(nil) + + space, err := sc.Update(ctx, &types.UpdateSpaceReq{ + ResourceID: tea.Int64(12), + UpdateRepoReq: types.UpdateRepoReq{ + Username: "user", + Namespace: "ns", + Name: "n", + }, + }) + require.Nil(t, err) + + require.Equal(t, &types.Space{ + ID: 321, + Name: "repo", + Hardware: `{"memory": "foo"}`, + SKU: "12", + }, space) + +} + +func TestSpaceComponent_Index(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + + sc.mocks.components.repo.EXPECT().PublicToUser( + ctx, types.SpaceRepo, "user", &types.RepoFilter{Sort: "z", Username: "user"}, 10, 1, + ).Return([]*database.Repository{ + {ID: 123, Name: "r1", Tags: []database.Tag{{Name: "t1"}}}, + {ID: 124, Name: "r2", Tags: []database.Tag{{Name: "t2"}}}, + }, 100, nil) + + sc.mocks.stores.SpaceMock().EXPECT().ByRepoIDs(ctx, []int64{123, 124}).Return( + []database.Space{ + {ID: 11, RepositoryID: 123, Repository: &database.Repository{ + ID: 123, + Name: "r1", + }}, + {ID: 12, RepositoryID: 124, Repository: &database.Repository{ + ID: 124, + Name: "r2", + }}, + }, nil, + ) + + data, total, err := sc.Index(ctx, &types.RepoFilter{Sort: "z", Username: "user"}, 10, 1) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Space{ + { + RepositoryID: 123, Name: "r1", Tags: []types.RepoTag{{Name: "t1"}}, + Status: "NoAppFile", + }, + { + RepositoryID: 124, Name: "r2", Tags: []types.RepoTag{{Name: "t2"}}, + Status: "NoAppFile", + }, + }, data) + +} + +func TestSpaceComponent_OrgSpaces(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + + sc.mocks.userSvcClient.EXPECT().GetMemberRole(ctx, "ns", "user").Return(membership.RoleAdmin, nil) + sc.mocks.stores.SpaceMock().EXPECT().ByOrgPath(ctx, "ns", 10, 1, false).Return( + []database.Space{ + {ID: 1, Repository: &database.Repository{ID: 11, Name: "r1"}}, + {ID: 2, Repository: &database.Repository{ID: 12, Name: "r2"}}, + }, 100, nil, + ) + + data, total, err := sc.OrgSpaces(ctx, &types.OrgDatasetsReq{ + Namespace: "ns", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Space{ + {ID: 1, Name: "r1", RepositoryID: 11, Status: "NoAppFile"}, + {ID: 2, Name: "r2", RepositoryID: 12, Status: "NoAppFile"}, + }, data) + +} + +func TestSpaceComponent_UserSpaces(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + + sc.mocks.stores.SpaceMock().EXPECT().ByUsername(ctx, "owner", 10, 1, true).Return( + []database.Space{ + {ID: 1, RepositoryID: 11, Repository: &database.Repository{ID: 11, Name: "r1"}}, + {ID: 2, RepositoryID: 12, Repository: &database.Repository{ID: 12, Name: "r2"}}, + }, 100, nil, + ) + + data, total, err := sc.UserSpaces(ctx, &types.UserDatasetsReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Space{ + {ID: 1, Name: "r1", RepositoryID: 11, Status: "NoAppFile"}, + {ID: 2, Name: "r2", RepositoryID: 12, Status: "NoAppFile"}, + }, data) + +} + +func TestSpaceComponent_UserLikeSpaces(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + + sc.mocks.stores.SpaceMock().EXPECT().ByUserLikes(ctx, int64(111), 10, 1).Return( + []database.Space{ + {ID: 1, RepositoryID: 11, Repository: &database.Repository{ID: 11, Name: "r1"}}, + {ID: 2, RepositoryID: 12, Repository: &database.Repository{ID: 12, Name: "r2"}}, + }, 100, nil, + ) + + data, total, err := sc.UserLikesSpaces(ctx, &types.UserDatasetsReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }, 111) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Space{ + {ID: 1, Name: "r1", Status: "NoAppFile"}, + {ID: 2, Name: "r2", Status: "NoAppFile"}, + }, data) + +} + +func TestSpaceComponent_ListByPath(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + + sc.mocks.stores.SpaceMock().EXPECT().ListByPath(ctx, []string{"foo"}).Return( + []database.Space{ + {ID: 1, RepositoryID: 11, Repository: &database.Repository{ID: 11, Name: "r1"}}, + {ID: 2, RepositoryID: 12, Repository: &database.Repository{ID: 12, Name: "r2"}}, + }, nil, + ) + + data, err := sc.ListByPath(ctx, []string{"foo"}) + require.Nil(t, err) + require.Equal(t, []*types.Space{ + {Name: "r1", Status: "NoAppFile", RepositoryID: 11}, + {Name: "r2", Status: "NoAppFile", RepositoryID: 12}, + }, data) + +} + +func TestSpaceComponent_AllowCallApi(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + + sc.mocks.stores.SpaceMock().EXPECT().ByID(ctx, int64(123)).Return(&database.Space{ + Repository: &database.Repository{Path: "foo/bar", RepositoryType: types.ModelRepo}, + }, nil) + + sc.mocks.components.repo.EXPECT().AllowReadAccess(ctx, types.ModelRepo, "foo", "bar", "user").Return(true, nil) + allow, err := sc.AllowCallApi(ctx, 123, "user") + require.Nil(t, err) + require.True(t, allow) + +} + +func TestSpaceComponent_Delete(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + + sc.mocks.stores.SpaceMock().EXPECT().FindByPath(ctx, "ns", "n").Return(&database.Space{ID: 1}, nil) + sc.mocks.components.repo.EXPECT().DeleteRepo(ctx, types.DeleteRepoReq{ + Username: "user", + Namespace: "ns", + Name: "n", + RepoType: types.SpaceRepo, + }).Return(nil, nil) + sc.mocks.stores.SpaceMock().EXPECT().Delete(ctx, database.Space{ID: 1}).Return(nil) + sc.mocks.stores.DeployTaskMock().EXPECT().GetLatestDeployBySpaceID(ctx, int64(1)).Return( + &database.Deploy{ + RepoID: 2, + UserID: 3, + ID: 4, + }, nil, + ) + sc.mocks.deployer.EXPECT().Stop(ctx, types.DeployRepo{ + SpaceID: 1, + Namespace: "ns", + Name: "n", + }).Return(nil) + sc.mocks.stores.DeployTaskMock().EXPECT().StopDeploy( + ctx, types.SpaceRepo, int64(2), int64(3), int64(4), + ).Return(nil) + + err := sc.Delete(ctx, "ns", "n", "user") + time.Sleep(1 * time.Second) + require.Nil(t, err) + +} + +func TestSpaceComponent_Deploy(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + + sc.mocks.stores.SpaceMock().EXPECT().FindByPath(ctx, "ns", "n").Return(&database.Space{ + ID: 1, + Repository: &database.Repository{Path: "foo/bar"}, + }, nil) + sc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{}, nil) + sc.mocks.deployer.EXPECT().Deploy(ctx, types.DeployRepo{ + SpaceID: 1, + Path: "foo/bar", + Annotation: "{\"hub-res-name\":\"ns/n\",\"hub-res-type\":\"space\"}", + }).Return(123, nil) + + id, err := sc.Deploy(ctx, "ns", "n", "user") + require.Nil(t, err) + require.Equal(t, int64(123), id) + +} + +func TestSpaceComponent_Wakeup(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + sc.mocks.stores.SpaceMock().EXPECT().FindByPath(ctx, "ns", "n").Return(&database.Space{ + ID: 1, + }, nil) + + sc.mocks.stores.DeployTaskMock().EXPECT().GetLatestDeployBySpaceID(ctx, int64(1)).Return( + &database.Deploy{SvcName: "svc"}, nil, + ) + + sc.mocks.deployer.EXPECT().Wakeup(ctx, types.DeployRepo{ + SpaceID: 1, + Namespace: "ns", + Name: "n", + SvcName: "svc", + }).Return(nil) + + err := sc.Wakeup(ctx, "ns", "n") + require.Nil(t, err) + +} + +func TestSpaceComponent_FixHasEntryFile(t *testing.T) { + + cases := []struct { + nginx bool + name string + tp string + exist bool + }{ + {false, "app.py", "file", true}, + {false, "app.py", "foo", false}, + {false, "z.py", "file", false}, + {true, "app.py", "file", false}, + {true, "nginx.conf", "file", true}, + } + + for _, c := range cases { + t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { + + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + + sc.mocks.gitServer.EXPECT().GetRepoFileTree(ctx, gitserver.GetRepoInfoByPathReq{ + Namespace: "foo", + Name: "bar", + RepoType: types.SpaceRepo, + }).Return([]*types.File{ + {Type: c.tp, Path: c.name}, + }, nil) + sdk := "" + if c.nginx { + sdk = scheduler.NGINX.Name + } + exist := sc.HasEntryFile(ctx, &database.Space{ + Repository: &database.Repository{Path: "foo/bar"}, + Sdk: sdk, + }) + require.Equal(t, c.exist, exist) + }) + } +} + +func TestSpaceComponent_Logs(t *testing.T) { + ctx := context.TODO() + sc := initializeTestSpaceComponent(ctx, t) + sc.mocks.stores.SpaceMock().EXPECT().FindByPath(ctx, "ns", "n").Return(&database.Space{ + ID: 1, + }, nil) + + sc.mocks.deployer.EXPECT().Logs(ctx, types.DeployRepo{ + SpaceID: 1, + Namespace: "ns", + Name: "n", + }).Return(&deploy.MultiLogReader{}, nil) + + r, err := sc.Logs(ctx, "ns", "n") + + require.Nil(t, err) + require.Equal(t, &deploy.MultiLogReader{}, r) + +} diff --git a/component/tagparser/tag_processor.go b/component/tagparser/tag_processor.go index 332b9dad..fb8a191f 100644 --- a/component/tagparser/tag_processor.go +++ b/component/tagparser/tag_processor.go @@ -94,7 +94,7 @@ func (p *tagProcessor) processTags(existingCategoryTagMap map[string]map[string] Name: tagName, Category: category, Scope: p.tagScope, - BuiltIn: false, // new tag is absolutly not built-in + BuiltIn: false, // new tag is absolutely not built-in Group: "", // keep empty }) } else { diff --git a/component/tagparser/tag_processor_test.go b/component/tagparser/tag_processor_test.go index 0bc4bffe..14c7e9dc 100644 --- a/component/tagparser/tag_processor_test.go +++ b/component/tagparser/tag_processor_test.go @@ -80,7 +80,7 @@ func Test_processTags(t *testing.T) { categoryTagMap := make(map[string][]string) categoryTagMap[categoryNameTask] = append(categoryTagMap[categoryNameTask], "finance", "code", "mit") //should create an "task" tag "mit" categoryTagMap[categoryNameLicense] = append(categoryTagMap[categoryNameLicense], "mit") //should match this one - categoryTagMap["Unkown"] = append(categoryTagMap["Unknown"], "mit") //should igore this one + categoryTagMap["Unknown"] = append(categoryTagMap["Unknown"], "mit") //should igore this one tagsMatched, tagsToCreate := p.processTags(existingCategoryTagMap, categoryTagMap) if len(tagsMatched) != 3 { diff --git a/component/user.go b/component/user.go index 72e9ef6f..544af650 100644 --- a/component/user.go +++ b/component/user.go @@ -42,20 +42,20 @@ type UserComponent interface { func NewUserComponent(config *config.Config) (UserComponent, error) { c := &userComponentImpl{} - c.ms = database.NewModelStore() - c.us = database.NewUserStore() - c.ds = database.NewDatasetStore() - c.cs = database.NewCodeStore() - c.ss = database.NewSpaceStore() - c.ns = database.NewNamespaceStore() - c.cos = database.NewCollectionStore() + c.modelStore = database.NewModelStore() + c.userStore = database.NewUserStore() + c.datasetStore = database.NewDatasetStore() + c.codeStore = database.NewCodeStore() + c.spaceStore = database.NewSpaceStore() + c.namespaceStore = database.NewNamespaceStore() + c.collectionStore = database.NewCollectionStore() var err error c.spaceComponent, err = NewSpaceComponent(config) if err != nil { newError := fmt.Errorf("failed to create space component,error:%w", err) return nil, newError } - c.gs, err = git.NewGitServer(config) + c.gitServer, err = git.NewGitServer(config) if err != nil { newError := fmt.Errorf("failed to create git server,error:%w", err) return nil, newError @@ -66,41 +66,41 @@ func NewUserComponent(config *config.Config) (UserComponent, error) { return nil, newError } c.deployer = deploy.NewDeployer() - c.uls = database.NewUserLikesStore() - c.repo = database.NewRepoStore() + c.userLikeStore = database.NewUserLikesStore() + c.repoStore = database.NewRepoStore() c.deploy = database.NewDeployTaskStore() - c.ac, err = NewAccountingComponent(config) + c.accountingComponent, err = NewAccountingComponent(config) if err != nil { return nil, err } - c.pt = database.NewPromptStore() + c.promptStore = database.NewPromptStore() return c, nil } type userComponentImpl struct { - us database.UserStore - ms database.ModelStore - ds database.DatasetStore - cs database.CodeStore - ss database.SpaceStore - ns database.NamespaceStore - gs gitserver.GitServer - spaceComponent SpaceComponent - repoComponent *repoComponentImpl - deployer deploy.Deployer - uls database.UserLikesStore - repo database.RepoStore - deploy database.DeployTaskStore - cos database.CollectionStore - ac AccountingComponent + userStore database.UserStore + modelStore database.ModelStore + datasetStore database.DatasetStore + codeStore database.CodeStore + spaceStore database.SpaceStore + namespaceStore database.NamespaceStore + gitServer gitserver.GitServer + spaceComponent SpaceComponent + repoComponent RepoComponent + deployer deploy.Deployer + userLikeStore database.UserLikesStore + repoStore database.RepoStore + deploy database.DeployTaskStore + collectionStore database.CollectionStore + accountingComponent AccountingComponent // srs database.SpaceResourceStore // urs *database.UserResourcesStore - pt database.PromptStore + promptStore database.PromptStore } func (c *userComponentImpl) Datasets(ctx context.Context, req *types.UserDatasetsReq) ([]types.Dataset, int, error) { var resDatasets []types.Dataset - userExists, err := c.us.IsExist(ctx, req.Owner) + userExists, err := c.userStore.IsExist(ctx, req.Owner) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user,error:%w", err) slog.Error(newError.Error()) @@ -112,7 +112,7 @@ func (c *userComponentImpl) Datasets(ctx context.Context, req *types.UserDataset } if req.CurrentUser != "" { - cuserExists, err := c.us.IsExist(ctx, req.CurrentUser) + cuserExists, err := c.userStore.IsExist(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of current user,error:%w", err) slog.Error(newError.Error()) @@ -125,7 +125,7 @@ func (c *userComponentImpl) Datasets(ctx context.Context, req *types.UserDataset } onlyPublic := req.Owner != req.CurrentUser - ds, total, err := c.ds.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) + ds, total, err := c.datasetStore.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) if err != nil { newError := fmt.Errorf("failed to get user datasets,error:%w", err) slog.Error(newError.Error()) @@ -153,7 +153,7 @@ func (c *userComponentImpl) Datasets(ctx context.Context, req *types.UserDataset func (c *userComponentImpl) Models(ctx context.Context, req *types.UserModelsReq) ([]types.Model, int, error) { var resModels []types.Model - userExists, err := c.us.IsExist(ctx, req.Owner) + userExists, err := c.userStore.IsExist(ctx, req.Owner) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user,error:%w", err) slog.Error(newError.Error()) @@ -165,7 +165,7 @@ func (c *userComponentImpl) Models(ctx context.Context, req *types.UserModelsReq } if req.CurrentUser != "" { - cuserExists, err := c.us.IsExist(ctx, req.CurrentUser) + cuserExists, err := c.userStore.IsExist(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of current user,error:%w", err) slog.Error(newError.Error()) @@ -178,7 +178,7 @@ func (c *userComponentImpl) Models(ctx context.Context, req *types.UserModelsReq } onlyPublic := req.Owner != req.CurrentUser - ms, total, err := c.ms.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) + ms, total, err := c.modelStore.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) if err != nil { newError := fmt.Errorf("failed to get user models,error:%w", err) slog.Error(newError.Error()) @@ -206,7 +206,7 @@ func (c *userComponentImpl) Models(ctx context.Context, req *types.UserModelsReq func (c *userComponentImpl) Codes(ctx context.Context, req *types.UserModelsReq) ([]types.Code, int, error) { var resCodes []types.Code - userExists, err := c.us.IsExist(ctx, req.Owner) + userExists, err := c.userStore.IsExist(ctx, req.Owner) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user,error:%w", err) slog.Error(newError.Error()) @@ -218,7 +218,7 @@ func (c *userComponentImpl) Codes(ctx context.Context, req *types.UserModelsReq) } if req.CurrentUser != "" { - cuserExists, err := c.us.IsExist(ctx, req.CurrentUser) + cuserExists, err := c.userStore.IsExist(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of current user,error:%w", err) slog.Error(newError.Error()) @@ -231,7 +231,7 @@ func (c *userComponentImpl) Codes(ctx context.Context, req *types.UserModelsReq) } onlyPublic := req.Owner != req.CurrentUser - ms, total, err := c.cs.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) + ms, total, err := c.codeStore.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) if err != nil { newError := fmt.Errorf("failed to get user codes,error:%w", err) slog.Error(newError.Error()) @@ -258,7 +258,7 @@ func (c *userComponentImpl) Codes(ctx context.Context, req *types.UserModelsReq) } func (c *userComponentImpl) Spaces(ctx context.Context, req *types.UserSpacesReq) ([]types.Space, int, error) { - userExists, err := c.us.IsExist(ctx, req.Owner) + userExists, err := c.userStore.IsExist(ctx, req.Owner) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user,error:%w", err) slog.Error(newError.Error()) @@ -270,7 +270,7 @@ func (c *userComponentImpl) Spaces(ctx context.Context, req *types.UserSpacesReq } if req.CurrentUser != "" { - cuserExists, err := c.us.IsExist(ctx, req.CurrentUser) + cuserExists, err := c.userStore.IsExist(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of current user,error:%w", err) slog.Error(newError.Error()) @@ -286,7 +286,7 @@ func (c *userComponentImpl) Spaces(ctx context.Context, req *types.UserSpacesReq } func (c *userComponentImpl) AddLikes(ctx context.Context, req *types.UserLikesRequest) error { - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user, error:%w", err) return newError @@ -297,11 +297,11 @@ func (c *userComponentImpl) AddLikes(ctx context.Context, req *types.UserLikesRe var opts []database.SelectOption opts = append(opts, database.Columns("id", "repository_type", "path", "user_id", "private")) - likesRepos, err := c.repo.FindByIds(ctx, likesRepoIDs, opts...) + likesRepos, err := c.repoStore.FindByIds(ctx, likesRepoIDs, opts...) if err != nil { return fmt.Errorf("failed to get likes repositories by ids, error: %w", err) } - likesRepos, err = c.repoComponent.visiableToUser(ctx, likesRepos, req.CurrentUser) + likesRepos, err = c.repoComponent.VisiableToUser(ctx, likesRepos, req.CurrentUser) if err != nil { return fmt.Errorf("failed to check likes repositories visiable to user:%s, %w", req.CurrentUser, err) } @@ -310,18 +310,18 @@ func (c *userComponentImpl) AddLikes(ctx context.Context, req *types.UserLikesRe return fmt.Errorf("do not found likes repositories visiable to user:%s, %w", req.CurrentUser, err) } - err = c.uls.Add(ctx, user.ID, req.Repo_id) + err = c.userLikeStore.Add(ctx, user.ID, req.Repo_id) return err } // user likes collection func (c *userComponentImpl) LikesCollection(ctx context.Context, req *types.UserSpacesReq) ([]types.Collection, int, error) { - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user, error:%w", err) return nil, 0, newError } - collections, total, err := c.cos.ByUserLikes(ctx, user.ID, req.PageSize, req.Page) + collections, total, err := c.collectionStore.ByUserLikes(ctx, user.ID, req.PageSize, req.Page) if err != nil { newError := fmt.Errorf("failed to get collections by username,%w", err) return nil, 0, newError @@ -339,7 +339,7 @@ func (c *userComponentImpl) LikesCollection(ctx context.Context, req *types.User // UserCollections get collections of owner or visible to current user func (c *userComponentImpl) Collections(ctx context.Context, req *types.UserCollectionReq) ([]types.Collection, int, error) { - userExists, err := c.us.IsExist(ctx, req.Owner) + userExists, err := c.userStore.IsExist(ctx, req.Owner) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user,error:%w", err) slog.Error(newError.Error()) @@ -351,7 +351,7 @@ func (c *userComponentImpl) Collections(ctx context.Context, req *types.UserColl } if req.CurrentUser != "" { - cuserExists, err := c.us.IsExist(ctx, req.CurrentUser) + cuserExists, err := c.userStore.IsExist(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of current user,error:%w", err) slog.Error(newError.Error()) @@ -364,7 +364,7 @@ func (c *userComponentImpl) Collections(ctx context.Context, req *types.UserColl } onlyPublic := req.Owner != req.CurrentUser - collections, total, err := c.cos.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) + collections, total, err := c.collectionStore.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) if err != nil { newError := fmt.Errorf("failed to get collections by username,%w", err) return nil, 0, newError @@ -381,13 +381,13 @@ func (c *userComponentImpl) Collections(ctx context.Context, req *types.UserColl } func (c *userComponentImpl) LikeCollection(ctx context.Context, req *types.UserLikesRequest) error { - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user, error:%w", err) return newError } - collection, err := c.cos.FindById(ctx, req.Collection_id) + collection, err := c.collectionStore.FindById(ctx, req.Collection_id) if err != nil { return fmt.Errorf("failed to get likes collection by id, error: %w", err) } @@ -396,32 +396,32 @@ func (c *userComponentImpl) LikeCollection(ctx context.Context, req *types.UserL return fmt.Errorf("no permission to like this collection for user:%s", req.CurrentUser) } - err = c.uls.LikeCollection(ctx, user.ID, req.Collection_id) + err = c.userLikeStore.LikeCollection(ctx, user.ID, req.Collection_id) return err } func (c *userComponentImpl) UnLikeCollection(ctx context.Context, req *types.UserLikesRequest) error { - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user,error:%w", err) return newError } - err = c.uls.UnLikeCollection(ctx, user.ID, req.Collection_id) + err = c.userLikeStore.UnLikeCollection(ctx, user.ID, req.Collection_id) return err } func (c *userComponentImpl) DeleteLikes(ctx context.Context, req *types.UserLikesRequest) error { - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user,error:%w", err) return newError } - err = c.uls.Delete(ctx, user.ID, req.Repo_id) + err = c.userLikeStore.Delete(ctx, user.ID, req.Repo_id) return err } func (c *userComponentImpl) LikesSpaces(ctx context.Context, req *types.UserSpacesReq) ([]types.Space, int, error) { - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user, error:%w", err) return nil, 0, newError @@ -431,13 +431,13 @@ func (c *userComponentImpl) LikesSpaces(ctx context.Context, req *types.UserSpac func (c *userComponentImpl) LikesCodes(ctx context.Context, req *types.UserModelsReq) ([]types.Code, int, error) { var resCodes []types.Code - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user, error:%w", err) return nil, 0, newError } - ms, total, err := c.cs.UserLikesCodes(ctx, user.ID, req.PageSize, req.Page) + ms, total, err := c.codeStore.UserLikesCodes(ctx, user.ID, req.PageSize, req.Page) if err != nil { newError := fmt.Errorf("failed to get user codes,error:%w", err) return nil, 0, newError @@ -464,13 +464,13 @@ func (c *userComponentImpl) LikesCodes(ctx context.Context, req *types.UserModel func (c *userComponentImpl) LikesModels(ctx context.Context, req *types.UserModelsReq) ([]types.Model, int, error) { var resModels []types.Model - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user, error:%w", err) return nil, 0, newError } - ms, total, err := c.ms.UserLikesModels(ctx, user.ID, req.PageSize, req.Page) + ms, total, err := c.modelStore.UserLikesModels(ctx, user.ID, req.PageSize, req.Page) if err != nil { newError := fmt.Errorf("failed to get user models,error:%w", err) return nil, 0, newError @@ -497,13 +497,13 @@ func (c *userComponentImpl) LikesModels(ctx context.Context, req *types.UserMode func (c *userComponentImpl) LikesDatasets(ctx context.Context, req *types.UserDatasetsReq) ([]types.Dataset, int, error) { var resDatasets []types.Dataset - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user, error:%w", err) return nil, 0, newError } - ds, total, err := c.ds.UserLikesDatasets(ctx, user.ID, req.PageSize, req.Page) + ds, total, err := c.datasetStore.UserLikesDatasets(ctx, user.ID, req.PageSize, req.Page) if err != nil { newError := fmt.Errorf("failed to get user datasets,error:%w", err) return nil, 0, newError @@ -529,7 +529,7 @@ func (c *userComponentImpl) LikesDatasets(ctx context.Context, req *types.UserDa } func (c *userComponentImpl) ListDeploys(ctx context.Context, repoType types.RepositoryType, req *types.DeployReq) ([]types.DeployRepo, int, error) { - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user:%s, error:%w", req.CurrentUser, err) return nil, 0, newError @@ -547,7 +547,7 @@ func (c *userComponentImpl) ListDeploys(ctx context.Context, repoType types.Repo ClusterID: deploy.ClusterID, Status: deploy.Status, } - endpoint, _ := c.repoComponent.generateEndpoint(ctx, d) + endpoint, _ := c.repoComponent.GenerateEndpoint(ctx, d) repoPath := strings.TrimPrefix(deploy.GitPath, string(repoType)+"s_") var hardware types.HardWare _ = json.Unmarshal([]byte(deploy.Hardware), &hardware) @@ -558,7 +558,7 @@ func (c *userComponentImpl) ListDeploys(ctx context.Context, repoType types.Repo resourceType = hardware.Cpu.Type } tag := "" - tags, _ := c.repo.TagsWithCategory(ctx, deploy.RepoID, "task") + tags, _ := c.repoStore.TagsWithCategory(ctx, deploy.RepoID, "task") if len(tags) > 0 { tag = tags[0].Name } @@ -591,7 +591,7 @@ func (c *userComponentImpl) ListDeploys(ctx context.Context, repoType types.Repo } func (c *userComponentImpl) ListInstances(ctx context.Context, req *types.UserRepoReq) ([]types.DeployRepo, int, error) { - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user:%s, error:%w", req.CurrentUser, err) return nil, 0, newError @@ -631,12 +631,12 @@ func (c *userComponentImpl) ListInstances(ctx context.Context, req *types.UserRe } func (c *userComponentImpl) ListServerless(ctx context.Context, req types.DeployReq) ([]types.DeployRepo, int, error) { - user, err := c.us.FindByUsername(ctx, req.CurrentUser) + user, err := c.userStore.FindByUsername(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user:%s, error:%w", req.CurrentUser, err) return nil, 0, newError } - isAdmin := c.repoComponent.isAdminRole(user) + isAdmin := c.repoComponent.IsAdminRole(user) if !isAdmin { return nil, 0, fmt.Errorf("user %s does not have admin privileges", req.CurrentUser) } @@ -676,7 +676,7 @@ func (c *userComponentImpl) ListServerless(ctx context.Context, req types.Deploy } func (c *userComponentImpl) GetUserByName(ctx context.Context, userName string) (*database.User, error) { - user, err := c.us.FindByUsername(ctx, userName) + user, err := c.userStore.FindByUsername(ctx, userName) if err != nil { return nil, fmt.Errorf("failed to check for the presence of the user %s,error:%w", userName, err) } @@ -685,7 +685,7 @@ func (c *userComponentImpl) GetUserByName(ctx context.Context, userName string) func (c *userComponentImpl) Prompts(ctx context.Context, req *types.UserPromptsReq) ([]types.PromptRes, int, error) { var resPrompts []types.PromptRes - userExists, err := c.us.IsExist(ctx, req.Owner) + userExists, err := c.userStore.IsExist(ctx, req.Owner) if err != nil { newError := fmt.Errorf("failed to check for the presence of the user,error:%w", err) slog.Error(newError.Error()) @@ -697,7 +697,7 @@ func (c *userComponentImpl) Prompts(ctx context.Context, req *types.UserPromptsR } if req.CurrentUser != "" { - cuserExists, err := c.us.IsExist(ctx, req.CurrentUser) + cuserExists, err := c.userStore.IsExist(ctx, req.CurrentUser) if err != nil { newError := fmt.Errorf("failed to check for the presence of current user,error:%w", err) slog.Error(newError.Error()) @@ -710,7 +710,7 @@ func (c *userComponentImpl) Prompts(ctx context.Context, req *types.UserPromptsR } onlyPublic := req.Owner != req.CurrentUser - ds, total, err := c.pt.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) + ds, total, err := c.promptStore.ByUsername(ctx, req.Owner, req.PageSize, req.Page, onlyPublic) if err != nil { newError := fmt.Errorf("failed to get user prompts,error:%w", err) slog.Error(newError.Error()) diff --git a/component/user_test.go b/component/user_test.go new file mode 100644 index 00000000..efc2b3fb --- /dev/null +++ b/component/user_test.go @@ -0,0 +1,481 @@ +package component + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "opencsg.com/csghub-server/builder/store/database" + "opencsg.com/csghub-server/common/types" +) + +func TestUserComponent_Datasets(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "owner").Return(true, nil) + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "user").Return(true, nil) + uc.mocks.stores.DatasetMock().EXPECT().ByUsername(ctx, "owner", 10, 1, true).Return([]database.Dataset{ + {ID: 1, Repository: &database.Repository{Name: "foo"}}, + }, 100, nil) + + data, total, err := uc.Datasets(ctx, &types.UserDatasetsReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Dataset{ + {ID: 1, Name: "foo"}, + }, data) + +} + +func TestUserComponent_Models(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "owner").Return(true, nil) + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "user").Return(true, nil) + uc.mocks.stores.ModelMock().EXPECT().ByUsername(ctx, "owner", 10, 1, true).Return([]database.Model{ + {ID: 1, Repository: &database.Repository{Name: "foo"}}, + }, 100, nil) + + data, total, err := uc.Models(ctx, &types.UserDatasetsReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Model{ + {ID: 1, Name: "foo"}, + }, data) +} + +func TestUserComponent_Codes(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "owner").Return(true, nil) + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "user").Return(true, nil) + uc.mocks.stores.CodeMock().EXPECT().ByUsername(ctx, "owner", 10, 1, true).Return([]database.Code{ + {ID: 1, Repository: &database.Repository{Name: "foo"}}, + }, 100, nil) + + data, total, err := uc.Codes(ctx, &types.UserDatasetsReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Code{ + {ID: 1, Name: "foo"}, + }, data) +} + +func TestUserComponent_Spaces(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "owner").Return(true, nil) + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "user").Return(true, nil) + + uc.mocks.components.space.EXPECT().UserSpaces(ctx, &types.UserSpacesReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }}).Return([]types.Space{ + {ID: 1, Name: "foo"}, + }, 100, nil) + + data, total, err := uc.Spaces(ctx, &types.UserSpacesReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Space{ + {ID: 1, Name: "foo"}, + }, data) + +} + +func TestUserComponent_AddLikes(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) + var opts []interface{} + opts = append(opts, database.Columns("id", "repository_type", "path", "user_id", "private")) + repos := []*database.Repository{ + {ID: 1}, + } + uc.mocks.stores.RepoMock().EXPECT().FindByIds(ctx, []int64{123}, opts...).Return(repos, nil) + visiable := []*database.Repository{ + {ID: 2}, + } + uc.mocks.components.repo.EXPECT().VisiableToUser(ctx, repos, "user").Return(visiable, nil) + uc.mocks.stores.UserLikesMock().EXPECT().Add(ctx, int64(1), int64(123)).Return(nil) + + err := uc.AddLikes(ctx, &types.UserLikesRequest{ + Username: "user", + Repo_id: 123, + Collection_id: 456, + CurrentUser: "user", + }) + require.Nil(t, err) +} + +func TestUserComponent_LikesCollection(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) + uc.mocks.stores.CollectionMock().EXPECT().ByUserLikes(ctx, int64(1), 10, 1).Return([]database.Collection{ + {ID: 1, Name: "foo"}, + }, 100, nil) + data, total, err := uc.LikesCollection(ctx, &types.UserSpacesReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Collection{ + {ID: 1, Name: "foo"}, + }, data) +} + +func TestUserComponent_Collections(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "owner").Return(true, nil) + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "user").Return(true, nil) + uc.mocks.stores.CollectionMock().EXPECT().ByUsername(ctx, "owner", 10, 1, true).Return([]database.Collection{ + {ID: 1, Name: "foo"}, + }, 100, nil) + data, total, err := uc.Collections(ctx, &types.UserSpacesReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Collection{ + {ID: 1, Name: "foo"}, + }, data) +} + +func TestUserComponent_LikeCollection(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) + uc.mocks.stores.CollectionMock().EXPECT().FindById(ctx, int64(456)).Return(database.Collection{ + ID: 1, Name: "foo", + }, nil) + uc.mocks.stores.UserLikesMock().EXPECT().LikeCollection(ctx, int64(1), int64(456)).Return(nil) + err := uc.LikeCollection(ctx, &types.UserLikesRequest{ + Username: "user", + Repo_id: 123, + Collection_id: 456, + CurrentUser: "user", + }) + require.Nil(t, err) +} + +func TestUserComponent_UnLikeCollection(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) + uc.mocks.stores.UserLikesMock().EXPECT().UnLikeCollection(ctx, int64(1), int64(456)).Return(nil) + err := uc.UnLikeCollection(ctx, &types.UserLikesRequest{ + Username: "user", + Repo_id: 123, + Collection_id: 456, + CurrentUser: "user", + }) + require.Nil(t, err) +} + +func TestUserComponent_DeleteLikes(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) + uc.mocks.stores.UserLikesMock().EXPECT().Delete(ctx, int64(1), int64(123)).Return(nil) + err := uc.DeleteLikes(ctx, &types.UserLikesRequest{ + Username: "user", + Repo_id: 123, + Collection_id: 456, + CurrentUser: "user", + }) + require.Nil(t, err) +} + +func TestUserComponent_LikesSpaces(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + req := &types.UserSpacesReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + } + uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) + uc.mocks.components.space.EXPECT().UserLikesSpaces(ctx, req, int64(1)).Return([]types.Space{ + {ID: 1, Name: "foo"}, + }, 100, nil) + data, total, err := uc.LikesSpaces(ctx, req) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Space{ + {ID: 1, Name: "foo"}, + }, data) +} + +func TestUserComponent_LikesCodes(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + req := &types.UserDatasetsReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + } + uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) + uc.mocks.stores.CodeMock().EXPECT().UserLikesCodes(ctx, int64(1), 10, 1).Return([]database.Code{ + {ID: 1, Repository: &database.Repository{Name: "foo"}}, + }, 100, nil) + data, total, err := uc.LikesCodes(ctx, req) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Code{ + {ID: 1, Name: "foo"}, + }, data) +} + +func TestUserComponent_LikesModels(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + req := &types.UserDatasetsReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + } + uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) + uc.mocks.stores.ModelMock().EXPECT().UserLikesModels(ctx, int64(1), 10, 1).Return([]database.Model{ + {ID: 1, Repository: &database.Repository{Name: "foo"}}, + }, 100, nil) + data, total, err := uc.LikesModels(ctx, req) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Model{ + {ID: 1, Name: "foo"}, + }, data) +} + +func TestUserComponent_LikesDatasets(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + req := &types.UserDatasetsReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + } + uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) + uc.mocks.stores.DatasetMock().EXPECT().UserLikesDatasets(ctx, int64(1), 10, 1).Return([]database.Dataset{ + {ID: 1, Repository: &database.Repository{Name: "foo"}}, + }, 100, nil) + data, total, err := uc.LikesDatasets(ctx, req) + require.Nil(t, err) + require.Equal(t, 100, total) + require.Equal(t, []types.Dataset{ + {ID: 1, Name: "foo"}, + }, data) +} + +// func TestUserComponent_ListDeploys(t *testing.T) { +// ctx := context.TODO() +// uc := initializeTestUserComponent(ctx, t) + +// req := &types.DeployReq{ +// CurrentUser: "user", +// PageOpts: types.PageOpts{ +// Page: 1, +// PageSize: 10, +// }, +// } +// uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) +// uc.mocks.stores.DeployTaskMock().EXPECT().ListDeployByUserID(ctx, int64(1), req).Return([]database.Deploy{ +// { +// SvcName: "svc", ClusterID: "cluster", SKU: "sku", +// GitPath: "models_foo/bar", Hardware: `{"memory": "foo"}`, +// RepoID: 123, +// }, +// }, 100, nil) + +// uc.mocks.components.repo.EXPECT().GenerateEndpoint(ctx, &database.Deploy{ +// SvcName: "svc", +// ClusterID: "cluster", +// }).Return("endpoint", "foo") +// uc.mocks.stores.RepoMock().EXPECT().TagsWithCategory(ctx, int64(123), "task").Return([]database.Tag{ +// {Name: "tag1"}, +// {Name: "tag2"}, +// }, nil) + +// data, total, err := uc.ListDeploys(ctx, types.ModelRepo, req) +// require.Nil(t, err) +// require.Equal(t, 100, total) +// require.Equal(t, []types.DeployRepo{ +// { +// Path: "foo/bar", Status: "Stopped", GitPath: "models_foo/bar", Hardware: `{"memory": "foo"}`, +// RepoID: 123, SvcName: "svc", Endpoint: "endpoint", ClusterID: "cluster", +// RepoTag: "tag1", +// }, +// }, data) + +// } + +// func TestUserComponent_ListInstances(t *testing.T) { +// ctx := context.TODO() +// uc := initializeTestUserComponent(ctx, t) + +// req := &types.UserRepoReq{ +// CurrentUser: "user", +// PageOpts: types.PageOpts{ +// Page: 1, +// PageSize: 10, +// }, +// } +// uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) +// uc.mocks.stores.DeployTaskMock().EXPECT().ListInstancesByUserID(ctx, int64(1), 10, 1).Return([]database.Deploy{ +// { +// SvcName: "svc", ClusterID: "cluster", SKU: "sku", +// GitPath: "models_foo/bar", Hardware: `{"memory": "foo"}`, +// RepoID: 123, +// }, +// }, 100, nil) + +// data, total, err := uc.ListInstances(ctx, req) +// require.Nil(t, err) +// require.Equal(t, 100, total) +// require.Equal(t, []types.DeployRepo{ +// { +// Path: "foo/bar", Status: "Stopped", GitPath: "models_foo/bar", Hardware: `{"memory": "foo"}`, +// RepoID: 123, SvcName: "svc", ClusterID: "cluster", +// }, +// }, data) + +// } + +// func TestUserComponent_ListServeless(t *testing.T) { +// ctx := context.TODO() +// uc := initializeTestUserComponent(ctx, t) + +// req := &types.DeployReq{ +// CurrentUser: "user", +// PageOpts: types.PageOpts{ +// Page: 1, +// PageSize: 10, +// }, +// } +// uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return(database.User{ID: 1}, nil) +// uc.mocks.components.repo.EXPECT().IsAdminRole(database.User{ID: 1}).Return(true) +// uc.mocks.stores.DeployTaskMock().EXPECT().ListServerless(ctx, *req).Return([]database.Deploy{ +// { +// SvcName: "svc", ClusterID: "cluster", SKU: "sku", +// GitPath: "models_foo/bar", Hardware: `{"memory": "foo"}`, +// RepoID: 123, +// }, +// }, 100, nil) + +// data, total, err := uc.ListServerless(ctx, *req) +// require.Nil(t, err) +// require.Equal(t, 100, total) +// require.Equal(t, []types.DeployRepo{ +// { +// Path: "models_foo/bar", Status: "Stopped", GitPath: "models_foo/bar", Hardware: `{"memory": "foo"}`, +// RepoID: 123, SvcName: "svc", ClusterID: "cluster", SKU: "sku", +// }, +// }, data) + +// } + +func TestUserComponent_GetUserByName(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().FindByUsername(ctx, "user").Return( + database.User{ID: 1, UUID: "uuid"}, nil, + ) + user, err := uc.GetUserByName(ctx, "user") + require.Nil(t, err) + require.Equal(t, "uuid", user.UUID) +} + +func TestUserComponent_Prompts(t *testing.T) { + ctx := context.TODO() + uc := initializeTestUserComponent(ctx, t) + + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "owner").Return(true, nil) + uc.mocks.stores.UserMock().EXPECT().IsExist(ctx, "user").Return(true, nil) + uc.mocks.stores.PromptMock().EXPECT().ByUsername(ctx, "owner", 10, 1, true).Return([]database.Prompt{ + {ID: 1, Repository: &database.Repository{Name: "foo"}}, + }, 100, nil) + + data, total, err := uc.Prompts(ctx, &types.UserDatasetsReq{ + Owner: "owner", + CurrentUser: "user", + PageOpts: types.PageOpts{ + Page: 1, + PageSize: 10, + }, + }) + require.Nil(t, err) + require.Equal(t, 100, total) + + require.Equal(t, []types.PromptRes{ + {ID: 1, Name: "foo"}, + }, data) +} diff --git a/component/wire.go b/component/wire.go new file mode 100644 index 00000000..5567b131 --- /dev/null +++ b/component/wire.go @@ -0,0 +1,107 @@ +//go:build wireinject +// +build wireinject + +package component + +import ( + "context" + + "github.com/google/wire" + "github.com/stretchr/testify/mock" +) + +type testRepoWithMocks struct { + *repoComponentImpl + mocks *Mocks +} + +func initializeTestRepoComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testRepoWithMocks { + wire.Build( + MockSuperSet, RepoComponentSet, + wire.Struct(new(testRepoWithMocks), "*"), + ) + return &testRepoWithMocks{} +} + +type testPromptWithMocks struct { + *promptComponentImpl + mocks *Mocks +} + +func initializeTestPromptComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testPromptWithMocks { + wire.Build( + MockSuperSet, PromptComponentSet, + wire.Struct(new(testPromptWithMocks), "*"), + ) + return &testPromptWithMocks{} +} + +type testUserWithMocks struct { + *userComponentImpl + mocks *Mocks +} + +func initializeTestUserComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testUserWithMocks { + wire.Build( + MockSuperSet, UserComponentSet, + wire.Struct(new(testUserWithMocks), "*"), + ) + return &testUserWithMocks{} +} + +type testSpaceWithMocks struct { + *spaceComponentImpl + mocks *Mocks +} + +func initializeTestSpaceComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testSpaceWithMocks { + wire.Build( + MockSuperSet, SpaceComponentSet, + wire.Struct(new(testSpaceWithMocks), "*"), + ) + return &testSpaceWithMocks{} +} + +type testModelWithMocks struct { + *modelComponentImpl + mocks *Mocks +} + +func initializeTestModelComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testModelWithMocks { + wire.Build( + MockSuperSet, ModelComponentSet, + wire.Struct(new(testModelWithMocks), "*"), + ) + return &testModelWithMocks{} +} + +type testAccountingWithMocks struct { + *accountingComponentImpl + mocks *Mocks +} + +func initializeTestAccountingComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testAccountingWithMocks { + wire.Build( + MockSuperSet, AccountingComponentSet, + wire.Struct(new(testAccountingWithMocks), "*"), + ) + return &testAccountingWithMocks{} +} diff --git a/component/wire_gen.go b/component/wire_gen.go new file mode 100644 index 00000000..8290271a --- /dev/null +++ b/component/wire_gen.go @@ -0,0 +1,330 @@ +// Code generated by Wire. DO NOT EDIT. + +//go:generate go run -mod=mod github.com/google/wire/cmd/wire +//go:build !wireinject +// +build !wireinject + +package component + +import ( + "context" + "github.com/stretchr/testify/mock" + "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/accounting" + "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/deploy" + "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/git/gitserver" + "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/git/mirrorserver" + "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/inference" + "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/rpc" + "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/store/s3" + "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/component" + "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/mirror/queue" + "opencsg.com/csghub-server/common/tests" +) + +// Injectors from wire.go: + +func initializeTestRepoComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testRepoWithMocks { + config := ProvideTestConfig() + mockStores := tests.NewMockStores(t) + mockUserSvcClient := rpc.NewMockUserSvcClient(t) + mockGitServer := gitserver.NewMockGitServer(t) + mockTagComponent := component.NewMockTagComponent(t) + mockClient := s3.NewMockClient(t) + mockDeployer := deploy.NewMockDeployer(t) + mockAccountingComponent := component.NewMockAccountingComponent(t) + mockPriorityQueue := queue.NewMockPriorityQueue(t) + mockMirrorServer := mirrorserver.NewMockMirrorServer(t) + componentRepoComponentImpl := NewTestRepoComponent(config, mockStores, mockUserSvcClient, mockGitServer, mockTagComponent, mockClient, mockDeployer, mockAccountingComponent, mockPriorityQueue, mockMirrorServer) + mockRepoComponent := component.NewMockRepoComponent(t) + mockSpaceComponent := component.NewMockSpaceComponent(t) + mockRuntimeArchitectureComponent := component.NewMockRuntimeArchitectureComponent(t) + componentMockedComponents := &mockedComponents{ + accounting: mockAccountingComponent, + repo: mockRepoComponent, + tag: mockTagComponent, + space: mockSpaceComponent, + runtimeArchitecture: mockRuntimeArchitectureComponent, + } + inferenceMockClient := inference.NewMockClient(t) + mockAccountingClient := accounting.NewMockAccountingClient(t) + mocks := &Mocks{ + stores: mockStores, + components: componentMockedComponents, + gitServer: mockGitServer, + userSvcClient: mockUserSvcClient, + s3Client: mockClient, + mirrorServer: mockMirrorServer, + mirrorQueue: mockPriorityQueue, + deployer: mockDeployer, + inferenceClient: inferenceMockClient, + accountingClient: mockAccountingClient, + } + componentTestRepoWithMocks := &testRepoWithMocks{ + repoComponentImpl: componentRepoComponentImpl, + mocks: mocks, + } + return componentTestRepoWithMocks +} + +func initializeTestPromptComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testPromptWithMocks { + config := ProvideTestConfig() + mockStores := tests.NewMockStores(t) + mockRepoComponent := component.NewMockRepoComponent(t) + mockUserSvcClient := rpc.NewMockUserSvcClient(t) + mockGitServer := gitserver.NewMockGitServer(t) + componentPromptComponentImpl := NewTestPromptComponent(config, mockStores, mockRepoComponent, mockUserSvcClient, mockGitServer) + mockAccountingComponent := component.NewMockAccountingComponent(t) + mockTagComponent := component.NewMockTagComponent(t) + mockSpaceComponent := component.NewMockSpaceComponent(t) + mockRuntimeArchitectureComponent := component.NewMockRuntimeArchitectureComponent(t) + componentMockedComponents := &mockedComponents{ + accounting: mockAccountingComponent, + repo: mockRepoComponent, + tag: mockTagComponent, + space: mockSpaceComponent, + runtimeArchitecture: mockRuntimeArchitectureComponent, + } + mockClient := s3.NewMockClient(t) + mockMirrorServer := mirrorserver.NewMockMirrorServer(t) + mockPriorityQueue := queue.NewMockPriorityQueue(t) + mockDeployer := deploy.NewMockDeployer(t) + inferenceMockClient := inference.NewMockClient(t) + mockAccountingClient := accounting.NewMockAccountingClient(t) + mocks := &Mocks{ + stores: mockStores, + components: componentMockedComponents, + gitServer: mockGitServer, + userSvcClient: mockUserSvcClient, + s3Client: mockClient, + mirrorServer: mockMirrorServer, + mirrorQueue: mockPriorityQueue, + deployer: mockDeployer, + inferenceClient: inferenceMockClient, + accountingClient: mockAccountingClient, + } + componentTestPromptWithMocks := &testPromptWithMocks{ + promptComponentImpl: componentPromptComponentImpl, + mocks: mocks, + } + return componentTestPromptWithMocks +} + +func initializeTestUserComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testUserWithMocks { + mockStores := tests.NewMockStores(t) + mockGitServer := gitserver.NewMockGitServer(t) + mockSpaceComponent := component.NewMockSpaceComponent(t) + mockRepoComponent := component.NewMockRepoComponent(t) + mockDeployer := deploy.NewMockDeployer(t) + mockAccountingComponent := component.NewMockAccountingComponent(t) + componentUserComponentImpl := NewTestUserComponent(mockStores, mockGitServer, mockSpaceComponent, mockRepoComponent, mockDeployer, mockAccountingComponent) + mockTagComponent := component.NewMockTagComponent(t) + mockRuntimeArchitectureComponent := component.NewMockRuntimeArchitectureComponent(t) + componentMockedComponents := &mockedComponents{ + accounting: mockAccountingComponent, + repo: mockRepoComponent, + tag: mockTagComponent, + space: mockSpaceComponent, + runtimeArchitecture: mockRuntimeArchitectureComponent, + } + mockUserSvcClient := rpc.NewMockUserSvcClient(t) + mockClient := s3.NewMockClient(t) + mockMirrorServer := mirrorserver.NewMockMirrorServer(t) + mockPriorityQueue := queue.NewMockPriorityQueue(t) + inferenceMockClient := inference.NewMockClient(t) + mockAccountingClient := accounting.NewMockAccountingClient(t) + mocks := &Mocks{ + stores: mockStores, + components: componentMockedComponents, + gitServer: mockGitServer, + userSvcClient: mockUserSvcClient, + s3Client: mockClient, + mirrorServer: mockMirrorServer, + mirrorQueue: mockPriorityQueue, + deployer: mockDeployer, + inferenceClient: inferenceMockClient, + accountingClient: mockAccountingClient, + } + componentTestUserWithMocks := &testUserWithMocks{ + userComponentImpl: componentUserComponentImpl, + mocks: mocks, + } + return componentTestUserWithMocks +} + +func initializeTestSpaceComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testSpaceWithMocks { + mockStores := tests.NewMockStores(t) + mockRepoComponent := component.NewMockRepoComponent(t) + mockGitServer := gitserver.NewMockGitServer(t) + mockDeployer := deploy.NewMockDeployer(t) + mockAccountingComponent := component.NewMockAccountingComponent(t) + config := ProvideTestConfig() + mockUserSvcClient := rpc.NewMockUserSvcClient(t) + componentSpaceComponentImpl := NewTestSpaceComponent(mockStores, mockRepoComponent, mockGitServer, mockDeployer, mockAccountingComponent, config, mockUserSvcClient) + mockTagComponent := component.NewMockTagComponent(t) + mockSpaceComponent := component.NewMockSpaceComponent(t) + mockRuntimeArchitectureComponent := component.NewMockRuntimeArchitectureComponent(t) + componentMockedComponents := &mockedComponents{ + accounting: mockAccountingComponent, + repo: mockRepoComponent, + tag: mockTagComponent, + space: mockSpaceComponent, + runtimeArchitecture: mockRuntimeArchitectureComponent, + } + mockClient := s3.NewMockClient(t) + mockMirrorServer := mirrorserver.NewMockMirrorServer(t) + mockPriorityQueue := queue.NewMockPriorityQueue(t) + inferenceMockClient := inference.NewMockClient(t) + mockAccountingClient := accounting.NewMockAccountingClient(t) + mocks := &Mocks{ + stores: mockStores, + components: componentMockedComponents, + gitServer: mockGitServer, + userSvcClient: mockUserSvcClient, + s3Client: mockClient, + mirrorServer: mockMirrorServer, + mirrorQueue: mockPriorityQueue, + deployer: mockDeployer, + inferenceClient: inferenceMockClient, + accountingClient: mockAccountingClient, + } + componentTestSpaceWithMocks := &testSpaceWithMocks{ + spaceComponentImpl: componentSpaceComponentImpl, + mocks: mocks, + } + return componentTestSpaceWithMocks +} + +func initializeTestModelComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testModelWithMocks { + config := ProvideTestConfig() + mockStores := tests.NewMockStores(t) + mockRepoComponent := component.NewMockRepoComponent(t) + mockSpaceComponent := component.NewMockSpaceComponent(t) + mockClient := inference.NewMockClient(t) + mockDeployer := deploy.NewMockDeployer(t) + mockAccountingComponent := component.NewMockAccountingComponent(t) + mockRuntimeArchitectureComponent := component.NewMockRuntimeArchitectureComponent(t) + mockGitServer := gitserver.NewMockGitServer(t) + mockUserSvcClient := rpc.NewMockUserSvcClient(t) + componentModelComponentImpl := NewTestModelComponent(config, mockStores, mockRepoComponent, mockSpaceComponent, mockClient, mockDeployer, mockAccountingComponent, mockRuntimeArchitectureComponent, mockGitServer, mockUserSvcClient) + mockTagComponent := component.NewMockTagComponent(t) + componentMockedComponents := &mockedComponents{ + accounting: mockAccountingComponent, + repo: mockRepoComponent, + tag: mockTagComponent, + space: mockSpaceComponent, + runtimeArchitecture: mockRuntimeArchitectureComponent, + } + s3MockClient := s3.NewMockClient(t) + mockMirrorServer := mirrorserver.NewMockMirrorServer(t) + mockPriorityQueue := queue.NewMockPriorityQueue(t) + mockAccountingClient := accounting.NewMockAccountingClient(t) + mocks := &Mocks{ + stores: mockStores, + components: componentMockedComponents, + gitServer: mockGitServer, + userSvcClient: mockUserSvcClient, + s3Client: s3MockClient, + mirrorServer: mockMirrorServer, + mirrorQueue: mockPriorityQueue, + deployer: mockDeployer, + inferenceClient: mockClient, + accountingClient: mockAccountingClient, + } + componentTestModelWithMocks := &testModelWithMocks{ + modelComponentImpl: componentModelComponentImpl, + mocks: mocks, + } + return componentTestModelWithMocks +} + +func initializeTestAccountingComponent(ctx context.Context, t interface { + Cleanup(func()) + mock.TestingT +}) *testAccountingWithMocks { + mockStores := tests.NewMockStores(t) + mockAccountingClient := accounting.NewMockAccountingClient(t) + componentAccountingComponentImpl := NewTestAccountingComponent(mockStores, mockAccountingClient) + mockAccountingComponent := component.NewMockAccountingComponent(t) + mockRepoComponent := component.NewMockRepoComponent(t) + mockTagComponent := component.NewMockTagComponent(t) + mockSpaceComponent := component.NewMockSpaceComponent(t) + mockRuntimeArchitectureComponent := component.NewMockRuntimeArchitectureComponent(t) + componentMockedComponents := &mockedComponents{ + accounting: mockAccountingComponent, + repo: mockRepoComponent, + tag: mockTagComponent, + space: mockSpaceComponent, + runtimeArchitecture: mockRuntimeArchitectureComponent, + } + mockGitServer := gitserver.NewMockGitServer(t) + mockUserSvcClient := rpc.NewMockUserSvcClient(t) + mockClient := s3.NewMockClient(t) + mockMirrorServer := mirrorserver.NewMockMirrorServer(t) + mockPriorityQueue := queue.NewMockPriorityQueue(t) + mockDeployer := deploy.NewMockDeployer(t) + inferenceMockClient := inference.NewMockClient(t) + mocks := &Mocks{ + stores: mockStores, + components: componentMockedComponents, + gitServer: mockGitServer, + userSvcClient: mockUserSvcClient, + s3Client: mockClient, + mirrorServer: mockMirrorServer, + mirrorQueue: mockPriorityQueue, + deployer: mockDeployer, + inferenceClient: inferenceMockClient, + accountingClient: mockAccountingClient, + } + componentTestAccountingWithMocks := &testAccountingWithMocks{ + accountingComponentImpl: componentAccountingComponentImpl, + mocks: mocks, + } + return componentTestAccountingWithMocks +} + +// wire.go: + +type testRepoWithMocks struct { + *repoComponentImpl + mocks *Mocks +} + +type testPromptWithMocks struct { + *promptComponentImpl + mocks *Mocks +} + +type testUserWithMocks struct { + *userComponentImpl + mocks *Mocks +} + +type testSpaceWithMocks struct { + *spaceComponentImpl + mocks *Mocks +} + +type testModelWithMocks struct { + *modelComponentImpl + mocks *Mocks +} + +type testAccountingWithMocks struct { + *accountingComponentImpl + mocks *Mocks +} diff --git a/component/wireset.go b/component/wireset.go new file mode 100644 index 00000000..06f01a7d --- /dev/null +++ b/component/wireset.go @@ -0,0 +1,278 @@ +package component + +import ( + "github.com/google/wire" + mock_accounting "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/accounting" + mock_deploy "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/deploy" + mock_git "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/git/gitserver" + mock_mirror "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/git/mirrorserver" + mock_inference "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/inference" + mock_rpc "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/rpc" + mock_s3 "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/builder/store/s3" + mock_component "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/component" + mock_mirror_queue "opencsg.com/csghub-server/_mocks/opencsg.com/csghub-server/mirror/queue" + "opencsg.com/csghub-server/builder/accounting" + "opencsg.com/csghub-server/builder/deploy" + "opencsg.com/csghub-server/builder/git/gitserver" + "opencsg.com/csghub-server/builder/git/mirrorserver" + "opencsg.com/csghub-server/builder/inference" + "opencsg.com/csghub-server/builder/llm" + "opencsg.com/csghub-server/builder/rpc" + "opencsg.com/csghub-server/builder/store/s3" + "opencsg.com/csghub-server/common/config" + "opencsg.com/csghub-server/common/tests" + "opencsg.com/csghub-server/mirror/queue" +) + +type mockedComponents struct { + accounting *mock_component.MockAccountingComponent + repo *mock_component.MockRepoComponent + tag *mock_component.MockTagComponent + space *mock_component.MockSpaceComponent + runtimeArchitecture *mock_component.MockRuntimeArchitectureComponent +} + +var MockedStoreSet = wire.NewSet( + tests.NewMockStores, +) + +var MockedComponentSet = wire.NewSet( + mock_component.NewMockAccountingComponent, + wire.Bind(new(AccountingComponent), new(*mock_component.MockAccountingComponent)), + mock_component.NewMockRepoComponent, + wire.Bind(new(RepoComponent), new(*mock_component.MockRepoComponent)), + mock_component.NewMockTagComponent, + wire.Bind(new(TagComponent), new(*mock_component.MockTagComponent)), + mock_component.NewMockSpaceComponent, + wire.Bind(new(SpaceComponent), new(*mock_component.MockSpaceComponent)), + mock_component.NewMockRuntimeArchitectureComponent, + wire.Bind(new(RuntimeArchitectureComponent), new(*mock_component.MockRuntimeArchitectureComponent)), +) + +var MockedGitServerSet = wire.NewSet( + mock_git.NewMockGitServer, + wire.Bind(new(gitserver.GitServer), new(*mock_git.MockGitServer)), +) + +var MockedUserSvcSet = wire.NewSet( + mock_rpc.NewMockUserSvcClient, + wire.Bind(new(rpc.UserSvcClient), new(*mock_rpc.MockUserSvcClient)), +) + +var MockedS3Set = wire.NewSet( + mock_s3.NewMockClient, + wire.Bind(new(s3.Client), new(*mock_s3.MockClient)), +) + +var MockedDeployerSet = wire.NewSet( + mock_deploy.NewMockDeployer, + wire.Bind(new(deploy.Deployer), new(*mock_deploy.MockDeployer)), +) + +var MockedMirrorServerSet = wire.NewSet( + mock_mirror.NewMockMirrorServer, + wire.Bind(new(mirrorserver.MirrorServer), new(*mock_mirror.MockMirrorServer)), +) + +var MockedMirrorQueueSet = wire.NewSet( + mock_mirror_queue.NewMockPriorityQueue, + wire.Bind(new(queue.PriorityQueue), new(*mock_mirror_queue.MockPriorityQueue)), +) + +var MockedInferenceClientSet = wire.NewSet( + mock_inference.NewMockClient, + wire.Bind(new(inference.Client), new(*mock_inference.MockClient)), +) + +var MockedAccountingClientSet = wire.NewSet( + mock_accounting.NewMockAccountingClient, + wire.Bind(new(accounting.AccountingClient), new(*mock_accounting.MockAccountingClient)), +) + +type Mocks struct { + stores *tests.MockStores + components *mockedComponents + gitServer *mock_git.MockGitServer + userSvcClient *mock_rpc.MockUserSvcClient + s3Client *mock_s3.MockClient + mirrorServer *mock_mirror.MockMirrorServer + mirrorQueue *mock_mirror_queue.MockPriorityQueue + deployer *mock_deploy.MockDeployer + inferenceClient *mock_inference.MockClient + accountingClient *mock_accounting.MockAccountingClient +} + +var AllMockSet = wire.NewSet( + wire.Struct(new(mockedComponents), "*"), + wire.Struct(new(Mocks), "*"), +) + +func ProvideTestConfig() *config.Config { + return &config.Config{} +} + +var MockSuperSet = wire.NewSet( + MockedComponentSet, AllMockSet, MockedStoreSet, MockedGitServerSet, MockedUserSvcSet, + MockedS3Set, MockedDeployerSet, ProvideTestConfig, MockedMirrorServerSet, + MockedMirrorQueueSet, MockedInferenceClientSet, MockedAccountingClientSet, +) + +func NewTestRepoComponent(config *config.Config, stores *tests.MockStores, rpcUser rpc.UserSvcClient, gitServer gitserver.GitServer, tagComponent TagComponent, s3Client s3.Client, deployer deploy.Deployer, accountingComponent AccountingComponent, mq queue.PriorityQueue, mirrorServer mirrorserver.MirrorServer) *repoComponentImpl { + return &repoComponentImpl{ + userStore: stores.User, + repoStore: stores.Repo, + repoRelationsStore: stores.RepoRelation, + namespaceStore: stores.Namespace, + userSvcClient: rpcUser, + config: config, + git: gitServer, + tagComponent: tagComponent, + s3Client: s3Client, + lfsMetaObjectStore: stores.LfsMetaObject, + mirrorStore: stores.Mirror, + mirrorSourceStore: stores.MirrorSource, + tokenStore: stores.AccessToken, + syncVersionStore: stores.SyncVersion, + syncClientSettingStore: stores.SyncClientSetting, + runtimeFrameworksStore: stores.RuntimeFramework, + deployTaskStore: stores.DeployTask, + deployer: deployer, + accountingComponent: accountingComponent, + spaceResourceStore: stores.SpaceResource, + mq: mq, + mirrorServer: mirrorServer, + } +} + +var RepoComponentSet = wire.NewSet(NewTestRepoComponent) + +func NewTestPromptComponent(config *config.Config, stores *tests.MockStores, repoComponent RepoComponent, rpcUser rpc.UserSvcClient, gitServer gitserver.GitServer) *promptComponentImpl { + config.APIServer.PublicDomain = "https://foo.com" + config.APIServer.SSHDomain = "ssh://test@127.0.0.1" + return &promptComponentImpl{ + userStore: stores.User, + userLikeStore: stores.UserLikes, + promptConvStore: stores.PromptConversation, + promptPrefixStore: stores.PromptPrefix, + llmConfigStore: stores.LLMConfig, + promptStore: stores.Prompt, + namespaceStore: stores.Namespace, + userSvcClient: rpcUser, + gitServer: gitServer, + repoStore: stores.Repo, + llmClient: llm.NewClient(), + config: config, + repoComponent: repoComponent, + } +} + +var PromptComponentSet = wire.NewSet(NewTestPromptComponent) + +func NewTestUserComponent( + stores *tests.MockStores, + gitServer gitserver.GitServer, + spaceComponent SpaceComponent, + repoComponent RepoComponent, + deployer deploy.Deployer, + accountingComponent AccountingComponent, +) *userComponentImpl { + return &userComponentImpl{ + userStore: stores.User, + modelStore: stores.Model, + datasetStore: stores.Dataset, + codeStore: stores.Code, + spaceStore: stores.Space, + namespaceStore: stores.Namespace, + gitServer: gitServer, + spaceComponent: spaceComponent, + repoComponent: repoComponent, + deployer: deployer, + userLikeStore: stores.UserLikes, + repoStore: stores.Repo, + collectionStore: stores.Collection, + accountingComponent: accountingComponent, + promptStore: stores.Prompt, + } +} + +var UserComponentSet = wire.NewSet(NewTestUserComponent) + +func NewTestSpaceComponent( + stores *tests.MockStores, + repoComponent RepoComponent, + git gitserver.GitServer, + deployer deploy.Deployer, + accountingComponent AccountingComponent, + config *config.Config, + userSvcClient rpc.UserSvcClient, +) *spaceComponentImpl { + return &spaceComponentImpl{ + repoComponent: repoComponent, + git: git, + spaceStore: stores.Space, + spaceSdkStore: stores.SpaceSdk, + spaceResourceStore: stores.SpaceResource, + repoStore: stores.Repo, + userStore: stores.User, + deployer: deployer, + publicRootDomain: config.Space.PublicRootDomain, + accountingComponent: accountingComponent, + serverBaseUrl: config.APIServer.PublicDomain, + userLikesStore: stores.UserLikes, + config: config, + userSvcClient: userSvcClient, + deployTaskStore: stores.DeployTask, + } +} + +var SpaceComponentSet = wire.NewSet(NewTestSpaceComponent) + +func NewTestModelComponent( + config *config.Config, + stores *tests.MockStores, + repoComponent RepoComponent, + spaceComponent SpaceComponent, + inferClient inference.Client, + deployer deploy.Deployer, + accountingComponent AccountingComponent, + runtimeArchComponent RuntimeArchitectureComponent, + gitServer gitserver.GitServer, + userSvcClient rpc.UserSvcClient, +) *modelComponentImpl { + config.APIServer.PublicDomain = "https://foo.com" + config.APIServer.SSHDomain = "ssh://test@127.0.0.1" + return &modelComponentImpl{ + config: config, + repoComponent: repoComponent, + spaceComponent: spaceComponent, + modelStore: stores.Model, + repoStore: stores.Repo, + spaceResourceStore: stores.SpaceResource, + inferClient: inferClient, + userStore: stores.User, + deployer: deployer, + accountingComponent: accountingComponent, + tagStore: stores.Tag, + runtimeArchComponent: runtimeArchComponent, + datasetStore: stores.Dataset, + recomStore: stores.Recom, + gitServer: gitServer, + userLikesStore: stores.UserLikes, + repoRuntimeFrameworkStore: stores.RepoRuntimeFramework, + deployTaskStore: stores.DeployTask, + runtimeFrameworksStore: stores.RuntimeFramework, + userSvcClient: userSvcClient, + } +} + +var ModelComponentSet = wire.NewSet(NewTestModelComponent) + +func NewTestAccountingComponent(stores *tests.MockStores, accountingClient accounting.AccountingClient) *accountingComponentImpl { + return &accountingComponentImpl{ + acctountingClient: accountingClient, + userStore: stores.User, + deployTaskStore: stores.DeployTask, + } +} + +var AccountingComponentSet = wire.NewSet(NewTestAccountingComponent) diff --git a/go.mod b/go.mod index 99c2b6f4..984d225f 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/gin-gonic/gin v1.9.1 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f + github.com/google/wire v0.6.0 github.com/jarcoal/httpmock v1.3.1 github.com/marcboeker/go-duckdb v1.5.6 github.com/minio/minio-go/v7 v7.0.66 diff --git a/go.sum b/go.sum index f6ae059f..db898931 100644 --- a/go.sum +++ b/go.sum @@ -303,10 +303,13 @@ github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af h1:kmjWCqn2qkEml422C2 github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo= github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/wire v0.6.0 h1:HBkoIh4BdSxoyo9PveV8giw7ZsaBOvzWKfcg/6MrVwI= +github.com/google/wire v0.6.0/go.mod h1:F4QhpQ9EDIdJ1Mbop/NZBRB+5yrR6qg3BnctaoUk6NA= github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs= github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= @@ -701,7 +704,9 @@ golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -728,6 +733,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -753,7 +760,9 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/oauth2 v0.0.0-20170912212905-13449ad91cb2/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -771,6 +780,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -809,8 +820,10 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -818,7 +831,9 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -830,6 +845,7 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20170424234030-8be79e1e0910/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -855,6 +871,8 @@ golang.org/x/tools v0.0.0-20210112230658-8b4aab62c064/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/mirror/lfssyncer/minio.go b/mirror/lfssyncer/minio.go index 8894e113..b689daca 100644 --- a/mirror/lfssyncer/minio.go +++ b/mirror/lfssyncer/minio.go @@ -22,12 +22,12 @@ import ( ) type MinioLFSSyncWorker struct { - mq *queue.PriorityQueue + mq queue.PriorityQueue tasks chan queue.MirrorTask wg sync.WaitGroup mirrorStore database.MirrorStore lfsMetaObjectStore database.LfsMetaObjectStore - s3Client *s3.Client + s3Client s3.Client config *config.Config repoStore database.RepoStore numWorkers int @@ -269,7 +269,7 @@ func (w *MinioLFSSyncWorker) DownloadAndUploadLFSFile(ctx context.Context, mirro req, err := http.NewRequest("GET", pointer.DownloadURL, nil) if err != nil { - return fmt.Errorf("failed to create downlaod request: %w", err) + return fmt.Errorf("failed to create download request: %w", err) } parsedURL, err := url.Parse(pointer.DownloadURL) diff --git a/mirror/prioriy_queue.go b/mirror/prioriy_queue.go index 9c94a328..e25f1b2c 100644 --- a/mirror/prioriy_queue.go +++ b/mirror/prioriy_queue.go @@ -12,7 +12,7 @@ import ( ) type MirrorPriorityQueue struct { - mq *queue.PriorityQueue + mq queue.PriorityQueue tasks chan queue.MirrorTask numWorkers int } diff --git a/mirror/queue/queue.go b/mirror/queue/queue.go index 97a6dcc6..dc2b80cf 100644 --- a/mirror/queue/queue.go +++ b/mirror/queue/queue.go @@ -74,19 +74,26 @@ func (mq *MirrorQueue) Pop() *MirrorTask { return &task } -type PriorityQueue struct { +type PriorityQueue interface { + PushRepoMirror(mt *MirrorTask) + PopRepoMirror() *MirrorTask + PushLfsMirror(mt *MirrorTask) + PopLfsMirror() *MirrorTask +} + +type priorityQueueImpl struct { RepoMirrorQueue MirrorQueue LfsMirrorQueue MirrorQueue } var ( - instance *PriorityQueue + instance PriorityQueue once sync.Once err error c *config.Config ) -func NewPriorityQueue(ctx context.Context, config *config.Config) (*PriorityQueue, error) { +func NewPriorityQueue(ctx context.Context, config *config.Config) (PriorityQueue, error) { redis, err := cache.NewCache(ctx, cache.RedisConfig{ Addr: config.Redis.Endpoint, Username: config.Redis.User, @@ -95,7 +102,7 @@ func NewPriorityQueue(ctx context.Context, config *config.Config) (*PriorityQueu if err != nil { return nil, fmt.Errorf("initializing redis: %w", err) } - mq := &PriorityQueue{ + mq := &priorityQueueImpl{ RepoMirrorQueue: MirrorQueue{ redis: redis, QueueName: repoQueueName, @@ -108,23 +115,23 @@ func NewPriorityQueue(ctx context.Context, config *config.Config) (*PriorityQueu return mq, nil } -func (pq *PriorityQueue) PushRepoMirror(mt *MirrorTask) { +func (pq *priorityQueueImpl) PushRepoMirror(mt *MirrorTask) { pq.RepoMirrorQueue.Push(mt) } -func (pq *PriorityQueue) PopRepoMirror() *MirrorTask { +func (pq *priorityQueueImpl) PopRepoMirror() *MirrorTask { return pq.RepoMirrorQueue.Pop() } -func (pq *PriorityQueue) PushLfsMirror(mt *MirrorTask) { +func (pq *priorityQueueImpl) PushLfsMirror(mt *MirrorTask) { pq.LfsMirrorQueue.Push(mt) } -func (pq *PriorityQueue) PopLfsMirror() *MirrorTask { +func (pq *priorityQueueImpl) PopLfsMirror() *MirrorTask { return pq.LfsMirrorQueue.Pop() } -func GetPriorityQueueInstance() (*PriorityQueue, error) { +func GetPriorityQueueInstance() (PriorityQueue, error) { once.Do(func() { c, err = config.LoadConfig() instance, err = NewPriorityQueue(context.Background(), c) diff --git a/mirror/reposyncer/local_woker.go b/mirror/reposyncer/local_woker.go index 3e7e54d4..530630b6 100644 --- a/mirror/reposyncer/local_woker.go +++ b/mirror/reposyncer/local_woker.go @@ -21,7 +21,7 @@ import ( ) type LocalMirrorWoker struct { - mq *queue.PriorityQueue + mq queue.PriorityQueue tasks chan queue.MirrorTask numWorkers int wg sync.WaitGroup diff --git a/servicerunner/handler/k8s.go b/servicerunner/handler/k8s.go index 2ac760a3..15f08164 100644 --- a/servicerunner/handler/k8s.go +++ b/servicerunner/handler/k8s.go @@ -356,7 +356,7 @@ func (s *K8sHander) ServiceStatus(c *gin.Context) { resp.DeployID = deployID resp.UserID = srv.Annotations["user_id"] - // retrive pod list and status + // retrieve pod list and status if request.NeedDetails { instList, err := s.s.GetServicePodsWithStatus(c.Request.Context(), *cluster, srvName, s.k8sNameSpace) if err != nil { @@ -392,7 +392,7 @@ func (s *K8sHander) ServiceStatus(c *gin.Context) { podNames, err := s.GetServicePods(c.Request.Context(), *cluster, srvName, s.k8sNameSpace, 1) if err != nil { slog.Error("get image status failed, can not get pods info", slog.String("srv_name", srvName), slog.Any("error", err)) - c.JSON(http.StatusInternalServerError, gin.H{"code": 0, "message": "unkown service status, failed to get pods"}) + c.JSON(http.StatusInternalServerError, gin.H{"code": 0, "message": "unknown service status, failed to get pods"}) return } if len(podNames) == 0 { diff --git a/user/component/member.go b/user/component/member.go index 94ab410a..1a6b7be8 100644 --- a/user/component/member.go +++ b/user/component/member.go @@ -156,7 +156,7 @@ func (c *memberComponentImpl) GetMemberRole(ctx context.Context, orgName, userNa } m, err := c.memberStore.Find(ctx, org.ID, user.ID) if err != nil && !errors.Is(err, sql.ErrNoRows) { - return membership.RoleUnknown, fmt.Errorf("failed to check memberhsip existance,caused by:%w", err) + return membership.RoleUnknown, fmt.Errorf("failed to check memberhsip existence,caused by:%w", err) } if m == nil { return membership.RoleUnknown, nil @@ -194,7 +194,7 @@ func (c *memberComponentImpl) AddMembers(ctx context.Context, orgName string, us } m, err := c.memberStore.Find(ctx, org.ID, user.ID) if err != nil && !errors.Is(err, sql.ErrNoRows) { - return fmt.Errorf("failed to check memberhsip existance, user:%s,caused by:%w", userName, err) + return fmt.Errorf("failed to check memberhsip existence, user:%s,caused by:%w", userName, err) } //skip existing member if m != nil { @@ -252,7 +252,7 @@ func (c *memberComponentImpl) Delete(ctx context.Context, orgName, userName, ope } m, err := c.memberStore.Find(ctx, org.ID, user.ID) if err != nil && !errors.Is(err, sql.ErrNoRows) { - return fmt.Errorf("failed to check memberhsip existance,caused by:%w", err) + return fmt.Errorf("failed to check memberhsip existence,caused by:%w", err) } //skip if not a member if m == nil { diff --git a/user/component/user.go b/user/component/user.go index 0d1bfa28..91a4b360 100644 --- a/user/component/user.go +++ b/user/component/user.go @@ -280,7 +280,7 @@ func (c *userComponentImpl) Update(ctx context.Context, req *types.UpdateUserReq return nil } -// user registery with wechat does not have email, so git user is not created after signin +// user registry with wechat does not have email, so git user is not created after signin // when user set email, a git user needs to be created func (c *userComponentImpl) upsertGitUser(username string, nickname *string, oldEmail, newEmail string) error { var err error @@ -621,7 +621,7 @@ func (c *userComponentImpl) Signin(ctx context.Context, code, state string) (*ty cu := claims.User exists, err := c.us.IsExistByUUID(ctx, cu.Id) if err != nil { - return nil, "", fmt.Errorf("failed to check user existance by name in db,error:%w", err) + return nil, "", fmt.Errorf("failed to check user existence by name in db,error:%w", err) } var dbu *database.User From de0d3aa3507f6253de233d3994844acded82f4ec Mon Sep 17 00:00:00 2001 From: yiling Date: Thu, 5 Dec 2024 16:36:08 +0800 Subject: [PATCH 2/2] remove debug print --- component/model.go | 1 - 1 file changed, 1 deletion(-) diff --git a/component/model.go b/component/model.go index f62bf97e..937fa64d 100644 --- a/component/model.go +++ b/component/model.go @@ -782,7 +782,6 @@ func (c *modelComponentImpl) DelRelationDataset(ctx context.Context, req types.R readmeReq.Email = user.Email readmeReq.Content = base64.StdEncoding.EncodeToString([]byte(output)) - fmt.Println("===== zzzzz") err = c.gitServer.UpdateRepoFile(&readmeReq) if err != nil { return fmt.Errorf("failed to delete dataset tag to %s file, cause: %w", readmeReq.FilePath, err)