Commit e29e8029 by Patrick Steinhardt

tests: odb: make hash of fake backend configurable

In the odb::backend::nonrefreshing test suite, we set up a fake backend
so that we are able to determine if backend functions are called
correctly. During the setup, we also parse an OID which is later on used
to read out the pseudo-object. While this procedure works right now, it
will create problems later when we implement hash verification for
looked up objects. The current OID ("deadbeef") will not match the hash
of contents we give back to the ODB layer and thus cannot be verified.

Make the hash configurable so that we can simply switch the returned for
single tests.
parent 7df580fa
......@@ -17,6 +17,8 @@ static git_repository *_repo;
static fake_backend *_fake;
static git_oid _oid;
#define HASH "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
static int fake_backend__exists(git_odb_backend *backend, const git_oid *oid)
{
fake_backend *fake;
......@@ -78,7 +80,6 @@ static int fake_backend__read_prefix(
{
fake_backend *fake;
GIT_UNUSED(out_oid);
GIT_UNUSED(buffer_p);
GIT_UNUSED(len_p);
GIT_UNUSED(type_p);
......@@ -89,6 +90,7 @@ static int fake_backend__read_prefix(
fake->read_prefix_calls++;
git_oid_cpy(out_oid, &_oid);
*len_p = 0;
*buffer_p = NULL;
*type_p = GIT_OBJ_BLOB;
......@@ -130,7 +132,7 @@ static int build_fake_backend(
return 0;
}
static void setup_repository_and_backend(git_error_code error_code)
static void setup_repository_and_backend(git_error_code error_code, const char *hash)
{
git_odb *odb = NULL;
git_odb_backend *backend = NULL;
......@@ -144,7 +146,7 @@ static void setup_repository_and_backend(git_error_code error_code)
_fake = (fake_backend *)backend;
cl_git_pass(git_oid_fromstr(&_oid, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
cl_git_pass(git_oid_fromstr(&_oid, hash));
}
void test_odb_backend_nonrefreshing__cleanup(void)
......@@ -156,7 +158,7 @@ void test_odb_backend_nonrefreshing__exists_is_invoked_once_on_failure(void)
{
git_odb *odb;
setup_repository_and_backend(GIT_ENOTFOUND);
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
cl_assert_equal_b(false, git_odb_exists(odb, &_oid));
......@@ -168,7 +170,7 @@ void test_odb_backend_nonrefreshing__read_is_invoked_once_on_failure(void)
{
git_object *obj;
setup_repository_and_backend(GIT_ENOTFOUND);
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
cl_git_fail_with(
git_object_lookup(&obj, _repo, &_oid, GIT_OBJ_ANY),
......@@ -181,7 +183,7 @@ void test_odb_backend_nonrefreshing__readprefix_is_invoked_once_on_failure(void)
{
git_object *obj;
setup_repository_and_backend(GIT_ENOTFOUND);
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
cl_git_fail_with(
git_object_lookup_prefix(&obj, _repo, &_oid, 7, GIT_OBJ_ANY),
......@@ -196,7 +198,7 @@ void test_odb_backend_nonrefreshing__readheader_is_invoked_once_on_failure(void)
size_t len;
git_otype type;
setup_repository_and_backend(GIT_ENOTFOUND);
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
......@@ -211,7 +213,7 @@ void test_odb_backend_nonrefreshing__exists_is_invoked_once_on_success(void)
{
git_odb *odb;
setup_repository_and_backend(GIT_OK);
setup_repository_and_backend(GIT_OK, HASH);
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
cl_assert_equal_b(true, git_odb_exists(odb, &_oid));
......@@ -223,7 +225,7 @@ void test_odb_backend_nonrefreshing__read_is_invoked_once_on_success(void)
{
git_object *obj;
setup_repository_and_backend(GIT_OK);
setup_repository_and_backend(GIT_OK, HASH);
cl_git_pass(git_object_lookup(&obj, _repo, &_oid, GIT_OBJ_ANY));
......@@ -236,7 +238,7 @@ void test_odb_backend_nonrefreshing__readprefix_is_invoked_once_on_success(void)
{
git_object *obj;
setup_repository_and_backend(GIT_OK);
setup_repository_and_backend(GIT_OK, EMPTY_HASH);
cl_git_pass(git_object_lookup_prefix(&obj, _repo, &_oid, 7, GIT_OBJ_ANY));
......@@ -251,7 +253,7 @@ void test_odb_backend_nonrefreshing__readheader_is_invoked_once_on_success(void)
size_t len;
git_otype type;
setup_repository_and_backend(GIT_OK);
setup_repository_and_backend(GIT_OK, HASH);
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
......@@ -264,7 +266,7 @@ void test_odb_backend_nonrefreshing__read_is_invoked_once_when_revparsing_a_full
{
git_object *obj;
setup_repository_and_backend(GIT_ENOTFOUND);
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
cl_git_fail_with(
git_revparse_single(&obj, _repo, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment