mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-05 16:51:42 +00:00

The object::lookup tests do use the "testrepo.git" repository in a read-only way, so we do not set up the repository as a sandbox but simply open it. But in a future commit, we will want to test looking up objects which are corrupted in some way, which requires us to modify the on-disk data. Doing this in a repository without creating the sandbox will modify contents of our libgit2 repository, though. Create the repository in a sandbox to avoid this.
65 lines
1.6 KiB
C
65 lines
1.6 KiB
C
#include "clar_libgit2.h"
|
|
|
|
#include "repository.h"
|
|
|
|
static git_repository *g_repo;
|
|
|
|
void test_object_lookup__initialize(void)
|
|
{
|
|
g_repo = cl_git_sandbox_init("testrepo.git");
|
|
}
|
|
|
|
void test_object_lookup__cleanup(void)
|
|
{
|
|
cl_git_sandbox_cleanup();
|
|
}
|
|
|
|
void test_object_lookup__lookup_wrong_type_returns_enotfound(void)
|
|
{
|
|
const char *commit = "e90810b8df3e80c413d903f631643c716887138d";
|
|
git_oid oid;
|
|
git_object *object;
|
|
|
|
cl_git_pass(git_oid_fromstr(&oid, commit));
|
|
cl_assert_equal_i(
|
|
GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJ_TAG));
|
|
}
|
|
|
|
void test_object_lookup__lookup_nonexisting_returns_enotfound(void)
|
|
{
|
|
const char *unknown = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
|
|
git_oid oid;
|
|
git_object *object;
|
|
|
|
cl_git_pass(git_oid_fromstr(&oid, unknown));
|
|
cl_assert_equal_i(
|
|
GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJ_ANY));
|
|
}
|
|
|
|
void test_object_lookup__lookup_wrong_type_by_abbreviated_id_returns_enotfound(void)
|
|
{
|
|
const char *commit = "e90810b";
|
|
git_oid oid;
|
|
git_object *object;
|
|
|
|
cl_git_pass(git_oid_fromstrn(&oid, commit, strlen(commit)));
|
|
cl_assert_equal_i(
|
|
GIT_ENOTFOUND, git_object_lookup_prefix(&object, g_repo, &oid, strlen(commit), GIT_OBJ_TAG));
|
|
}
|
|
|
|
void test_object_lookup__lookup_wrong_type_eventually_returns_enotfound(void)
|
|
{
|
|
const char *commit = "e90810b8df3e80c413d903f631643c716887138d";
|
|
git_oid oid;
|
|
git_object *object;
|
|
|
|
cl_git_pass(git_oid_fromstr(&oid, commit));
|
|
|
|
cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJ_COMMIT));
|
|
git_object_free(object);
|
|
|
|
cl_assert_equal_i(
|
|
GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJ_TAG));
|
|
}
|
|
|