Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Conversation

@igorpeshansky
Copy link
Contributor

Includes one drive-by include fix in health_check_unittest.


TEST_F(EnvironmentTest, ReadApplicationDefaultCredentialsSucceeds) {
TemporaryFile credentials_file(
std::string(test_info_->name()) + "_creds.json",
Copy link
Contributor

@supriyagarg supriyagarg Apr 4, 2018

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?

Copy link
Contributor

@ACEmilG ACEmilG Apr 4, 2018

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.

Copy link
Contributor Author

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_F(EnvironmentTest, ReadApplicationDefaultCredentialsCaches) {
TemporaryFile credentials_file(
std::string(test_info_->name()) + "_creds.json",
"{\"client_email\":\"foo@bar.com\",\"private_key\":\"12345\"}");
Copy link
Contributor

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

Copy link
Contributor Author

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+= ''
Copy link
Contributor

@ACEmilG ACEmilG Apr 4, 2018

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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",
Copy link
Contributor

@ACEmilG ACEmilG Apr 4, 2018

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));
Copy link
Contributor

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.

Copy link
Contributor Author

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));
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@igorpeshansky igorpeshansky left a 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+= ''
Copy link
Contributor Author

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));
Copy link
Contributor Author

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.

Copy link
Contributor

@ACEmilG ACEmilG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor Author

@igorpeshansky igorpeshansky left a 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+= ''
Copy link
Contributor Author

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.

Copy link
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@igorpeshansky igorpeshansky merged commit f1efd1c into master Apr 10, 2018
@igorpeshansky igorpeshansky deleted the igorp-credentials-tests branch April 10, 2018 17:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants