1919
2020#include " iceberg/update/update_properties.h"
2121
22- #include " iceberg/table.h"
22+ #include < gtest/gtest.h>
23+
2324#include " iceberg/table_update.h"
2425#include " iceberg/test/matchers.h"
2526#include " iceberg/test/update_test_base.h"
@@ -28,11 +29,6 @@ namespace iceberg {
2829
2930class UpdatePropertiesTest : public UpdateTestBase {};
3031
31- TEST_F (UpdatePropertiesTest, EmptyUpdates) {
32- ICEBERG_UNWRAP_OR_FAIL (auto update, table_->NewUpdateProperties ());
33- EXPECT_THAT (update->Commit (), IsOk ());
34- }
35-
3632TEST_F (UpdatePropertiesTest, SetProperty) {
3733 ICEBERG_UNWRAP_OR_FAIL (auto update, table_->NewUpdateProperties ());
3834 update->Set (" key1" , " value1" ).Set (" key2" , " value2" );
@@ -43,7 +39,14 @@ TEST_F(UpdatePropertiesTest, SetProperty) {
4339}
4440
4541TEST_F (UpdatePropertiesTest, RemoveProperty) {
46- ICEBERG_UNWRAP_OR_FAIL (auto update, table_->NewUpdateProperties ());
42+ // First, add properties to remove
43+ ICEBERG_UNWRAP_OR_FAIL (auto setup_update, table_->NewUpdateProperties ());
44+ setup_update->Set (" key1" , " value1" ).Set (" key2" , " value2" );
45+ EXPECT_THAT (setup_update->Commit (), IsOk ());
46+
47+ // Reload and remove the properties
48+ ICEBERG_UNWRAP_OR_FAIL (auto reloaded, catalog_->LoadTable (table_ident_));
49+ ICEBERG_UNWRAP_OR_FAIL (auto update, reloaded->NewUpdateProperties ());
4750 update->Remove (" key1" ).Remove (" key2" );
4851
4952 ICEBERG_UNWRAP_OR_FAIL (auto result, update->Apply ());
@@ -69,6 +72,17 @@ TEST_F(UpdatePropertiesTest, RemoveThenSetSameKey) {
6972 EXPECT_THAT (result, HasErrorMessage (" already marked for removal" ));
7073}
7174
75+ TEST_F (UpdatePropertiesTest, SetAndRemoveDifferentKeys) {
76+ ICEBERG_UNWRAP_OR_FAIL (auto update, table_->NewUpdateProperties ());
77+ update->Set (" key1" , " value1" ).Remove (" key2" );
78+ EXPECT_THAT (update->Commit (), IsOk ());
79+
80+ ICEBERG_UNWRAP_OR_FAIL (auto reloaded, catalog_->LoadTable (table_ident_));
81+ const auto & props = reloaded->properties ().configs ();
82+ EXPECT_EQ (props.at (" key1" ), " value1" );
83+ EXPECT_FALSE (props.contains (" key2" ));
84+ }
85+
7286TEST_F (UpdatePropertiesTest, UpgradeFormatVersionValid) {
7387 ICEBERG_UNWRAP_OR_FAIL (auto update, table_->NewUpdateProperties ());
7488 update->Set (" format-version" , " 2" );
@@ -108,33 +122,20 @@ TEST_F(UpdatePropertiesTest, UpgradeFormatVersionUnsupported) {
108122}
109123
110124TEST_F (UpdatePropertiesTest, CommitSuccess) {
125+ ICEBERG_UNWRAP_OR_FAIL (auto empty_update, table_->NewUpdateProperties ());
126+ EXPECT_THAT (empty_update->Commit (), IsOk ());
127+
111128 ICEBERG_UNWRAP_OR_FAIL (auto update, table_->NewUpdateProperties ());
112129 update->Set (" new.property" , " new.value" );
130+ update->Set (" format-version" , " 3" );
113131
114132 EXPECT_THAT (update->Commit (), IsOk ());
115133
116134 ICEBERG_UNWRAP_OR_FAIL (auto reloaded, catalog_->LoadTable (table_ident_));
117135 const auto & props = reloaded->properties ().configs ();
118136 EXPECT_EQ (props.at (" new.property" ), " new.value" );
119- }
120-
121- TEST_F (UpdatePropertiesTest, FluentInterface) {
122- ICEBERG_UNWRAP_OR_FAIL (auto update, table_->NewUpdateProperties ());
123- auto & ref = update->Set (" key1" , " value1" ).Remove (" key2" );
124-
125- EXPECT_EQ (&ref, update.get ());
126- EXPECT_THAT (update->Apply (), IsOk ());
127- }
128-
129- TEST_F (UpdatePropertiesTest, SetAndRemoveDifferentKeys) {
130- ICEBERG_UNWRAP_OR_FAIL (auto update, table_->NewUpdateProperties ());
131- update->Set (" key1" , " value1" ).Remove (" key2" );
132- EXPECT_THAT (update->Commit (), IsOk ());
133-
134- ICEBERG_UNWRAP_OR_FAIL (auto reloaded, catalog_->LoadTable (table_ident_));
135- const auto & props = reloaded->properties ().configs ();
136- EXPECT_EQ (props.at (" key1" ), " value1" );
137- EXPECT_FALSE (props.contains (" key2" ));
137+ const auto & format_version = reloaded->metadata ()->format_version ;
138+ EXPECT_EQ (format_version, 3 );
138139}
139140
140141} // namespace iceberg
0 commit comments