]> git.proxmox.com Git - libgit2.git/commitdiff
tests: odb: implement `exists_prefix` for the fake backend
authorPatrick Steinhardt <ps@pks.im>
Tue, 13 Jun 2017 09:39:36 +0000 (11:39 +0200)
committerPatrick Steinhardt <ps@pks.im>
Tue, 13 Jun 2017 09:43:20 +0000 (11:43 +0200)
The fake backend currently implements all reading functions except for
the `exists_prefix` one. Implement it to enable further testing of the
ODB layer.

tests/odb/backend/backend_helpers.c
tests/odb/backend/backend_helpers.h

index f9211e706d7b1931c04f9d353e467ed4f13f33f2..37a8fd2004ec2eeb3d755b43769b5730b50dfb8a 100644 (file)
@@ -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;
index 6cc1ce90df77810b8d2f73c819d35cc08fa056c8..5c393c0a53651ef29ff3fd53b2de2e57614ab09e 100644 (file)
@@ -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;