Add test for GetNodeMetadata in kubernetes#102
Conversation
| $(YAML_CPP_LIBS): | ||
| cd $(SRC_DIR) && $(MAKE) $@ | ||
|
|
||
| $(CPP_NETLIB_LIBS): |
There was a problem hiding this comment.
Let's keep these in the same order as src/Makefile (i.e., move this above the $(YAML_CPP_LIBS) target).
| configuration_unittest: $(GTEST_LIB) $(YAML_CPP_LIBS) configuration_unittest.o $(SRC_DIR)/configuration.o | ||
| $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ | ||
| kubernetes_unittest: $(GTEST_LIB) kubernetes_unittest.o $(SRC_DIR)/kubernetes.o | ||
| $(SRC_DIR)/json.o $(SRC_DIR)/logging.o $(SRC_DIR)/environment.o |
There was a problem hiding this comment.
I think you meant these as a continuation of the dependencies, right?.. Let's just keep them all on one line for now, even if it runs over 80 characters.
| @@ -0,0 +1,70 @@ | |||
| #include "../src/kubernetes.h" | |||
| #include "../src/updater.h" | |||
| #include "../src/configuration.h" | |||
There was a problem hiding this comment.
Let's alphabetize these.
| {"version", json::string("TestVersion")}, | ||
| {"raw", json::object({ | ||
| {"infrastructureResource", | ||
| InstanceReader::InstanceResource(environment).ToJSON()}, |
There was a problem hiding this comment.
Just construct the instance resource JSON, rather than replicating the construction from the source. We can test this function separately.
There was a problem hiding this comment.
Not sure what you mean here - can you give some psudocode?
There was a problem hiding this comment.
Better — I can give you code 😄:
{"infrastructureResource", json::object({
{"type", json::string("gce_instance")},
{"labels", json::object({
{"instance_id", json::string("TestID")},
{"zone", json::string("TestZone")},
})},
})},There was a problem hiding this comment.
Done. However, to me, this seems more like testing the InstanceReader::InstanceResource function to me; If that function changes, this test will break.
There was a problem hiding this comment.
We are actually testing that the metadata for a Kubernetes node looks as expected, regardless of the InstanceReader::InstanceResource implementation. If that function's implementation changes, we'll need to fix the call, not the test.
| json::value node_json = json::object({ | ||
| {"metadata", json::object({ | ||
| {"name", json::string("testname")}, | ||
| {"creationTimestamp", json::string("2018-03-03T01:23:45.678901234Z")} |
There was a problem hiding this comment.
Let's keep trailing commas in these key/value pairs for inline JSON. Also below.
|
|
||
| TEST_F(KubernetesTest, GetNodeMetadata) { | ||
| Configuration config(std::stringstream( | ||
| "KubernetesClusterName: 'TestClusterName'\n" |
There was a problem hiding this comment.
Single quotes behave weirdly in YAML. Since these are all bare words, let's just not quote them at all?..
| })} | ||
| }); | ||
| const json::Object* node = node_json->As<json::Object>(); | ||
| MetadataUpdater::ResourceMetadata metadata( |
There was a problem hiding this comment.
const auto metadata = ...
There was a problem hiding this comment.
You forgot to change the parens to =...
| {"node_name", "testname"}, | ||
| {"location", "TestClusterLocation"} | ||
| })); | ||
| EXPECT_EQ(metadata.metadata.version, "TestVersion"); |
There was a problem hiding this comment.
metadata.metadata looks weird (and metadata.metadata.metadata even weirder 😄). How about we call it rmd (for "resource metadata")?
There was a problem hiding this comment.
While I agree it looks weird, I think changing the name to rmd would be more confusing. I'm not sure how to get around having metadata.metadata.metadata, since that really seems to be what this is.
There was a problem hiding this comment.
How about just m? It's a test, so variable naming can be a little looser.
| -lcppnetlib-client-connections -lcppnetlib-server-parsers -lnetwork-uri \ | ||
| -lpthread -lboost_program_options -lboost_system -lboost_thread \ | ||
| -lboost_filesystem -lyaml-cpp -lyajl -lcrypto -lssl | ||
| LDFLAGS=-L$(CPP_NETLIB_LIBDIR) -L$(NETWORK_URI_LIBDIR) -L$(YAML_CPP_LIBDIR) |
There was a problem hiding this comment.
Let's put LDFLAGS above LDLIBS to make it consistent with src/Makefile (yes, I know this pre-dates your change, but you're already touching both lines).
| LDLIBS=-lpthread -lboost_program_options -lyaml-cpp -lyajl | ||
| LDFLAGS=-L$(YAML_CPP_LIBDIR) | ||
| LDLIBS=\ | ||
| -lcppnetlib-client-connections -lcppnetlib-server-parsers -lnetwork-uri \ |
There was a problem hiding this comment.
Let's make the order of the libraries match the one in src/Makefile exactly (since the set is now identical).
| })} | ||
| }); | ||
| const json::Object* node = node_json->As<json::Object>(); | ||
| MetadataUpdater::ResourceMetadata metadata( |
There was a problem hiding this comment.
You forgot to change the parens to =...
| {"node_name", "testname"}, | ||
| {"location", "TestClusterLocation"} | ||
| })); | ||
| EXPECT_EQ(metadata.metadata.version, "TestVersion"); |
There was a problem hiding this comment.
How about just m? It's a test, so variable naming can be a little looser.
| "KubernetesClusterName: TestClusterName\n" | ||
| "KubernetesClusterLocation: TestClusterLocation\n" | ||
| "MetadataIngestionRawContentVersion: TestVersion\n" | ||
| "InstanceZone: TestZone\n" |
There was a problem hiding this comment.
Should also add "InstanceResourceType: gce_instance\n".
| {"version", json::string("TestVersion")}, | ||
| {"raw", json::object({ | ||
| {"infrastructureResource", | ||
| InstanceReader::InstanceResource(environment).ToJSON()}, |
There was a problem hiding this comment.
Better — I can give you code 😄:
{"infrastructureResource", json::object({
{"type", json::string("gce_instance")},
{"labels", json::object({
{"instance_id", json::string("TestID")},
{"zone", json::string("TestZone")},
})},
})},| })}, | ||
| })}, | ||
| {"api", json::object({ | ||
| {"version", json::string("1.6")}, // Hard-coded in kubernetes.cc |
There was a problem hiding this comment.
Nit: still missing the trailing ..
| namespace google { | ||
|
|
||
| class KubernetesTest : public ::testing::Test { | ||
| protected: |
There was a problem hiding this comment.
Please indent access modifiers by 1 space, and the class body by 2 spaces (style guide).
| "KubernetesClusterLocation: TestClusterLocation\n" | ||
| "MetadataIngestionRawContentVersion: TestVersion\n" | ||
| "InstanceZone: TestZone\n" | ||
| "InstanceResourceType: gce_instance\n" |
There was a problem hiding this comment.
Let's put this above InstanceZone.
| {"version", json::string("TestVersion")}, | ||
| {"raw", json::object({ | ||
| {"infrastructureResource", | ||
| InstanceReader::InstanceResource(environment).ToJSON()}, |
There was a problem hiding this comment.
We are actually testing that the metadata for a Kubernetes node looks as expected, regardless of the InstanceReader::InstanceResource implementation. If that function's implementation changes, we'll need to fix the call, not the test.
| @@ -0,0 +1,72 @@ | |||
| #include "../src/configuration.h" | |||
| #include "../src/instance.h" | |||
dhrupadb
left a comment
There was a problem hiding this comment.
One minor nit comment, otherwise
LGTM 👌
| "InstanceId: TestID\n" | ||
| )); | ||
| Environment environment(config); | ||
| KubernetesReader reader(config, nullptr); |
There was a problem hiding this comment.
Let's add a comment with what we're nulling out here -- makes it easier to understand.
No description provided.