Skip to content

Commit e29e802

Browse files
committed
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.
1 parent 7df580f commit e29e802

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

tests/odb/backend/nonrefreshing.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ static git_repository *_repo;
1717
static fake_backend *_fake;
1818
static git_oid _oid;
1919

20+
#define HASH "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
21+
2022
static int fake_backend__exists(git_odb_backend *backend, const git_oid *oid)
2123
{
2224
fake_backend *fake;
@@ -78,7 +80,6 @@ static int fake_backend__read_prefix(
7880
{
7981
fake_backend *fake;
8082

81-
GIT_UNUSED(out_oid);
8283
GIT_UNUSED(buffer_p);
8384
GIT_UNUSED(len_p);
8485
GIT_UNUSED(type_p);
@@ -89,6 +90,7 @@ static int fake_backend__read_prefix(
8990

9091
fake->read_prefix_calls++;
9192

93+
git_oid_cpy(out_oid, &_oid);
9294
*len_p = 0;
9395
*buffer_p = NULL;
9496
*type_p = GIT_OBJ_BLOB;
@@ -130,7 +132,7 @@ static int build_fake_backend(
130132
return 0;
131133
}
132134

133-
static void setup_repository_and_backend(git_error_code error_code)
135+
static void setup_repository_and_backend(git_error_code error_code, const char *hash)
134136
{
135137
git_odb *odb = NULL;
136138
git_odb_backend *backend = NULL;
@@ -144,7 +146,7 @@ static void setup_repository_and_backend(git_error_code error_code)
144146

145147
_fake = (fake_backend *)backend;
146148

147-
cl_git_pass(git_oid_fromstr(&_oid, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
149+
cl_git_pass(git_oid_fromstr(&_oid, hash));
148150
}
149151

150152
void test_odb_backend_nonrefreshing__cleanup(void)
@@ -156,7 +158,7 @@ void test_odb_backend_nonrefreshing__exists_is_invoked_once_on_failure(void)
156158
{
157159
git_odb *odb;
158160

159-
setup_repository_and_backend(GIT_ENOTFOUND);
161+
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
160162

161163
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
162164
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)
168170
{
169171
git_object *obj;
170172

171-
setup_repository_and_backend(GIT_ENOTFOUND);
173+
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
172174

173175
cl_git_fail_with(
174176
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)
181183
{
182184
git_object *obj;
183185

184-
setup_repository_and_backend(GIT_ENOTFOUND);
186+
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
185187

186188
cl_git_fail_with(
187189
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)
196198
size_t len;
197199
git_otype type;
198200

199-
setup_repository_and_backend(GIT_ENOTFOUND);
201+
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
200202

201203
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
202204

@@ -211,7 +213,7 @@ void test_odb_backend_nonrefreshing__exists_is_invoked_once_on_success(void)
211213
{
212214
git_odb *odb;
213215

214-
setup_repository_and_backend(GIT_OK);
216+
setup_repository_and_backend(GIT_OK, HASH);
215217

216218
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
217219
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)
223225
{
224226
git_object *obj;
225227

226-
setup_repository_and_backend(GIT_OK);
228+
setup_repository_and_backend(GIT_OK, HASH);
227229

228230
cl_git_pass(git_object_lookup(&obj, _repo, &_oid, GIT_OBJ_ANY));
229231

@@ -236,7 +238,7 @@ void test_odb_backend_nonrefreshing__readprefix_is_invoked_once_on_success(void)
236238
{
237239
git_object *obj;
238240

239-
setup_repository_and_backend(GIT_OK);
241+
setup_repository_and_backend(GIT_OK, EMPTY_HASH);
240242

241243
cl_git_pass(git_object_lookup_prefix(&obj, _repo, &_oid, 7, GIT_OBJ_ANY));
242244

@@ -251,7 +253,7 @@ void test_odb_backend_nonrefreshing__readheader_is_invoked_once_on_success(void)
251253
size_t len;
252254
git_otype type;
253255

254-
setup_repository_and_backend(GIT_OK);
256+
setup_repository_and_backend(GIT_OK, HASH);
255257

256258
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
257259

@@ -264,7 +266,7 @@ void test_odb_backend_nonrefreshing__read_is_invoked_once_when_revparsing_a_full
264266
{
265267
git_object *obj;
266268

267-
setup_repository_and_backend(GIT_ENOTFOUND);
269+
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
268270

269271
cl_git_fail_with(
270272
git_revparse_single(&obj, _repo, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"),

0 commit comments

Comments
 (0)