-
Notifications
You must be signed in to change notification settings - Fork 11
Conversation
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.
Minor comment.
test/configuration_unittest.cc
Outdated
| TestDefaultConfig(config); | ||
| } | ||
|
|
||
| TEST(ConfigurationTest, SpecificTest) { |
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.
Rename SpecificTest to PopulatedYamlTest or similar for parity with the previous name.
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.
Or PopulatedConfigFileTest...
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.
Changed tests to "NoConfigTest", "EmptyConfigTest", "PopulatedConfigTest"
src/configuration.h
Outdated
| MetadataAgentConfiguration(); | ||
| int ParseArguments(int ac, char** av); | ||
| void ParseConfigFile(const std::string& filename); | ||
| void ParseYamlConfig(YAML::Node config); |
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 prefer to not expose the implementation details in the header, but instead define
void ParseConfiguration(std::istream& input);and use YAML::Load() instead of YAML::LoadFile() in the implementation of ParseConfigFile. Then you can just use std::stringstream in the test.
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.
Done
| } | ||
|
|
||
| private: | ||
| void ParseConfigFile(const std::string& filename); |
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.
Keep this as private and add the test class as a friend instead. I think there's even a FRIEND_TEST macro...
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.
Done.
test/Makefile
Outdated
| CPP_NETLIB_DIR=$(LIBDIR)/cpp-netlib | ||
| YAML_CPP_DIR=$(LIBDIR)/yaml-cpp | ||
| YAML_CPP_LIBDIR=$(YAML_CPP_DIR) | ||
| SUBMODULE_DIRS=$(CPP_NETLIB_DIR) $(YAML_CPP_DIR) |
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.
Is this used anywhere? If not, let's remove it.
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.
Removed.
| # TODO: Factor out the common variables. | ||
| CPP_NETLIB_DIR=$(LIBDIR)/cpp-netlib | ||
| YAML_CPP_DIR=$(LIBDIR)/yaml-cpp | ||
| YAML_CPP_LIBDIR=$(YAML_CPP_DIR) |
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.
We should really factor these into a common include file, but I am not asking you to do it now -- just musing.
test/Makefile
Outdated
| -DMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ \ | ||
| -DYAML_CPP_BUILD_TOOLS=OFF | ||
|
|
||
| $(YAML_CPP_LIBS): build-yaml-cpp |
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.
Instead of copying all of this make cruft from src/Makefile here, why not delegate:
$(YAML_CPP_LIBS):
cd $(SRC_DIR) && $(MAKE) $@?
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.
Much better, changed.
test/configuration_unittest.cc
Outdated
| TestDefaultConfig(config); | ||
| } | ||
|
|
||
| TEST(ConfigurationTest, BlankYamlTest) { |
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.
How about BlankConfigFileTest?
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.
Modified test names, see below
test/configuration_unittest.cc
Outdated
| TestDefaultConfig(config); | ||
| } | ||
|
|
||
| TEST(ConfigurationTest, SpecificTest) { |
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.
Or PopulatedConfigFileTest...
|
|
||
| TEST(ConfigurationTest, SpecificTest) { | ||
| YAML::Node node = YAML::Load( | ||
| "ProjectId: TestProjectId\n" |
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.
You should also test that comments are skipped appropriately, possibly in another test case...
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.
Added
test/configuration_unittest.cc
Outdated
|
|
||
| namespace { | ||
|
|
||
| void TestDefaultConfig(google::MetadataAgentConfiguration& config) { |
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'm not too happy about this, as it'll need to be updated when defaults change, but I don't have any better ideas for now, so let's keep it.
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.
Agreed
test/configuration_unittest.cc
Outdated
| EXPECT_EQ(false, config.MetadataReporterPurgeDeleted()); | ||
| EXPECT_EQ( | ||
| "https://stackdriver.googleapis.com/" | ||
| "v1beta2/projects/{{project_id}}/resourceMetadata:batchUpdate", |
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.
We should eventually add a CheckConfiguration function that verifies, e.g., that these format strings have the appropriate substitution parameters, etc. Not asking you to do it now, though.
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.
Agreed, left for later
src/configuration.cc
Outdated
| std::lock_guard<std::mutex> lock(mutex_); | ||
| if (filename.empty()) return; | ||
| std::ifstream ifs; | ||
| ifs.open (filename, std::ifstream::in); |
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.
How about combining this with construction, i.e.:
std::ifstream input(filename);
ParseConfiguration(input);? BTW, in is the default mode.
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.
Much better, thanks.
| private: | ||
| friend class MetadataAgentConfigurationTest; | ||
| void ParseConfigFile(const std::string& filename); | ||
|
|
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.
Let's keep this blank line to separate functions from instance variables.
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.
Replaced.
test/Makefile
Outdated
| base64_unittest: $(GTEST_LIB) base64_unittest.o $(SRC_DIR)/base64.o | ||
| $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ | ||
|
|
||
| configuration_unittest: $(GTEST_LIB) configuration_unittest.o $(SRC_DIR)/configuration.o |
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 believe it's still relevant -- if you don't add that dependency, then make test in a fresh checkout will fail to link (because it won't rebuild $(YAML_CPP_LIBS)).
test/Makefile
Outdated
| $(YAML_CPP_LIBS): | ||
| cd $(SRC_DIR) && $(MAKE) $@ | ||
|
|
||
| build-yaml-cpp: $(YAML_CPP_DIR)/Makefile |
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.
Since you're delegating $(YAML_CPP_LIBS) to src/Makefile, the build-yaml-cpp and yaml-cpp targets are no longer needed.
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.
Fixed, thanks.
test/configuration_unittest.cc
Outdated
| static void SetUpTestCase() {} | ||
| static void TearDownTestCase() {} | ||
|
|
||
| void TestDefaultConfig(MetadataAgentConfiguration& config) { |
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.
This doesn't depend on any state in the fixture and only calls public methods. Is there any reason to not keep it as a standalone top-level function?
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.
No particular reason - moved out of the class.
test/configuration_unittest.cc
Outdated
|
|
||
| class MetadataAgentConfigurationTest : public ::testing::Test { | ||
| public: | ||
| void CallParseConfiguration(MetadataAgentConfiguration& config, std::istream& stream) { |
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.
Just ParseConfiguration is fine.
| }; | ||
|
|
||
| TEST_F(MetadataAgentConfigurationTest, NoConfigTest) { | ||
| MetadataAgentConfiguration config; |
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.
You start every test with this. Might as well make this a field in the fixture.
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.
Done.
test/configuration_unittest.cc
Outdated
| EXPECT_EQ(true, config.MetadataReporterPurgeDeleted()); | ||
| } | ||
|
|
||
| TEST_F(MetadataAgentConfigurationTest, CommentSkippedTest) { |
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.
Let's also test for blank 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.
Added a new test
test/configuration_unittest.cc
Outdated
|
|
||
| class MetadataAgentConfigurationTest : public ::testing::Test { | ||
| public: | ||
| void CallParseConfiguration(MetadataAgentConfiguration& config, std::istream& stream) { |
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.
As written, this can be static.
test/configuration_unittest.cc
Outdated
|
|
||
| class MetadataAgentConfigurationTest : public ::testing::Test { | ||
| public: | ||
| void CallParseConfiguration(MetadataAgentConfiguration& config, std::istream& stream) { |
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.
Since you always pass in a stringstream initialized from a string, and you have to call this function anyway to get access to the private method, why not make this method take a string (well, const std::string&) and do the stream stuff in this method?
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.
Fixed all.
src/configuration.cc
Outdated
| if (filename.empty()) return; | ||
|
|
||
| YAML::Node config = YAML::LoadFile(filename); | ||
| std::ifstream ifs(filename); |
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.
Let's replace ifs with input -- it reads better, IMO.
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.
Agreed, done.
| } | ||
|
|
||
| private: | ||
| friend class MetadataAgentConfigurationTest; |
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.
Please add a blank line after this to visually separate it from the functions.
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.
Done.
test/Makefile
Outdated
| base64_unittest: $(GTEST_LIB) base64_unittest.o $(SRC_DIR)/base64.o | ||
| $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ | ||
|
|
||
| configuration_unittest: $(GTEST_LIB) configuration_unittest.o $(SRC_DIR)/configuration.o $(YAML_CPP_LIBS) |
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.
Need to put $(YAML_CPP_LIBS) first, otherwise the build of configuration.o will fail because the includes won't find yaml-cpp/yaml.h.
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.
Done, thanks.
test/Makefile
Outdated
| $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ | ||
|
|
||
| .PHONY: all test clean purge | ||
| .PHONY: all test clean purge yaml-cpp |
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.
You've removed the yaml-cpp target, right?
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.
Correct, removed this from phony list.
test/configuration_unittest.cc
Outdated
| namespace google { | ||
|
|
||
| class MetadataAgentConfigurationTest : public ::testing::Test { | ||
| public: |
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.
protected?
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.
Sure, done.
test/configuration_unittest.cc
Outdated
| class MetadataAgentConfigurationTest : public ::testing::Test { | ||
| public: | ||
| MetadataAgentConfiguration config; | ||
| static void ParseConfiguration(MetadataAgentConfiguration& config, const std::string configString) { |
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.
const std::string&.
test/configuration_unittest.cc
Outdated
| class MetadataAgentConfigurationTest : public ::testing::Test { | ||
| public: | ||
| MetadataAgentConfiguration config; | ||
| static void ParseConfiguration(MetadataAgentConfiguration& config, const std::string configString) { |
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.
Actually, now that you have an instance variable, you might as well remove the config parameter and let it refer to the config instance variable. Of course, this can then no longer be static.
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.
Done.
test/configuration_unittest.cc
Outdated
| } | ||
| }; | ||
|
|
||
| static void TestDefaultConfig(MetadataAgentConfiguration& config) { |
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 didn't notice earlier: this can take a const reference. However, if you make it an instance function, you should instead make it a const function (i.e.,
void VerifyDefaultConfig() const {
...
}).
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.
Done.
test/configuration_unittest.cc
Outdated
| EXPECT_EQ(3, config.MetadataApiNumThreads()); | ||
| } | ||
|
|
||
| TEST_F(MetadataAgentConfigurationTest, EmptyLineTest) { |
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.
s/Empty/Blank/.
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.
Changed.
test/configuration_unittest.cc
Outdated
|
|
||
| TEST_F(MetadataAgentConfigurationTest, EmptyLineTest) { | ||
| ParseConfiguration(config, | ||
| "ProjectId: TestProjectId\n\n\n\n" |
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.
While this is technically correct, it's easier to visualize what's going on if you move each of the "\n" to its own line.
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.
Agreed, changed.
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.
Minor nits.
test/configuration_unittest.cc
Outdated
|
|
||
| class MetadataAgentConfigurationTest : public ::testing::Test { | ||
| protected: | ||
| void ParseConfiguration(const std::string& configString) { |
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.
The Google style is to use snake_case for variables and parameter names. But you could just name it input instead.
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.
Changed to input.
test/configuration_unittest.cc
Outdated
| ParseConfiguration( | ||
| "ProjectId: TestProjectId\n" | ||
| "MetadataApiNumThreads: 13\n" | ||
| "MetadataReporterPurgeDeleted: true"); |
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.
Tip: if you put the closing parenthesis on the next line, you can add extra lines even after the last one without affecting git blame. If you choose to do this, apply it below as well.
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.
Interesting. Changed below and above.
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.
This only applied to cases where the only argument is a multi-line string with implicit concatenation. Not the EXPECT_EQ calls above (which have two arguments each, and the strings aren't even multi-line). Let's revert those two...
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.
Reverted, sorry about that.
test/configuration_unittest.cc
Outdated
| MetadataAgentConfiguration config; | ||
| }; | ||
|
|
||
| TEST_F(MetadataAgentConfigurationTest, NoConfigTest) { |
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.
Nit: the Test suffix is redundant (in the test names in all TEST_F 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.
Removed.
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.
One remaining issue.
test/configuration_unittest.cc
Outdated
| ParseConfiguration( | ||
| "ProjectId: TestProjectId\n" | ||
| "MetadataApiNumThreads: 13\n" | ||
| "MetadataReporterPurgeDeleted: true"); |
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.
This only applied to cases where the only argument is a multi-line string with implicit concatenation. Not the EXPECT_EQ calls above (which have two arguments each, and the strings aren't even multi-line). Let's revert those two...
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.
One last look unearthed a few more minor things in the Makefile...
test/Makefile
Outdated
| CPPFLAGS+=-isystem $(GTEST_DIR)/include | ||
| CXXFLAGS=-std=c++11 -g -pthread | ||
| LDLIBS=-lpthread | ||
| CXXFLAGS=-std=c++11 -g -pthread -I$(YAML_CPP_DIR)/include |
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.
The -I directive should go into CPPFLAGS.
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.
Moved.
test/Makefile
Outdated
|
|
||
| YAML_CPP_LIBS=$(YAML_CPP_LIBDIR)/libyaml-cpp.a | ||
|
|
||
| CMAKE=cmake |
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.
Unused.
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.
Removed.
| TESTS=\ | ||
| base64_unittest \ | ||
| format_unittest \ | ||
| base64_unittest \ |
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.
This looks like a merge conflict. Let's have only one of these (in alphabetical order).
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.
Correct - fixed.
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.
LGTM ![]()
|
FYI, I've backed out the merge and instead squashed all of the commits from this PR into one. |
No description provided.