aboutsummaryrefslogtreecommitdiff
path: root/cc/monitoring
diff options
context:
space:
mode:
authorambrosin <ambrosin@google.com>2022-04-04 05:46:26 -0700
committerCopybara-Service <copybara-worker@google.com>2022-04-04 05:47:05 -0700
commit789460264b124da4cfb1ac9449f13cf486363154 (patch)
tree39bf0f18389d49f5c03b9fa58d5d9968fbc83b92 /cc/monitoring
parent02e89b22b16022e9b1409f250f2bcae1ff263c98 (diff)
downloadtink-789460264b124da4cfb1ac9449f13cf486363154.tar.gz
Add mock monitoring client and factory.
Mock classes are more flexible and expected to be used for unit testing monitoring functionalities in primitive wrappers. PiperOrigin-RevId: 439293493
Diffstat (limited to 'cc/monitoring')
-rw-r--r--cc/monitoring/BUILD.bazel11
-rw-r--r--cc/monitoring/CMakeLists.txt9
-rw-r--r--cc/monitoring/monitoring_client_mocks.h45
3 files changed, 65 insertions, 0 deletions
diff --git a/cc/monitoring/BUILD.bazel b/cc/monitoring/BUILD.bazel
index a1c1cbbdc..22d3886a0 100644
--- a/cc/monitoring/BUILD.bazel
+++ b/cc/monitoring/BUILD.bazel
@@ -11,3 +11,14 @@ cc_library(
"@com_google_absl//absl/container:flat_hash_map",
],
)
+
+cc_library(
+ name = "monitoring_client_mocks",
+ testonly = 1,
+ hdrs = ["monitoring_client_mocks.h"],
+ include_prefix = "tink/monitoring",
+ deps = [
+ ":monitoring",
+ "@com_google_googletest//:gtest",
+ ],
+)
diff --git a/cc/monitoring/CMakeLists.txt b/cc/monitoring/CMakeLists.txt
index 53c732858..961388547 100644
--- a/cc/monitoring/CMakeLists.txt
+++ b/cc/monitoring/CMakeLists.txt
@@ -8,3 +8,12 @@ tink_cc_library(
absl::flat_hash_map
tink::util::statusor
)
+
+tink_cc_library(
+ NAME monitoring_client_mocks
+ SRCS
+ monitoring_client_mocks.h
+ DEPS
+ tink::monitoring::monitoring
+ gmock
+)
diff --git a/cc/monitoring/monitoring_client_mocks.h b/cc/monitoring/monitoring_client_mocks.h
new file mode 100644
index 000000000..8a59b47c0
--- /dev/null
+++ b/cc/monitoring/monitoring_client_mocks.h
@@ -0,0 +1,45 @@
+// Copyright 2022 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+///////////////////////////////////////////////////////////////////////////////
+#ifndef TINK_MONITORING_MOCK_MONITORING_CLIENT_FACTORY_H_
+#define TINK_MONITORING_MOCK_MONITORING_CLIENT_FACTORY_H_
+
+#include <cstdint>
+
+#include "gmock/gmock.h"
+#include "tink/monitoring/monitoring.h"
+
+namespace crypto {
+namespace tink {
+
+// Mock MonitoringClientFactory class.
+class MockMonitoringClientFactory : public MonitoringClientFactory {
+ public:
+ MOCK_METHOD(util::StatusOr<std::unique_ptr<MonitoringClient>>, New,
+ (const MonitoringContext& context), (override));
+};
+
+// Mock MonitoringClient class.
+class MockMonitoringClient : public MonitoringClient {
+ public:
+ MOCK_METHOD(void, Log, (uint32_t key_id, int64_t num_bytes_as_input),
+ (override));
+ MOCK_METHOD(void, LogFailure, (), (override));
+};
+
+} // namespace tink
+} // namespace crypto
+
+#endif // TINK_MONITORING_MOCK_MONITORING_CLIENT_FACTORY_H_