Conversation
test/configuration_unittest.cc
Outdated
| TestDefaultConfig(config); | ||
| } | ||
|
|
||
| TEST(ConfigurationTest, SpecificTest) { |
There was a problem hiding this comment.
Rename SpecificTest to PopulatedYamlTest or similar for parity with the previous name.
There was a problem hiding this comment.
Or PopulatedConfigFileTest...
There was a problem hiding this comment.
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.
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.
| } | ||
|
|
||
| private: | ||
| void ParseConfigFile(const std::string& filename); |
There was a problem hiding this comment.
Keep this as private and add the test class as a friend instead. I think there's even a FRIEND_TEST macro...
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.
Is this used anywhere? If not, let's remove it.
| # 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.
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.
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.
Much better, changed.
test/configuration_unittest.cc
Outdated
| TestDefaultConfig(config); | ||
| } | ||
|
|
||
| TEST(ConfigurationTest, BlankYamlTest) { |
There was a problem hiding this comment.
How about BlankConfigFileTest?
There was a problem hiding this comment.
Modified test names, see below
test/configuration_unittest.cc
Outdated
| TestDefaultConfig(config); | ||
| } | ||
|
|
||
| TEST(ConfigurationTest, SpecificTest) { |
There was a problem hiding this comment.
Or PopulatedConfigFileTest...
|
|
||
| TEST(ConfigurationTest, SpecificTest) { | ||
| YAML::Node node = YAML::Load( | ||
| "ProjectId: TestProjectId\n" |
There was a problem hiding this comment.
You should also test that comments are skipped appropriately, possibly in another test case...
test/configuration_unittest.cc
Outdated
|
|
||
| namespace { | ||
|
|
||
| void TestDefaultConfig(google::MetadataAgentConfiguration& config) { |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
Much better, thanks.
| private: | ||
| friend class MetadataAgentConfigurationTest; | ||
| void ParseConfigFile(const std::string& filename); | ||
|
|
There was a problem hiding this comment.
Let's keep this blank line to separate functions from instance variables.
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.
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.
Since you're delegating $(YAML_CPP_LIBS) to src/Makefile, the build-yaml-cpp and yaml-cpp targets are no longer needed.
test/configuration_unittest.cc
Outdated
| static void SetUpTestCase() {} | ||
| static void TearDownTestCase() {} | ||
|
|
||
| void TestDefaultConfig(MetadataAgentConfiguration& config) { |
There was a problem hiding this comment.
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.
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.
Just ParseConfiguration is fine.
| }; | ||
|
|
||
| TEST_F(MetadataAgentConfigurationTest, NoConfigTest) { | ||
| MetadataAgentConfiguration config; |
There was a problem hiding this comment.
You start every test with this. Might as well make this a field in the fixture.
test/configuration_unittest.cc
Outdated
| EXPECT_EQ(true, config.MetadataReporterPurgeDeleted()); | ||
| } | ||
|
|
||
| TEST_F(MetadataAgentConfigurationTest, CommentSkippedTest) { |
There was a problem hiding this comment.
Let's also test for blank lines...
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.
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.
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?
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.
Let's replace ifs with input -- it reads better, IMO.
| } | ||
|
|
||
| private: | ||
| friend class MetadataAgentConfigurationTest; |
There was a problem hiding this comment.
Please add a blank line after this to visually separate it from the functions.
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.
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.
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.
You've removed the yaml-cpp target, right?
There was a problem hiding this comment.
Correct, removed this from phony list.
test/configuration_unittest.cc
Outdated
| namespace google { | ||
|
|
||
| class MetadataAgentConfigurationTest : public ::testing::Test { | ||
| public: |
test/configuration_unittest.cc
Outdated
| class MetadataAgentConfigurationTest : public ::testing::Test { | ||
| public: | ||
| MetadataAgentConfiguration config; | ||
| static void ParseConfiguration(MetadataAgentConfiguration& config, const std::string configString) { |
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.
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.
test/configuration_unittest.cc
Outdated
| } | ||
| }; | ||
|
|
||
| static void TestDefaultConfig(MetadataAgentConfiguration& config) { |
There was a problem hiding this comment.
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 {
...
}).
test/configuration_unittest.cc
Outdated
| EXPECT_EQ(3, config.MetadataApiNumThreads()); | ||
| } | ||
|
|
||
| TEST_F(MetadataAgentConfigurationTest, EmptyLineTest) { |
test/configuration_unittest.cc
Outdated
|
|
||
| TEST_F(MetadataAgentConfigurationTest, EmptyLineTest) { | ||
| ParseConfiguration(config, | ||
| "ProjectId: TestProjectId\n\n\n\n" |
There was a problem hiding this comment.
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.
test/configuration_unittest.cc
Outdated
|
|
||
| class MetadataAgentConfigurationTest : public ::testing::Test { | ||
| protected: | ||
| void ParseConfiguration(const std::string& configString) { |
There was a problem hiding this comment.
The Google style is to use snake_case for variables and parameter names. But you could just name it input instead.
test/configuration_unittest.cc
Outdated
| ParseConfiguration( | ||
| "ProjectId: TestProjectId\n" | ||
| "MetadataApiNumThreads: 13\n" | ||
| "MetadataReporterPurgeDeleted: true"); |
There was a problem hiding this comment.
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.
Interesting. Changed below and above.
There was a problem hiding this comment.
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.
Reverted, sorry about that.
test/configuration_unittest.cc
Outdated
| MetadataAgentConfiguration config; | ||
| }; | ||
|
|
||
| TEST_F(MetadataAgentConfigurationTest, NoConfigTest) { |
There was a problem hiding this comment.
Nit: the Test suffix is redundant (in the test names in all TEST_F lines).
igorpeshansky
left a comment
There was a problem hiding this comment.
One remaining issue.
test/configuration_unittest.cc
Outdated
| ParseConfiguration( | ||
| "ProjectId: TestProjectId\n" | ||
| "MetadataApiNumThreads: 13\n" | ||
| "MetadataReporterPurgeDeleted: true"); |
There was a problem hiding this comment.
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.
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.
The -I directive should go into CPPFLAGS.
test/Makefile
Outdated
|
|
||
| YAML_CPP_LIBS=$(YAML_CPP_LIBDIR)/libyaml-cpp.a | ||
|
|
||
| CMAKE=cmake |
| TESTS=\ | ||
| base64_unittest \ | ||
| format_unittest \ | ||
| base64_unittest \ |
There was a problem hiding this comment.
This looks like a merge conflict. Let's have only one of these (in alphabetical order).
|
FYI, I've backed out the merge and instead squashed all of the commits from this PR into one. |
No description provided.