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