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

Added test for ComputePodAssociations #109

Merged
merged 7 commits into from
Mar 31, 2018
Merged

Conversation

ACEmilG
Copy link
Contributor

@ACEmilG ACEmilG commented Mar 30, 2018

No description provided.

@@ -13,6 +15,16 @@ class KubernetesTest : public ::testing::Test {
throw(json::Exception) {
return reader.GetNodeMetadata(node, collected_at, is_deleted);
}

json::value ComputePodAssociations(const json::Object* pod,
const KubernetesReader& reader) {
Copy link
Member

Choose a reason for hiding this comment

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

Indentation. Want to switch your editor config to expand tabs to spaces? Also below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed all over

"InstanceId: TestID\n"
));
Environment environment(config);
KubernetesReader reader(config, nullptr); // Don't need HealthChecker.
Copy link
Member

Choose a reason for hiding this comment

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

The statement in the comment is kind of obvious from you setting it to nullptr, but if you choose to keep it, please update the other place where you do the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should already be commented in all other locations.

Copy link
Member

Choose a reason for hiding this comment

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

This seems to be the only place, FWIW.

Environment environment(config);
KubernetesReader reader(config, nullptr); // Don't need HealthChecker.
const std::string encoded_ref = boost::algorithm::join(
std::vector<std::string>{api_version, kind, uid1}, "/");
Copy link
Member

Choose a reason for hiding this comment

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

Let's avoid this kind of logic in tests. Anything more complicated than "the same string goes in and out" is probably not worth the readability hit. Just use literal strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, done.

return reader.ComputePodAssociations(pod);
}

void InsertIntoOwners(const std::string& key, json::value& value,
Copy link
Member

Choose a reason for hiding this comment

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

UpdateOwnersCache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

const std::string encoded_ref = boost::algorithm::join(
std::vector<std::string>{api_version, kind, uid1}, "/");
json::value controller = json::object({
{"controller", json::boolean(true)},
Copy link
Member

Choose a reason for hiding this comment

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

2-space indent, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

})},
});

auto associations = ComputePodAssociations(pod->As<json::Object>(), reader);
Copy link
Member

Choose a reason for hiding this comment

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

const auto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


auto associations = ComputePodAssociations(pod->As<json::Object>(), reader);

EXPECT_EQ(associations->ToString(), json::object({
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest pulling this json::object out into an expected_associations local.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


auto associations = ComputePodAssociations(pod->As<json::Object>(), reader);

EXPECT_EQ(associations->ToString(), json::object({
Copy link
Member

Choose a reason for hiding this comment

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

Let's stick with the EXPECT_EQ(expected, actual) parameter order throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

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

One minor formatting nit.

"InstanceId: TestID\n"
));
Environment environment(config);
KubernetesReader reader(config, nullptr); // Don't need HealthChecker.
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be the only place, FWIW.

})},
{"version", json::string("TestVersion")},
});
const auto associations = ComputePodAssociations(pod->As<json::Object>(), reader);
Copy link
Member

Choose a reason for hiding this comment

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

Let's stay within 80 characters. I'd break after the =, personally...

Copy link
Member

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

Minor nits.

@@ -13,6 +15,16 @@ class KubernetesTest : public ::testing::Test {
throw(json::Exception) {
return reader.GetNodeMetadata(node, collected_at, is_deleted);
}

json::value ComputePodAssociations(const json::Object* pod,
Copy link
Member

Choose a reason for hiding this comment

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

Just noticed — let's make reader the first argument, both here and in UpdateOwnersCache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return reader.ComputePodAssociations(pod);
}

void UpdateOwnersCache(const std::string& key, json::value& value,
Copy link
Member

Choose a reason for hiding this comment

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

const json::value& value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -68,4 +80,67 @@ TEST_F(KubernetesTest, GetNodeMetadata) {
});
EXPECT_EQ(big->ToString(), m.metadata.metadata->ToString());
}

TEST_F(KubernetesTest, ComputePodAssociations) {
const std::string api_version = "1.2.3";
Copy link
Member

Choose a reason for hiding this comment

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

Let's inline these as well and get rid of the local variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

{"infrastructureResource", json::object({
{"labels", json::object({
{"instance_id", json::string("TestID")},
{"zone", json::string("TestZone")}
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep the trailing comma.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inserted.

Copy link
Member

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

One more tiny cleanup.

));
Environment environment(config);
KubernetesReader reader(config, nullptr); // Don't need HealthChecker.
const std::string encoded_ref = "1.2.3/TestKind/TestUID1";
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this to just before the call to UpdateOwnersCache. Or, better yet, just inline the value into the call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inlined

Environment environment(config);
KubernetesReader reader(config, nullptr); // Don't need HealthChecker.
const std::string encoded_ref = "1.2.3/TestKind/TestUID1";
json::value controller = json::object({
Copy link
Member

Choose a reason for hiding this comment

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

Let's just inline the json::object() call into the UpdateOwnersCache call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inlined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually: we use controller in another location, and thus I think its better to keep as a variable.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you're right, but then let's use std::move(controller) instead of controller->Clone() below (no point in making gratuitous copies).

Copy link
Member

Choose a reason for hiding this comment

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

Just pushed a commit with a fix.

Environment environment(config);
KubernetesReader reader(config, nullptr); // Don't need HealthChecker.
const std::string encoded_ref = "1.2.3/TestKind/TestUID1";
json::value controller = json::object({
Copy link
Member

Choose a reason for hiding this comment

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

Ah, you're right, but then let's use std::move(controller) instead of controller->Clone() below (no point in making gratuitous copies).

Copy link
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

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

Environment environment(config);
KubernetesReader reader(config, nullptr); // Don't need HealthChecker.
const std::string encoded_ref = "1.2.3/TestKind/TestUID1";
json::value controller = json::object({
Copy link
Member

Choose a reason for hiding this comment

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

Just pushed a commit with a fix.

@igorpeshansky igorpeshansky merged commit 67de9d0 into master Mar 31, 2018
@igorpeshansky igorpeshansky deleted the ACEmilG-compute_unittest branch March 31, 2018 21:10
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