Added test for ComputePodAssociations#109
Conversation
test/kubernetes_unittest.cc
Outdated
| } | ||
|
|
||
| json::value ComputePodAssociations(const json::Object* pod, | ||
| const KubernetesReader& reader) { |
There was a problem hiding this comment.
Indentation. Want to switch your editor config to expand tabs to spaces? Also below.
| "InstanceId: TestID\n" | ||
| )); | ||
| Environment environment(config); | ||
| KubernetesReader reader(config, nullptr); // Don't need HealthChecker. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
It should already be commented in all other locations.
There was a problem hiding this comment.
This seems to be the only place, FWIW.
test/kubernetes_unittest.cc
Outdated
| 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}, "/"); |
There was a problem hiding this comment.
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.
test/kubernetes_unittest.cc
Outdated
| return reader.ComputePodAssociations(pod); | ||
| } | ||
|
|
||
| void InsertIntoOwners(const std::string& key, json::value& value, |
test/kubernetes_unittest.cc
Outdated
| 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)}, |
There was a problem hiding this comment.
2-space indent, please.
test/kubernetes_unittest.cc
Outdated
| })}, | ||
| }); | ||
|
|
||
| auto associations = ComputePodAssociations(pod->As<json::Object>(), reader); |
test/kubernetes_unittest.cc
Outdated
|
|
||
| auto associations = ComputePodAssociations(pod->As<json::Object>(), reader); | ||
|
|
||
| EXPECT_EQ(associations->ToString(), json::object({ |
There was a problem hiding this comment.
I would suggest pulling this json::object out into an expected_associations local.
test/kubernetes_unittest.cc
Outdated
|
|
||
| auto associations = ComputePodAssociations(pod->As<json::Object>(), reader); | ||
|
|
||
| EXPECT_EQ(associations->ToString(), json::object({ |
There was a problem hiding this comment.
Let's stick with the EXPECT_EQ(expected, actual) parameter order throughout.
igorpeshansky
left a comment
There was a problem hiding this comment.
One minor formatting nit.
| "InstanceId: TestID\n" | ||
| )); | ||
| Environment environment(config); | ||
| KubernetesReader reader(config, nullptr); // Don't need HealthChecker. |
There was a problem hiding this comment.
This seems to be the only place, FWIW.
test/kubernetes_unittest.cc
Outdated
| })}, | ||
| {"version", json::string("TestVersion")}, | ||
| }); | ||
| const auto associations = ComputePodAssociations(pod->As<json::Object>(), reader); |
There was a problem hiding this comment.
Let's stay within 80 characters. I'd break after the =, personally...
test/kubernetes_unittest.cc
Outdated
| return reader.GetNodeMetadata(node, collected_at, is_deleted); | ||
| } | ||
|
|
||
| json::value ComputePodAssociations(const json::Object* pod, |
There was a problem hiding this comment.
Just noticed — let's make reader the first argument, both here and in UpdateOwnersCache.
test/kubernetes_unittest.cc
Outdated
| return reader.ComputePodAssociations(pod); | ||
| } | ||
|
|
||
| void UpdateOwnersCache(const std::string& key, json::value& value, |
There was a problem hiding this comment.
const json::value& value.
test/kubernetes_unittest.cc
Outdated
| } | ||
|
|
||
| TEST_F(KubernetesTest, ComputePodAssociations) { | ||
| const std::string api_version = "1.2.3"; |
There was a problem hiding this comment.
Let's inline these as well and get rid of the local variables.
test/kubernetes_unittest.cc
Outdated
| {"infrastructureResource", json::object({ | ||
| {"labels", json::object({ | ||
| {"instance_id", json::string("TestID")}, | ||
| {"zone", json::string("TestZone")} |
There was a problem hiding this comment.
Let's keep the trailing comma.
igorpeshansky
left a comment
There was a problem hiding this comment.
One more tiny cleanup.
test/kubernetes_unittest.cc
Outdated
| )); | ||
| Environment environment(config); | ||
| KubernetesReader reader(config, nullptr); // Don't need HealthChecker. | ||
| const std::string encoded_ref = "1.2.3/TestKind/TestUID1"; |
There was a problem hiding this comment.
Let's move this to just before the call to UpdateOwnersCache. Or, better yet, just inline the value into the call.
| 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({ |
There was a problem hiding this comment.
Let's just inline the json::object() call into the UpdateOwnersCache call.
There was a problem hiding this comment.
Actually: we use controller in another location, and thus I think its better to keep as a variable.
There was a problem hiding this comment.
Ah, you're right, but then let's use std::move(controller) instead of controller->Clone() below (no point in making gratuitous copies).
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
Ah, you're right, but then let's use std::move(controller) instead of controller->Clone() below (no point in making gratuitous copies).
| 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({ |
There was a problem hiding this comment.
Just pushed a commit with a fix.
No description provided.