-
Notifications
You must be signed in to change notification settings - Fork 11
Add test for GetNodeMetadata in kubernetes #102
Conversation
test/Makefile
Outdated
@@ -63,6 +75,9 @@ init-submodules: | |||
$(YAML_CPP_LIBS): | |||
cd $(SRC_DIR) && $(MAKE) $@ | |||
|
|||
$(CPP_NETLIB_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.
Let's keep these in the same order as src/Makefile
(i.e., move this above the $(YAML_CPP_LIBS)
target).
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
@@ -83,6 +98,12 @@ base64_unittest: $(GTEST_LIB) base64_unittest.o $(SRC_DIR)/base64.o | |||
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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/kubernetes_unittest.cc
Outdated
@@ -0,0 +1,70 @@ | |||
#include "../src/kubernetes.h" | |||
#include "../src/updater.h" | |||
#include "../src/configuration.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.
Let's alphabetize these.
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/kubernetes_unittest.cc
Outdated
{"version", json::string("TestVersion")}, | ||
{"raw", json::object({ | ||
{"infrastructureResource", | ||
InstanceReader::InstanceResource(environment).ToJSON()}, |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean here - can you give some psudocode?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
test/kubernetes_unittest.cc
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep trailing commas in these key/value pairs for inline JSON. Also below.
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/kubernetes_unittest.cc
Outdated
|
||
TEST_F(KubernetesTest, GetNodeMetadata) { | ||
Configuration config(std::stringstream( | ||
"KubernetesClusterName: 'TestClusterName'\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.
Single quotes behave weirdly in YAML. Since these are all bare words, let's just not quote them at all?..
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 quotes.
test/kubernetes_unittest.cc
Outdated
})} | ||
}); | ||
const json::Object* node = node_json->As<json::Object>(); | ||
MetadataUpdater::ResourceMetadata metadata( |
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 auto metadata = ...
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
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 forgot to change the parens to =
...
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.
test/kubernetes_unittest.cc
Outdated
{"node_name", "testname"}, | ||
{"location", "TestClusterLocation"} | ||
})); | ||
EXPECT_EQ(metadata.metadata.version, "TestVersion"); |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just m
? It's a test, so variable naming can be a little looser.
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.
test/Makefile
Outdated
-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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make the order of the libraries match the one in src/Makefile
exactly (since the set is now identical).
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/kubernetes_unittest.cc
Outdated
})} | ||
}); | ||
const json::Object* node = node_json->As<json::Object>(); | ||
MetadataUpdater::ResourceMetadata metadata( |
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 forgot to change the parens to =
...
test/kubernetes_unittest.cc
Outdated
{"node_name", "testname"}, | ||
{"location", "TestClusterLocation"} | ||
})); | ||
EXPECT_EQ(metadata.metadata.version, "TestVersion"); |
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 just m
? It's a test, so variable naming can be a little looser.
test/kubernetes_unittest.cc
Outdated
"KubernetesClusterName: TestClusterName\n" | ||
"KubernetesClusterLocation: TestClusterLocation\n" | ||
"MetadataIngestionRawContentVersion: TestVersion\n" | ||
"InstanceZone: TestZone\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.
Should also add "InstanceResourceType: gce_instance\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.
Added
test/kubernetes_unittest.cc
Outdated
{"version", json::string("TestVersion")}, | ||
{"raw", json::object({ | ||
{"infrastructureResource", | ||
InstanceReader::InstanceResource(environment).ToJSON()}, |
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.
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")},
})},
})},
test/kubernetes_unittest.cc
Outdated
})}, | ||
})}, | ||
{"api", json::object({ | ||
{"version", json::string("1.6")}, // Hard-coded in kubernetes.cc |
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: still missing the trailing .
.
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/kubernetes_unittest.cc
Outdated
namespace google { | ||
|
||
class KubernetesTest : public ::testing::Test { | ||
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.
Please indent access modifiers by 1 space, and the class body by 2 spaces (style guide).
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
test/kubernetes_unittest.cc
Outdated
"KubernetesClusterLocation: TestClusterLocation\n" | ||
"MetadataIngestionRawContentVersion: TestVersion\n" | ||
"InstanceZone: TestZone\n" | ||
"InstanceResourceType: gce_instance\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.
Let's put this above InstanceZone
.
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/kubernetes_unittest.cc
Outdated
{"version", json::string("TestVersion")}, | ||
{"raw", json::object({ | ||
{"infrastructureResource", | ||
InstanceReader::InstanceResource(environment).ToJSON()}, |
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 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.
test/kubernetes_unittest.cc
Outdated
@@ -0,0 +1,72 @@ | |||
#include "../src/configuration.h" | |||
#include "../src/instance.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.
No longer used.
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
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
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 minor nit comment, otherwise
LGTM 👌
test/kubernetes_unittest.cc
Outdated
"InstanceId: TestID\n" | ||
)); | ||
Environment environment(config); | ||
KubernetesReader reader(config, nullptr); |
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 add a comment with what we're nulling out here -- makes it easier to understand.
No description provided.