21 #include <gmock/gmock.h>
22 #include <gtest/gtest.h>
24 #include "absl/strings/str_format.h"
34 const char* kIdentityCertFile =
"/path/to/identity_cert_file";
35 const char* kPrivateKeyFile =
"/path/to/private_key_file";
36 const char* kRootCertFile =
"/path/to/root_cert_file";
37 const int kRefreshInterval = 400;
39 TEST(FileWatcherConfigTest, Basic) {
42 " \"certificate_file\": \"%s\","
43 " \"private_key_file\": \"%s\","
44 " \"ca_certificate_file\": \"%s\","
45 " \"refresh_interval\": \"%ds\""
47 kIdentityCertFile, kPrivateKeyFile, kRootCertFile, kRefreshInterval);
60 TEST(FileWatcherConfigTest, DefaultRefreshInterval) {
63 " \"certificate_file\": \"%s\","
64 " \"private_key_file\": \"%s\","
65 " \"ca_certificate_file\": \"%s\""
67 kIdentityCertFile, kPrivateKeyFile, kRootCertFile);
80 TEST(FileWatcherConfigTest, OnlyRootCertificatesFileProvided) {
83 " \"ca_certificate_file\": \"%s\""
98 TEST(FileWatcherConfigTest, OnlyIdenityCertificatesAndPrivateKeyProvided) {
101 " \"certificate_file\": \"%s\","
102 " \"private_key_file\": \"%s\""
104 kIdentityCertFile, kPrivateKeyFile);
117 TEST(FileWatcherConfigTest, WrongTypes) {
118 const char* json_str =
120 " \"certificate_file\": 123,"
121 " \"private_key_file\": 123,"
122 " \"ca_certificate_file\": 123,"
123 " \"refresh_interval\": 123"
132 "field:certificate_file error:type should be STRING.*"
133 "field:private_key_file error:type should be STRING.*"
134 "field:ca_certificate_file error:type should be STRING.*"
135 "field:refresh_interval error:type should be STRING of the "
137 "google.proto.Duration.*"));
141 TEST(FileWatcherConfigTest, IdentityCertProvidedButPrivateKeyMissing) {
144 " \"certificate_file\": \"%s\""
154 "fields \"certificate_file\" and \"private_key_file\" must "
155 "be both set or both unset."));
159 TEST(FileWatcherConfigTest, PrivateKeyProvidedButIdentityCertMissing) {
162 " \"private_key_file\": \"%s\""
172 "fields \"certificate_file\" and \"private_key_file\" must "
173 "be both set or both unset."));
177 TEST(FileWatcherConfigTest, EmptyJsonObject) {
187 "\"ca_certificate_file\" must be specified."));
195 int main(
int argc,
char** argv) {