@@ -91,7 +91,7 @@ static void t_log_buffer_size(void)
9191 int i ;
9292 struct reftable_log_record
9393 log = { .refname = (char * ) "refs/heads/master" ,
94- .update_index = 0xa ,
94+ .update_index = update_index ,
9595 .value_type = REFTABLE_LOG_UPDATE ,
9696 .value = { .update = {
9797 .name = (char * ) "Han-Wen Nienhuys" ,
@@ -128,7 +128,7 @@ static void t_log_overflow(void)
128128 int err ;
129129 struct reftable_log_record log = {
130130 .refname = (char * ) "refs/heads/master" ,
131- .update_index = 0xa ,
131+ .update_index = update_index ,
132132 .value_type = REFTABLE_LOG_UPDATE ,
133133 .value = {
134134 .update = {
@@ -152,6 +152,48 @@ static void t_log_overflow(void)
152152 reftable_buf_release (& buf );
153153}
154154
155+ static void t_log_write_limits (void )
156+ {
157+ struct reftable_write_options opts = { 0 };
158+ struct reftable_buf buf = REFTABLE_BUF_INIT ;
159+ struct reftable_writer * w = t_reftable_strbuf_writer (& buf , & opts );
160+ struct reftable_log_record log = {
161+ .refname = (char * )"refs/head/master" ,
162+ .update_index = 0 ,
163+ .value_type = REFTABLE_LOG_UPDATE ,
164+ .value = {
165+ .update = {
166+ .old_hash = { 1 },
167+ .new_hash = { 2 },
168+ .name = (char * )"Han-Wen Nienhuys" ,
169+ .email = (char * )"hanwen@google.com" ,
170+ .tz_offset = 100 ,
171+ .time = 0x5e430672 ,
172+ },
173+ },
174+ };
175+ int err ;
176+
177+ reftable_writer_set_limits (w , 1 , 1 );
178+
179+ /* write with update_index (0) below set limits (1, 1) */
180+ err = reftable_writer_add_log (w , & log );
181+ check_int (err , = = , 0 );
182+
183+ /* write with update_index (1) in the set limits (1, 1) */
184+ log .update_index = 1 ;
185+ err = reftable_writer_add_log (w , & log );
186+ check_int (err , = = , 0 );
187+
188+ /* write with update_index (3) above set limits (1, 1) */
189+ log .update_index = 3 ;
190+ err = reftable_writer_add_log (w , & log );
191+ check_int (err , = = , REFTABLE_API_ERROR );
192+
193+ reftable_writer_free (w );
194+ reftable_buf_release (& buf );
195+ }
196+
155197static void t_log_write_read (void )
156198{
157199 struct reftable_write_options opts = {
@@ -918,6 +960,7 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
918960 TEST (t_corrupt_table_empty (), "read-write on an empty table" );
919961 TEST (t_log_buffer_size (), "buffer extension for log compression" );
920962 TEST (t_log_overflow (), "log overflow returns expected error" );
963+ TEST (t_log_write_limits (), "writer limits for writing log records" );
921964 TEST (t_log_write_read (), "read-write on log records" );
922965 TEST (t_log_zlib_corruption (), "reading corrupted log record returns expected error" );
923966 TEST (t_table_read_api (), "read on a table" );
0 commit comments