]> git.proxmox.com Git - libgit2.git/blame - tests/libgit2/odb/backend/multiple.c
Merge https://salsa.debian.org/debian/libgit2 into proxmox/bullseye
[libgit2.git] / tests / libgit2 / odb / backend / multiple.c
CommitLineData
f148258a
PS
1#include "clar_libgit2.h"
2#include "repository.h"
3#include "backend_helpers.h"
4
5#define EXISTING_HASH "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
6
7static git_repository *_repo;
8static git_odb_object *_obj;
9static fake_backend *_fake_empty;
10static fake_backend *_fake_filled;
11
12static git_oid _existing_oid;
13
14static const fake_object _objects_filled[] = {
15 { EXISTING_HASH, "" },
16 { NULL, NULL }
17};
18
19static const fake_object _objects_empty[] = {
20 { NULL, NULL }
21};
22
23void test_odb_backend_multiple__initialize(void)
24{
25 git_odb_backend *backend;
26
27 git_oid_fromstr(&_existing_oid, EXISTING_HASH);
28
29 _obj = NULL;
30 _repo = cl_git_sandbox_init("testrepo.git");
31
e579e0f7 32 cl_git_pass(build_fake_backend(&backend, _objects_filled, false));
f148258a
PS
33 _fake_filled = (fake_backend *)backend;
34
e579e0f7 35 cl_git_pass(build_fake_backend(&backend, _objects_empty, false));
f148258a
PS
36 _fake_empty = (fake_backend *)backend;
37}
38
39void test_odb_backend_multiple__cleanup(void)
40{
41 git_odb_object_free(_obj);
42 cl_git_sandbox_cleanup();
43}
44
45void test_odb_backend_multiple__read_with_empty_first_succeeds(void)
46{
47 git_odb *odb;
48
49 cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
50 cl_git_pass(git_odb_add_backend(odb, (git_odb_backend *)_fake_filled, 10));
51 cl_git_pass(git_odb_add_backend(odb, (git_odb_backend *)_fake_empty, 50));
52
53 cl_git_pass(git_odb_read(&_obj, odb, &_existing_oid));
54
55 cl_assert_equal_i(1, _fake_filled->read_calls);
56 cl_assert_equal_i(1, _fake_empty->read_calls);
57}
58
59void test_odb_backend_multiple__read_with_first_matching_stops(void)
60{
61 git_odb *odb;
62
63 cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
64 cl_git_pass(git_odb_add_backend(odb, (git_odb_backend *)_fake_empty, 10));
65 cl_git_pass(git_odb_add_backend(odb, (git_odb_backend *)_fake_filled, 50));
66
67 cl_git_pass(git_odb_read(&_obj, odb, &_existing_oid));
68
69 cl_assert_equal_i(1, _fake_filled->read_calls);
70 cl_assert_equal_i(0, _fake_empty->read_calls);
71}
72
73void test_odb_backend_multiple__read_prefix_with_first_empty_succeeds(void)
74{
75 git_odb *odb;
76
77 cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
78 cl_git_pass(git_odb_add_backend(odb, (git_odb_backend *)_fake_filled, 10));
79 cl_git_pass(git_odb_add_backend(odb, (git_odb_backend *)_fake_empty, 50));
80
81 cl_git_pass(git_odb_read_prefix(&_obj, odb, &_existing_oid, 7));
82
83 cl_assert_equal_i(1, _fake_filled->read_prefix_calls);
84 cl_assert_equal_i(1, _fake_empty->read_prefix_calls);
85}
86
87void test_odb_backend_multiple__read_prefix_with_first_matching_reads_both(void)
88{
89 git_odb *odb;
90
91 cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
92 cl_git_pass(git_odb_add_backend(odb, (git_odb_backend *)_fake_empty, -10));
93 cl_git_pass(git_odb_add_backend(odb, (git_odb_backend *)_fake_filled, 50));
94
95 cl_git_pass(git_odb_read_prefix(&_obj, odb, &_existing_oid, 7));
96
97 cl_assert_equal_i(1, _fake_filled->read_prefix_calls);
98 cl_assert_equal_i(1, _fake_empty->read_prefix_calls);
99}
100
101void test_odb_backend_multiple__read_prefix_with_first_matching_succeeds_without_hash_verification(void)
102{
103 git_odb *odb;
104
105 git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0);
106
107 cl_git_pass(git_repository_odb__weakptr(&odb, _repo));
108 cl_git_pass(git_odb_add_backend(odb, (git_odb_backend *)_fake_empty, -10));
109 cl_git_pass(git_odb_add_backend(odb, (git_odb_backend *)_fake_filled, 50));
110
111 cl_git_pass(git_odb_read_prefix(&_obj, odb, &_existing_oid, 7));
112
113 /*
114 * Both backends should be checked as we have to check
115 * for collisions
116 */
117 cl_assert_equal_i(1, _fake_filled->read_prefix_calls);
118 cl_assert_equal_i(1, _fake_empty->read_prefix_calls);
119
120 git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 1);
121}