Skip to content

Commit b2e53f3

Browse files
committed
tests: odb: implement exists_prefix for the fake backend
The fake backend currently implements all reading functions except for the `exists_prefix` one. Implement it to enable further testing of the ODB layer.
1 parent 983e627 commit b2e53f3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/odb/backend/backend_helpers.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ static int fake_backend__exists(git_odb_backend *backend, const git_oid *oid)
3737
return search_object(NULL, fake, oid, GIT_OID_HEXSZ) == GIT_OK;
3838
}
3939

40+
static int fake_backend__exists_prefix(
41+
git_oid *out, git_odb_backend *backend, const git_oid *oid, size_t len)
42+
{
43+
const fake_object *obj;
44+
fake_backend *fake;
45+
int error;
46+
47+
fake = (fake_backend *)backend;
48+
49+
fake->exists_prefix_calls++;
50+
51+
if ((error = search_object(&obj, fake, oid, len)) < 0)
52+
return error;
53+
54+
if (out)
55+
git_oid_fromstr(out, obj->oid);
56+
57+
return 0;
58+
}
59+
4060
static int fake_backend__read(
4161
void **buffer_p, size_t *len_p, git_otype *type_p,
4262
git_odb_backend *backend, const git_oid *oid)
@@ -130,6 +150,7 @@ int build_fake_backend(
130150
backend->parent.read_prefix = fake_backend__read_prefix;
131151
backend->parent.read_header = fake_backend__read_header;
132152
backend->parent.exists = fake_backend__exists;
153+
backend->parent.exists_prefix = fake_backend__exists_prefix;
133154
backend->parent.free = &fake_backend__free;
134155

135156
*out = (git_odb_backend *)backend;

tests/odb/backend/backend_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ typedef struct {
99
git_odb_backend parent;
1010

1111
int exists_calls;
12+
int exists_prefix_calls;
1213
int read_calls;
1314
int read_header_calls;
1415
int read_prefix_calls;

0 commit comments

Comments
 (0)