3 // Copyright 2020 gRPC authors.
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #include <grpc/support/port_platform.h>
21 #include <gmock/gmock.h>
23 #include "src/core/ext/xds/certificate_provider_registry.h"
25 #include "test/core/util/test_config.h"
31 class FakeCertificateProviderFactory1 : public CertificateProviderFactory {
33 const char* name() const override { return "fake1"; }
35 RefCountedPtr<Config> CreateCertificateProviderConfig(
36 const Json& /*config_json*/, grpc_error** /*error*/) override {
40 RefCountedPtr<grpc_tls_certificate_provider> CreateCertificateProvider(
41 RefCountedPtr<Config> /*config*/) override {
46 class FakeCertificateProviderFactory2 : public CertificateProviderFactory {
48 const char* name() const override { return "fake2"; }
50 RefCountedPtr<Config> CreateCertificateProviderConfig(
51 const Json& /*config_json*/, grpc_error** /*error*/) override {
55 RefCountedPtr<grpc_tls_certificate_provider> CreateCertificateProvider(
56 RefCountedPtr<Config> /*config*/) override {
61 TEST(CertificateProviderRegistryTest, Basic) {
62 CertificateProviderRegistry::InitRegistry();
63 auto* fake_factory_1 = new FakeCertificateProviderFactory1;
64 auto* fake_factory_2 = new FakeCertificateProviderFactory2;
65 CertificateProviderRegistry::RegisterCertificateProviderFactory(
66 std::unique_ptr<CertificateProviderFactory>(fake_factory_1));
67 CertificateProviderRegistry::RegisterCertificateProviderFactory(
68 std::unique_ptr<CertificateProviderFactory>(fake_factory_2));
70 CertificateProviderRegistry::LookupCertificateProviderFactory("fake1"),
73 CertificateProviderRegistry::LookupCertificateProviderFactory("fake2"),
76 CertificateProviderRegistry::LookupCertificateProviderFactory("fake3"),
78 CertificateProviderRegistry::ShutdownRegistry();
82 } // namespace testing
83 } // namespace grpc_core
85 int main(int argc, char** argv) {
86 ::testing::InitGoogleTest(&argc, argv);
87 grpc::testing::TestEnvironment env(argc, argv);
88 auto result = RUN_ALL_TESTS();