diff options
| author | Vicent Marti <tanoku@gmail.com> | 2012-06-19 02:33:03 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2012-06-19 02:33:03 +0200 |
| commit | b93688d06d4128480ef746856532afa1e53d1e23 (patch) | |
| tree | fcba34f7f9c51f2cef5e7fe4ae3f4cd22c0a52a3 /tests-clar/notes/notes.c | |
| parent | 515a4c7c0634018097d3cd85f6a819dabe4cfd32 (diff) | |
| parent | 027d77ee5c3e9ac859ceac986ceb215da388b28e (diff) | |
| download | libgit2-b93688d06d4128480ef746856532afa1e53d1e23.tar.gz | |
Merge remote-tracking branch 'yorah/fix/notes-creation' into development
Conflicts:
src/notes.c
Diffstat (limited to 'tests-clar/notes/notes.c')
| -rw-r--r-- | tests-clar/notes/notes.c | 191 |
1 files changed, 159 insertions, 32 deletions
diff --git a/tests-clar/notes/notes.c b/tests-clar/notes/notes.c index 5185f25ea..5f7f5a9c3 100644 --- a/tests-clar/notes/notes.c +++ b/tests-clar/notes/notes.c @@ -15,6 +15,16 @@ void test_notes_notes__cleanup(void) cl_git_sandbox_cleanup(); } +static void assert_note_equal(git_note *note, char *message, git_oid *note_oid) { + git_blob *blob; + + cl_assert_equal_s(git_note_message(note), message); + cl_assert(!git_oid_cmp(git_note_oid(note), note_oid)); + + cl_git_pass(git_blob_lookup(&blob, _repo, note_oid)); + cl_assert_equal_s(git_note_message(note), (const char *)git_blob_rawcontent(blob)); +} + static void create_note(git_oid *note_oid, const char *canonical_namespace, const char *target_sha, const char *message) { git_oid oid; @@ -23,38 +33,6 @@ static void create_note(git_oid *note_oid, const char *canonical_namespace, cons cl_git_pass(git_note_create(note_oid, _repo, _sig, _sig, canonical_namespace, &oid, message)); } -void test_notes_notes__1(void) -{ - git_oid oid, note_oid; - static git_note *note; - static git_blob *blob; - - cl_git_pass(git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479")); - - cl_git_pass(git_note_create(¬e_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &oid, "hello world\n")); - cl_git_pass(git_note_create(¬e_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n")); - - cl_git_pass(git_note_read(¬e, _repo, NULL, &oid)); - - cl_assert_equal_s(git_note_message(note), "hello world\n"); - cl_assert(!git_oid_cmp(git_note_oid(note), ¬e_oid)); - - cl_git_pass(git_blob_lookup(&blob, _repo, ¬e_oid)); - cl_assert_equal_s(git_note_message(note), git_blob_rawcontent(blob)); - - cl_git_fail(git_note_create(¬e_oid, _repo, _sig, _sig, NULL, &oid, "hello world\n")); - cl_git_fail(git_note_create(¬e_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &oid, "hello world\n")); - - cl_git_pass(git_note_remove(_repo, NULL, _sig, _sig, &oid)); - cl_git_pass(git_note_remove(_repo, "refs/notes/some/namespace", _sig, _sig, &oid)); - - cl_git_fail(git_note_remove(_repo, NULL, _sig, _sig, ¬e_oid)); - cl_git_fail(git_note_remove(_repo, "refs/notes/some/namespace", _sig, _sig, &oid)); - - git_note_free(note); - git_blob_free(blob); -} - static struct { const char *note_sha; const char *annotated_object_sha; @@ -131,3 +109,152 @@ void test_notes_notes__retrieving_a_list_of_notes_for_an_unknown_namespace_retur cl_assert_equal_i(0, retrieved_notes); } + +void test_notes_notes__inserting_a_note_without_passing_a_namespace_uses_the_default_namespace(void) +{ + git_oid note_oid, target_oid; + git_note *note, *default_namespace_note; + const char *default_ref; + + cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); + cl_git_pass(git_note_default_ref(&default_ref, _repo)); + + create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n"); + + cl_git_pass(git_note_read(¬e, _repo, NULL, &target_oid)); + cl_git_pass(git_note_read(&default_namespace_note, _repo, default_ref, &target_oid)); + + assert_note_equal(note, "hello world\n", ¬e_oid); + assert_note_equal(default_namespace_note, "hello world\n", ¬e_oid); + + git_note_free(note); + git_note_free(default_namespace_note); +} + +void test_notes_notes__can_insert_a_note_with_a_custom_namespace(void) +{ + git_oid note_oid, target_oid; + git_note *note; + + cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); + + create_note(¬e_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world on a custom namespace\n"); + + cl_git_pass(git_note_read(¬e, _repo, "refs/notes/some/namespace", &target_oid)); + + assert_note_equal(note, "hello world on a custom namespace\n", ¬e_oid); + + git_note_free(note); +} + +/* + * $ git notes --ref fanout list 8496071c1b46c854b31185ea97743be6a8774479 + * 08b041783f40edfe12bb406c9c9a8a040177c125 + */ +void test_notes_notes__creating_a_note_on_a_target_which_already_has_one_returns_EEXISTS(void) +{ + int error; + git_oid note_oid, target_oid; + + cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); + + create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n"); + error = git_note_create(¬e_oid, _repo, _sig, _sig, NULL, &target_oid, "hello world\n"); + cl_git_fail(error); + cl_assert_equal_i(GIT_EEXISTS, error); + + create_note(¬e_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n"); + error = git_note_create(¬e_oid, _repo, _sig, _sig, "refs/notes/some/namespace", &target_oid, "hello world\n"); + cl_git_fail(error); + cl_assert_equal_i(GIT_EEXISTS, error); +} + +static char *messages[] = { + "08c041783f40edfe12bb406c9c9a8a040177c125", + "96c45fbe09ab7445fc7c60fd8d17f32494399343", + "48cc7e38dcfc1ec87e70ec03e08c3e83d7a16aa1", + "24c3eaafb681c3df668f9df96f58e7b8c756eb04", + "96ca1b6ccc7858ae94684777f85ac0e7447f7040", + "7ac2db4378a08bb244a427c357e0082ee0d57ac6", + "e6cba23dbf4ef84fe35e884f017f4e24dc228572", + "c8cf3462c7d8feba716deeb2ebe6583bd54589e2", + "39c16b9834c2d665ac5f68ad91dc5b933bad8549", + "f3c582b1397df6a664224ebbaf9d4cc952706597", + "29cec67037fe8e89977474988219016ae7f342a6", + "36c4cd238bf8e82e27b740e0741b025f2e8c79ab", + "f1c45a47c02e01d5a9a326f1d9f7f756373387f8", + "4aca84406f5daee34ab513a60717c8d7b1763ead", + "84ce167da452552f63ed8407b55d5ece4901845f", + NULL +}; + +#define MESSAGES_COUNT (sizeof(messages)/sizeof(messages[0])) - 1 + +/* + * $ git ls-tree refs/notes/fanout + * 040000 tree 4b22b35d44b5a4f589edf3dc89196399771796ea 84 + * + * $ git ls-tree 4b22b35 + * 040000 tree d71aab4f9b04b45ce09bcaa636a9be6231474759 96 + * + * $ git ls-tree d71aab4 + * 100644 blob 08b041783f40edfe12bb406c9c9a8a040177c125 071c1b46c854b31185ea97743be6a8774479 + */ +void test_notes_notes__can_insert_a_note_in_an_existing_fanout(void) +{ + size_t i; + git_oid note_oid, target_oid; + git_note *_note; + + cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); + + for (i = 0; i < MESSAGES_COUNT; i++) { + cl_git_pass(git_note_create(¬e_oid, _repo, _sig, _sig, "refs/notes/fanout", &target_oid, messages[i])); + cl_git_pass(git_note_read(&_note, _repo, "refs/notes/fanout", &target_oid)); + git_note_free(_note); + + git_oid_cpy(&target_oid, ¬e_oid); + } +} + +/* + * $ git notes --ref fanout list 8496071c1b46c854b31185ea97743be6a8774479 + * 08b041783f40edfe12bb406c9c9a8a040177c125 + */ +void test_notes_notes__can_read_a_note_in_an_existing_fanout(void) +{ + git_oid note_oid, target_oid; + git_note *note; + + cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479")); + cl_git_pass(git_note_read(¬e, _repo, "refs/notes/fanout", &target_oid)); + + cl_git_pass(git_oid_fromstr(¬e_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); + cl_assert(!git_oid_cmp(git_note_oid(note), ¬e_oid)); + + git_note_free(note); +} + +void test_notes_notes__can_remove_a_note_in_an_existing_fanout(void) +{ + git_oid target_oid; + git_note *note; + + cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479")); + cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid)); + + cl_git_fail(git_note_read(¬e, _repo, "refs/notes/fanout", &target_oid)); +} + +void test_notes_notes__removing_a_note_which_doesnt_exists_returns_ENOTFOUND(void) +{ + int error; + git_oid target_oid; + + cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479")); + cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid)); + + error = git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid); + cl_git_fail(error); + cl_assert_equal_i(GIT_ENOTFOUND, error); +} |
