diff options
author | Edward Thomson <ethomson@microsoft.com> | 2014-03-05 11:35:47 -0800 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2014-03-05 11:35:47 -0800 |
commit | 7bd2f401540e1e9c92183fd61aa9e2a4ef0ed051 (patch) | |
tree | 9f3388edb63b9ff34f3d92b72e2a87e6028eb2f0 /tests/odb | |
parent | fb52ba19ff0a620b4fd9482132206ccb4daee8e0 (diff) | |
download | libgit2-7bd2f401540e1e9c92183fd61aa9e2a4ef0ed051.tar.gz |
ODB writing fails gracefully when unsupported
If no ODB backends support writing, we should fail gracefully.
Diffstat (limited to 'tests/odb')
-rw-r--r-- | tests/odb/backend/nobackend.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/odb/backend/nobackend.c b/tests/odb/backend/nobackend.c new file mode 100644 index 000000000..7ed5acced --- /dev/null +++ b/tests/odb/backend/nobackend.c @@ -0,0 +1,41 @@ +#include "clar_libgit2.h" +#include "repository.h" +#include "git2/sys/repository.h" + +static git_repository *_repo; + +void test_odb_backend_nobackend__initialize(void) +{ + git_config *config; + git_odb *odb; + git_refdb *refdb; + + cl_git_pass(git_repository_new(&_repo)); + cl_git_pass(git_config_new(&config)); + cl_git_pass(git_odb_new(&odb)); + cl_git_pass(git_refdb_new(&refdb, _repo)); + + git_repository_set_config(_repo, config); + git_repository_set_odb(_repo, odb); + git_repository_set_refdb(_repo, refdb); +} + +void test_odb_backend_nobackend__cleanup(void) +{ + git_repository_free(_repo); +} + +void test_odb_backend_nobackend__write_fails_gracefully(void) +{ + git_oid id; + git_odb *odb; + const git_error *err; + + git_repository_odb(&odb, _repo); + cl_git_fail(git_odb_write(&id, odb, "Hello world!\n", 13, GIT_OBJ_BLOB)); + + err = giterr_last(); + cl_assert_equal_s(err->message, "Cannot write object - unsupported in the loaded odb backends"); + + git_odb_free(odb); +} |