Re: [PATCH 5/6] reftable/reader: make table iterator reseekable
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Sep 16, 2024, 06:56 UTC
- Message-ID
- <ZufWjY053IKObF8T@pks.im>
- In-Reply-To
- <CAOLa=ZRA=vFjnWZC7PQBAxOxDfD9X6767ddgBqwaen5n6JLt0w@mail.gmail.com>
On Fri, Sep 13, 2024 at 07:11:54AM -0500, karthik nayak wrote:
Show 43 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/t/unit-tests/t-reftable-reader.c b/t/unit-tests/t-reftable-reader.c
> > new file mode 100644
> > index 00000000000..7a46580b6f1
> > --- /dev/null
> > +++ b/t/unit-tests/t-reftable-reader.c
> > @@ -0,0 +1,96 @@
> > +#include "test-lib.h"
> > +#include "lib-reftable.h"
> > +#include "reftable/blocksource.h"
> > +#include "reftable/reader.h"
> > +
> > +static int t_reader_seek_once(void)
> > +{
> > + struct reftable_ref_record records[] = {
> > + {
> > + .refname = (char *) "refs/heads/main",
> > + .value_type = REFTABLE_REF_VAL1,
> > + .value.val1 = { 42 },
> > + },
> > + };
> > + struct reftable_block_source source = { 0 };
> > + struct reftable_ref_record ref = { 0 };
> > + struct reftable_iterator it = { 0 };
> > + struct reftable_reader *reader;
> > + struct strbuf buf = STRBUF_INIT;
> > + int ret;
> > +
> > + t_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
> > + block_source_from_strbuf(&source, &buf);
> > +
> > + ret = reftable_reader_new(&reader, &source, "name");
> > + check_int(ret, ==, 0);
> > +
> > + reftable_reader_init_ref_iterator(reader, &it);
> > + ret = reftable_iterator_seek_ref(&it, "");
> > + check_int(ret, ==, 0);
> > + ret = reftable_iterator_next_ref(&it, &ref);
> > + check_int(ret, ==, 0);
> > +
> > + ret = reftable_ref_record_equal(&ref, &records[0], 20);
>
> s/20/GIT_SHA1_RAWSZIndeed.
> Also here and elsewhere, shouldn't we just do > `check(reftable_ref_record_equal(...))` or even > `!check(reftable_iterator_seek_ref(...))` ?
I guess you mean `check(!reftable_iteraror_seek_ref())`, right?
In the case where we just expect a zero error code I can certainly adapt the code to use `check(...)`. But the other cases shouldn't use `check(!...)` because it is important that the returnd error code is positive.
Patrick