summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-06-13 11:39:36 +0200
committerPatrick Steinhardt <ps@pks.im>2017-06-13 11:43:20 +0200
commitb2e53f369239c9fc2c13ebf47398d05bc0a172fb (patch)
tree83e999ab0fbd72a7775f0544a4e2fc0a71a2578c
parent983e627d10215807d2727cc8321d83d02f11fee7 (diff)
downloadlibgit2-b2e53f369239c9fc2c13ebf47398d05bc0a172fb.tar.gz
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.
-rw-r--r--tests/odb/backend/backend_helpers.c21
-rw-r--r--tests/odb/backend/backend_helpers.h1
2 files changed, 22 insertions, 0 deletions
diff --git a/tests/odb/backend/backend_helpers.c b/tests/odb/backend/backend_helpers.c
index f9211e706..37a8fd200 100644
--- a/tests/odb/backend/backend_helpers.c
+++ b/tests/odb/backend/backend_helpers.c
@@ -37,6 +37,26 @@ static int fake_backend__exists(git_odb_backend *backend, const git_oid *oid)
return search_object(NULL, fake, oid, GIT_OID_HEXSZ) == GIT_OK;
}
+static int fake_backend__exists_prefix(
+ git_oid *out, git_odb_backend *backend, const git_oid *oid, size_t len)
+{
+ const fake_object *obj;
+ fake_backend *fake;
+ int error;
+
+ fake = (fake_backend *)backend;
+
+ fake->exists_prefix_calls++;
+
+ if ((error = search_object(&obj, fake, oid, len)) < 0)
+ return error;
+
+ if (out)
+ git_oid_fromstr(out, obj->oid);
+
+ return 0;
+}
+
static int fake_backend__read(
void **buffer_p, size_t *len_p, git_otype *type_p,
git_odb_backend *backend, const git_oid *oid)
@@ -130,6 +150,7 @@ int build_fake_backend(
backend->parent.read_prefix = fake_backend__read_prefix;
backend->parent.read_header = fake_backend__read_header;
backend->parent.exists = fake_backend__exists;
+ backend->parent.exists_prefix = fake_backend__exists_prefix;
backend->parent.free = &fake_backend__free;
*out = (git_odb_backend *)backend;
diff --git a/tests/odb/backend/backend_helpers.h b/tests/odb/backend/backend_helpers.h
index 6cc1ce90d..5c393c0a5 100644
--- a/tests/odb/backend/backend_helpers.h
+++ b/tests/odb/backend/backend_helpers.h
@@ -9,6 +9,7 @@ typedef struct {
git_odb_backend parent;
int exists_calls;
+ int exists_prefix_calls;
int read_calls;
int read_header_calls;
int read_prefix_calls;