-
Notifications
You must be signed in to change notification settings - Fork 11
Conversation
|
|
||
| TEST_F(EnvironmentTest, ReadApplicationDefaultCredentialsSucceeds) { | ||
| TemporaryFile credentials_file( | ||
| std::string(test_info_->name()) + "_creds.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does test_info_ come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_info_ is provided by gtest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Umm, yeah, except the preferred way to access it seems to be by calling current_test_info() on UnitTest. I'll send a separate PR with a fix.
test/environment_unittest.cc
Outdated
| TEST_F(EnvironmentTest, ReadApplicationDefaultCredentialsCaches) { | ||
| TemporaryFile credentials_file( | ||
| std::string(test_info_->name()) + "_creds.json", | ||
| "{\"client_email\":\"foo@bar.com\",\"private_key\":\"12345\"}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe give these names like:
email: original@bar.com
key: orignal-key
so it is easy to see that the original values were kept in the environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the approach, but these are too long and don't fit on a line. But see if you like the new code better...
test/Makefile
Outdated
| CPPFLAGS+= -UNOOPT -DNOOPT='[[clang::optnone]]' -I/usr/local/include | ||
| CXXFLAGS+= -Wno-deprecated-declarations -Wno-c++14-extensions | ||
| LDFLAGS+= -L/usr/local/lib | ||
| SED_I+= '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be confused here, but it doesn't look like SED_I or SED_EXTRA are used below in this file; do we need these lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not, but this is a verbatim copy from src/Makefile — I think it's good to keep them in sync so that we can factor this out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out you were right — these weren't needed. Removed.
|
|
||
| TEST_F(EnvironmentTest, ReadApplicationDefaultCredentialsSucceeds) { | ||
| TemporaryFile credentials_file( | ||
| std::string(test_info_->name()) + "_creds.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_info_ is provided by gtest.
| "CredentialsFile: '" + credentials_file.FullPath().native() + "'\n" | ||
| )); | ||
| Environment environment(config); | ||
| EXPECT_NO_THROW(ReadApplicationDefaultCredentials(environment)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion this line is not required. It will be called on any call to CredentialsClientEmail or CredentialsPrivateKey. If it throws, the test case will exit and fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but I'd like to control where the credentials file is actually read. Especially in the next test.
| "CredentialsFile: '" + credentials_file.FullPath().native() + "'\n" | ||
| )); | ||
| Environment environment(config); | ||
| EXPECT_NO_THROW(ReadApplicationDefaultCredentials(environment)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally change this line to something like EXPECT_EQ("foo@bar.com", environment.CredentialsClientEmail());. This will 1) load the cache and 2) demonstrate the expectation (that the cache is loaded) to the test-reader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above. This is checking that the first call to ReadApplicationDefaultCredentials caches both the client email and the private key values.
igorpeshansky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL.
test/Makefile
Outdated
| CPPFLAGS+= -UNOOPT -DNOOPT='[[clang::optnone]]' -I/usr/local/include | ||
| CXXFLAGS+= -Wno-deprecated-declarations -Wno-c++14-extensions | ||
| LDFLAGS+= -L/usr/local/lib | ||
| SED_I+= '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not, but this is a verbatim copy from src/Makefile — I think it's good to keep them in sync so that we can factor this out.
| "CredentialsFile: '" + credentials_file.FullPath().native() + "'\n" | ||
| )); | ||
| Environment environment(config); | ||
| EXPECT_NO_THROW(ReadApplicationDefaultCredentials(environment)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above. This is checking that the first call to ReadApplicationDefaultCredentials caches both the client email and the private key values.
ACEmilG
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
igorpeshansky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also removed the NOOPT macros — I thought they were required on MacOS, but turns out they weren't needed either. PTAL.
test/Makefile
Outdated
| CPPFLAGS+= -UNOOPT -DNOOPT='[[clang::optnone]]' -I/usr/local/include | ||
| CXXFLAGS+= -Wno-deprecated-declarations -Wno-c++14-extensions | ||
| LDFLAGS+= -L/usr/local/lib | ||
| SED_I+= '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out you were right — these weren't needed. Removed.
supriyagarg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Includes one drive-by include fix in health_check_unittest.