Skip to content

Commit 369cb45

Browse files
committed
tests: do not reuse OID from backend
In order to make the fake backend more useful, we want to enable it holding multiple object references. To do so, we need to decouple it from the single fake OID it currently holds, which we simply move up into the calling tests.
1 parent 2add34d commit 369cb45

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

tests/odb/backend/nonrefreshing.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ static fake_backend *_fake;
88
#define HASH "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
99
#define EMPTY_HASH "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
1010

11+
static git_oid _oid;
12+
static git_oid _empty_oid;
13+
1114
static void setup_repository_and_backend(git_error_code error_code, const char *hash)
1215
{
1316
git_odb *odb = NULL;
@@ -25,6 +28,12 @@ static void setup_repository_and_backend(git_error_code error_code, const char *
2528
_fake = (fake_backend *)backend;
2629
}
2730

31+
void test_odb_backend_nonrefreshing__initialize(void)
32+
{
33+
git_oid_fromstr(&_oid, HASH);
34+
git_oid_fromstr(&_empty_oid, EMPTY_HASH);
35+
}
36+
2837
void test_odb_backend_nonrefreshing__cleanup(void)
2938
{
3039
cl_git_sandbox_cleanup();
@@ -37,7 +46,7 @@ void test_odb_backend_nonrefreshing__exists_is_invoked_once_on_failure(void)
3746
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
3847

3948
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
40-
cl_assert_equal_b(false, git_odb_exists(odb, &_fake->oid));
49+
cl_assert_equal_b(false, git_odb_exists(odb, &_oid));
4150

4251
cl_assert_equal_i(1, _fake->exists_calls);
4352
}
@@ -49,7 +58,7 @@ void test_odb_backend_nonrefreshing__read_is_invoked_once_on_failure(void)
4958
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
5059

5160
cl_git_fail_with(
52-
git_object_lookup(&obj, _repo, &_fake->oid, GIT_OBJ_ANY),
61+
git_object_lookup(&obj, _repo, &_oid, GIT_OBJ_ANY),
5362
GIT_ENOTFOUND);
5463

5564
cl_assert_equal_i(1, _fake->read_calls);
@@ -62,7 +71,7 @@ void test_odb_backend_nonrefreshing__readprefix_is_invoked_once_on_failure(void)
6271
setup_repository_and_backend(GIT_ENOTFOUND, HASH);
6372

6473
cl_git_fail_with(
65-
git_object_lookup_prefix(&obj, _repo, &_fake->oid, 7, GIT_OBJ_ANY),
74+
git_object_lookup_prefix(&obj, _repo, &_oid, 7, GIT_OBJ_ANY),
6675
GIT_ENOTFOUND);
6776

6877
cl_assert_equal_i(1, _fake->read_prefix_calls);
@@ -79,7 +88,7 @@ void test_odb_backend_nonrefreshing__readheader_is_invoked_once_on_failure(void)
7988
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
8089

8190
cl_git_fail_with(
82-
git_odb_read_header(&len, &type, odb, &_fake->oid),
91+
git_odb_read_header(&len, &type, odb, &_oid),
8392
GIT_ENOTFOUND);
8493

8594
cl_assert_equal_i(1, _fake->read_header_calls);
@@ -92,7 +101,7 @@ void test_odb_backend_nonrefreshing__exists_is_invoked_once_on_success(void)
92101
setup_repository_and_backend(GIT_OK, HASH);
93102

94103
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
95-
cl_assert_equal_b(true, git_odb_exists(odb, &_fake->oid));
104+
cl_assert_equal_b(true, git_odb_exists(odb, &_oid));
96105

97106
cl_assert_equal_i(1, _fake->exists_calls);
98107
}
@@ -103,7 +112,7 @@ void test_odb_backend_nonrefreshing__read_is_invoked_once_on_success(void)
103112

104113
setup_repository_and_backend(GIT_OK, EMPTY_HASH);
105114

106-
cl_git_pass(git_object_lookup(&obj, _repo, &_fake->oid, GIT_OBJ_ANY));
115+
cl_git_pass(git_object_lookup(&obj, _repo, &_empty_oid, GIT_OBJ_ANY));
107116

108117
cl_assert_equal_i(1, _fake->read_calls);
109118

@@ -116,7 +125,7 @@ void test_odb_backend_nonrefreshing__readprefix_is_invoked_once_on_success(void)
116125

117126
setup_repository_and_backend(GIT_OK, EMPTY_HASH);
118127

119-
cl_git_pass(git_object_lookup_prefix(&obj, _repo, &_fake->oid, 7, GIT_OBJ_ANY));
128+
cl_git_pass(git_object_lookup_prefix(&obj, _repo, &_empty_oid, 7, GIT_OBJ_ANY));
120129

121130
cl_assert_equal_i(1, _fake->read_prefix_calls);
122131

@@ -133,7 +142,7 @@ void test_odb_backend_nonrefreshing__readheader_is_invoked_once_on_success(void)
133142

134143
cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
135144

136-
cl_git_pass(git_odb_read_header(&len, &type, odb, &_fake->oid));
145+
cl_git_pass(git_odb_read_header(&len, &type, odb, &_oid));
137146

138147
cl_assert_equal_i(1, _fake->read_header_calls);
139148
}

0 commit comments

Comments
 (0)