@@ -93,7 +93,7 @@ static void t_log_buffer_size(void)
9393 int i ;
9494 struct reftable_log_record
9595 log = { .refname = (char * ) "refs/heads/master" ,
96- .update_index = 0xa ,
96+ .update_index = update_index ,
9797 .value_type = REFTABLE_LOG_UPDATE ,
9898 .value = { .update = {
9999 .name = (char * ) "Han-Wen Nienhuys" ,
@@ -130,7 +130,7 @@ static void t_log_overflow(void)
130130 int err ;
131131 struct reftable_log_record log = {
132132 .refname = (char * ) "refs/heads/master" ,
133- .update_index = 0xa ,
133+ .update_index = update_index ,
134134 .value_type = REFTABLE_LOG_UPDATE ,
135135 .value = {
136136 .update = {
@@ -154,6 +154,48 @@ static void t_log_overflow(void)
154154 reftable_buf_release (& buf );
155155}
156156
157+ static void t_log_write_limits (void )
158+ {
159+ struct reftable_write_options opts = { 0 };
160+ struct reftable_buf buf = REFTABLE_BUF_INIT ;
161+ struct reftable_writer * w = t_reftable_strbuf_writer (& buf , & opts );
162+ struct reftable_log_record log = {
163+ .refname = (char * )"refs/head/master" ,
164+ .update_index = 0 ,
165+ .value_type = REFTABLE_LOG_UPDATE ,
166+ .value = {
167+ .update = {
168+ .old_hash = { 1 },
169+ .new_hash = { 2 },
170+ .name = (char * )"Han-Wen Nienhuys" ,
171+ .
email = (
char * )
"[email protected] " ,
172+ .tz_offset = 100 ,
173+ .time = 0x5e430672 ,
174+ },
175+ },
176+ };
177+ int err ;
178+
179+ reftable_writer_set_limits (w , 1 , 1 );
180+
181+ /* write with update_index (0) below set limits (1, 1) */
182+ err = reftable_writer_add_log (w , & log );
183+ check_int (err , = = , 0 );
184+
185+ /* write with update_index (1) in the set limits (1, 1) */
186+ log .update_index = 1 ;
187+ err = reftable_writer_add_log (w , & log );
188+ check_int (err , = = , 0 );
189+
190+ /* write with update_index (3) above set limits (1, 1) */
191+ log .update_index = 3 ;
192+ err = reftable_writer_add_log (w , & log );
193+ check_int (err , = = , REFTABLE_API_ERROR );
194+
195+ reftable_writer_free (w );
196+ reftable_buf_release (& buf );
197+ }
198+
157199static void t_log_write_read (void )
158200{
159201 struct reftable_write_options opts = {
@@ -920,6 +962,7 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
920962 TEST (t_corrupt_table_empty (), "read-write on an empty table" );
921963 TEST (t_log_buffer_size (), "buffer extension for log compression" );
922964 TEST (t_log_overflow (), "log overflow returns expected error" );
965+ TEST (t_log_write_limits (), "writer limits for writing log records" );
923966 TEST (t_log_write_read (), "read-write on log records" );
924967 TEST (t_log_zlib_corruption (), "reading corrupted log record returns expected error" );
925968 TEST (t_table_read_api (), "read on a table" );
0 commit comments