@@ -1133,28 +1133,19 @@ TEST(TableMetadataBuilderTest, RemoveSchemasAfterSchemaChange) {
11331133 ASSERT_THAT (builder->Build (), HasErrorMessage (" Cannot remove current schema: 1" ));
11341134}
11351135
1136- // Test RemoveSnapshotRef
1137- TEST (TableMetadataBuilderTest, RemoveSnapshotRefBasic) {
1136+ TEST (TableMetadataBuilderTest, RemoveSnapshotRef) {
11381137 auto base = CreateBaseMetadata ();
11391138 auto builder = TableMetadataBuilder::BuildFrom (base.get ());
11401139
11411140 // Add multiple snapshots
1142- auto snapshot1 = std::make_shared<Snapshot>();
1143- snapshot1->snapshot_id = 1 ;
1144- builder->AddSnapshot (snapshot1);
1145- auto snapshot2 = std::make_shared<Snapshot>();
1146- snapshot2->snapshot_id = 2 ;
1147- builder->AddSnapshot (snapshot2);
1141+ builder->AddSnapshot (std::make_shared<Snapshot>(Snapshot{.snapshot_id = 1 }));
1142+ builder->AddSnapshot (std::make_shared<Snapshot>(Snapshot{.snapshot_id = 2 }));
11481143
11491144 // Add multiple refs
1150- auto ref1 = std::make_shared<SnapshotRef>();
1151- ref1->snapshot_id = 1 ;
1152- ref1->retention = SnapshotRef::Branch{};
1153- builder->SetRef (" ref1" , ref1);
1154- auto ref2 = std::make_shared<SnapshotRef>();
1155- ref2->snapshot_id = 2 ;
1156- ref2->retention = SnapshotRef::Tag{};
1157- builder->SetRef (" ref2" , ref2);
1145+ ICEBERG_UNWRAP_OR_FAIL (auto ref1, SnapshotRef::MakeBranch (1 ));
1146+ ICEBERG_UNWRAP_OR_FAIL (auto ref2, SnapshotRef::MakeBranch (2 ));
1147+ builder->SetRef (" ref1" , std::move (ref1));
1148+ builder->SetRef (" ref2" , std::move (ref2));
11581149
11591150 ICEBERG_UNWRAP_OR_FAIL (auto metadata, builder->Build ());
11601151 ASSERT_EQ (metadata->refs .size (), 2 );
@@ -1167,68 +1158,50 @@ TEST(TableMetadataBuilderTest, RemoveSnapshotRefBasic) {
11671158 EXPECT_TRUE (metadata->refs .contains (" ref1" ));
11681159}
11691160
1170- // Test RemoveSnapshot
1171- TEST (TableMetadataBuilderTest, RemoveSnapshotBasic) {
1161+ TEST (TableMetadataBuilderTest, RemoveSnapshot) {
11721162 auto base = CreateBaseMetadata ();
11731163 auto builder = TableMetadataBuilder::BuildFrom (base.get ());
11741164
11751165 // Add multiple snapshots
1176- auto snapshot1 = std::make_shared<Snapshot>();
1177- snapshot1->snapshot_id = 1 ;
1178- builder->AddSnapshot (snapshot1);
1179- auto snapshot2 = std::make_shared<Snapshot>();
1180- snapshot2->snapshot_id = 2 ;
1181- builder->AddSnapshot (snapshot2);
1166+ builder->AddSnapshot (std::make_shared<Snapshot>(Snapshot{.snapshot_id = 1 }));
1167+ builder->AddSnapshot (std::make_shared<Snapshot>(Snapshot{.snapshot_id = 2 }));
11821168
11831169 ICEBERG_UNWRAP_OR_FAIL (auto metadata, builder->Build ());
11841170 ASSERT_EQ (metadata->snapshots .size (), 2 );
11851171
11861172 // Remove one snapshot
11871173 builder = TableMetadataBuilder::BuildFrom (metadata.get ());
1188- std::vector<int64_t > to_remove{snapshot2-> snapshot_id };
1174+ std::vector<int64_t > to_remove{2 };
11891175 builder->RemoveSnapshots (to_remove);
11901176 ICEBERG_UNWRAP_OR_FAIL (metadata, builder->Build ());
11911177 ASSERT_EQ (metadata->snapshots .size (), 1 );
1192- for (const auto & s : metadata->snapshots ) {
1193- std::cout << s->snapshot_id << std::endl;
1194- }
1195- EXPECT_TRUE (
1196- std::ranges::find_if (metadata->snapshots , [&](const std::shared_ptr<Snapshot>& s) {
1197- return s->snapshot_id == snapshot1->snapshot_id ;
1198- }) != metadata->snapshots .end ());
1178+ ASSERT_THAT (metadata->SnapshotById (2 ), IsError (ErrorKind::kNotFound ));
11991179}
12001180
12011181TEST (TableMetadataBuilderTest, RemoveSnapshotNotExist) {
12021182 auto base = CreateBaseMetadata ();
12031183 auto builder = TableMetadataBuilder::BuildFrom (base.get ());
12041184
12051185 // Add multiple snapshots
1206- auto snapshot1 = std::make_shared<Snapshot>();
1207- snapshot1->snapshot_id = 1 ;
1208- builder->AddSnapshot (snapshot1);
1209- auto snapshot2 = std::make_shared<Snapshot>();
1210- snapshot2->snapshot_id = 2 ;
1211- builder->AddSnapshot (snapshot2);
1186+ builder->AddSnapshot (std::make_shared<Snapshot>(Snapshot{.snapshot_id = 1 }));
1187+ builder->AddSnapshot (std::make_shared<Snapshot>(Snapshot{.snapshot_id = 2 }));
12121188
12131189 ICEBERG_UNWRAP_OR_FAIL (auto metadata, builder->Build ());
12141190 ASSERT_EQ (metadata->snapshots .size (), 2 );
12151191
12161192 // Remove one snapshot
12171193 builder = TableMetadataBuilder::BuildFrom (metadata.get ());
1218- std::vector<int64_t > to_remove{3 };
1219- builder->RemoveSnapshots (to_remove);
1194+ builder->RemoveSnapshots (std::vector<int64_t >{3 });
12201195 ICEBERG_UNWRAP_OR_FAIL (metadata, builder->Build ());
12211196 ASSERT_EQ (metadata->snapshots .size (), 2 );
12221197
12231198 builder = TableMetadataBuilder::BuildFrom (metadata.get ());
1224- to_remove = {1 , 2 };
1225- builder->RemoveSnapshots (to_remove);
1199+ builder->RemoveSnapshots (std::vector<int64_t >{1 , 2 });
12261200 ICEBERG_UNWRAP_OR_FAIL (metadata, builder->Build ());
12271201 ASSERT_EQ (metadata->snapshots .size (), 0 );
12281202}
12291203
1230- // Test RemovePartitionSpec
1231- TEST (TableMetadataBuilderTest, RemovePartitionSpecBasic) {
1204+ TEST (TableMetadataBuilderTest, RemovePartitionSpec) {
12321205 // Add multiple specs
12331206 PartitionField field1 (2 , 4 , " field1" , Transform::Identity ());
12341207 PartitionField field2 (3 , 5 , " field2" , Transform::Identity ());
@@ -1248,10 +1221,7 @@ TEST(TableMetadataBuilderTest, RemovePartitionSpecBasic) {
12481221 builder->RemovePartitionSpecs ({2 });
12491222 ICEBERG_UNWRAP_OR_FAIL (metadata, builder->Build ());
12501223 ASSERT_EQ (metadata->partition_specs .size (), 1 );
1251- EXPECT_TRUE (std::ranges::find_if (metadata->partition_specs ,
1252- [&](const std::shared_ptr<PartitionSpec>& s) {
1253- return s->spec_id () == 1 ;
1254- }) != metadata->partition_specs .end ());
1224+ ASSERT_THAT (metadata->PartitionSpecById (2 ), IsError (ErrorKind::kNotFound ));
12551225}
12561226
12571227TEST (TableMetadataBuilderTest, RemovePartitionSpecNotExist) {
@@ -1269,7 +1239,7 @@ TEST(TableMetadataBuilderTest, RemovePartitionSpecNotExist) {
12691239 ICEBERG_UNWRAP_OR_FAIL (auto metadata, builder->Build ());
12701240 ASSERT_EQ (metadata->partition_specs .size (), 2 );
12711241
1272- // Remove one not exist spec
1242+ // Remove one non-existing spec
12731243 builder = TableMetadataBuilder::BuildFrom (metadata.get ());
12741244 builder->RemovePartitionSpecs ({3 });
12751245 ICEBERG_UNWRAP_OR_FAIL (metadata, builder->Build ());
0 commit comments