3022 lines
144 KiB
Diff
3022 lines
144 KiB
Diff
From 6de0c825b7d8dd2d7b1c53524f6ecebcef22bc75 Mon Sep 17 00:00:00 2001
|
|
From: liuxu <liuxu156@huawei.com>
|
|
Date: Fri, 22 Nov 2024 14:11:42 +0800
|
|
Subject: [PATCH 156/156] sandbox: sandbox api adapt rust interface UT
|
|
|
|
Signed-off-by: liuxu <liuxu156@huawei.com>
|
|
---
|
|
test/cutils/utils_transform/CMakeLists.txt | 1 -
|
|
test/mocks/controller_stub_mock.cc | 314 ----------------
|
|
test/mocks/controller_stub_mock.h | 239 ------------
|
|
test/mocks/grpc_async_wait_call_mock.cc | 92 -----
|
|
test/mocks/grpc_async_wait_call_mock.h | 37 --
|
|
test/mocks/grpc_sandboxer_client_mock.cc | 44 +--
|
|
test/mocks/grpc_sandboxer_client_mock.h | 11 +-
|
|
test/mocks/grpc_sandboxer_monitor_mock.cc | 51 ---
|
|
test/mocks/rust_sandbox_api_mock.cc | 103 ++++++
|
|
test/mocks/rust_sandbox_api_mock.h | 39 ++
|
|
test/mocks/sandbox_manager_mock.cc | 42 +++
|
|
..._monitor_mock.h => sandbox_manager_mock.h} | 35 +-
|
|
test/mocks/sandboxer_controller_mock.cc | 116 ++++++
|
|
test/mocks/sandboxer_controller_mock.h | 52 +++
|
|
test/mocks/sandboxer_sandbox_mock.cc | 72 ++++
|
|
test/mocks/sandboxer_sandbox_mock.h | 43 +++
|
|
test/mocks/shim_controller_mock.cc | 36 +-
|
|
test/mocks/shim_controller_mock.h | 11 +-
|
|
test/mocks/shim_sandbox_mock.cc | 72 ++++
|
|
test/mocks/shim_sandbox_mock.h | 43 +++
|
|
test/sandbox/controller/CMakeLists.txt | 2 -
|
|
test/sandbox/controller/controller_common.cc | 51 ++-
|
|
test/sandbox/controller/controller_common.h | 9 +-
|
|
.../sandbox/controller/manager/CMakeLists.txt | 15 +-
|
|
.../controller/sandboxer/CMakeLists.txt | 1 -
|
|
.../sandboxer/async_wait_call/CMakeLists.txt | 37 --
|
|
.../async_wait_call/async_wait_call_ut.cc | 115 ------
|
|
.../async_wait_call/dummy_monitor_utils.h | 121 ------
|
|
.../sandboxer/sandboxer_client/CMakeLists.txt | 22 +-
|
|
.../sandboxer_client/sandboxer_client_ut.cc | 344 ++++++++----------
|
|
.../sandboxer_controller/CMakeLists.txt | 11 +-
|
|
.../sandboxer_controller_ut.cc | 62 +---
|
|
test/sandbox/controller/shim/CMakeLists.txt | 7 +-
|
|
test/sandbox/sandbox/CMakeLists.txt | 21 +-
|
|
test/sandbox/sandbox/sandbox_ut.cc | 5 +-
|
|
test/sandbox/sandbox_manager/CMakeLists.txt | 21 +-
|
|
36 files changed, 861 insertions(+), 1436 deletions(-)
|
|
delete mode 100644 test/mocks/controller_stub_mock.cc
|
|
delete mode 100644 test/mocks/controller_stub_mock.h
|
|
delete mode 100644 test/mocks/grpc_async_wait_call_mock.cc
|
|
delete mode 100644 test/mocks/grpc_async_wait_call_mock.h
|
|
delete mode 100644 test/mocks/grpc_sandboxer_monitor_mock.cc
|
|
create mode 100644 test/mocks/rust_sandbox_api_mock.cc
|
|
create mode 100644 test/mocks/rust_sandbox_api_mock.h
|
|
create mode 100644 test/mocks/sandbox_manager_mock.cc
|
|
rename test/mocks/{grpc_sandboxer_monitor_mock.h => sandbox_manager_mock.h} (55%)
|
|
create mode 100644 test/mocks/sandboxer_controller_mock.cc
|
|
create mode 100644 test/mocks/sandboxer_controller_mock.h
|
|
create mode 100644 test/mocks/sandboxer_sandbox_mock.cc
|
|
create mode 100644 test/mocks/sandboxer_sandbox_mock.h
|
|
create mode 100644 test/mocks/shim_sandbox_mock.cc
|
|
create mode 100644 test/mocks/shim_sandbox_mock.h
|
|
delete mode 100644 test/sandbox/controller/sandboxer/async_wait_call/CMakeLists.txt
|
|
delete mode 100644 test/sandbox/controller/sandboxer/async_wait_call/async_wait_call_ut.cc
|
|
delete mode 100644 test/sandbox/controller/sandboxer/async_wait_call/dummy_monitor_utils.h
|
|
|
|
diff --git a/test/cutils/utils_transform/CMakeLists.txt b/test/cutils/utils_transform/CMakeLists.txt
|
|
index fde9c9f9..23c870fa 100644
|
|
--- a/test/cutils/utils_transform/CMakeLists.txt
|
|
+++ b/test/cutils/utils_transform/CMakeLists.txt
|
|
@@ -15,7 +15,6 @@ target_include_directories(${EXE} PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cpputils
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/google/protobuf
|
|
)
|
|
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lprotobuf -lyajl -lz)
|
|
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
|
diff --git a/test/mocks/controller_stub_mock.cc b/test/mocks/controller_stub_mock.cc
|
|
deleted file mode 100644
|
|
index 712540bb..00000000
|
|
--- a/test/mocks/controller_stub_mock.cc
|
|
+++ /dev/null
|
|
@@ -1,314 +0,0 @@
|
|
-#include "controller_stub_mock.h"
|
|
-
|
|
-static std::shared_ptr<MockControllerStub> g_controller_stub_mock = NULL;
|
|
-
|
|
-std::unique_ptr<DummyControllerStub> NewDummyControllerStub()
|
|
-{
|
|
- std::unique_ptr<DummyControllerStub> stub(new DummyControllerStub());
|
|
- return stub;
|
|
-}
|
|
-
|
|
-void MockControllerStub_SetMock(std::shared_ptr<MockControllerStub> mock)
|
|
-{
|
|
- g_controller_stub_mock = mock;
|
|
-}
|
|
-
|
|
-::grpc::Status DummyControllerStub::Create(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerCreateRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerCreateResponse* response)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return ::grpc::Status::OK;
|
|
- }
|
|
- return g_controller_stub_mock->Create(context, request, response);
|
|
-}
|
|
-
|
|
-::grpc::Status DummyControllerStub::Start(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStartRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerStartResponse* response)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return ::grpc::Status::OK;
|
|
- }
|
|
- return g_controller_stub_mock->Start(context, request, response);
|
|
-}
|
|
-
|
|
-::grpc::Status DummyControllerStub::Platform(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerPlatformResponse* response)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return ::grpc::Status::OK;
|
|
- }
|
|
- return g_controller_stub_mock->Platform(context, request, response);
|
|
-}
|
|
-
|
|
-::grpc::Status DummyControllerStub::Prepare(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::PrepareRequest &request,
|
|
- ::containerd::services::sandbox::v1::PrepareResponse* response)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return ::grpc::Status::OK;
|
|
- }
|
|
- return g_controller_stub_mock->Prepare(context, request, response);
|
|
-}
|
|
-
|
|
-::grpc::Status DummyControllerStub::Purge(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::PurgeRequest &request,
|
|
- ::containerd::services::sandbox::v1::PurgeResponse* response)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return ::grpc::Status::OK;
|
|
- }
|
|
- return g_controller_stub_mock->Purge(context, request, response);
|
|
-}
|
|
-
|
|
-::grpc::Status DummyControllerStub::UpdateResources(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request,
|
|
- ::containerd::services::sandbox::v1::UpdateResourcesResponse* response)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return ::grpc::Status::OK;
|
|
- }
|
|
- return g_controller_stub_mock->UpdateResources(context, request, response);
|
|
-}
|
|
-
|
|
-::grpc::Status DummyControllerStub::Stop(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStopRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerStopResponse* response)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return ::grpc::Status::OK;
|
|
- }
|
|
- return g_controller_stub_mock->Stop(context, request, response);
|
|
-}
|
|
-
|
|
-::grpc::Status DummyControllerStub::Wait(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerWaitRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerWaitResponse* response)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return ::grpc::Status::OK;
|
|
- }
|
|
- return g_controller_stub_mock->Wait(context, request, response);
|
|
-}
|
|
-
|
|
-::grpc::Status DummyControllerStub::Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStatusRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerStatusResponse* response)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return ::grpc::Status::OK;
|
|
- }
|
|
- return g_controller_stub_mock->Status(context, request, response);
|
|
-}
|
|
-
|
|
-::grpc::Status DummyControllerStub::Shutdown(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerShutdownResponse* response)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return ::grpc::Status::OK;
|
|
- }
|
|
- return g_controller_stub_mock->Shutdown(context, request, response);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>*
|
|
-DummyControllerStub::AsyncCreateRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->AsyncCreateRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>*
|
|
-DummyControllerStub::PrepareAsyncCreateRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->PrepareAsyncCreateRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>*
|
|
-DummyControllerStub::AsyncStartRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->AsyncStartRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>*
|
|
-DummyControllerStub::PrepareAsyncStartRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->PrepareAsyncStartRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>*
|
|
-DummyControllerStub::AsyncPlatformRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->AsyncPlatformRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>*
|
|
-DummyControllerStub::PrepareAsyncPlatformRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->PrepareAsyncPlatformRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>*
|
|
-DummyControllerStub::AsyncPrepareRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::PrepareRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->AsyncPrepareRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>*
|
|
-DummyControllerStub::PrepareAsyncPrepareRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::PrepareRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->PrepareAsyncPrepareRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>*
|
|
-DummyControllerStub::AsyncPurgeRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::PurgeRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->AsyncPurgeRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>*
|
|
-DummyControllerStub::PrepareAsyncPurgeRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::PurgeRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->PrepareAsyncPurgeRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>*
|
|
-DummyControllerStub::AsyncUpdateResourcesRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->AsyncUpdateResourcesRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>*
|
|
-DummyControllerStub::PrepareAsyncUpdateResourcesRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->PrepareAsyncUpdateResourcesRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>*
|
|
-DummyControllerStub::AsyncStopRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->AsyncStopRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>*
|
|
-DummyControllerStub::PrepareAsyncStopRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->PrepareAsyncStopRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>*
|
|
-DummyControllerStub::AsyncWaitRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->AsyncWaitRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>*
|
|
-DummyControllerStub::PrepareAsyncWaitRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->PrepareAsyncWaitRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>*
|
|
-DummyControllerStub::AsyncStatusRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->AsyncStatusRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>*
|
|
-DummyControllerStub::PrepareAsyncStatusRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->PrepareAsyncStatusRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>*
|
|
-DummyControllerStub::AsyncShutdownRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->AsyncShutdownRaw(context, request, cq);
|
|
-}
|
|
-
|
|
-::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>*
|
|
-DummyControllerStub::PrepareAsyncShutdownRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ::grpc::CompletionQueue* cq)
|
|
-{
|
|
- if (g_controller_stub_mock == NULL) {
|
|
- return NULL;
|
|
- }
|
|
- return g_controller_stub_mock->PrepareAsyncShutdownRaw(context, request, cq);
|
|
-}
|
|
diff --git a/test/mocks/controller_stub_mock.h b/test/mocks/controller_stub_mock.h
|
|
deleted file mode 100644
|
|
index 85cb82bb..00000000
|
|
--- a/test/mocks/controller_stub_mock.h
|
|
+++ /dev/null
|
|
@@ -1,239 +0,0 @@
|
|
-/******************************************************************************
|
|
- * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
- * iSulad licensed under the Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
- * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
- * PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- * Author: xuxuepeng
|
|
- * Create: 2023-07-15
|
|
- * Description: provide grpc controller stub mock
|
|
- ******************************************************************************/
|
|
-
|
|
-#ifndef _ISULAD_TEST_MOCKS_CONTROLLER_STUB_MOCK_H
|
|
-#define _ISULAD_TEST_MOCKS_CONTROLLER_STUB_MOCK_H
|
|
-
|
|
-
|
|
-#include <gmock/gmock.h>
|
|
-#include "sandbox.grpc.pb.h"
|
|
-
|
|
-// MockControllerStub is a mock implementation of the Controller::StubInterface interface.
|
|
-class MockControllerStub {
|
|
-public:
|
|
- MOCK_METHOD3(Create, ::grpc::Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerCreateRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerCreateResponse* response));
|
|
- MOCK_METHOD3(Start, ::grpc::Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStartRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerStartResponse* response));
|
|
- MOCK_METHOD3(Platform, ::grpc::Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerPlatformResponse* response));
|
|
- MOCK_METHOD3(Prepare, ::grpc::Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::PrepareRequest &request,
|
|
- ::containerd::services::sandbox::v1::PrepareResponse* response));
|
|
- MOCK_METHOD3(Purge, ::grpc::Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::PurgeRequest &request,
|
|
- ::containerd::services::sandbox::v1::PurgeResponse* response));
|
|
- MOCK_METHOD3(UpdateResources, ::grpc::Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request,
|
|
- ::containerd::services::sandbox::v1::UpdateResourcesResponse* response));
|
|
- MOCK_METHOD3(Stop, ::grpc::Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStopRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerStopResponse* response));
|
|
- MOCK_METHOD3(Wait, ::grpc::Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerWaitRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerWaitResponse* response));
|
|
- MOCK_METHOD3(Status, ::grpc::Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStatusRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerStatusResponse* response));
|
|
- MOCK_METHOD3(Shutdown, ::grpc::Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerShutdownResponse* response));
|
|
- MOCK_METHOD3(AsyncCreateRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(PrepareAsyncCreateRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerCreateRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(AsyncStartRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(PrepareAsyncStartRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStartRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(AsyncPlatformRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(PrepareAsyncPlatformRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(AsyncPrepareRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(PrepareAsyncPrepareRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(AsyncPurgeRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(PrepareAsyncPurgeRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(AsyncUpdateResourcesRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(PrepareAsyncUpdateResourcesRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(AsyncStopRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(PrepareAsyncStopRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(AsyncWaitRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(PrepareAsyncWaitRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(AsyncStatusRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(PrepareAsyncStatusRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStatusRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(AsyncShutdownRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
- MOCK_METHOD3(PrepareAsyncShutdownRaw,
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>*
|
|
- (::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request,
|
|
- ::grpc::CompletionQueue* cq));
|
|
-};
|
|
-
|
|
-class DummyControllerStub: public containerd::services::sandbox::v1::Controller::StubInterface {
|
|
-public:
|
|
- DummyControllerStub() = default;
|
|
- ~DummyControllerStub() = default;
|
|
- ::grpc::Status Create(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerCreateRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerCreateResponse* response) override;
|
|
- ::grpc::Status Start(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStartRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerStartResponse* response) override;
|
|
- ::grpc::Status Platform(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerPlatformResponse* response) override;
|
|
- ::grpc::Status Prepare(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::PrepareRequest &request,
|
|
- ::containerd::services::sandbox::v1::PrepareResponse* response) override;
|
|
- ::grpc::Status Purge(::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest &request,
|
|
- ::containerd::services::sandbox::v1::PurgeResponse* response) override;
|
|
- ::grpc::Status UpdateResources(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request,
|
|
- ::containerd::services::sandbox::v1::UpdateResourcesResponse* response) override;
|
|
- ::grpc::Status Stop(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStopRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerStopResponse* response) override;
|
|
- ::grpc::Status Wait(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerWaitRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerWaitResponse* response) override;
|
|
- ::grpc::Status Status(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStatusRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerStatusResponse* response) override;
|
|
- ::grpc::Status Shutdown(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request,
|
|
- ::containerd::services::sandbox::v1::ControllerShutdownResponse* response) override;
|
|
-private:
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>*
|
|
- AsyncCreateRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerCreateResponse>*
|
|
- PrepareAsyncCreateRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerCreateRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>*
|
|
- AsyncStartRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStartResponse>*
|
|
- PrepareAsyncStartRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStartRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>*
|
|
- AsyncPlatformRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerPlatformResponse>*
|
|
- PrepareAsyncPlatformRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerPlatformRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>* AsyncPrepareRaw(
|
|
- ::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PrepareRequest &request,
|
|
- ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PrepareResponse>*
|
|
- PrepareAsyncPrepareRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::PrepareRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* AsyncPurgeRaw(
|
|
- ::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest &request,
|
|
- ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::PurgeResponse>* PrepareAsyncPurgeRaw(
|
|
- ::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::PurgeRequest &request,
|
|
- ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>*
|
|
- AsyncUpdateResourcesRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::UpdateResourcesResponse>*
|
|
- PrepareAsyncUpdateResourcesRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::UpdateResourcesRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>* AsyncStopRaw(
|
|
- ::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerStopRequest &request,
|
|
- ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStopResponse>*
|
|
- PrepareAsyncStopRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStopRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>* AsyncWaitRaw(
|
|
- ::grpc::ClientContext* context, const ::containerd::services::sandbox::v1::ControllerWaitRequest &request,
|
|
- ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerWaitResponse>*
|
|
- PrepareAsyncWaitRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerWaitRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>*
|
|
- AsyncStatusRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerStatusResponse>*
|
|
- PrepareAsyncStatusRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerStatusRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>*
|
|
- AsyncShutdownRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
- ::grpc::ClientAsyncResponseReaderInterface< ::containerd::services::sandbox::v1::ControllerShutdownResponse>*
|
|
- PrepareAsyncShutdownRaw(::grpc::ClientContext* context,
|
|
- const ::containerd::services::sandbox::v1::ControllerShutdownRequest &request, ::grpc::CompletionQueue* cq) override;
|
|
-};
|
|
-
|
|
-std::unique_ptr<DummyControllerStub> NewDummyControllerStub();
|
|
-
|
|
-void MockControllerStub_SetMock(std::shared_ptr<MockControllerStub> stub);
|
|
-
|
|
-
|
|
-#endif // _ISULAD_TEST_MOCKS_CONTROLLER_STUB_MOCK_H
|
|
\ No newline at end of file
|
|
diff --git a/test/mocks/grpc_async_wait_call_mock.cc b/test/mocks/grpc_async_wait_call_mock.cc
|
|
deleted file mode 100644
|
|
index 5eef1794..00000000
|
|
--- a/test/mocks/grpc_async_wait_call_mock.cc
|
|
+++ /dev/null
|
|
@@ -1,92 +0,0 @@
|
|
-/******************************************************************************
|
|
- * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
- * iSulad licensed under the Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
- * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
- * PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- * Author: xuxuepeng
|
|
- * Create: 2023-07-31
|
|
- * Description: provide grpc sandboxer async wait call mock
|
|
- ******************************************************************************/
|
|
-
|
|
-#include "grpc_async_wait_call_mock.h"
|
|
-
|
|
-static std::shared_ptr<SandboxerAsyncWaitCallMock> g_sandboxer_async_wait_call_mock = NULL;
|
|
-
|
|
-void MockSandboxerAsyncWaitCall_SetMock(std::shared_ptr<SandboxerAsyncWaitCallMock> mock)
|
|
-{
|
|
- g_sandboxer_async_wait_call_mock = mock;
|
|
-}
|
|
-
|
|
-SandboxerAsyncWaitCall::SandboxerAsyncWaitCall(std::shared_ptr<SandboxStatusCallback> cb,
|
|
- const std::string &sandboxId, const std::string &sandboxer)
|
|
-{
|
|
- m_cb = cb;
|
|
- m_sandboxId = sandboxId;
|
|
- m_sandboxer = sandboxer;
|
|
- m_status = grpc::Status::OK;
|
|
- m_retryTimes = 0;
|
|
- m_retryCounter = 0;
|
|
- m_remove = false;
|
|
-}
|
|
-
|
|
-auto SandboxerAsyncWaitCall::Call(containerd::services::sandbox::v1::Controller::StubInterface &stub,
|
|
- grpc::CompletionQueue &cq) -> bool
|
|
-{
|
|
- if (g_sandboxer_async_wait_call_mock == NULL) {
|
|
- return true;
|
|
- }
|
|
- return g_sandboxer_async_wait_call_mock->Call(stub, cq);
|
|
-}
|
|
-
|
|
-auto SandboxerAsyncWaitCall::HandleResponse() -> SandboxerAsyncWaitStatus
|
|
-{
|
|
- if (g_sandboxer_async_wait_call_mock == NULL) {
|
|
- return SANDBOXER_ASYNC_WAIT_STATUS_OK;
|
|
- }
|
|
- return g_sandboxer_async_wait_call_mock->HandleResponse();
|
|
-}
|
|
-
|
|
-auto SandboxerAsyncWaitCall::Timeout() -> bool
|
|
-{
|
|
- if (g_sandboxer_async_wait_call_mock == NULL) {
|
|
- return true;
|
|
- }
|
|
- return g_sandboxer_async_wait_call_mock->Timeout();
|
|
-}
|
|
-
|
|
-void SandboxerAsyncWaitCall::SandboxExitCallback(bool statusOK, const ControllerExitInfo &exitInfo)
|
|
-{
|
|
- if (g_sandboxer_async_wait_call_mock == NULL) {
|
|
- return;
|
|
- }
|
|
- return g_sandboxer_async_wait_call_mock->SandboxExitCallback(statusOK, exitInfo);
|
|
-}
|
|
-
|
|
-void SandboxerAsyncWaitCall::SandboxPendingCallback()
|
|
-{
|
|
- if (g_sandboxer_async_wait_call_mock == NULL) {
|
|
- return;
|
|
- }
|
|
- return g_sandboxer_async_wait_call_mock->SandboxPendingCallback();
|
|
-}
|
|
-
|
|
-void SandboxerAsyncWaitCall::SandboxReadyCallback()
|
|
-{
|
|
- if (g_sandboxer_async_wait_call_mock == NULL) {
|
|
- return;
|
|
- }
|
|
- return g_sandboxer_async_wait_call_mock->SandboxReadyCallback();
|
|
-}
|
|
-
|
|
-auto SandboxerAsyncWaitCall::GetSandboxId() -> const std::string &
|
|
-{
|
|
- if (g_sandboxer_async_wait_call_mock == NULL) {
|
|
- return m_sandboxId;
|
|
- }
|
|
- return g_sandboxer_async_wait_call_mock->GetSandboxId();
|
|
-}
|
|
diff --git a/test/mocks/grpc_async_wait_call_mock.h b/test/mocks/grpc_async_wait_call_mock.h
|
|
deleted file mode 100644
|
|
index c79f998e..00000000
|
|
--- a/test/mocks/grpc_async_wait_call_mock.h
|
|
+++ /dev/null
|
|
@@ -1,37 +0,0 @@
|
|
-/******************************************************************************
|
|
- * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
- * iSulad licensed under the Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
- * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
- * PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- * Author: xuxuepeng
|
|
- * Create: 2023-07-31
|
|
- * Description: provide grpc sandboxer async wait call mock
|
|
- ******************************************************************************/
|
|
-
|
|
-#ifndef _ISULAD_TEST_MOCKS_GRPC_SANDBOXER_ASYNC_WAIT_CALL_MOCK_H
|
|
-#define _ISULAD_TEST_MOCKS_GRPC_SANDBOXER_ASYNC_WAIT_CALL_MOCK_H
|
|
-
|
|
-#include <gmock/gmock.h>
|
|
-#include "grpc_async_wait_call.h"
|
|
-using namespace sandbox;
|
|
-
|
|
-// Mock above class
|
|
-class SandboxerAsyncWaitCallMock {
|
|
-public:
|
|
- MOCK_METHOD2(Call, bool(containerd::services::sandbox::v1::Controller::StubInterface &stub, grpc::CompletionQueue &cq));
|
|
- MOCK_METHOD0(HandleResponse, SandboxerAsyncWaitStatus());
|
|
- MOCK_METHOD0(Timeout, bool());
|
|
- MOCK_METHOD2(SandboxExitCallback, void(bool statusOK, const ControllerExitInfo &exitInfo));
|
|
- MOCK_METHOD0(SandboxPendingCallback, void());
|
|
- MOCK_METHOD0(SandboxReadyCallback, void());
|
|
- MOCK_METHOD0(GetSandboxId, const std::string & ());
|
|
-};
|
|
-
|
|
-void MockSandboxerAsyncWaitCall_SetMock(std::shared_ptr<SandboxerAsyncWaitCallMock> mock);
|
|
-
|
|
-#endif // _ISULAD_TEST_MOCKS_GRPC_SANDBOXER_ASYNC_WAIT_CALL_MOCK_H
|
|
\ No newline at end of file
|
|
diff --git a/test/mocks/grpc_sandboxer_client_mock.cc b/test/mocks/grpc_sandboxer_client_mock.cc
|
|
index 03df9048..1f03a00e 100644
|
|
--- a/test/mocks/grpc_sandboxer_client_mock.cc
|
|
+++ b/test/mocks/grpc_sandboxer_client_mock.cc
|
|
@@ -14,7 +14,6 @@
|
|
******************************************************************************/
|
|
|
|
#include "grpc_sandboxer_client_mock.h"
|
|
-#include "controller_stub_mock.h"
|
|
|
|
static std::shared_ptr<SandboxerClientMock> g_sandboxer_client_mock = NULL;
|
|
|
|
@@ -22,24 +21,6 @@ SandboxerClient::SandboxerClient(const std::string &sandboxer, const std::string
|
|
{
|
|
m_sandboxer = sandboxer;
|
|
m_address = address;
|
|
- m_channel = grpc::CreateChannel(m_address, grpc::InsecureChannelCredentials());
|
|
- m_stub = NewDummyControllerStub();
|
|
-}
|
|
-
|
|
-void SandboxerClient::Init(Errors &error)
|
|
-{
|
|
- if (g_sandboxer_client_mock == NULL) {
|
|
- return;
|
|
- }
|
|
- g_sandboxer_client_mock->Init(error);
|
|
-}
|
|
-
|
|
-void SandboxerClient::Destroy()
|
|
-{
|
|
- if (g_sandboxer_client_mock == NULL) {
|
|
- return;
|
|
- }
|
|
- return g_sandboxer_client_mock->Destroy();
|
|
}
|
|
|
|
auto SandboxerClient::Create(const std::string &sandboxId, const ControllerCreateParams ¶ms, Errors &error) -> bool
|
|
@@ -67,31 +48,12 @@ auto SandboxerClient::Platform(const std::string &sandboxId, ControllerPlatformI
|
|
return g_sandboxer_client_mock->Platform(sandboxId, platformInfo, error);
|
|
}
|
|
|
|
-auto SandboxerClient::Prepare(const std::string &sandboxId, const ControllerPrepareParams ¶ms, std::string &bundle,
|
|
- Errors &error) -> bool
|
|
+auto SandboxerClient::Update(sandbox_sandbox *apiSandbox, string_array *fields, Errors &error) -> bool
|
|
{
|
|
if (g_sandboxer_client_mock == NULL) {
|
|
return true;
|
|
}
|
|
- return g_sandboxer_client_mock->Prepare(sandboxId, params, bundle, error);
|
|
-}
|
|
-
|
|
-auto SandboxerClient::Purge(const std::string &sandboxId, const std::string &containerId,
|
|
- const std::string &execId, Errors &error) -> bool
|
|
-{
|
|
- if (g_sandboxer_client_mock == NULL) {
|
|
- return true;
|
|
- }
|
|
- return g_sandboxer_client_mock->Purge(sandboxId, containerId, execId, error);
|
|
-}
|
|
-
|
|
-auto SandboxerClient::UpdateResources(const std::string &sandboxId, const ControllerUpdateResourcesParams ¶ms,
|
|
- Errors &error) -> bool
|
|
-{
|
|
- if (g_sandboxer_client_mock == NULL) {
|
|
- return true;
|
|
- }
|
|
- return g_sandboxer_client_mock->UpdateResources(sandboxId, params, error);
|
|
+ return g_sandboxer_client_mock->Update(apiSandbox, fields, error);
|
|
}
|
|
|
|
auto SandboxerClient::Stop(const std::string &sandboxId, uint32_t timeoutSecs, Errors &error) -> bool
|
|
@@ -131,4 +93,4 @@ auto SandboxerClient::Shutdown(const std::string &sandboxId, Errors &error) -> b
|
|
void MockSandboxerClient_SetMock(std::shared_ptr<SandboxerClientMock> mock)
|
|
{
|
|
g_sandboxer_client_mock = mock;
|
|
-}
|
|
\ No newline at end of file
|
|
+}
|
|
diff --git a/test/mocks/grpc_sandboxer_client_mock.h b/test/mocks/grpc_sandboxer_client_mock.h
|
|
index ac06462a..8d535013 100644
|
|
--- a/test/mocks/grpc_sandboxer_client_mock.h
|
|
+++ b/test/mocks/grpc_sandboxer_client_mock.h
|
|
@@ -17,23 +17,18 @@
|
|
#define _ISULAD_TEST_MOCKS_GRPC_SANDBOXER_CLIENT_MOCK_H
|
|
|
|
#include <gmock/gmock.h>
|
|
+#include <isula_sandbox_api.h>
|
|
+
|
|
#include "grpc_sandboxer_client.h"
|
|
using namespace sandbox;
|
|
|
|
class SandboxerClientMock {
|
|
public:
|
|
SandboxerClientMock() = default;
|
|
- MOCK_METHOD1(Init, void(Errors &error));
|
|
- MOCK_METHOD0(Destroy, void());
|
|
MOCK_METHOD3(Create, bool(const std::string &sandboxId, const ControllerCreateParams ¶ms, Errors &error));
|
|
MOCK_METHOD3(Start, bool(const std::string &sandboxId, ControllerSandboxInfo &sandboxInfo, Errors &error));
|
|
MOCK_METHOD3(Platform, bool(const std::string &sandboxId, ControllerPlatformInfo &platformInfo, Errors &error));
|
|
- MOCK_METHOD4(Prepare, bool(const std::string &sandboxId, const ControllerPrepareParams ¶ms, std::string &bundle,
|
|
- Errors &error));
|
|
- MOCK_METHOD4(Purge, bool(const std::string &sandboxId, const std::string &containerId, const std::string &execId,
|
|
- Errors &error));
|
|
- MOCK_METHOD3(UpdateResources, bool(const std::string &sandboxId, const ControllerUpdateResourcesParams ¶ms,
|
|
- Errors &error));
|
|
+ MOCK_METHOD3(Update, bool(sandbox_sandbox *apiSandbox, string_array *fields, Errors &error));
|
|
MOCK_METHOD3(Stop, bool(const std::string &sandboxId, uint32_t timeoutSecs, Errors &error));
|
|
MOCK_METHOD3(Wait, bool(std::shared_ptr<SandboxStatusCallback> cb, const std::string &sandboxId, Errors &error));
|
|
MOCK_METHOD4(Status, bool(const std::string &sandboxId, bool verbose, ControllerSandboxStatus &sandboxStatus,
|
|
diff --git a/test/mocks/grpc_sandboxer_monitor_mock.cc b/test/mocks/grpc_sandboxer_monitor_mock.cc
|
|
deleted file mode 100644
|
|
index b3ddda87..00000000
|
|
--- a/test/mocks/grpc_sandboxer_monitor_mock.cc
|
|
+++ /dev/null
|
|
@@ -1,51 +0,0 @@
|
|
-/******************************************************************************
|
|
- * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
- * iSulad licensed under the Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
- * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
- * PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- * Author: xuxuepeng
|
|
- * Create: 2023-07-31
|
|
- * Description: provide grpc sandboxer client monitor mock
|
|
- ******************************************************************************/
|
|
-
|
|
-#include "grpc_sandboxer_monitor_mock.h"
|
|
-
|
|
-static std::shared_ptr<SandboxerClientMonitorMock> g_sandboxer_client_monitor_mock = NULL;
|
|
-
|
|
-
|
|
-SandboxerClientMonitor::SandboxerClientMonitor(std::shared_ptr<grpc::Channel> channel, const std::string &sandboxer):
|
|
- m_channel(channel), m_sandboxer(sandboxer), m_teardown(false) {}
|
|
-
|
|
-void SandboxerClientMonitor::Start()
|
|
-{
|
|
- if (g_sandboxer_client_monitor_mock == NULL) {
|
|
- return;
|
|
- }
|
|
- return g_sandboxer_client_monitor_mock->Start();
|
|
-}
|
|
-
|
|
-void SandboxerClientMonitor::Stop()
|
|
-{
|
|
- if (g_sandboxer_client_monitor_mock == NULL) {
|
|
- return;
|
|
- }
|
|
- return g_sandboxer_client_monitor_mock->Stop();
|
|
-}
|
|
-
|
|
-bool SandboxerClientMonitor::Monitor(SandboxerAsyncWaitCall *call)
|
|
-{
|
|
- if (g_sandboxer_client_monitor_mock == NULL) {
|
|
- return true;
|
|
- }
|
|
- return g_sandboxer_client_monitor_mock->Monitor(call);
|
|
-}
|
|
-
|
|
-void MockSandboxerMonitor_SetMock(std::shared_ptr<SandboxerClientMonitorMock> mock)
|
|
-{
|
|
- g_sandboxer_client_monitor_mock = mock;
|
|
-}
|
|
diff --git a/test/mocks/rust_sandbox_api_mock.cc b/test/mocks/rust_sandbox_api_mock.cc
|
|
new file mode 100644
|
|
index 00000000..b595e4b8
|
|
--- /dev/null
|
|
+++ b/test/mocks/rust_sandbox_api_mock.cc
|
|
@@ -0,0 +1,103 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
+ * iSulad licensed under the Mulan PSL v2.
|
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
|
+ * http://license.coscl.org.cn/MulanPSL2
|
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
+ * PURPOSE.
|
|
+ * See the Mulan PSL v2 for more details.
|
|
+ * Author: liuxu
|
|
+ * Create: 2024-11-22
|
|
+ * Description: provide rust sandbox api mock
|
|
+ ******************************************************************************/
|
|
+
|
|
+#include "rust_sandbox_api_mock.h"
|
|
+
|
|
+static std::shared_ptr<RustSandboxApiMock> g_rust_sandbox_api_mock = NULL;
|
|
+
|
|
+void RustSandboxApiMock_SetMock(std::shared_ptr<RustSandboxApiMock> mock)
|
|
+{
|
|
+ g_rust_sandbox_api_mock = mock;
|
|
+}
|
|
+
|
|
+ControllerHandle_t sandbox_api_build_controller(const char *sandboxer, const char *address)
|
|
+{
|
|
+ if (g_rust_sandbox_api_mock != nullptr) {
|
|
+ return g_rust_sandbox_api_mock->sandbox_api_build_controller(sandboxer, address);
|
|
+ }
|
|
+ return nullptr;
|
|
+}
|
|
+
|
|
+int sandbox_api_create(ControllerHandle_t chandle, const sandbox_create_request *request, sandbox_create_response *response)
|
|
+{
|
|
+ if (g_rust_sandbox_api_mock != nullptr) {
|
|
+ return g_rust_sandbox_api_mock->sandbox_api_create(chandle, request, response);
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int sandbox_api_start(ControllerHandle_t chandle, const sandbox_start_request *request, sandbox_start_response *response)
|
|
+{
|
|
+ if (g_rust_sandbox_api_mock != nullptr) {
|
|
+ return g_rust_sandbox_api_mock->sandbox_api_start(chandle, request, response);
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int sandbox_api_platform(ControllerHandle_t chandle, const sandbox_platform_request *request, sandbox_platform_response *response)
|
|
+{
|
|
+ if (g_rust_sandbox_api_mock != nullptr) {
|
|
+ return g_rust_sandbox_api_mock->sandbox_api_platform(chandle, request, response);
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int sandbox_api_stop(ControllerHandle_t chandle, const sandbox_stop_request *request)
|
|
+{
|
|
+ if (g_rust_sandbox_api_mock != nullptr) {
|
|
+ return g_rust_sandbox_api_mock->sandbox_api_stop(chandle, request);
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int sandbox_api_wait(ControllerHandle_t chandle, const sandbox_wait_request *request, sandbox_api_wait_callback callback)
|
|
+{
|
|
+ if (g_rust_sandbox_api_mock != nullptr) {
|
|
+ return g_rust_sandbox_api_mock->sandbox_api_wait(chandle, request, callback);
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int sandbox_api_status(ControllerHandle_t chandle, const sandbox_status_request *request, sandbox_status_response *response)
|
|
+{
|
|
+ if (g_rust_sandbox_api_mock != nullptr) {
|
|
+ return g_rust_sandbox_api_mock->sandbox_api_status(chandle, request, response);
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int sandbox_api_shutdown(ControllerHandle_t chandle, const sandbox_shutdown_request *request)
|
|
+{
|
|
+ if (g_rust_sandbox_api_mock != nullptr) {
|
|
+ return g_rust_sandbox_api_mock->sandbox_api_shutdown(chandle, request);
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int sandbox_api_metrics(ControllerHandle_t chandle, const sandbox_metrics_request *request, sandbox_metrics_response *response)
|
|
+{
|
|
+ if (g_rust_sandbox_api_mock != nullptr) {
|
|
+ return g_rust_sandbox_api_mock->sandbox_api_metrics(chandle, request, response);
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int sandbox_api_update(ControllerHandle_t chandle, const sandbox_update_request *request)
|
|
+{
|
|
+ if (g_rust_sandbox_api_mock != nullptr) {
|
|
+ return g_rust_sandbox_api_mock->sandbox_api_update(chandle, request);
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
diff --git a/test/mocks/rust_sandbox_api_mock.h b/test/mocks/rust_sandbox_api_mock.h
|
|
new file mode 100644
|
|
index 00000000..134d71e9
|
|
--- /dev/null
|
|
+++ b/test/mocks/rust_sandbox_api_mock.h
|
|
@@ -0,0 +1,39 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
+ * iSulad licensed under the Mulan PSL v2.
|
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
|
+ * http://license.coscl.org.cn/MulanPSL2
|
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
+ * PURPOSE.
|
|
+ * See the Mulan PSL v2 for more details.
|
|
+ * Author: liuxu
|
|
+ * Create: 2024-11-22
|
|
+ * Description: provide rust sandbox api mock
|
|
+ ******************************************************************************/
|
|
+
|
|
+#ifndef _ISULAD_TEST_MOCKS_RUST_SANDBOX_API_MOCK_H
|
|
+#define _ISULAD_TEST_MOCKS_RUST_SANDBOX_API_MOCK_H
|
|
+
|
|
+#include <gmock/gmock.h>
|
|
+#include <isula_sandbox_api.h>
|
|
+
|
|
+class RustSandboxApiMock {
|
|
+public:
|
|
+ RustSandboxApiMock() = default;
|
|
+ MOCK_METHOD2(sandbox_api_build_controller, ControllerHandle_t(const char *sandboxer, const char *address));
|
|
+ MOCK_METHOD3(sandbox_api_create, int(ControllerHandle_t chandle, const sandbox_create_request *request, sandbox_create_response *response));
|
|
+ MOCK_METHOD3(sandbox_api_start, int(ControllerHandle_t chandle, const sandbox_start_request *request, sandbox_start_response *response));
|
|
+ MOCK_METHOD2(sandbox_api_stop, int(ControllerHandle_t chandle, const sandbox_stop_request *request));
|
|
+ MOCK_METHOD3(sandbox_api_wait, int(ControllerHandle_t chandle, const sandbox_wait_request *request, sandbox_api_wait_callback callback));
|
|
+ MOCK_METHOD3(sandbox_api_status, int(ControllerHandle_t chandle, const sandbox_status_request *request, sandbox_status_response *response));
|
|
+ MOCK_METHOD2(sandbox_api_shutdown, int(ControllerHandle_t chandle, const sandbox_shutdown_request *request));
|
|
+ MOCK_METHOD3(sandbox_api_metrics, int(ControllerHandle_t chandle, const sandbox_metrics_request *request, sandbox_metrics_response *response));
|
|
+ MOCK_METHOD3(sandbox_api_platform, int(ControllerHandle_t chandle, const sandbox_platform_request *request, sandbox_platform_response *response));
|
|
+ MOCK_METHOD2(sandbox_api_update, int(ControllerHandle_t chandle, const sandbox_update_request *request));
|
|
+};
|
|
+
|
|
+void RustSandboxApiMock_SetMock(std::shared_ptr<RustSandboxApiMock> mock);
|
|
+
|
|
+#endif // _ISULAD_TEST_MOCKS_RUST_SANDBOX_API_MOCK_H
|
|
diff --git a/test/mocks/sandbox_manager_mock.cc b/test/mocks/sandbox_manager_mock.cc
|
|
new file mode 100644
|
|
index 00000000..c3c32e52
|
|
--- /dev/null
|
|
+++ b/test/mocks/sandbox_manager_mock.cc
|
|
@@ -0,0 +1,42 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
+ * iSulad licensed under the Mulan PSL v2.
|
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
|
+ * http://license.coscl.org.cn/MulanPSL2
|
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
+ * PURPOSE.
|
|
+ * See the Mulan PSL v2 for more details.
|
|
+ * Author: jikai
|
|
+ * Create: 2023-10-20
|
|
+ * Description: provide sandboxer controller mock
|
|
+ ******************************************************************************/
|
|
+
|
|
+#include "sandbox_manager_mock.h"
|
|
+
|
|
+namespace sandbox {
|
|
+static std::shared_ptr<MockSandboxManager> g_sandbox_manager_mock = nullptr;
|
|
+
|
|
+void MockSandboxManager_SetMock(std::shared_ptr<MockSandboxManager> mock)
|
|
+{
|
|
+ g_sandbox_manager_mock = mock;
|
|
+}
|
|
+
|
|
+SandboxManager *SandboxManager::GetInstance() noexcept
|
|
+{
|
|
+ if (g_sandbox_manager_mock != nullptr) {
|
|
+ return g_sandbox_manager_mock->GetInstance();
|
|
+ }
|
|
+ return nullptr;
|
|
+}
|
|
+
|
|
+std::shared_ptr<Sandbox> SandboxManager::GetSandbox(const std::string &idOrName)
|
|
+{
|
|
+ if (g_sandbox_manager_mock != nullptr) {
|
|
+ return g_sandbox_manager_mock->GetSandbox(idOrName);
|
|
+ }
|
|
+ return nullptr;
|
|
+}
|
|
+
|
|
+}
|
|
diff --git a/test/mocks/grpc_sandboxer_monitor_mock.h b/test/mocks/sandbox_manager_mock.h
|
|
similarity index 55%
|
|
rename from test/mocks/grpc_sandboxer_monitor_mock.h
|
|
rename to test/mocks/sandbox_manager_mock.h
|
|
index 0ab21e00..1378d5b7 100644
|
|
--- a/test/mocks/grpc_sandboxer_monitor_mock.h
|
|
+++ b/test/mocks/sandbox_manager_mock.h
|
|
@@ -8,26 +8,35 @@
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
* PURPOSE.
|
|
* See the Mulan PSL v2 for more details.
|
|
- * Author: xuxuepeng
|
|
- * Create: 2023-07-31
|
|
- * Description: provide grpc sandboxer client monitor mock
|
|
+ * Author: jikai
|
|
+ * Create: 2023-10-20
|
|
+ * Description: provide sandbox manager mock
|
|
******************************************************************************/
|
|
|
|
-#ifndef _ISULAD_TEST_MOCKS_GRPC_SANDBOXER_MONITOR_MOCK_H
|
|
-#define _ISULAD_TEST_MOCKS_GRPC_SANDBOXER_MONITOR_MOCK_H
|
|
+#ifndef _ISULAD_TEST_MOCKS_SANDBOX_MANAGER_MOCK_H
|
|
+#define _ISULAD_TEST_MOCKS_SANDBOX_MANAGER_MOCK_H
|
|
|
|
#include <gmock/gmock.h>
|
|
-#include "grpc_sandboxer_monitor.h"
|
|
+#include <memory>
|
|
|
|
-using namespace sandbox;
|
|
+#include "sandbox.h"
|
|
+#include "sandbox_manager.h"
|
|
|
|
-class SandboxerClientMonitorMock {
|
|
+namespace sandbox {
|
|
+
|
|
+class MockSandboxManager {
|
|
public:
|
|
- MOCK_METHOD1(Monitor, bool(SandboxerAsyncWaitCall *call));
|
|
- MOCK_METHOD0(Start, void());
|
|
- MOCK_METHOD0(Stop, void());
|
|
+ MockSandboxManager() = default;
|
|
+ virtual ~MockSandboxManager() = default;
|
|
+
|
|
+ MOCK_METHOD0(GetInstance, SandboxManager *());
|
|
+
|
|
+ MOCK_METHOD1(GetSandbox, std::shared_ptr<Sandbox>(const std::string &idOrName));
|
|
+
|
|
};
|
|
|
|
-void MockSandboxerMonitor_SetMock(std::shared_ptr<SandboxerClientMonitorMock> mock);
|
|
+void MockSandboxManager_SetMock(std::shared_ptr<MockSandboxManager> mock);
|
|
+
|
|
+}
|
|
|
|
-#endif // _ISULAD_TEST_MOCKS_GRPC_SANDBOXER_MONITOR_MOCK_H
|
|
+#endif
|
|
\ No newline at end of file
|
|
diff --git a/test/mocks/sandboxer_controller_mock.cc b/test/mocks/sandboxer_controller_mock.cc
|
|
new file mode 100644
|
|
index 00000000..4f7258d5
|
|
--- /dev/null
|
|
+++ b/test/mocks/sandboxer_controller_mock.cc
|
|
@@ -0,0 +1,116 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
+ * iSulad licensed under the Mulan PSL v2.
|
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
|
+ * http://license.coscl.org.cn/MulanPSL2
|
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
+ * PURPOSE.
|
|
+ * See the Mulan PSL v2 for more details.
|
|
+ * Author: jikai
|
|
+ * Create: 2023-10-20
|
|
+ * Description: provide sandboxer controller mock
|
|
+ ******************************************************************************/
|
|
+
|
|
+#include "sandboxer_controller_mock.h"
|
|
+
|
|
+namespace sandbox {
|
|
+static std::shared_ptr<MockSandboxerController> g_sandboxer_controller_mock = nullptr;
|
|
+
|
|
+SandboxerController::SandboxerController(const std::string &sandboxer, const std::string &address)
|
|
+{
|
|
+}
|
|
+
|
|
+SandboxerController::~SandboxerController()
|
|
+{
|
|
+}
|
|
+
|
|
+void MockSandboxerController_SetMock(std::shared_ptr<MockSandboxerController> mock)
|
|
+{
|
|
+ g_sandboxer_controller_mock = mock;
|
|
+}
|
|
+
|
|
+bool SandboxerController::Init(Errors &error)
|
|
+{
|
|
+ if (g_sandboxer_controller_mock != nullptr) {
|
|
+ return g_sandboxer_controller_mock->Init(error);
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+bool SandboxerController::Create(const std::string &sandboxId,
|
|
+ const ControllerCreateParams ¶ms,
|
|
+ Errors &error)
|
|
+{
|
|
+ if (g_sandboxer_controller_mock != nullptr) {
|
|
+ return g_sandboxer_controller_mock->Create(sandboxId, params, error);
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+std::unique_ptr<ControllerSandboxInfo> SandboxerController::Start(const std::string &sandboxId, Errors &error)
|
|
+{
|
|
+ if (g_sandboxer_controller_mock != nullptr) {
|
|
+ return g_sandboxer_controller_mock->Start(sandboxId, error);
|
|
+ }
|
|
+ return nullptr;
|
|
+}
|
|
+
|
|
+std::unique_ptr<ControllerPlatformInfo> SandboxerController::Platform(const std::string &sandboxId, Errors &error)
|
|
+{
|
|
+ if (g_sandboxer_controller_mock != nullptr) {
|
|
+ return g_sandboxer_controller_mock->Platform(sandboxId, error);
|
|
+ }
|
|
+ return nullptr;
|
|
+}
|
|
+
|
|
+bool SandboxerController::Update(sandbox_sandbox *apiSandbox,
|
|
+ string_array *fields, Errors &error)
|
|
+{
|
|
+ return g_sandboxer_controller_mock->Update(apiSandbox, fields, error);
|
|
+}
|
|
+
|
|
+bool SandboxerController::Stop(const std::string &sandboxId, uint32_t timeoutSecs, Errors &error)
|
|
+{
|
|
+ if (g_sandboxer_controller_mock != nullptr) {
|
|
+ return g_sandboxer_controller_mock->Stop(sandboxId, timeoutSecs, error);
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+bool SandboxerController::Wait(std::shared_ptr<SandboxStatusCallback> cb, const std::string &sandboxId, Errors &error)
|
|
+{
|
|
+ if (g_sandboxer_controller_mock != nullptr) {
|
|
+ return g_sandboxer_controller_mock->Wait(cb, sandboxId, error);
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+std::unique_ptr<ControllerSandboxStatus> SandboxerController::Status(const std::string &sandboxId, bool verbose,
|
|
+ Errors &error)
|
|
+{
|
|
+ if (g_sandboxer_controller_mock != nullptr) {
|
|
+ return g_sandboxer_controller_mock->Status(sandboxId, verbose, error);
|
|
+ }
|
|
+ return nullptr;
|
|
+}
|
|
+
|
|
+bool SandboxerController::Shutdown(const std::string &sandboxId, Errors &error)
|
|
+{
|
|
+ if (g_sandboxer_controller_mock != nullptr) {
|
|
+ return g_sandboxer_controller_mock->Shutdown(sandboxId, error);
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+bool SandboxerController::UpdateNetworkSettings(const std::string &sandboxId, const std::string &networkSettings,
|
|
+ Errors &error)
|
|
+{
|
|
+ if (g_sandboxer_controller_mock != nullptr) {
|
|
+ return g_sandboxer_controller_mock->UpdateNetworkSettings(sandboxId, networkSettings, error);
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+}
|
|
diff --git a/test/mocks/sandboxer_controller_mock.h b/test/mocks/sandboxer_controller_mock.h
|
|
new file mode 100644
|
|
index 00000000..be0f4016
|
|
--- /dev/null
|
|
+++ b/test/mocks/sandboxer_controller_mock.h
|
|
@@ -0,0 +1,52 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
+ * iSulad licensed under the Mulan PSL v2.
|
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
|
+ * http://license.coscl.org.cn/MulanPSL2
|
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
+ * PURPOSE.
|
|
+ * See the Mulan PSL v2 for more details.
|
|
+ * Author: jikai
|
|
+ * Create: 2023-10-20
|
|
+ * Description: provide sandboxer controller mock
|
|
+ ******************************************************************************/
|
|
+
|
|
+#ifndef _ISULAD_TEST_MOCKS_SANDBOXER_CONTROLLER_MOCK_H
|
|
+#define _ISULAD_TEST_MOCKS_SANDBOXER_CONTROLLER_MOCK_H
|
|
+
|
|
+#include <gmock/gmock.h>
|
|
+#include <memory>
|
|
+
|
|
+#include "sandboxer_controller.h"
|
|
+
|
|
+namespace sandbox {
|
|
+
|
|
+class MockSandboxerController {
|
|
+public:
|
|
+ MockSandboxerController() = default;
|
|
+ virtual ~MockSandboxerController() = default;
|
|
+
|
|
+ MOCK_METHOD1(Init, bool(Errors &error));
|
|
+ MOCK_METHOD3(Create, bool(const std::string &sandboxId,
|
|
+ const ControllerCreateParams ¶ms,
|
|
+ Errors &error));
|
|
+ MOCK_METHOD2(Start, std::unique_ptr<ControllerSandboxInfo>(const std::string &sandboxId, Errors &error));
|
|
+ MOCK_METHOD2(Platform, std::unique_ptr<ControllerPlatformInfo>(const std::string &sandboxId, Errors &error));
|
|
+ MOCK_METHOD3(Update, bool(sandbox_sandbox *apiSandbox,
|
|
+ string_array *fields, Errors &error));
|
|
+ MOCK_METHOD3(Stop, bool(const std::string &sandboxId, uint32_t timeoutSecs, Errors &error));
|
|
+ MOCK_METHOD3(Wait, bool(std::shared_ptr<SandboxStatusCallback> cb, const std::string &sandboxId, Errors &error));
|
|
+ MOCK_METHOD3(Status, std::unique_ptr<ControllerSandboxStatus>(const std::string &sandboxId, bool verbose,
|
|
+ Errors &error));
|
|
+ MOCK_METHOD2(Shutdown, bool(const std::string &sandboxId, Errors &error));
|
|
+ MOCK_METHOD3(UpdateNetworkSettings, bool(const std::string &sandboxId, const std::string &networkSettings,
|
|
+ Errors &error));
|
|
+};
|
|
+
|
|
+void MockSandboxerController_SetMock(std::shared_ptr<MockSandboxerController> mock);
|
|
+
|
|
+}
|
|
+
|
|
+#endif
|
|
\ No newline at end of file
|
|
diff --git a/test/mocks/sandboxer_sandbox_mock.cc b/test/mocks/sandboxer_sandbox_mock.cc
|
|
new file mode 100644
|
|
index 00000000..cce58842
|
|
--- /dev/null
|
|
+++ b/test/mocks/sandboxer_sandbox_mock.cc
|
|
@@ -0,0 +1,72 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
+ * iSulad licensed under the Mulan PSL v2.
|
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
|
+ * http://license.coscl.org.cn/MulanPSL2
|
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
+ * PURPOSE.
|
|
+ * See the Mulan PSL v2 for more details.
|
|
+ * Author: liuxu
|
|
+ * Create: 2024-11-21
|
|
+ * Description: provide sandbox mock
|
|
+ ******************************************************************************/
|
|
+
|
|
+#include <gmock/gmock.h>
|
|
+#include "sandboxer_sandbox_mock.h"
|
|
+
|
|
+namespace sandbox {
|
|
+MockSandboxerSandbox *g_sandboxer_sandbox_mock = nullptr;
|
|
+
|
|
+SandboxerSandbox::SandboxerSandbox(const std::string id, const std::string &rootdir, const std::string &statedir, const std::string name,
|
|
+ const RuntimeInfo info, std::string netMode, std::string netNsPath, const runtime::v1::PodSandboxConfig sandboxConfig,
|
|
+ std::string image):Sandbox(id, rootdir, statedir, name, info, netMode,
|
|
+ netNsPath, sandboxConfig, image)
|
|
+{
|
|
+}
|
|
+
|
|
+void MockSandboxerSandbox_SetMock(MockSandboxerSandbox *mock)
|
|
+{
|
|
+ g_sandboxer_sandbox_mock = mock;
|
|
+}
|
|
+
|
|
+void SandboxerSandbox::LoadSandboxTasks() {}
|
|
+
|
|
+auto SandboxerSandbox::SaveSandboxTasks() -> bool
|
|
+{
|
|
+ if (g_sandboxer_sandbox_mock != nullptr) {
|
|
+ return g_sandboxer_sandbox_mock->SaveSandboxTasks();
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+auto SandboxerSandbox::AddSandboxTasks(sandbox_task *task) -> bool
|
|
+{
|
|
+ if (g_sandboxer_sandbox_mock != nullptr) {
|
|
+ return g_sandboxer_sandbox_mock->AddSandboxTasks(task);
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+auto SandboxerSandbox::GetAnySandboxTasks() -> std::string
|
|
+{
|
|
+ if (g_sandboxer_sandbox_mock != nullptr) {
|
|
+ return g_sandboxer_sandbox_mock->GetAnySandboxTasks();
|
|
+ }
|
|
+ return std::string("Nothing for sandboxer.");
|
|
+}
|
|
+
|
|
+void SandboxerSandbox::DeleteSandboxTasks(const char *containerId) {}
|
|
+
|
|
+auto SandboxerSandbox::AddSandboxTasksProcess(const char *containerId, sandbox_process *processes) -> bool
|
|
+{
|
|
+ if (g_sandboxer_sandbox_mock != nullptr) {
|
|
+ return g_sandboxer_sandbox_mock->AddSandboxTasksProcess(containerId, processes);
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+void SandboxerSandbox::DeleteSandboxTasksProcess(const char *containerId, const char *execId) {}
|
|
+
|
|
+}
|
|
\ No newline at end of file
|
|
diff --git a/test/mocks/sandboxer_sandbox_mock.h b/test/mocks/sandboxer_sandbox_mock.h
|
|
new file mode 100644
|
|
index 00000000..4f76e5fc
|
|
--- /dev/null
|
|
+++ b/test/mocks/sandboxer_sandbox_mock.h
|
|
@@ -0,0 +1,43 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
+ * iSulad licensed under the Mulan PSL v2.
|
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
|
+ * http://license.coscl.org.cn/MulanPSL2
|
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
+ * PURPOSE.
|
|
+ * See the Mulan PSL v2 for more details.
|
|
+ * Author: liuxu
|
|
+ * Create: 2024-11-21
|
|
+ * Description: provide sandbox mock
|
|
+ ******************************************************************************/
|
|
+
|
|
+#ifndef _ISULAD_TEST_MOCKS_SANDBOXER_SANDBOX_MOCK_H
|
|
+#define _ISULAD_TEST_MOCKS_SANDBOXER_SANDBOX_MOCK_H
|
|
+
|
|
+#include <gmock/gmock.h>
|
|
+#include "sandbox_mock.h"
|
|
+#include "sandboxer_sandbox.h"
|
|
+
|
|
+namespace sandbox {
|
|
+
|
|
+class MockSandboxerSandbox : public MockSandbox {
|
|
+public:
|
|
+ MockSandboxerSandbox() = default;
|
|
+ virtual ~MockSandboxerSandbox() = default;
|
|
+
|
|
+ MOCK_METHOD0(LoadSandboxTasks, void());
|
|
+ MOCK_METHOD0(SaveSandboxTasks, bool());
|
|
+ MOCK_METHOD1(AddSandboxTasks, bool(sandbox_task *task));
|
|
+ MOCK_METHOD0(GetAnySandboxTasks, std::string());
|
|
+ MOCK_METHOD1(DeleteSandboxTasks, void(const char *containerId));
|
|
+ MOCK_METHOD2(AddSandboxTasksProcess, bool(const char *containerId, sandbox_process *processes));
|
|
+ MOCK_METHOD2(DeleteSandboxTasksProcess, void(const char *containerId, const char *execId));
|
|
+};
|
|
+
|
|
+void MockSandboxerSandbox_SetMock(MockSandboxerSandbox *mock);
|
|
+
|
|
+}
|
|
+
|
|
+#endif
|
|
diff --git a/test/mocks/shim_controller_mock.cc b/test/mocks/shim_controller_mock.cc
|
|
index e0ffc563..d9067e22 100644
|
|
--- a/test/mocks/shim_controller_mock.cc
|
|
+++ b/test/mocks/shim_controller_mock.cc
|
|
@@ -39,13 +39,6 @@ bool ShimController::Init(Errors &error)
|
|
return true;
|
|
}
|
|
|
|
-void ShimController::Destroy()
|
|
-{
|
|
- if (g_shim_controller_mock != nullptr) {
|
|
- g_shim_controller_mock->Destroy();
|
|
- }
|
|
-}
|
|
-
|
|
bool ShimController::Create(const std::string &sandboxId,
|
|
const ControllerCreateParams ¶ms,
|
|
Errors &error)
|
|
@@ -72,33 +65,10 @@ std::unique_ptr<ControllerPlatformInfo> ShimController::Platform(const std::stri
|
|
return nullptr;
|
|
}
|
|
|
|
-std::string ShimController::Prepare(const std::string &sandboxId,
|
|
- const ControllerPrepareParams ¶ms,
|
|
- Errors &error)
|
|
-{
|
|
- if (g_shim_controller_mock != nullptr) {
|
|
- return g_shim_controller_mock->Prepare(sandboxId, params, error);
|
|
- }
|
|
- return "";
|
|
-}
|
|
-
|
|
-bool ShimController::Purge(const std::string &sandboxId, const std::string &containerId,
|
|
- const std::string &execId, Errors &error)
|
|
+bool ShimController::Update(sandbox_sandbox *apiSandbox,
|
|
+ string_array *fields, Errors &error)
|
|
{
|
|
- if (g_shim_controller_mock != nullptr) {
|
|
- return g_shim_controller_mock->Purge(sandboxId, containerId, execId, error);
|
|
- }
|
|
- return true;
|
|
-}
|
|
-
|
|
-bool ShimController::UpdateResources(const std::string &sandboxId,
|
|
- const ControllerUpdateResourcesParams ¶ms,
|
|
- Errors &error)
|
|
-{
|
|
- if (g_shim_controller_mock != nullptr) {
|
|
- return g_shim_controller_mock->UpdateResources(sandboxId, params, error);
|
|
- }
|
|
- return true;
|
|
+ return g_shim_controller_mock->Update(apiSandbox, fields, error);
|
|
}
|
|
|
|
bool ShimController::Stop(const std::string &sandboxId, uint32_t timeoutSecs, Errors &error)
|
|
diff --git a/test/mocks/shim_controller_mock.h b/test/mocks/shim_controller_mock.h
|
|
index 6d0de591..d3a1d0a5 100644
|
|
--- a/test/mocks/shim_controller_mock.h
|
|
+++ b/test/mocks/shim_controller_mock.h
|
|
@@ -29,20 +29,13 @@ public:
|
|
virtual ~MockShimController() = default;
|
|
|
|
MOCK_METHOD1(Init, bool(Errors &error));
|
|
- MOCK_METHOD0(Destroy, void());
|
|
MOCK_METHOD3(Create, bool(const std::string &sandboxId,
|
|
const ControllerCreateParams ¶ms,
|
|
Errors &error));
|
|
MOCK_METHOD2(Start, std::unique_ptr<ControllerSandboxInfo>(const std::string &sandboxId, Errors &error));
|
|
MOCK_METHOD2(Platform, std::unique_ptr<ControllerPlatformInfo>(const std::string &sandboxId, Errors &error));
|
|
- MOCK_METHOD3(Prepare, std::string(const std::string &sandboxId,
|
|
- const ControllerPrepareParams ¶ms,
|
|
- Errors &error));
|
|
- MOCK_METHOD4(Purge, bool(const std::string &sandboxId, const std::string &containerId,
|
|
- const std::string &execId, Errors &error));
|
|
- MOCK_METHOD3(UpdateResources, bool(const std::string &sandboxId,
|
|
- const ControllerUpdateResourcesParams ¶ms,
|
|
- Errors &error));
|
|
+ MOCK_METHOD3(Update, bool(sandbox_sandbox *apiSandbox,
|
|
+ string_array *fields, Errors &error));
|
|
MOCK_METHOD3(Stop, bool(const std::string &sandboxId, uint32_t timeoutSecs, Errors &error));
|
|
MOCK_METHOD3(Wait, bool(std::shared_ptr<SandboxStatusCallback> cb, const std::string &sandboxId, Errors &error));
|
|
MOCK_METHOD3(Status, std::unique_ptr<ControllerSandboxStatus>(const std::string &sandboxId, bool verbose,
|
|
diff --git a/test/mocks/shim_sandbox_mock.cc b/test/mocks/shim_sandbox_mock.cc
|
|
new file mode 100644
|
|
index 00000000..ccefb424
|
|
--- /dev/null
|
|
+++ b/test/mocks/shim_sandbox_mock.cc
|
|
@@ -0,0 +1,72 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
+ * iSulad licensed under the Mulan PSL v2.
|
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
|
+ * http://license.coscl.org.cn/MulanPSL2
|
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
+ * PURPOSE.
|
|
+ * See the Mulan PSL v2 for more details.
|
|
+ * Author: liuxu
|
|
+ * Create: 2024-11-21
|
|
+ * Description: provide sandbox mock
|
|
+ ******************************************************************************/
|
|
+
|
|
+#include <gmock/gmock.h>
|
|
+#include "shim_sandbox_mock.h"
|
|
+
|
|
+namespace sandbox {
|
|
+MockShimSandbox *g_shim_sandbox_mock = nullptr;
|
|
+
|
|
+ShimSandbox::ShimSandbox(const std::string id, const std::string &rootdir, const std::string &statedir, const std::string name,
|
|
+ const RuntimeInfo info, std::string netMode, std::string netNsPath, const runtime::v1::PodSandboxConfig sandboxConfig,
|
|
+ std::string image):Sandbox(id, rootdir, statedir, name, info, netMode,
|
|
+ netNsPath, sandboxConfig, image)
|
|
+{
|
|
+}
|
|
+
|
|
+void MockShimSandbox_SetMock(MockShimSandbox *mock)
|
|
+{
|
|
+ g_shim_sandbox_mock = mock;
|
|
+}
|
|
+
|
|
+void ShimSandbox::LoadSandboxTasks() {}
|
|
+
|
|
+auto ShimSandbox::SaveSandboxTasks() -> bool
|
|
+{
|
|
+ if (g_shim_sandbox_mock != nullptr) {
|
|
+ return g_shim_sandbox_mock->SaveSandboxTasks();
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+auto ShimSandbox::AddSandboxTasks(sandbox_task *task) -> bool
|
|
+{
|
|
+ if (g_shim_sandbox_mock != nullptr) {
|
|
+ return g_shim_sandbox_mock->AddSandboxTasks(task);
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+auto ShimSandbox::GetAnySandboxTasks() -> std::string
|
|
+{
|
|
+ if (g_shim_sandbox_mock != nullptr) {
|
|
+ return g_shim_sandbox_mock->GetAnySandboxTasks();
|
|
+ }
|
|
+ return std::string("Nothing for shim.");
|
|
+}
|
|
+
|
|
+void ShimSandbox::DeleteSandboxTasks(const char *containerId) {}
|
|
+
|
|
+auto ShimSandbox::AddSandboxTasksProcess(const char *containerId, sandbox_process *processes) -> bool
|
|
+{
|
|
+ if (g_shim_sandbox_mock != nullptr) {
|
|
+ return g_shim_sandbox_mock->AddSandboxTasksProcess(containerId, processes);
|
|
+ }
|
|
+ return true;
|
|
+}
|
|
+
|
|
+void ShimSandbox::DeleteSandboxTasksProcess(const char *containerId, const char *execId) {}
|
|
+
|
|
+}
|
|
\ No newline at end of file
|
|
diff --git a/test/mocks/shim_sandbox_mock.h b/test/mocks/shim_sandbox_mock.h
|
|
new file mode 100644
|
|
index 00000000..1b16a4cc
|
|
--- /dev/null
|
|
+++ b/test/mocks/shim_sandbox_mock.h
|
|
@@ -0,0 +1,43 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
+ * iSulad licensed under the Mulan PSL v2.
|
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
|
+ * http://license.coscl.org.cn/MulanPSL2
|
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
+ * PURPOSE.
|
|
+ * See the Mulan PSL v2 for more details.
|
|
+ * Author: liuxu
|
|
+ * Create: 2024-11-21
|
|
+ * Description: provide sandbox mock
|
|
+ ******************************************************************************/
|
|
+
|
|
+#ifndef _ISULAD_TEST_MOCKS_SHIM_SANDBOX_MOCK_H
|
|
+#define _ISULAD_TEST_MOCKS_SHIM_SANDBOX_MOCK_H
|
|
+
|
|
+#include <gmock/gmock.h>
|
|
+#include "sandbox_mock.h"
|
|
+#include "shim_sandbox.h"
|
|
+
|
|
+namespace sandbox {
|
|
+
|
|
+class MockShimSandbox : public MockSandbox {
|
|
+public:
|
|
+ MockShimSandbox() = default;
|
|
+ virtual ~MockShimSandbox() = default;
|
|
+
|
|
+ MOCK_METHOD0(LoadSandboxTasks, void());
|
|
+ MOCK_METHOD0(SaveSandboxTasks, bool());
|
|
+ MOCK_METHOD1(AddSandboxTasks, bool(sandbox_task *task));
|
|
+ MOCK_METHOD0(GetAnySandboxTasks, std::string());
|
|
+ MOCK_METHOD1(DeleteSandboxTasks, void(const char *containerId));
|
|
+ MOCK_METHOD2(AddSandboxTasksProcess, bool(const char *containerId, sandbox_process *processes));
|
|
+ MOCK_METHOD2(DeleteSandboxTasksProcess, void(const char *containerId, const char *execId));
|
|
+};
|
|
+
|
|
+void MockShimSandbox_SetMock(MockShimSandbox *mock);
|
|
+
|
|
+}
|
|
+
|
|
+#endif
|
|
diff --git a/test/sandbox/controller/CMakeLists.txt b/test/sandbox/controller/CMakeLists.txt
|
|
index 0ba23735..d201872b 100644
|
|
--- a/test/sandbox/controller/CMakeLists.txt
|
|
+++ b/test/sandbox/controller/CMakeLists.txt
|
|
@@ -1,7 +1,5 @@
|
|
project(iSulad_UT)
|
|
|
|
-aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox/types grpc_sandbox_type_srcs)
|
|
-list(APPEND grpc_sandbox_type_srcs ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox.pb.cc)
|
|
list(APPEND grpc_sandbox_type_srcs ${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1/api_v1.pb.cc)
|
|
list(APPEND grpc_sandbox_type_srcs ${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/gogo.pb.cc)
|
|
add_subdirectory(sandboxer)
|
|
diff --git a/test/sandbox/controller/controller_common.cc b/test/sandbox/controller/controller_common.cc
|
|
index 5f870c34..8621dfd9 100644
|
|
--- a/test/sandbox/controller/controller_common.cc
|
|
+++ b/test/sandbox/controller/controller_common.cc
|
|
@@ -14,6 +14,7 @@
|
|
******************************************************************************/
|
|
|
|
#include "controller_common.h"
|
|
+#include "utils.h"
|
|
|
|
std::unique_ptr<sandbox::ControllerMountInfo> CreateTestMountInfo()
|
|
{
|
|
@@ -43,24 +44,40 @@ std::unique_ptr<sandbox::ControllerStreamInfo> CreateTestStreamInfo()
|
|
return streamInfo;
|
|
}
|
|
|
|
-std::unique_ptr<sandbox::ControllerPrepareParams> CreateTestPrepareParams()
|
|
+std::unique_ptr<CStructWrapper<sandbox_sandbox>> CreateTestUpdateApiSandbox()
|
|
{
|
|
- std::unique_ptr<sandbox::ControllerPrepareParams> params(new sandbox::ControllerPrepareParams());
|
|
- params->containerId = DUMMY_CONTAINER_ID;
|
|
- params->execId = DUMMY_EXEC_ID;
|
|
- params->spec = std::unique_ptr<std::string>(new std::string("{spec: test}"));
|
|
- params->rootfs.push_back(std::move(CreateTestMountInfo()));
|
|
- params->rootfs.push_back(std::move(CreateTestMountInfo()));
|
|
- params->streamInfo = CreateTestStreamInfo();
|
|
- return params;
|
|
+ sandbox_sandbox *apiSandbox = nullptr;
|
|
+
|
|
+ auto apiSandbox_wrapper = makeUniquePtrCStructWrapper<sandbox_sandbox>(free_sandbox_sandbox);
|
|
+ if (apiSandbox_wrapper == nullptr) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ apiSandbox = apiSandbox_wrapper->get();
|
|
+
|
|
+ apiSandbox->sandbox_id = util_strdup_s(DUMMY_SANDBOX_ID.c_str());
|
|
+ apiSandbox->sandboxer = util_strdup_s(DUMMY_SANDBOXER.c_str());
|
|
+
|
|
+ return apiSandbox_wrapper;
|
|
}
|
|
|
|
-std::unique_ptr<sandbox::ControllerUpdateResourcesParams> CreateTestUpdateResourcesParams(
|
|
- google::protobuf::Map<std::string, std::string> &annotations)
|
|
+std::unique_ptr<CStructWrapper<string_array>> CreateTestFields()
|
|
{
|
|
- std::unique_ptr<std::string> resources(new std::string("{cpu: 12}"));
|
|
- std::unique_ptr<sandbox::ControllerUpdateResourcesParams> params(
|
|
- new sandbox::ControllerUpdateResourcesParams{DUMMY_SANDBOX_ID, std::move(resources), annotations}
|
|
- );
|
|
- return params;
|
|
-}
|
|
+ size_t fields_len = 1;
|
|
+ string_array *fields = nullptr;
|
|
+
|
|
+ auto fields_wrapper = makeUniquePtrCStructWrapper<string_array>(util_free_string_array);
|
|
+ if (fields_wrapper == nullptr) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ fields = fields_wrapper->get();
|
|
+
|
|
+ fields = util_string_array_new(fields_len);
|
|
+ if (fields == nullptr) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ if (util_append_string_array(fields, DUMMY_SANDBOX_EXTENSIONS_TASKS.c_str())) {
|
|
+ return nullptr;
|
|
+ }
|
|
+
|
|
+ return fields_wrapper;
|
|
+}
|
|
\ No newline at end of file
|
|
diff --git a/test/sandbox/controller/controller_common.h b/test/sandbox/controller/controller_common.h
|
|
index c01ae83c..b41f24e2 100644
|
|
--- a/test/sandbox/controller/controller_common.h
|
|
+++ b/test/sandbox/controller/controller_common.h
|
|
@@ -16,6 +16,8 @@
|
|
#ifndef _ISULAD_TEST_SANDBOX_CONTROLLER_CONTROLLER_COMMON_H
|
|
#define _ISULAD_TEST_SANDBOX_CONTROLLER_CONTROLLER_COMMON_H
|
|
#include "controller.h"
|
|
+#include "cstruct_wrapper.h"
|
|
+#include "utils_array.h"
|
|
|
|
const std::string DUMMY_SANDBOX_ID = "604db93a33ec4c7787e4f369338f5887";
|
|
const std::string DUMMY_CONTAINER_ID = "504db93a32ec4c9789e4d369a38f3889";
|
|
@@ -24,6 +26,8 @@ const uint64_t SECOND_TO_NANOS = 1000000000;
|
|
const uint64_t DUMMY_CREATE_AT = 1588 * SECOND_TO_NANOS + 1588;
|
|
const uint64_t DUMMY_EXITED_AT = 1688 * SECOND_TO_NANOS + 1588;
|
|
const std::string DUMMY_TASK_ADDRESS = "vsock://18982:1";
|
|
+const std::string DUMMY_SANDBOXER = "vmm";
|
|
+const std::string DUMMY_SANDBOX_EXTENSIONS_TASKS = "extensions.tasks";
|
|
|
|
std::unique_ptr<sandbox::ControllerMountInfo> CreateTestMountInfo();
|
|
|
|
@@ -31,9 +35,8 @@ std::unique_ptr<sandbox::ControllerCreateParams> CreateTestCreateParams();
|
|
|
|
std::unique_ptr<sandbox::ControllerStreamInfo> CreateTestStreamInfo();
|
|
|
|
-std::unique_ptr<sandbox::ControllerPrepareParams> CreateTestPrepareParams();
|
|
+std::unique_ptr<CStructWrapper<sandbox_sandbox>> CreateTestUpdateApiSandbox();
|
|
|
|
-std::unique_ptr<sandbox::ControllerUpdateResourcesParams> CreateTestUpdateResourcesParams(
|
|
- google::protobuf::Map<std::string, std::string> &annotations);
|
|
+std::unique_ptr<CStructWrapper<string_array>> CreateTestFields();
|
|
|
|
#endif // _ISULAD_TEST_SANDBOX_CONTROLLER_CONTROLLER_COMMON_H
|
|
\ No newline at end of file
|
|
diff --git a/test/sandbox/controller/manager/CMakeLists.txt b/test/sandbox/controller/manager/CMakeLists.txt
|
|
index 6e8c9052..1d8ca372 100644
|
|
--- a/test/sandbox/controller/manager/CMakeLists.txt
|
|
+++ b/test/sandbox/controller/manager/CMakeLists.txt
|
|
@@ -4,14 +4,12 @@ SET(EXE controller_manager_ut)
|
|
|
|
add_executable(${EXE}
|
|
${grpc_sandbox_type_srcs}
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox.pb.cc
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1/api_v1.pb.cc
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/gogo.pb.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cpputils/errors.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/controller/sandboxer/sandboxer_controller.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/controller/controller_manager.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/sandboxer/controller/sandboxer_controller.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/controller_manager.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../test/mocks/grpc_sandboxer_client_mock.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../test/mocks/controller_stub_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../test/mocks/isulad_config_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../test/mocks/shim_controller_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../test/sandbox/controller/controller_common.cc
|
|
@@ -25,10 +23,11 @@ target_include_directories(${EXE} PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/config
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/entry/cri
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/executor
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/controller
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/controller/sandboxer
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/controller/sandboxer/client
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/controller/shim
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/sandboxer
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/sandboxer/controller
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/sandboxer/controller/client
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/shim/controller
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/common
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/map
|
|
diff --git a/test/sandbox/controller/sandboxer/CMakeLists.txt b/test/sandbox/controller/sandboxer/CMakeLists.txt
|
|
index e77c2e6d..11689cae 100644
|
|
--- a/test/sandbox/controller/sandboxer/CMakeLists.txt
|
|
+++ b/test/sandbox/controller/sandboxer/CMakeLists.txt
|
|
@@ -2,4 +2,3 @@ project(iSulad_UT)
|
|
|
|
add_subdirectory(sandboxer_client)
|
|
add_subdirectory(sandboxer_controller)
|
|
-add_subdirectory(async_wait_call)
|
|
diff --git a/test/sandbox/controller/sandboxer/async_wait_call/CMakeLists.txt b/test/sandbox/controller/sandboxer/async_wait_call/CMakeLists.txt
|
|
deleted file mode 100644
|
|
index 0631988a..00000000
|
|
--- a/test/sandbox/controller/sandboxer/async_wait_call/CMakeLists.txt
|
|
+++ /dev/null
|
|
@@ -1,37 +0,0 @@
|
|
-project(iSulad_UT)
|
|
-
|
|
-SET(EXE sandboxer_client_async_wait_call_ut)
|
|
-
|
|
-add_executable(${EXE}
|
|
- ${grpc_sandbox_type_srcs}
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller/sandboxer/client/grpc_async_wait_call.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller/sandboxer/client/grpc_client_utils.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cpputils/errors.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/mocks/controller_stub_mock.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/async_wait_call_ut.cc)
|
|
-
|
|
-target_include_directories(${EXE} PUBLIC
|
|
- ${GTEST_INCLUDE_DIR}
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/sandbox/controller
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/sandbox/controller/sandboxer/async_wait_call
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/mocks
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/entry/cri
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller/sandboxer
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller/sandboxer/client
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/common
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cutils
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cutils/map
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/sha256
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cpputils
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/cri
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/google/protobuf
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox/types
|
|
-)
|
|
-
|
|
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lgrpc -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
|
|
-target_link_libraries(${EXE} -Wl,--as-needed ${ISULAD_ABSL_USED_TARGETS})
|
|
-add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
|
-set_tests_properties(${EXE} PROPERTIES TIMEOUT 120)
|
|
diff --git a/test/sandbox/controller/sandboxer/async_wait_call/async_wait_call_ut.cc b/test/sandbox/controller/sandboxer/async_wait_call/async_wait_call_ut.cc
|
|
deleted file mode 100644
|
|
index 1a58344c..00000000
|
|
--- a/test/sandbox/controller/sandboxer/async_wait_call/async_wait_call_ut.cc
|
|
+++ /dev/null
|
|
@@ -1,115 +0,0 @@
|
|
-/******************************************************************************
|
|
- * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
- * iSulad licensed under the Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
- * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
- * PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- * Author: xuxuepeng
|
|
- * Create: 2023-08-01
|
|
- * Description: Async wait call UT
|
|
- ******************************************************************************/
|
|
-
|
|
-#include "gtest/gtest.h"
|
|
-#include "grpc_async_wait_call.h"
|
|
-#include "dummy_monitor_utils.h"
|
|
-#include "controller_stub_mock.h"
|
|
-#include "grpc_client_utils.h"
|
|
-#include "controller.h"
|
|
-
|
|
-class SandboxerAsyncWaitCallWrapper : public sandbox::SandboxerAsyncWaitCall {
|
|
-public:
|
|
- SandboxerAsyncWaitCallWrapper(std::shared_ptr<sandbox::SandboxStatusCallback> cb,
|
|
- const std::string &sandboxId, const std::string &sandboxer)
|
|
- : sandbox::SandboxerAsyncWaitCall(cb, sandboxId, sandboxer) {}
|
|
- ~SandboxerAsyncWaitCallWrapper() = default;
|
|
-
|
|
- grpc::ClientAsyncResponseReaderInterface<containerd::services::sandbox::v1::ControllerWaitResponse> &GetReader()
|
|
- {
|
|
- return *m_responseReader;
|
|
- }
|
|
-};
|
|
-
|
|
-class AsyncWaitCallTest : public testing::Test {
|
|
-protected:
|
|
- void SetUp() override
|
|
- {
|
|
- m_sandboxId = "8040f13d54889ad4cd";
|
|
- m_sandboxer = "test_sandboxer";
|
|
- m_callback = std::shared_ptr<DummyCallback>(new DummyCallback());
|
|
- m_call = std::unique_ptr<sandbox::SandboxerAsyncWaitCall>(new sandbox::SandboxerAsyncWaitCall(m_callback, m_sandboxId,
|
|
- m_sandboxer));
|
|
- m_stub = std::unique_ptr<DummyControllerStub>(NewDummyControllerStub());
|
|
- m_stub_mock = std::make_shared<MockControllerStub>();
|
|
- MockControllerStub_SetMock(m_stub_mock);
|
|
- }
|
|
-
|
|
- void TearDown() override
|
|
- {
|
|
- MockControllerStub_SetMock(nullptr);
|
|
- }
|
|
-
|
|
- std::string m_sandboxId;
|
|
- std::string m_sandboxer;
|
|
- std::shared_ptr<DummyCallback> m_callback;
|
|
- std::unique_ptr<sandbox::SandboxerAsyncWaitCall> m_call;
|
|
- std::unique_ptr<DummyControllerStub> m_stub;
|
|
- std::shared_ptr<MockControllerStub> m_stub_mock;
|
|
- grpc::CompletionQueue m_cq;
|
|
-};
|
|
-
|
|
-TEST_F(AsyncWaitCallTest, CallStatusOK)
|
|
-{
|
|
- auto reader = new DummyClientAsyncResponseReader();
|
|
- auto timestamp = google::protobuf::Timestamp();
|
|
- timestamp.set_seconds(123456);
|
|
- reader->SetExitAt(timestamp);
|
|
- reader->SetExitStatus(1);
|
|
- reader->SetStatus(grpc::Status::OK);
|
|
- EXPECT_CALL(*m_stub_mock, PrepareAsyncWaitRaw).WillOnce(testing::Return(reader));
|
|
- EXPECT_TRUE(m_call->Call(*m_stub, m_cq));
|
|
- EXPECT_EQ(m_call->HandleResponse(), sandbox::SANDBOXER_ASYNC_WAIT_STATUS_OK);
|
|
- EXPECT_EQ(m_callback->GetStatus(), ASYNC_WAIT_CALL_STATUS_EXIT);
|
|
- EXPECT_EQ(m_callback->GetExitStatus(), 1);
|
|
- EXPECT_EQ(m_callback->GetExitedAt(), TimestampToNanos(timestamp));
|
|
-}
|
|
-
|
|
-TEST_F(AsyncWaitCallTest, CallStatusError)
|
|
-{
|
|
- auto reader = new DummyClientAsyncResponseReader();
|
|
- reader->SetStatus(grpc::Status(grpc::StatusCode::PERMISSION_DENIED, "Permission denied"));
|
|
- EXPECT_CALL(*m_stub_mock, PrepareAsyncWaitRaw).WillOnce(testing::Return(reader));
|
|
- EXPECT_TRUE(m_call->Call(*m_stub, m_cq));
|
|
- EXPECT_EQ(m_call->HandleResponse(), sandbox::SANDBOXER_ASYNC_WAIT_STATUS_ERROR);
|
|
- EXPECT_EQ(m_callback->GetStatus(), ASYNC_WAIT_CALL_STATUS_EXIT);
|
|
-}
|
|
-
|
|
-TEST_F(AsyncWaitCallTest, CallStatusNotFound)
|
|
-{
|
|
- auto reader = new DummyClientAsyncResponseReader();
|
|
- reader->SetStatus(grpc::Status(grpc::StatusCode::NOT_FOUND, "Not found"));
|
|
- EXPECT_CALL(*m_stub_mock, PrepareAsyncWaitRaw).WillOnce(testing::Return(reader));
|
|
- EXPECT_TRUE(m_call->Call(*m_stub, m_cq));
|
|
- EXPECT_EQ(m_call->HandleResponse(), sandbox::SANDBOXER_ASYNC_WAIT_STATUS_NOT_FOUND);
|
|
- EXPECT_EQ(m_callback->GetStatus(), ASYNC_WAIT_CALL_STATUS_EXIT);
|
|
-}
|
|
-
|
|
-TEST_F(AsyncWaitCallTest, CallStatusUnavailable)
|
|
-{
|
|
- auto reader = new DummyClientAsyncResponseReader();
|
|
- reader->SetStatus(grpc::Status(grpc::StatusCode::UNAVAILABLE, "Unavailable"));
|
|
- EXPECT_CALL(*m_stub_mock, PrepareAsyncWaitRaw).WillOnce(testing::Return(reader));
|
|
- EXPECT_TRUE(m_call->Call(*m_stub, m_cq));
|
|
- EXPECT_EQ(m_call->HandleResponse(), sandbox::SANDBOXER_ASYNC_WAIT_STATUS_RETRY);
|
|
- EXPECT_EQ(m_callback->GetStatus(), ASYNC_WAIT_CALL_STATUS_PENDING);
|
|
-}
|
|
-
|
|
-TEST_F(AsyncWaitCallTest, CallStatusPrepareAsyncWaitFailed)
|
|
-{
|
|
- EXPECT_CALL(*m_stub_mock, PrepareAsyncWaitRaw).WillOnce(testing::Return(nullptr));
|
|
- EXPECT_FALSE(m_call->Call(*m_stub, m_cq));
|
|
- EXPECT_EQ(m_callback->GetStatus(), ASYNC_WAIT_CALL_STATUS_EXIT);
|
|
-}
|
|
diff --git a/test/sandbox/controller/sandboxer/async_wait_call/dummy_monitor_utils.h b/test/sandbox/controller/sandboxer/async_wait_call/dummy_monitor_utils.h
|
|
deleted file mode 100644
|
|
index 7e98d844..00000000
|
|
--- a/test/sandbox/controller/sandboxer/async_wait_call/dummy_monitor_utils.h
|
|
+++ /dev/null
|
|
@@ -1,121 +0,0 @@
|
|
-/******************************************************************************
|
|
- * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
|
- * iSulad licensed under the Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
- * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
- * PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- * Author: xuxuepeng
|
|
- * Create: 2023-08-01
|
|
- * Description: provide dummy class definition for monitor unit tests
|
|
- *********************************************************************************/
|
|
-
|
|
-#ifndef DUMMY_MONITOR_UTILS_H_
|
|
-#define DUMMY_MONITOR_UTILS_H_
|
|
-
|
|
-#include "sandbox.pb.h"
|
|
-#include "sandbox.grpc.pb.h"
|
|
-
|
|
-#include "controller.h"
|
|
-
|
|
-class DummyClientAsyncResponseReader: public
|
|
- grpc::ClientAsyncResponseReaderInterface<containerd::services::sandbox::v1::ControllerWaitResponse> {
|
|
-public:
|
|
- DummyClientAsyncResponseReader() = default;
|
|
- ~DummyClientAsyncResponseReader() = default;
|
|
-
|
|
- void StartCall() override {}
|
|
-
|
|
- void ReadInitialMetadata(void *tag) override {}
|
|
-
|
|
- void Finish(containerd::services::sandbox::v1::ControllerWaitResponse *response, grpc::Status *status,
|
|
- void *tag) override
|
|
- {
|
|
- response->set_exit_status(m_exitStatus);
|
|
- response->mutable_exited_at()->CopyFrom(m_exitedAt);
|
|
- *status = m_status;
|
|
- m_tag = tag;
|
|
- }
|
|
-
|
|
- void SetExitAt(const google::protobuf::Timestamp &exitAt)
|
|
- {
|
|
- m_exitedAt = exitAt;
|
|
- }
|
|
-
|
|
- void SetExitStatus(uint32_t status)
|
|
- {
|
|
- m_exitStatus = status;
|
|
- }
|
|
-
|
|
- void SetStatus(grpc::Status status)
|
|
- {
|
|
- m_status = status;
|
|
- }
|
|
-
|
|
- void *GetTag()
|
|
- {
|
|
- return m_tag;
|
|
- }
|
|
-
|
|
-private:
|
|
- google::protobuf::Timestamp m_exitedAt;
|
|
- uint32_t m_exitStatus;
|
|
- containerd::services::sandbox::v1::ControllerWaitResponse *m_response;
|
|
- grpc::Status m_status;
|
|
- void *m_tag;
|
|
-};
|
|
-
|
|
-enum AsyncWaitCallStatus {
|
|
- ASYNC_WAIT_CALL_STATUS_UNKNOWN,
|
|
- ASYNC_WAIT_CALL_STATUS_READY,
|
|
- ASYNC_WAIT_CALL_STATUS_EXIT,
|
|
- ASYNC_WAIT_CALL_STATUS_PENDING,
|
|
-};
|
|
-
|
|
-class DummyCallback: public sandbox::SandboxStatusCallback {
|
|
-public:
|
|
- DummyCallback()
|
|
- {
|
|
- m_status = ASYNC_WAIT_CALL_STATUS_UNKNOWN;
|
|
- }
|
|
- ~DummyCallback() = default;
|
|
-
|
|
- void OnSandboxReady() override
|
|
- {
|
|
- m_status = ASYNC_WAIT_CALL_STATUS_READY;
|
|
- }
|
|
- void OnSandboxPending() override
|
|
- {
|
|
- m_status = ASYNC_WAIT_CALL_STATUS_PENDING;
|
|
- }
|
|
- void OnSandboxExit(const sandbox::ControllerExitInfo &exitInfo) override
|
|
- {
|
|
- m_status = ASYNC_WAIT_CALL_STATUS_EXIT;
|
|
- m_exitStatus = exitInfo.exitStatus;
|
|
- m_exitedAt = exitInfo.exitedAt;
|
|
- }
|
|
-
|
|
- AsyncWaitCallStatus GetStatus()
|
|
- {
|
|
- return m_status;
|
|
- }
|
|
-
|
|
- uint32_t GetExitStatus()
|
|
- {
|
|
- return m_exitStatus;
|
|
- }
|
|
-
|
|
- uint64_t GetExitedAt()
|
|
- {
|
|
- return m_exitedAt;
|
|
- }
|
|
-private:
|
|
- AsyncWaitCallStatus m_status;
|
|
- uint32_t m_exitStatus;
|
|
- uint64_t m_exitedAt;
|
|
-};
|
|
-
|
|
-#endif // DUMMY_MONITOR_UTILS_H_
|
|
\ No newline at end of file
|
|
diff --git a/test/sandbox/controller/sandboxer/sandboxer_client/CMakeLists.txt b/test/sandbox/controller/sandboxer/sandboxer_client/CMakeLists.txt
|
|
index 881797c6..3a136489 100644
|
|
--- a/test/sandbox/controller/sandboxer/sandboxer_client/CMakeLists.txt
|
|
+++ b/test/sandbox/controller/sandboxer/sandboxer_client/CMakeLists.txt
|
|
@@ -4,14 +4,11 @@ SET(EXE controller_sandboxer_client_ut)
|
|
|
|
add_executable(${EXE}
|
|
${grpc_sandbox_type_srcs}
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox.pb.cc
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox.grpc.pb.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller/sandboxer/client/grpc_sandboxer_client.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller/sandboxer/client/grpc_client_utils.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/sandboxer/controller/client/grpc_sandboxer_client.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cpputils/errors.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/mocks/controller_stub_mock.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/mocks/grpc_sandboxer_monitor_mock.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/mocks/grpc_async_wait_call_mock.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cpputils/transform.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/mocks/sandbox_manager_mock.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/mocks/rust_sandbox_api_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/sandbox/controller/controller_common.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/sandboxer_client_ut.cc)
|
|
|
|
@@ -19,10 +16,12 @@ target_include_directories(${EXE} PUBLIC
|
|
${GTEST_INCLUDE_DIR}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/sandbox/controller
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/mocks
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/config
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/entry/cri
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller/sandboxer
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller/sandboxer/client
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/sandboxer
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/sandboxer/controller
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/sandboxer/controller/client
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/common
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cutils
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cutils/map
|
|
@@ -30,9 +29,6 @@ target_include_directories(${EXE} PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cpputils
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/google/protobuf
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox/types
|
|
)
|
|
|
|
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lgrpc -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
|
|
diff --git a/test/sandbox/controller/sandboxer/sandboxer_client/sandboxer_client_ut.cc b/test/sandbox/controller/sandboxer/sandboxer_client/sandboxer_client_ut.cc
|
|
index 3b02d95d..019e777c 100644
|
|
--- a/test/sandbox/controller/sandboxer/sandboxer_client/sandboxer_client_ut.cc
|
|
+++ b/test/sandbox/controller/sandboxer/sandboxer_client/sandboxer_client_ut.cc
|
|
@@ -13,21 +13,16 @@
|
|
* Description: Sandboxer client UT
|
|
******************************************************************************/
|
|
|
|
+#include <isula_libutils/json_common.h>
|
|
+
|
|
#include "gtest/gtest.h"
|
|
-#include "controller_stub_mock.h"
|
|
#include "grpc_sandboxer_client.h"
|
|
+#include "grpc_sandboxer_client_mock.h"
|
|
+#include "rust_sandbox_api_mock.h"
|
|
+#include "sandbox_manager_mock.h"
|
|
#include "controller_common.h"
|
|
#include "controller.h"
|
|
-
|
|
-class SandboxerClientWrapper : public sandbox::SandboxerClient {
|
|
-public:
|
|
- SandboxerClientWrapper(const std::string &sandboxer, const std::string &address) : SandboxerClient(sandboxer, address)
|
|
- {
|
|
- m_stub = NewDummyControllerStub();
|
|
- }
|
|
-
|
|
- ~SandboxerClientWrapper() = default;
|
|
-};
|
|
+#include "utils.h"
|
|
|
|
class ControllerSandboxerClientTest : public testing::Test {
|
|
protected:
|
|
@@ -35,78 +30,38 @@ protected:
|
|
{
|
|
m_sandboxer = "sandboxer";
|
|
m_address = "/tmp/sandboxer.sock";
|
|
+ ControllerHandle_t handle_ptr = (ControllerHandle_t)(0x1); // just not nullptr
|
|
+
|
|
+ m_sandboxManagerMock = std::make_shared<MockSandboxManager>();
|
|
+ MockSandboxManager_SetMock(m_sandboxManagerMock);
|
|
+ m_rustSandboxApiMock = std::make_shared<RustSandboxApiMock>();
|
|
+ RustSandboxApiMock_SetMock(m_rustSandboxApiMock);
|
|
|
|
- m_sandboxerClient = std::make_shared<SandboxerClientWrapper>(m_sandboxer, m_address);
|
|
- m_stub = std::make_shared<MockControllerStub>();
|
|
- MockControllerStub_SetMock(m_stub);
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_build_controller).Times(1).WillOnce(testing::DoAll(testing::Return(handle_ptr)));
|
|
+ m_sandboxerClient = std::make_shared<SandboxerClient>(m_sandboxer, m_address);
|
|
}
|
|
|
|
void TearDown() override
|
|
{
|
|
- MockControllerStub_SetMock(nullptr);
|
|
+ MockSandboxManager_SetMock(nullptr);
|
|
+ RustSandboxApiMock_SetMock(nullptr);
|
|
}
|
|
|
|
std::string m_sandboxer;
|
|
std::string m_address;
|
|
-
|
|
- std::shared_ptr<MockControllerStub> m_stub;
|
|
- std::shared_ptr<SandboxerClientWrapper> m_sandboxerClient;
|
|
+ std::shared_ptr<SandboxerClient> m_sandboxerClient;
|
|
+ std::shared_ptr<MockSandboxManager> m_sandboxManagerMock = nullptr;
|
|
+ std::shared_ptr<RustSandboxApiMock> m_rustSandboxApiMock = nullptr;
|
|
};
|
|
|
|
-static std::unique_ptr<containerd::services::sandbox::v1::ControllerStartResponse> CreateTestGrpcStartResponse()
|
|
-{
|
|
- std::unique_ptr<containerd::services::sandbox::v1::ControllerStartResponse> response(
|
|
- new containerd::services::sandbox::v1::ControllerStartResponse());
|
|
- response->set_sandbox_id(DUMMY_SANDBOX_ID);
|
|
- response->set_pid(1);
|
|
- response->mutable_created_at()->set_seconds(DUMMY_CREATE_AT / SECOND_TO_NANOS);
|
|
- response->mutable_created_at()->set_nanos(DUMMY_CREATE_AT % SECOND_TO_NANOS);
|
|
- response->mutable_labels()->insert({"label1", "value1"});
|
|
- return response;
|
|
-}
|
|
-
|
|
-// Create platform response for test.
|
|
-static std::unique_ptr<containerd::services::sandbox::v1::ControllerPlatformResponse> CreateTestPlatformResponse()
|
|
-{
|
|
- std::unique_ptr<containerd::services::sandbox::v1::ControllerPlatformResponse> response(
|
|
- new containerd::services::sandbox::v1::ControllerPlatformResponse()
|
|
- );
|
|
- response->mutable_platform()->set_os("linux");
|
|
- response->mutable_platform()->set_architecture("amd64");
|
|
- response->mutable_platform()->set_variant("ubuntu");
|
|
- return response;
|
|
-}
|
|
-
|
|
-// Create status response for test
|
|
-static std::unique_ptr<containerd::services::sandbox::v1::ControllerStatusResponse> CreateTestStatusResponse()
|
|
-{
|
|
- std::unique_ptr<containerd::services::sandbox::v1::ControllerStatusResponse> response(
|
|
- new containerd::services::sandbox::v1::ControllerStatusResponse()
|
|
- );
|
|
- response->set_sandbox_id(DUMMY_SANDBOX_ID);
|
|
- response->set_state("running");
|
|
- response->set_pid(1);
|
|
- response->set_task_address(DUMMY_TASK_ADDRESS);
|
|
- response->mutable_created_at()->set_seconds(DUMMY_CREATE_AT / SECOND_TO_NANOS);
|
|
- response->mutable_created_at()->set_nanos(DUMMY_CREATE_AT % SECOND_TO_NANOS);
|
|
- response->mutable_exited_at()->set_seconds(DUMMY_CREATE_AT / SECOND_TO_NANOS);
|
|
- response->mutable_exited_at()->set_nanos(DUMMY_CREATE_AT % SECOND_TO_NANOS);
|
|
- response->mutable_info()->insert({"info1", "value1"});
|
|
- response->mutable_extra()->set_value("{extra: test}");
|
|
- return response;
|
|
-}
|
|
-
|
|
/************* Unit tests for Create *************/
|
|
TEST_F(ControllerSandboxerClientTest, CreateTestSucceed)
|
|
{
|
|
Errors err;
|
|
std::unique_ptr<sandbox::ControllerCreateParams> params = CreateTestCreateParams();
|
|
- // Fake a grpc create response.
|
|
- containerd::services::sandbox::v1::ControllerCreateResponse response;
|
|
- response.set_sandbox_id(DUMMY_SANDBOX_ID);
|
|
- // Set response to return sandbox_id, and return OK for stub_->Create().
|
|
- EXPECT_CALL(*m_stub, Create).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(response),
|
|
- testing::Return(grpc::Status::OK)));
|
|
+
|
|
+ // Set response to return sandbox_id, and return OK for sandbox_api_create().
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_create).Times(1).WillOnce(testing::DoAll(testing::Return(0)));
|
|
EXPECT_TRUE(m_sandboxerClient->Create(DUMMY_SANDBOX_ID, *params, err));
|
|
EXPECT_TRUE(err.Empty());
|
|
}
|
|
@@ -117,7 +72,7 @@ TEST_F(ControllerSandboxerClientTest, CreateTestNullConfig)
|
|
std::unique_ptr<sandbox::ControllerCreateParams> params(new sandbox::ControllerCreateParams());
|
|
params->config = nullptr;
|
|
// Stub should not be called
|
|
- EXPECT_CALL(*m_stub, Create).Times(0);
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_create).Times(0);
|
|
EXPECT_FALSE(m_sandboxerClient->Create(DUMMY_SANDBOX_ID, *params, err));
|
|
EXPECT_FALSE(err.Empty());
|
|
EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("Failed to init create request for sandboxer create request"));
|
|
@@ -128,13 +83,9 @@ TEST_F(ControllerSandboxerClientTest, CreateTestNullMount)
|
|
Errors err;
|
|
std::unique_ptr<sandbox::ControllerCreateParams> params = CreateTestCreateParams();
|
|
params->mounts.push_back(nullptr);
|
|
- containerd::services::sandbox::v1::ControllerCreateRequest request;
|
|
// Save request to check mount size.
|
|
- EXPECT_CALL(*m_stub, Create).Times(1).WillOnce(testing::DoAll(testing::SaveArg<1>(&request),
|
|
- testing::Return(grpc::Status::OK)));
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_create).Times(1).WillOnce(testing::DoAll(testing::Return(0)));
|
|
EXPECT_TRUE(m_sandboxerClient->Create(DUMMY_SANDBOX_ID, *params, err));
|
|
- // The nullptr pushed in params should not be counted.
|
|
- EXPECT_EQ(request.rootfs_size(), 1);
|
|
EXPECT_TRUE(err.Empty());
|
|
}
|
|
|
|
@@ -142,22 +93,65 @@ TEST_F(ControllerSandboxerClientTest, CreateTestStatusNotOK)
|
|
{
|
|
Errors err;
|
|
std::unique_ptr<sandbox::ControllerCreateParams> params = CreateTestCreateParams();
|
|
- // Fake a grpc create response.
|
|
- containerd::services::sandbox::v1::ControllerCreateResponse response;
|
|
- response.set_sandbox_id(DUMMY_SANDBOX_ID);
|
|
- EXPECT_CALL(*m_stub, Create).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort")));
|
|
+
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_create).Times(1).WillOnce(testing::Return(-1));
|
|
EXPECT_FALSE(m_sandboxerClient->Create(DUMMY_SANDBOX_ID, *params, err));
|
|
- EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort"));
|
|
}
|
|
|
|
/************* Unit tests for Start *************/
|
|
+static std::unique_ptr<CStructWrapper<json_map_string_string>> GetMockLabels()
|
|
+{
|
|
+ json_map_string_string *labels = nullptr;
|
|
+ size_t len = 1;
|
|
+
|
|
+ auto labels_wrapper = makeUniquePtrCStructWrapper<json_map_string_string>(free_json_map_string_string);
|
|
+ if (labels_wrapper == nullptr) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ labels = labels_wrapper->get();
|
|
+
|
|
+ labels->keys = (char **)util_smart_calloc_s(sizeof(char *), len);
|
|
+ if (labels->keys == nullptr) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ labels->keys[0] = util_strdup_s("label1");
|
|
+ labels->values = (char **)util_smart_calloc_s(sizeof(char *), len);
|
|
+ if (labels->values == nullptr) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ labels->values[0] = util_strdup_s("value1");
|
|
+ labels->len = len;
|
|
+
|
|
+ return labels_wrapper;
|
|
+}
|
|
+
|
|
+static std::unique_ptr<CStructWrapper<sandbox_start_response>> GetMockSandboxStartResponse()
|
|
+{
|
|
+ sandbox_start_response *reponse = nullptr;
|
|
+
|
|
+ auto reponse_wrapper = makeUniquePtrCStructWrapper<sandbox_start_response>(free_sandbox_start_response);
|
|
+ if (reponse_wrapper == nullptr) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ reponse = reponse_wrapper->get();
|
|
+
|
|
+ reponse->sandbox_id = util_strdup_s(DUMMY_SANDBOX_ID.c_str());
|
|
+ reponse->pid = 1;
|
|
+ reponse->created_at = DUMMY_CREATE_AT;
|
|
+ reponse->address = util_strdup_s(DUMMY_TASK_ADDRESS.c_str());
|
|
+ reponse->version = 0;
|
|
+ reponse->labels = GetMockLabels()->move();
|
|
+
|
|
+ return reponse_wrapper;
|
|
+}
|
|
+
|
|
TEST_F(ControllerSandboxerClientTest, StartTestSucceed)
|
|
{
|
|
Errors err;
|
|
sandbox::ControllerSandboxInfo sandboxInfo;
|
|
- std::unique_ptr<containerd::services::sandbox::v1::ControllerStartResponse> response = CreateTestGrpcStartResponse();
|
|
- EXPECT_CALL(*m_stub, Start).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*response),
|
|
- testing::Return(grpc::Status::OK)));
|
|
+
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_start).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*(GetMockSandboxStartResponse()->move())),
|
|
+ testing::Return(0)));
|
|
EXPECT_TRUE(m_sandboxerClient->Start(DUMMY_SANDBOX_ID, sandboxInfo, err));
|
|
EXPECT_TRUE(err.Empty());
|
|
EXPECT_EQ(sandboxInfo.id, DUMMY_SANDBOX_ID);
|
|
@@ -171,128 +165,55 @@ TEST_F(ControllerSandboxerClientTest, StartTestStatusNotOK)
|
|
{
|
|
Errors err;
|
|
sandbox::ControllerSandboxInfo sandboxInfo;
|
|
- EXPECT_CALL(*m_stub, Start).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort")));
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_start).Times(1).WillOnce(testing::Return(-1));
|
|
EXPECT_FALSE(m_sandboxerClient->Start(DUMMY_SANDBOX_ID, sandboxInfo, err));
|
|
- EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort"));
|
|
-}
|
|
-
|
|
-/************* Unit tests for Prepare *************/
|
|
-TEST_F(ControllerSandboxerClientTest, PrepareTestSucceed)
|
|
-{
|
|
- Errors err;
|
|
- std::string bundle;
|
|
- std::unique_ptr<sandbox::ControllerPrepareParams> params = CreateTestPrepareParams();
|
|
- // Fake a grpc prepare response.
|
|
- containerd::services::sandbox::v1::PrepareResponse response;
|
|
- response.set_bundle("/tmp/bundle");
|
|
- // Set response to return bundle, and return OK for stub_->Prepare().
|
|
- EXPECT_CALL(*m_stub, Prepare).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(response),
|
|
- testing::Return(grpc::Status::OK)));
|
|
- EXPECT_TRUE(m_sandboxerClient->Prepare(DUMMY_SANDBOX_ID, *params, bundle, err));
|
|
- EXPECT_TRUE(err.Empty());
|
|
- EXPECT_EQ(bundle, "/tmp/bundle");
|
|
-}
|
|
-
|
|
-TEST_F(ControllerSandboxerClientTest, PrepareTestNullSpec)
|
|
-{
|
|
- Errors err;
|
|
- std::string bundle;
|
|
- std::unique_ptr<sandbox::ControllerPrepareParams> params = CreateTestPrepareParams();
|
|
- params->spec = nullptr;
|
|
- // Stub should not be called
|
|
- EXPECT_CALL(*m_stub, Prepare).Times(0);
|
|
- EXPECT_FALSE(m_sandboxerClient->Prepare(DUMMY_SANDBOX_ID, *params, bundle, err));
|
|
- EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("Failed to init prepare request for sandboxer prepare request"));
|
|
}
|
|
|
|
-TEST_F(ControllerSandboxerClientTest, PrepareTestNullMount)
|
|
+/************* Unit tests for Update *************/
|
|
+TEST_F(ControllerSandboxerClientTest, UpdateTestSucceed)
|
|
{
|
|
Errors err;
|
|
- std::string bundle;
|
|
- std::unique_ptr<sandbox::ControllerPrepareParams> params = CreateTestPrepareParams();
|
|
- params->rootfs.push_back(nullptr);
|
|
- containerd::services::sandbox::v1::PrepareRequest request;
|
|
- // Save request to check mount size.
|
|
- EXPECT_CALL(*m_stub, Prepare).Times(1).WillOnce(testing::DoAll(testing::SaveArg<1>(&request),
|
|
- testing::Return(grpc::Status::OK)));
|
|
- EXPECT_TRUE(m_sandboxerClient->Prepare(DUMMY_SANDBOX_ID, *params, bundle, err));
|
|
- // The nullptr pushed in params should not be counted.
|
|
- EXPECT_EQ(request.rootfs_size(), 2);
|
|
+ auto apiSandbox = CreateTestUpdateApiSandbox();
|
|
+ auto fields = CreateTestFields();
|
|
+ // Set response to return bundle, and return OK for sandbox_api_update().
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_update).Times(1).WillOnce(testing::DoAll(testing::Return(0)));
|
|
+ EXPECT_TRUE(m_sandboxerClient->Update(apiSandbox->get(), fields->get(), err));
|
|
EXPECT_TRUE(err.Empty());
|
|
}
|
|
|
|
-TEST_F(ControllerSandboxerClientTest, PrepareTestStatusNotOK)
|
|
+TEST_F(ControllerSandboxerClientTest, UpdateTestStatusNotOK)
|
|
{
|
|
Errors err;
|
|
- std::string bundle;
|
|
- std::unique_ptr<sandbox::ControllerPrepareParams> params = CreateTestPrepareParams();
|
|
- EXPECT_CALL(*m_stub, Prepare).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort")));
|
|
- EXPECT_FALSE(m_sandboxerClient->Prepare(DUMMY_SANDBOX_ID, *params, bundle, err));
|
|
- EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort"));
|
|
+ auto apiSandbox = CreateTestUpdateApiSandbox();
|
|
+ auto fields = CreateTestFields();
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_update).Times(1).WillOnce(testing::Return(-1));
|
|
+ EXPECT_FALSE(m_sandboxerClient->Update(apiSandbox->get(), fields->get(), err));
|
|
}
|
|
|
|
-/************* Unit tests for Purge *************/
|
|
-TEST_F(ControllerSandboxerClientTest, PurgeTestSucceed)
|
|
-{
|
|
- Errors err;
|
|
- // Set response to return OK for stub_->Purge().
|
|
- EXPECT_CALL(*m_stub, Purge).Times(1).WillOnce(testing::Return(grpc::Status::OK));
|
|
- EXPECT_TRUE(m_sandboxerClient->Purge(DUMMY_SANDBOX_ID, DUMMY_CONTAINER_ID, DUMMY_EXEC_ID, err));
|
|
- EXPECT_TRUE(err.Empty());
|
|
-}
|
|
-
|
|
-TEST_F(ControllerSandboxerClientTest, PurgeTestStatusNotOK)
|
|
+/************* Unit tests for Platform *************/
|
|
+static std::unique_ptr<CStructWrapper<sandbox_platform_response>> GetMockSandboxPlatformResponse()
|
|
{
|
|
- Errors err;
|
|
- EXPECT_CALL(*m_stub, Purge).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort")));
|
|
- EXPECT_FALSE(m_sandboxerClient->Purge(DUMMY_SANDBOX_ID, DUMMY_CONTAINER_ID, DUMMY_EXEC_ID, err));
|
|
- EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort"));
|
|
-}
|
|
+ sandbox_platform_response *reponse = nullptr;
|
|
|
|
-/************* Unit tests for UpdateResources *************/
|
|
-TEST_F(ControllerSandboxerClientTest, UpdateResourcesTestSucceed)
|
|
-{
|
|
- Errors err;
|
|
- google::protobuf::Map<std::string, std::string> annotations;
|
|
- std::unique_ptr<sandbox::ControllerUpdateResourcesParams> params = CreateTestUpdateResourcesParams(annotations);
|
|
- // Set response to return OK for stub_->UpdateResources().
|
|
- EXPECT_CALL(*m_stub, UpdateResources).Times(1).WillOnce(testing::Return(grpc::Status::OK));
|
|
- EXPECT_TRUE(m_sandboxerClient->UpdateResources(DUMMY_SANDBOX_ID, *params, err));
|
|
- EXPECT_TRUE(err.Empty());
|
|
-}
|
|
+ auto reponse_wrapper = makeUniquePtrCStructWrapper<sandbox_platform_response>(free_sandbox_platform_response);
|
|
+ if (reponse_wrapper == nullptr) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ reponse = reponse_wrapper->get();
|
|
|
|
-TEST_F(ControllerSandboxerClientTest, UpdateResourcesTestNullResources)
|
|
-{
|
|
- Errors err;
|
|
- google::protobuf::Map<std::string, std::string> annotations;
|
|
- std::unique_ptr<sandbox::ControllerUpdateResourcesParams> params = CreateTestUpdateResourcesParams(annotations);
|
|
- params->resources = nullptr;
|
|
- // Stub should not be called
|
|
- EXPECT_CALL(*m_stub, UpdateResources).Times(0);
|
|
- EXPECT_FALSE(m_sandboxerClient->UpdateResources(DUMMY_SANDBOX_ID, *params, err));
|
|
- EXPECT_THAT(err.GetCMessage(),
|
|
- testing::HasSubstr("Failed to init update-resources request for sandboxer update-resources request"));
|
|
-}
|
|
+ reponse->os = util_strdup_s("linux");
|
|
+ reponse->architecture = util_strdup_s("amd64");
|
|
+ reponse->variant = util_strdup_s("ubuntu");
|
|
|
|
-TEST_F(ControllerSandboxerClientTest, UpdateResourcesTestStatusNotOK)
|
|
-{
|
|
- Errors err;
|
|
- google::protobuf::Map<std::string, std::string> annotations;
|
|
- std::unique_ptr<sandbox::ControllerUpdateResourcesParams> params = CreateTestUpdateResourcesParams(annotations);
|
|
- EXPECT_CALL(*m_stub, UpdateResources).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED,
|
|
- "gRPC Abort")));
|
|
- EXPECT_FALSE(m_sandboxerClient->UpdateResources(DUMMY_SANDBOX_ID, *params, err));
|
|
- EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort"));
|
|
+ return reponse_wrapper;
|
|
}
|
|
|
|
-/************* Unit tests for Platform *************/
|
|
TEST_F(ControllerSandboxerClientTest, PlatformTestSucceed)
|
|
{
|
|
Errors err;
|
|
sandbox::ControllerPlatformInfo platformInfo;
|
|
- std::unique_ptr<containerd::services::sandbox::v1::ControllerPlatformResponse> response = CreateTestPlatformResponse();
|
|
- EXPECT_CALL(*m_stub, Platform).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*response),
|
|
- testing::Return(grpc::Status::OK)));
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_platform).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*(GetMockSandboxPlatformResponse()->move())),
|
|
+ testing::Return(0)));
|
|
EXPECT_TRUE(m_sandboxerClient->Platform(DUMMY_SANDBOX_ID, platformInfo, err));
|
|
EXPECT_TRUE(err.Empty());
|
|
EXPECT_EQ(platformInfo.os, "linux");
|
|
@@ -304,18 +225,16 @@ TEST_F(ControllerSandboxerClientTest, PlatformTestStatusNotOK)
|
|
{
|
|
Errors err;
|
|
sandbox::ControllerPlatformInfo platformInfo;
|
|
- EXPECT_CALL(*m_stub, Platform).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED,
|
|
- "gRPC Abort")));
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_platform).Times(1).WillOnce(testing::Return(-1));
|
|
EXPECT_FALSE(m_sandboxerClient->Platform(DUMMY_SANDBOX_ID, platformInfo, err));
|
|
- EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort"));
|
|
}
|
|
|
|
/************* Unit tests for Stop *************/
|
|
TEST_F(ControllerSandboxerClientTest, StopTestSucceed)
|
|
{
|
|
Errors err;
|
|
- // Set response to return OK for stub_->Stop().
|
|
- EXPECT_CALL(*m_stub, Stop).Times(1).WillOnce(testing::Return(grpc::Status::OK));
|
|
+ // Set response to return OK for sandbox_api_stop().
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_stop).Times(1).WillOnce(testing::Return(0));
|
|
EXPECT_TRUE(m_sandboxerClient->Stop(DUMMY_SANDBOX_ID, 0, err));
|
|
EXPECT_TRUE(err.Empty());
|
|
}
|
|
@@ -323,19 +242,49 @@ TEST_F(ControllerSandboxerClientTest, StopTestSucceed)
|
|
TEST_F(ControllerSandboxerClientTest, StopTestStatusNotOK)
|
|
{
|
|
Errors err;
|
|
- EXPECT_CALL(*m_stub, Stop).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort")));
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_stop).Times(1).WillOnce(testing::Return(-1));
|
|
EXPECT_FALSE(m_sandboxerClient->Stop(DUMMY_SANDBOX_ID, 0, err));
|
|
- EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort"));
|
|
}
|
|
|
|
/************* Unit tests for Status *************/
|
|
+static std::unique_ptr<CStructWrapper<sandbox_status_response>> GetMockSandboxStatusResponse()
|
|
+{
|
|
+ sandbox_status_response *reponse = nullptr;
|
|
+
|
|
+ auto reponse_wrapper = makeUniquePtrCStructWrapper<sandbox_status_response>(free_sandbox_status_response);
|
|
+ if (reponse_wrapper == nullptr) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ reponse = reponse_wrapper->get();
|
|
+
|
|
+ reponse->sandbox_id = util_strdup_s(DUMMY_SANDBOX_ID.c_str());
|
|
+ reponse->pid = 1;
|
|
+ reponse->state = util_strdup_s("running");
|
|
+ reponse->info = GetMockLabels()->move();
|
|
+ if (reponse->info == nullptr) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ reponse->created_at = DUMMY_CREATE_AT;
|
|
+ reponse->exited_at = DUMMY_CREATE_AT;
|
|
+ reponse->extra = (defs_any *)util_common_calloc_s(sizeof(defs_any));
|
|
+ if (reponse->extra == nullptr) {
|
|
+ return nullptr;
|
|
+ }
|
|
+ reponse->extra->value = (uint8_t*)util_strdup_s("{extra: test}");
|
|
+ reponse->extra->value_len = 13;
|
|
+ reponse->address = util_strdup_s(DUMMY_TASK_ADDRESS.c_str());
|
|
+ reponse->version = 0;
|
|
+
|
|
+ return reponse_wrapper;
|
|
+}
|
|
+
|
|
TEST_F(ControllerSandboxerClientTest, StatusTestSucceed)
|
|
{
|
|
Errors err;
|
|
sandbox::ControllerSandboxStatus sandboxStatus;
|
|
- std::unique_ptr<containerd::services::sandbox::v1::ControllerStatusResponse> response = CreateTestStatusResponse();
|
|
- EXPECT_CALL(*m_stub, Status).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*response),
|
|
- testing::Return(grpc::Status::OK)));
|
|
+
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_status).Times(1).WillOnce(testing::DoAll(testing::SetArgPointee<2>(*(GetMockSandboxStatusResponse()->move())),
|
|
+ testing::Return(0)));
|
|
EXPECT_TRUE(m_sandboxerClient->Status(DUMMY_SANDBOX_ID, false, sandboxStatus, err));
|
|
EXPECT_TRUE(err.Empty());
|
|
EXPECT_EQ(sandboxStatus.id, DUMMY_SANDBOX_ID);
|
|
@@ -345,7 +294,7 @@ TEST_F(ControllerSandboxerClientTest, StatusTestSucceed)
|
|
EXPECT_EQ(sandboxStatus.createdAt, DUMMY_CREATE_AT);
|
|
EXPECT_EQ(sandboxStatus.exitedAt, DUMMY_CREATE_AT);
|
|
EXPECT_EQ(sandboxStatus.info.size(), 1);
|
|
- EXPECT_EQ(sandboxStatus.info["info1"], "value1");
|
|
+ EXPECT_EQ(sandboxStatus.info["label1"], "value1");
|
|
EXPECT_EQ(sandboxStatus.extra, "{extra: test}");
|
|
}
|
|
|
|
@@ -353,17 +302,16 @@ TEST_F(ControllerSandboxerClientTest, StatusTestStatusNotOK)
|
|
{
|
|
Errors err;
|
|
sandbox::ControllerSandboxStatus sandboxStatus;
|
|
- EXPECT_CALL(*m_stub, Status).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED, "gRPC Abort")));
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_status).Times(1).WillOnce(testing::Return(-1));
|
|
EXPECT_FALSE(m_sandboxerClient->Status(DUMMY_SANDBOX_ID, false, sandboxStatus, err));
|
|
- EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort"));
|
|
}
|
|
|
|
/************* Unit tests for Shutdown *************/
|
|
TEST_F(ControllerSandboxerClientTest, ShutdownTestSucceed)
|
|
{
|
|
Errors err;
|
|
- // Set response to return OK for stub_->Shutdown().
|
|
- EXPECT_CALL(*m_stub, Shutdown).Times(1).WillOnce(testing::Return(grpc::Status::OK));
|
|
+ // Set response to return OK for sandbox_api_shutdown().
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_shutdown).Times(1).WillOnce(testing::Return(0));
|
|
EXPECT_TRUE(m_sandboxerClient->Shutdown(DUMMY_SANDBOX_ID, err));
|
|
EXPECT_TRUE(err.Empty());
|
|
}
|
|
@@ -371,8 +319,6 @@ TEST_F(ControllerSandboxerClientTest, ShutdownTestSucceed)
|
|
TEST_F(ControllerSandboxerClientTest, ShutdownTestStatusNotOK)
|
|
{
|
|
Errors err;
|
|
- EXPECT_CALL(*m_stub, Shutdown).Times(1).WillOnce(testing::Return(grpc::Status(grpc::StatusCode::ABORTED,
|
|
- "gRPC Abort")));
|
|
+ EXPECT_CALL(*m_rustSandboxApiMock, sandbox_api_shutdown).Times(1).WillOnce(testing::Return(-1));
|
|
EXPECT_FALSE(m_sandboxerClient->Shutdown(DUMMY_SANDBOX_ID, err));
|
|
- EXPECT_THAT(err.GetCMessage(), testing::HasSubstr("gRPC Abort"));
|
|
}
|
|
diff --git a/test/sandbox/controller/sandboxer/sandboxer_controller/CMakeLists.txt b/test/sandbox/controller/sandboxer/sandboxer_controller/CMakeLists.txt
|
|
index 963ce9a5..e03cc58e 100644
|
|
--- a/test/sandbox/controller/sandboxer/sandboxer_controller/CMakeLists.txt
|
|
+++ b/test/sandbox/controller/sandboxer/sandboxer_controller/CMakeLists.txt
|
|
@@ -4,13 +4,11 @@ SET(EXE sandbox_controller_ut)
|
|
|
|
add_executable(${EXE}
|
|
${grpc_sandbox_type_srcs}
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox.pb.cc
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1/api_v1.pb.cc
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/gogo.pb.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cpputils/errors.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller/sandboxer/sandboxer_controller.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/sandboxer/controller/sandboxer_controller.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/mocks/grpc_sandboxer_client_mock.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/mocks/controller_stub_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/sandbox/controller/controller_common.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/sandboxer_controller_ut.cc)
|
|
|
|
@@ -19,9 +17,10 @@ target_include_directories(${EXE} PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/sandbox/controller
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../test/mocks
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/entry/cri
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller/sandboxer
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/controller/sandboxer/client
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/sandboxer
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/sandboxer/controller
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/daemon/sandbox/sandboxer/controller/client
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/common
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cutils
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/utils/cutils/map
|
|
diff --git a/test/sandbox/controller/sandboxer/sandboxer_controller/sandboxer_controller_ut.cc b/test/sandbox/controller/sandboxer/sandboxer_controller/sandboxer_controller_ut.cc
|
|
index f49d7cc5..726464e8 100644
|
|
--- a/test/sandbox/controller/sandboxer/sandboxer_controller/sandboxer_controller_ut.cc
|
|
+++ b/test/sandbox/controller/sandboxer/sandboxer_controller/sandboxer_controller_ut.cc
|
|
@@ -27,8 +27,6 @@ protected:
|
|
m_contoller = std::move(std::unique_ptr<SandboxerController>(new SandboxerController(m_sandboxer, m_address)));
|
|
m_sandboxerClientMock = std::make_shared<SandboxerClientMock>();
|
|
MockSandboxerClient_SetMock(m_sandboxerClientMock);
|
|
- EXPECT_CALL(*m_sandboxerClientMock, Init).Times(1);
|
|
- m_contoller->Init(err);
|
|
}
|
|
|
|
void TearDown() override
|
|
@@ -119,61 +117,27 @@ TEST_F(SandboxerControllerTest, PlatformTestFailed)
|
|
EXPECT_EQ(ret, nullptr);
|
|
}
|
|
|
|
-/************* Unit tests for Prepare *************/
|
|
-TEST_F(SandboxerControllerTest, PrepareTestSucceed)
|
|
+/************* Unit tests for Update *************/
|
|
+TEST_F(SandboxerControllerTest, UpdateTestSucceed)
|
|
{
|
|
Errors err;
|
|
- std::string bundle = "/tmp/bundle";
|
|
- // Set response to return sandbox_id, and return OK for stub_->Prepare().
|
|
- EXPECT_CALL(*m_sandboxerClientMock, Prepare).Times(1).WillOnce(testing::DoAll(testing::SetArgReferee<2>(bundle),
|
|
- testing::Return(true)));
|
|
- std::string ret = m_contoller->Prepare(DUMMY_SANDBOX_ID, *CreateTestPrepareParams(), err);
|
|
- EXPECT_EQ(ret, bundle);
|
|
-}
|
|
-
|
|
-TEST_F(SandboxerControllerTest, PrepareTestFailed)
|
|
-{
|
|
- Errors err;
|
|
- // Set response to return sandbox_id, and return OK for stub_->Prepare().
|
|
- EXPECT_CALL(*m_sandboxerClientMock, Prepare).Times(1).WillOnce(testing::Return(false));
|
|
- std::string ret = m_contoller->Prepare(DUMMY_SANDBOX_ID, *CreateTestPrepareParams(), err);
|
|
- EXPECT_EQ(ret, "");
|
|
-}
|
|
-
|
|
-/************* Unit tests for Purge *************/
|
|
-TEST_F(SandboxerControllerTest, PurgeTestSucceed)
|
|
-{
|
|
- Errors err;
|
|
- // Set response to return sandbox_id, and return OK for stub_->Purge().
|
|
- EXPECT_CALL(*m_sandboxerClientMock, Purge).Times(1).WillOnce(testing::Return(true));
|
|
- EXPECT_TRUE(m_contoller->Purge(DUMMY_SANDBOX_ID, DUMMY_CONTAINER_ID, DUMMY_EXEC_ID, err));
|
|
-}
|
|
+ auto apiSandbox = CreateTestUpdateApiSandbox();
|
|
+ auto fields = CreateTestFields();
|
|
|
|
-TEST_F(SandboxerControllerTest, PurgeTestFailed)
|
|
-{
|
|
- Errors err;
|
|
- // Set response to return sandbox_id, and return OK for stub_->Purge().
|
|
- EXPECT_CALL(*m_sandboxerClientMock, Purge).Times(1).WillOnce(testing::Return(false));
|
|
- EXPECT_FALSE(m_contoller->Purge(DUMMY_SANDBOX_ID, DUMMY_CONTAINER_ID, DUMMY_EXEC_ID, err));
|
|
+ // return OK for stub_->Update().
|
|
+ EXPECT_CALL(*m_sandboxerClientMock, Update).Times(1).WillOnce(testing::DoAll(testing::Return(true)));
|
|
+ EXPECT_TRUE(m_contoller->Update(apiSandbox->get(), fields->get(), err));
|
|
}
|
|
|
|
-/************* Unit tests for UpdateResources *************/
|
|
-TEST_F(SandboxerControllerTest, UpdateResourcesTestSucceed)
|
|
+TEST_F(SandboxerControllerTest, UpdateTestFailed)
|
|
{
|
|
Errors err;
|
|
- google::protobuf::Map<std::string, std::string> annotations;
|
|
- // Set response to return sandbox_id, and return OK for stub_->UpdateResources().
|
|
- EXPECT_CALL(*m_sandboxerClientMock, UpdateResources).Times(1).WillOnce(testing::Return(true));
|
|
- EXPECT_TRUE(m_contoller->UpdateResources(DUMMY_SANDBOX_ID, *CreateTestUpdateResourcesParams(annotations), err));
|
|
-}
|
|
+ auto apiSandbox = CreateTestUpdateApiSandbox();
|
|
+ auto fields = CreateTestFields();
|
|
|
|
-TEST_F(SandboxerControllerTest, UpdateResourcesTestFailed)
|
|
-{
|
|
- Errors err;
|
|
- google::protobuf::Map<std::string, std::string> annotations;
|
|
- // Set response to return sandbox_id, and return OK for stub_->UpdateResources().
|
|
- EXPECT_CALL(*m_sandboxerClientMock, UpdateResources).Times(1).WillOnce(testing::Return(false));
|
|
- EXPECT_FALSE(m_contoller->UpdateResources(DUMMY_SANDBOX_ID, *CreateTestUpdateResourcesParams(annotations), err));
|
|
+ // return OK for stub_->Update().
|
|
+ EXPECT_CALL(*m_sandboxerClientMock, Update).Times(1).WillOnce(testing::Return(false));
|
|
+ EXPECT_FALSE(m_contoller->Update(apiSandbox->get(), fields->get(), err));
|
|
}
|
|
|
|
/************* Unit tests for Stop *************/
|
|
diff --git a/test/sandbox/controller/shim/CMakeLists.txt b/test/sandbox/controller/shim/CMakeLists.txt
|
|
index d18d1861..069312c9 100644
|
|
--- a/test/sandbox/controller/shim/CMakeLists.txt
|
|
+++ b/test/sandbox/controller/shim/CMakeLists.txt
|
|
@@ -14,7 +14,7 @@ add_executable(${EXE}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/common/err_msg.c
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/config/daemon_arguments.c
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/config/isulad_config.c
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/controller/shim/shim_controller.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/shim/controller/shim_controller.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cpputils/errors.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cpputils/cxxutils.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/sha256/sha256.c
|
|
@@ -41,8 +41,9 @@ target_include_directories(${EXE} PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/controller
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/controller/shim
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/shim
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/sandbox/shim/controller
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cpputils
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/sha256
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../../test/sandbox/controller
|
|
diff --git a/test/sandbox/sandbox/CMakeLists.txt b/test/sandbox/sandbox/CMakeLists.txt
|
|
index 2a35388f..9ee67033 100644
|
|
--- a/test/sandbox/sandbox/CMakeLists.txt
|
|
+++ b/test/sandbox/sandbox/CMakeLists.txt
|
|
@@ -6,7 +6,6 @@ aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox/t
|
|
|
|
add_executable(${EXE}
|
|
${sandbox_type_srcs}
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox.pb.cc
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1/api_v1.pb.cc
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/gogo.pb.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cpputils/errors.cc
|
|
@@ -14,14 +13,15 @@ add_executable(${EXE}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cpputils/transform.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cpputils/cxxutils.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/sandbox.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller/controller_manager.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller/sandboxer/sandboxer_controller.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/sandbox_task.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller_manager.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/sandboxer/controller/sandboxer_controller.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/shim/shim_sandbox.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/common/id_name_manager.c
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/config/isulad_config.c
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/sandbox/controller/controller_common.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/config/daemon_arguments.c
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/grpc_sandboxer_client_mock.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/controller_stub_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/shim_controller_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/mailbox_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/common/err_msg.c
|
|
@@ -35,18 +35,17 @@ target_include_directories(${EXE} PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/entry/cri
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/executor
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/mailbox
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller/shim
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller/sandboxer
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller/sandboxer/client
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/shim
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/shim/controller
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/sandboxer
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/sandboxer/controller
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/sandboxer/controller/client
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/common
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cpputils
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/google/protobuf
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox/types
|
|
)
|
|
|
|
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lgrpc -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
|
|
diff --git a/test/sandbox/sandbox/sandbox_ut.cc b/test/sandbox/sandbox/sandbox_ut.cc
|
|
index dd84d8fb..192d46ef 100644
|
|
--- a/test/sandbox/sandbox/sandbox_ut.cc
|
|
+++ b/test/sandbox/sandbox/sandbox_ut.cc
|
|
@@ -16,6 +16,7 @@
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "sandbox.h"
|
|
+#include "shim_sandbox.h"
|
|
|
|
namespace sandbox {
|
|
|
|
@@ -40,7 +41,7 @@ TEST_F(SandboxTest, TestDefaultGetters)
|
|
std::string name = "test";
|
|
RuntimeInfo info = {"runc", "shim", "kuasar"};
|
|
|
|
- auto sandbox = new Sandbox(id, rootdir, statedir, name, info);
|
|
+ auto sandbox = new ShimSandbox(id, rootdir, statedir, name, info);
|
|
ASSERT_NE(sandbox, nullptr);
|
|
|
|
ASSERT_EQ(sandbox->IsReady(), false);
|
|
@@ -66,7 +67,7 @@ TEST_F(SandboxTest, TestGettersAndSetters)
|
|
std::string statedir = "/test2/statedir";
|
|
std::string mode = "host";
|
|
|
|
- auto sandbox = new Sandbox(id, rootdir, statedir);
|
|
+ auto sandbox = new ShimSandbox(id, rootdir, statedir);
|
|
ASSERT_NE(sandbox, nullptr);
|
|
|
|
sandbox->SetNetMode(mode);
|
|
diff --git a/test/sandbox/sandbox_manager/CMakeLists.txt b/test/sandbox/sandbox_manager/CMakeLists.txt
|
|
index 5a7cb2ea..9254263c 100644
|
|
--- a/test/sandbox/sandbox_manager/CMakeLists.txt
|
|
+++ b/test/sandbox/sandbox_manager/CMakeLists.txt
|
|
@@ -6,22 +6,22 @@ aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox/t
|
|
|
|
add_executable(${EXE}
|
|
${sandbox_type_srcs}
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox.pb.cc
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1/api_v1.pb.cc
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/gogo.pb.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cpputils/errors.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cpputils/read_write_lock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cpputils/transform.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/sandbox_mock.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/shim_sandbox_mock.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/sandboxer_sandbox_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/sandbox_manager.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/common/id_name_manager.c
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/isulad_config_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/common/err_msg.c
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/config/daemon_arguments.c
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller/controller_manager.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller/sandboxer/sandboxer_controller.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller_manager.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/grpc_sandboxer_client_mock.cc
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/controller_stub_mock.cc
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/sandboxer_controller_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/shim_controller_mock.cc
|
|
${CMAKE_CURRENT_SOURCE_DIR}/sandbox_manager_ut.cc)
|
|
|
|
@@ -33,18 +33,17 @@ target_include_directories(${EXE} PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/config
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/entry/cri
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/executor
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller/shim
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller/sandboxer
|
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/controller/sandboxer/client
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/shim
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/shim/controller
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/sandboxer
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/sandboxer/controller
|
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox/sandboxer/controller/client
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/sandbox
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/daemon/common
|
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cpputils
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri
|
|
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/google/protobuf
|
|
- ${CMAKE_BINARY_DIR}/grpc/src/api/services/sandbox/sandbox/types
|
|
)
|
|
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_list_all_subdir")
|
|
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lgrpc -lgrpc++ -lprotobuf -lcrypto -lyajl -lz)
|
|
--
|
|
2.34.1
|
|
|