From f9c8ce98cf6dd3e305087354a8a689ce6d86a442 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 7 Dec 2015 08:21:57 -0800 Subject: [PATCH] Add test for grpc_get_well_known_google_credentials_file_path --- test/core/security/credentials_test.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index b2b7cfdb6e0..9af76be257e 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -31,8 +31,10 @@ * */ +#include #include "src/core/security/credentials.h" +#include #include #include "src/core/httpcli/httpcli.h" @@ -1013,6 +1015,30 @@ static void test_metadata_plugin_failure(void) { grpc_exec_ctx_finish(&exec_ctx); } +static void test_get_well_known_google_credentials_file_path(void) { +#ifdef GPR_POSIX_FILE + char *path; + char *old_home = gpr_getenv("HOME"); + gpr_setenv("HOME", "/tmp"); + path = grpc_get_well_known_google_credentials_file_path(); + GPR_ASSERT(path != NULL); + GPR_ASSERT(0 == strcmp("/tmp/.config/" GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY + "/" GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE, + path)); + gpr_free(path); +#if defined(GPR_POSIX_ENV) || defined(GPR_LINUX_ENV) + unsetenv("HOME"); + path = grpc_get_well_known_google_credentials_file_path(); + GPR_ASSERT(path == NULL); +#endif /* GPR_POSIX_ENV || GPR_LINUX_ENV */ + gpr_setenv("HOME", old_home); +#else /* GPR_POSIX_FILE */ + char *path = grpc_get_well_known_google_credentials_file_path(); + GPR_ASSERT(path != NULL); + gpr_free(path); +#endif +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); test_empty_md_store(); @@ -1043,5 +1069,6 @@ int main(int argc, char **argv) { test_google_default_creds_access_token(); test_metadata_plugin_success(); test_metadata_plugin_failure(); + test_get_well_known_google_credentials_file_path(); return 0; }