summaryrefslogtreecommitdiff
path: root/tests/odb/backend/nonrefreshing.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-06-12 15:43:56 +0200
committerPatrick Steinhardt <ps@pks.im>2017-06-12 17:24:53 +0200
commit6e010bb126360d084b1c38056728c7fd3286a443 (patch)
tree799692f140211ac6f03cbe1af0a0adab732eb192 /tests/odb/backend/nonrefreshing.c
parent369cb45fc300e6a7951c5c9a65bbf0c0f6f32f16 (diff)
downloadlibgit2-6e010bb126360d084b1c38056728c7fd3286a443.tar.gz
tests: odb: allow passing fake objects to the fake backend
Right now, the fake backend is quite restrained in the way how it works: we pass it an OID which it is to return later as well as an error code we want it to return. While this is sufficient for existing tests, we can make the fake backend a little bit more generic in order to allow us testing for additional scenarios. To do so, we change the backend to not accept an error code and OID which it is to return for queries, but instead a simple array of OIDs with their respective blob contents. On each query, the fake backend simply iterates through this array and returns the first matching object.
Diffstat (limited to 'tests/odb/backend/nonrefreshing.c')
-rw-r--r--tests/odb/backend/nonrefreshing.c58
1 files changed, 22 insertions, 36 deletions
diff --git a/tests/odb/backend/nonrefreshing.c b/tests/odb/backend/nonrefreshing.c
index 42da31201..6abc0c6d2 100644
--- a/tests/odb/backend/nonrefreshing.c
+++ b/tests/odb/backend/nonrefreshing.c
@@ -5,22 +5,25 @@
static git_repository *_repo;
static fake_backend *_fake;
-#define HASH "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
-#define EMPTY_HASH "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
+#define NONEXISTING_HASH "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
+#define EXISTING_HASH "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
-static git_oid _oid;
-static git_oid _empty_oid;
+static const fake_object _objects[] = {
+ { EXISTING_HASH, "" },
+ { NULL, NULL }
+};
-static void setup_repository_and_backend(git_error_code error_code, const char *hash)
+static git_oid _nonexisting_oid;
+static git_oid _existing_oid;
+
+static void setup_repository_and_backend(void)
{
git_odb *odb = NULL;
git_odb_backend *backend = NULL;
- git_oid oid;
_repo = cl_git_sandbox_init("testrepo.git");
- cl_git_pass(git_oid_fromstr(&oid, hash));
- cl_git_pass(build_fake_backend(&backend, error_code, &oid));
+ cl_git_pass(build_fake_backend(&backend, _objects));
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
cl_git_pass(git_odb_add_backend(odb, backend, 10));
@@ -30,8 +33,9 @@ static void setup_repository_and_backend(git_error_code error_code, const char *
void test_odb_backend_nonrefreshing__initialize(void)
{
- git_oid_fromstr(&_oid, HASH);
- git_oid_fromstr(&_empty_oid, EMPTY_HASH);
+ git_oid_fromstr(&_nonexisting_oid, NONEXISTING_HASH);
+ git_oid_fromstr(&_existing_oid, EXISTING_HASH);
+ setup_repository_and_backend();
}
void test_odb_backend_nonrefreshing__cleanup(void)
@@ -43,10 +47,8 @@ void test_odb_backend_nonrefreshing__exists_is_invoked_once_on_failure(void)
{
git_odb *odb;
- 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));
+ cl_assert_equal_b(false, git_odb_exists(odb, &_nonexisting_oid));
cl_assert_equal_i(1, _fake->exists_calls);
}
@@ -55,10 +57,8 @@ void test_odb_backend_nonrefreshing__read_is_invoked_once_on_failure(void)
{
git_object *obj;
- setup_repository_and_backend(GIT_ENOTFOUND, HASH);
-
cl_git_fail_with(
- git_object_lookup(&obj, _repo, &_oid, GIT_OBJ_ANY),
+ git_object_lookup(&obj, _repo, &_nonexisting_oid, GIT_OBJ_ANY),
GIT_ENOTFOUND);
cl_assert_equal_i(1, _fake->read_calls);
@@ -68,10 +68,8 @@ void test_odb_backend_nonrefreshing__readprefix_is_invoked_once_on_failure(void)
{
git_object *obj;
- setup_repository_and_backend(GIT_ENOTFOUND, HASH);
-
cl_git_fail_with(
- git_object_lookup_prefix(&obj, _repo, &_oid, 7, GIT_OBJ_ANY),
+ git_object_lookup_prefix(&obj, _repo, &_nonexisting_oid, 7, GIT_OBJ_ANY),
GIT_ENOTFOUND);
cl_assert_equal_i(1, _fake->read_prefix_calls);
@@ -83,12 +81,10 @@ void test_odb_backend_nonrefreshing__readheader_is_invoked_once_on_failure(void)
size_t len;
git_otype type;
- setup_repository_and_backend(GIT_ENOTFOUND, HASH);
-
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
cl_git_fail_with(
- git_odb_read_header(&len, &type, odb, &_oid),
+ git_odb_read_header(&len, &type, odb, &_nonexisting_oid),
GIT_ENOTFOUND);
cl_assert_equal_i(1, _fake->read_header_calls);
@@ -98,10 +94,8 @@ void test_odb_backend_nonrefreshing__exists_is_invoked_once_on_success(void)
{
git_odb *odb;
- 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));
+ cl_assert_equal_b(true, git_odb_exists(odb, &_existing_oid));
cl_assert_equal_i(1, _fake->exists_calls);
}
@@ -110,9 +104,7 @@ void test_odb_backend_nonrefreshing__read_is_invoked_once_on_success(void)
{
git_object *obj;
- setup_repository_and_backend(GIT_OK, EMPTY_HASH);
-
- cl_git_pass(git_object_lookup(&obj, _repo, &_empty_oid, GIT_OBJ_ANY));
+ cl_git_pass(git_object_lookup(&obj, _repo, &_existing_oid, GIT_OBJ_ANY));
cl_assert_equal_i(1, _fake->read_calls);
@@ -123,9 +115,7 @@ void test_odb_backend_nonrefreshing__readprefix_is_invoked_once_on_success(void)
{
git_object *obj;
- setup_repository_and_backend(GIT_OK, EMPTY_HASH);
-
- cl_git_pass(git_object_lookup_prefix(&obj, _repo, &_empty_oid, 7, GIT_OBJ_ANY));
+ cl_git_pass(git_object_lookup_prefix(&obj, _repo, &_existing_oid, 7, GIT_OBJ_ANY));
cl_assert_equal_i(1, _fake->read_prefix_calls);
@@ -138,11 +128,9 @@ void test_odb_backend_nonrefreshing__readheader_is_invoked_once_on_success(void)
size_t len;
git_otype type;
- setup_repository_and_backend(GIT_OK, HASH);
-
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
- cl_git_pass(git_odb_read_header(&len, &type, odb, &_oid));
+ cl_git_pass(git_odb_read_header(&len, &type, odb, &_existing_oid));
cl_assert_equal_i(1, _fake->read_header_calls);
}
@@ -151,8 +139,6 @@ void test_odb_backend_nonrefreshing__read_is_invoked_once_when_revparsing_a_full
{
git_object *obj;
- setup_repository_and_backend(GIT_ENOTFOUND, HASH);
-
cl_git_fail_with(
git_revparse_single(&obj, _repo, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"),
GIT_ENOTFOUND);