Re: [PATCH v4 6/6] t-reftable-stack: add test for stack iterators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 04, 2024 at 08:08:06PM +0530, Chandra Pratap wrote:
> reftable_stack_init_ref_iterator and reftable_stack_init_log_iterator
> as defined by reftable/stack.{c,h} initialize a stack iterator to
> iterate over the ref and log records in a reftable stack respectively.
> Since these functions are not exercised by any of the existing tests,
> add a test for them.
> 
> Mentored-by: Patrick Steinhardt <ps@xxxxxx>
> Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
> Signed-off-by: Chandra Pratap <chandrapratap3519@xxxxxxxxx>
> ---
>  t/unit-tests/t-reftable-stack.c | 80 +++++++++++++++++++++++++++++++++
>  1 file changed, 80 insertions(+)
> 
> diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c
> index 4acf07ab0c..e209652031 100644
> --- a/t/unit-tests/t-reftable-stack.c
> +++ b/t/unit-tests/t-reftable-stack.c
> @@ -544,6 +544,85 @@ static void t_reftable_stack_add(void)
>  	clear_dir(dir);
>  }
>  
> +static void t_reftable_stack_iterator(void)
> +{
> +	struct reftable_write_options opts = { 0 };
> +	struct reftable_stack *st = NULL;
> +	char *dir = get_tmp_dir(__LINE__);
> +	struct reftable_ref_record refs[10] = { 0 };
> +	struct reftable_log_record logs[10] = { 0 };
> +	struct reftable_iterator it = { 0 };
> +	size_t N = ARRAY_SIZE(refs), i;
> +	int err;
> +
> +	err = reftable_new_stack(&st, dir, &opts);
> +	check(!err);
> +
> +	for (i = 0; i < N; i++) {
> +		refs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
> +		refs[i].update_index = i + 1;
> +		refs[i].value_type = REFTABLE_REF_VAL1;
> +		set_test_hash(refs[i].value.val1, i);
> +
> +		logs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
> +		logs[i].update_index = i + 1;
> +		logs[i].value_type = REFTABLE_LOG_UPDATE;
> +		logs[i].value.update.email = xstrdup("johndoe@invalid");
> +		logs[i].value.update.message = xstrdup("commit\n");
> +		set_test_hash(logs[i].value.update.new_hash, i);
> +	}
> +
> +	for (i = 0; i < N; i++) {
> +		err = reftable_stack_add(st, write_test_ref, &refs[i]);
> +		check(!err);
> +	}
> +
> +	for (i = 0; i < N; i++) {
> +		struct write_log_arg arg = {
> +			.log = &logs[i],
> +			.update_index = reftable_stack_next_update_index(st),
> +		};

Nit: Let's add a newline between the variable declarations and the code,
both here and in the other loops further down.

Patrick




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux