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

Add test for GetNodeMetadata in kubernetes#102

Merged
ACEmilG merged 7 commits intomasterfrom
ACEmilG-GetNodeMetadata-unittest
Mar 30, 2018
Merged

Add test for GetNodeMetadata in kubernetes#102
ACEmilG merged 7 commits intomasterfrom
ACEmilG-GetNodeMetadata-unittest

Conversation

@ACEmilG
Copy link
Copy Markdown
Contributor

@ACEmilG ACEmilG commented Mar 29, 2018

No description provided.

Comment thread test/Makefile Outdated
$(YAML_CPP_LIBS):
cd $(SRC_DIR) && $(MAKE) $@

$(CPP_NETLIB_LIBS):
Copy link
Copy Markdown
Contributor

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread test/Makefile Outdated
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
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread test/kubernetes_unittest.cc Outdated
@@ -0,0 +1,70 @@
#include "../src/kubernetes.h"
#include "../src/updater.h"
#include "../src/configuration.h"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's alphabetize these.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread test/kubernetes_unittest.cc Outdated
{"version", json::string("TestVersion")},
{"raw", json::object({
{"infrastructureResource",
InstanceReader::InstanceResource(environment).ToJSON()},
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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?

Copy link
Copy Markdown
Contributor

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")},
            })},
          })},

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

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.

Comment thread 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")}
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added.

Comment thread test/kubernetes_unittest.cc Outdated

TEST_F(KubernetesTest, GetNodeMetadata) {
Configuration config(std::stringstream(
"KubernetesClusterName: 'TestClusterName'\n"
Copy link
Copy Markdown
Contributor

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?..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed quotes.

Comment thread test/kubernetes_unittest.cc Outdated
})}
});
const json::Object* node = node_json->As<json::Object>();
MetadataUpdater::ResourceMetadata metadata(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const auto metadata = ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed

Copy link
Copy Markdown
Contributor

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 =...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread test/kubernetes_unittest.cc Outdated
{"node_name", "testname"},
{"location", "TestClusterLocation"}
}));
EXPECT_EQ(metadata.metadata.version, "TestVersion");
Copy link
Copy Markdown
Contributor

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")?

Copy link
Copy Markdown
Contributor Author

@ACEmilG ACEmilG Mar 29, 2018

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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, changed.

Comment thread 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)
Copy link
Copy Markdown
Contributor

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread test/Makefile
LDLIBS=-lpthread -lboost_program_options -lyaml-cpp -lyajl
LDFLAGS=-L$(YAML_CPP_LIBDIR)
LDLIBS=\
-lcppnetlib-client-connections -lcppnetlib-server-parsers -lnetwork-uri \
Copy link
Copy Markdown
Contributor

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread test/kubernetes_unittest.cc Outdated
})}
});
const json::Object* node = node_json->As<json::Object>();
MetadataUpdater::ResourceMetadata metadata(
Copy link
Copy Markdown
Contributor

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 =...

Comment thread test/kubernetes_unittest.cc Outdated
{"node_name", "testname"},
{"location", "TestClusterLocation"}
}));
EXPECT_EQ(metadata.metadata.version, "TestVersion");
Copy link
Copy Markdown
Contributor

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.

"KubernetesClusterName: TestClusterName\n"
"KubernetesClusterLocation: TestClusterLocation\n"
"MetadataIngestionRawContentVersion: TestVersion\n"
"InstanceZone: TestZone\n"
Copy link
Copy Markdown
Contributor

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".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added

Comment thread test/kubernetes_unittest.cc Outdated
{"version", json::string("TestVersion")},
{"raw", json::object({
{"infrastructureResource",
InstanceReader::InstanceResource(environment).ToJSON()},
Copy link
Copy Markdown
Contributor

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")},
            })},
          })},

Comment thread test/kubernetes_unittest.cc Outdated
})},
})},
{"api", json::object({
{"version", json::string("1.6")}, // Hard-coded in kubernetes.cc
Copy link
Copy Markdown
Contributor

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 ..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added.

Comment thread test/kubernetes_unittest.cc Outdated
namespace google {

class KubernetesTest : public ::testing::Test {
protected:
Copy link
Copy Markdown
Contributor

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

"KubernetesClusterLocation: TestClusterLocation\n"
"MetadataIngestionRawContentVersion: TestVersion\n"
"InstanceZone: TestZone\n"
"InstanceResourceType: gce_instance\n"
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved

Comment thread test/kubernetes_unittest.cc Outdated
{"version", json::string("TestVersion")},
{"raw", json::object({
{"infrastructureResource",
InstanceReader::InstanceResource(environment).ToJSON()},
Copy link
Copy Markdown
Contributor

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.

Comment thread test/kubernetes_unittest.cc Outdated
@@ -0,0 +1,72 @@
#include "../src/configuration.h"
#include "../src/instance.h"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No longer used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

@igorpeshansky igorpeshansky requested a review from dhrupadb March 30, 2018 13:48
Copy link
Copy Markdown
Contributor

@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.

LGTM :shipit:

Copy link
Copy Markdown
Contributor

@dhrupadb dhrupadb left a 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 👌

Comment thread test/kubernetes_unittest.cc Outdated
"InstanceId: TestID\n"
));
Environment environment(config);
KubernetesReader reader(config, nullptr);
Copy link
Copy Markdown
Contributor

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.

@ACEmilG ACEmilG merged commit f6b9b59 into master Mar 30, 2018
@ACEmilG ACEmilG deleted the ACEmilG-GetNodeMetadata-unittest branch March 30, 2018 14:59
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