Commit ebecf1e7 by nulltoken

clone: reorganize tests

parent d280c71b
...@@ -15,12 +15,11 @@ void test_clone_clone__initialize(void) ...@@ -15,12 +15,11 @@ void test_clone_clone__initialize(void)
g_repo = NULL; g_repo = NULL;
} }
void test_clone_clone__cleanup(void) static void cleanup_repository(void *path)
{ {
if (g_repo) { if (g_repo)
git_repository_free(g_repo); git_repository_free(g_repo);
g_repo = NULL; cl_fixture_cleanup((const char *)path);
}
} }
// TODO: This is copy/pasted from network/remotelocal.c. // TODO: This is copy/pasted from network/remotelocal.c.
...@@ -63,7 +62,6 @@ static void build_local_file_url(git_buf *out, const char *fixture) ...@@ -63,7 +62,6 @@ static void build_local_file_url(git_buf *out, const char *fixture)
git_buf_free(&path_buf); git_buf_free(&path_buf);
} }
void test_clone_clone__bad_url(void) void test_clone_clone__bad_url(void)
{ {
/* Clone should clean up the mess if the URL isn't a git repository */ /* Clone should clean up the mess if the URL isn't a git repository */
...@@ -73,33 +71,44 @@ void test_clone_clone__bad_url(void) ...@@ -73,33 +71,44 @@ void test_clone_clone__bad_url(void)
cl_assert(!git_path_exists("./foo.git")); cl_assert(!git_path_exists("./foo.git"));
} }
void test_clone_clone__local(void) void test_clone_clone__local(void)
{ {
git_buf src = GIT_BUF_INIT; git_buf src = GIT_BUF_INIT;
build_local_file_url(&src, cl_fixture("testrepo.git")); build_local_file_url(&src, cl_fixture("testrepo.git"));
#if DO_LOCAL_TEST #if DO_LOCAL_TEST
cl_set_cleanup(&cleanup_repository, "./local");
cl_git_pass(git_clone(&g_repo, git_buf_cstr(&src), "./local", NULL, NULL, NULL)); cl_git_pass(git_clone(&g_repo, git_buf_cstr(&src), "./local", NULL, NULL, NULL));
git_repository_free(g_repo);
git_futils_rmdir_r("./local", GIT_DIRREMOVAL_FILES_AND_DIRS);
cl_git_pass(git_clone_bare(&g_repo, git_buf_cstr(&src), "./local.git", NULL));
git_futils_rmdir_r("./local.git", GIT_DIRREMOVAL_FILES_AND_DIRS);
#endif #endif
git_buf_free(&src); git_buf_free(&src);
} }
void test_clone_clone__local_bare(void)
{
git_buf src = GIT_BUF_INIT;
build_local_file_url(&src, cl_fixture("testrepo.git"));
#if DO_LOCAL_TEST
cl_set_cleanup(&cleanup_repository, "./local.git");
cl_git_pass(git_clone_bare(&g_repo, git_buf_cstr(&src), "./local.git", NULL));
#endif
git_buf_free(&src);
}
void test_clone_clone__network_full(void) void test_clone_clone__network_full(void)
{ {
#if DO_LIVE_NETWORK_TESTS #if DO_LIVE_NETWORK_TESTS
git_remote *origin; git_remote *origin;
cl_set_cleanup(&cleanup_repository, "./test2");
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./test2", NULL, NULL, NULL)); cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./test2", NULL, NULL, NULL));
cl_assert(!git_repository_is_bare(g_repo)); cl_assert(!git_repository_is_bare(g_repo));
cl_git_pass(git_remote_load(&origin, g_repo, "origin")); cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
git_futils_rmdir_r("./test2", GIT_DIRREMOVAL_FILES_AND_DIRS);
#endif #endif
} }
...@@ -108,32 +117,38 @@ void test_clone_clone__network_bare(void) ...@@ -108,32 +117,38 @@ void test_clone_clone__network_bare(void)
#if DO_LIVE_NETWORK_TESTS #if DO_LIVE_NETWORK_TESTS
git_remote *origin; git_remote *origin;
cl_git_pass(git_clone_bare(&g_repo, LIVE_REPO_URL, "test", NULL)); cl_set_cleanup(&cleanup_repository, "./test");
cl_git_pass(git_clone_bare(&g_repo, LIVE_REPO_URL, "./test", NULL));
cl_assert(git_repository_is_bare(g_repo)); cl_assert(git_repository_is_bare(g_repo));
cl_git_pass(git_remote_load(&origin, g_repo, "origin")); cl_git_pass(git_remote_load(&origin, g_repo, "origin"));
git_futils_rmdir_r("./test", GIT_DIRREMOVAL_FILES_AND_DIRS);
#endif #endif
} }
void test_clone_clone__cope_with_already_existing_directory(void)
void test_clone_clone__already_exists(void)
{ {
#if DO_LIVE_NETWORK_TESTS #if DO_LIVE_NETWORK_TESTS
/* Should pass with existing-but-empty dir */ cl_set_cleanup(&cleanup_repository, "./foo");
p_mkdir("./foo", GIT_DIR_MODE); p_mkdir("./foo", GIT_DIR_MODE);
cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL));
git_repository_free(g_repo); g_repo = NULL; git_repository_free(g_repo); g_repo = NULL;
git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS);
#endif #endif
}
void test_clone_clone__fail_when_the_target_is_a_file(void)
{
cl_set_cleanup(&cleanup_repository, "./foo");
/* Should fail with a file */
cl_git_mkfile("./foo", "Bar!"); cl_git_mkfile("./foo", "Bar!");
cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL));
git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS); }
void test_clone_clone__fail_with_already_existing_but_non_empty_directory(void)
{
cl_set_cleanup(&cleanup_repository, "./foo");
/* Should fail with existing-and-nonempty dir */
p_mkdir("./foo", GIT_DIR_MODE); p_mkdir("./foo", GIT_DIR_MODE);
cl_git_mkfile("./foo/bar", "Baz!"); cl_git_mkfile("./foo/bar", "Baz!");
cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL));
git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment