Skip to content

Commit

Permalink
Cleanup metadata_state dupes in test (pixie-io#1446)
Browse files Browse the repository at this point in the history
Summary: These tests use the same metadata state and the duplicate
construction of the state makes it difficult to keep track of the
state and update it.

Type of change: /kind cleanup

Test Plan: The metadata_ops_test still passes.

Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>
  • Loading branch information
vihangm authored Jun 7, 2023
1 parent f3741ba commit 1dbe6ac
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions src/carnot/funcs/metadata/metadata_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1268,10 +1268,7 @@ TEST_F(MetadataOpsTest, in_value_or_array_test) {
}

TEST_F(MetadataOpsTest, vizier_id_test) {
auto metadata_state = std::make_shared<px::md::AgentMetadataState>(
/* hostname */ "myhost",
/* asid */ 1, /* pid */ 123, agent_id_, "mypod", vizier_id_, "myvizier", "myviziernamespace");
auto function_ctx = std::make_unique<FunctionContext>(metadata_state, nullptr);
auto function_ctx = std::make_unique<FunctionContext>(metadata_state_, nullptr);
auto udf_tester = px::carnot::udf::UDFTester<VizierIDUDF>(std::move(function_ctx));
udf_tester.ForInput().Expect(vizier_id_.str());
}
Expand All @@ -1287,45 +1284,31 @@ TEST_F(MetadataOpsTest, empty_vizier_id_test) {
}

TEST_F(MetadataOpsTest, vizier_name_test) {
auto metadata_state = std::make_shared<px::md::AgentMetadataState>(
/* hostname */ "myhost",
/* asid */ 1, /* pid */ 123, agent_id_, "mypod", vizier_id_, "myvizier", "myviziernamespace");
auto function_ctx = std::make_unique<FunctionContext>(metadata_state, nullptr);
auto function_ctx = std::make_unique<FunctionContext>(metadata_state_, nullptr);
auto udf_tester = px::carnot::udf::UDFTester<VizierNameUDF>(std::move(function_ctx));
udf_tester.ForInput().Expect("myvizier");
}

TEST_F(MetadataOpsTest, vizier_namespace_test) {
auto metadata_state = std::make_shared<px::md::AgentMetadataState>(
/* hostname */ "myhost",
/* asid */ 1, /* pid */ 123, agent_id_, "mypod", vizier_id_, "myvizier", "myviziernamespace");
auto function_ctx = std::make_unique<FunctionContext>(metadata_state, nullptr);
auto function_ctx = std::make_unique<FunctionContext>(metadata_state_, nullptr);
auto udf_tester = px::carnot::udf::UDFTester<VizierNamespaceUDF>(std::move(function_ctx));
udf_tester.ForInput().Expect("myviziernamespace");
}

TEST_F(MetadataOpsTest, basic_upid_test) {
auto metadata_state = std::make_shared<px::md::AgentMetadataState>(
/* hostname */ "myhost",
/* asid */ 1, /* pid */ 123, agent_id_, "mypod", vizier_id_, "myvizier", "myviziernamespace");
auto function_ctx = std::make_unique<FunctionContext>(metadata_state, nullptr);
auto function_ctx = std::make_unique<FunctionContext>(metadata_state_, nullptr);
auto udf_tester = px::carnot::udf::UDFTester<CreateUPIDUDF>(std::move(function_ctx));
udf_tester.ForInput(100, 23123).Expect(md::UPID(1, 100, 23123).value());
}

TEST_F(MetadataOpsTest, basic_upid_with_asid_test) {
auto metadata_state = std::make_shared<px::md::AgentMetadataState>(
/* hostname */ "myhost",
/* asid */ 1, /* pid */ 123, agent_id_, "mypod", vizier_id_, "myvizier", "myviziernamespace");
auto function_ctx = std::make_unique<FunctionContext>(metadata_state, nullptr);
auto function_ctx = std::make_unique<FunctionContext>(metadata_state_, nullptr);
auto udf_tester = px::carnot::udf::UDFTester<CreateUPIDWithASIDUDF>(std::move(function_ctx));
udf_tester.ForInput(2, 100, 23123).Expect(md::UPID(2, 100, 23123).value());
}

TEST_F(MetadataOpsTest, get_cidrs) {
auto metadata_state = std::make_shared<px::md::AgentMetadataState>(
/* hostname */ "myhost",
/* asid */ 1, /* pid */ 123, agent_id_, "mypod", vizier_id_, "myvizier", "myviziernamespace");
auto metadata_state = metadata_state_->CloneToShared();
px::CIDRBlock pod_cidr;
std::string pod_cidr_str("10.0.0.20/32");
ASSERT_OK(px::ParseCIDRBlock(pod_cidr_str, &pod_cidr));
Expand Down

0 comments on commit 1dbe6ac

Please sign in to comment.