notes: simplify tests
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
diff --git a/tests-clar/notes/notes.c b/tests-clar/notes/notes.c
index 068e44c..5f7f5a9 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;
@@ -132,6 +110,65 @@ 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",
@@ -163,7 +200,7 @@ static char *messages[] = {
* $ git ls-tree d71aab4
* 100644 blob 08b041783f40edfe12bb406c9c9a8a040177c125 071c1b46c854b31185ea97743be6a8774479
*/
-void test_notes_notes__can_correctly_insert_a_note_in_an_existing_fanout(void)
+void test_notes_notes__can_insert_a_note_in_an_existing_fanout(void)
{
size_t i;
git_oid note_oid, target_oid;
@@ -198,10 +235,6 @@ void test_notes_notes__can_read_a_note_in_an_existing_fanout(void)
git_note_free(note);
}
-/*
- * $ git notes --ref fanout list 8496071c1b46c854b31185ea97743be6a8774479
- * 08b041783f40edfe12bb406c9c9a8a040177c125
- */
void test_notes_notes__can_remove_a_note_in_an_existing_fanout(void)
{
git_oid target_oid;
@@ -212,3 +245,16 @@ void test_notes_notes__can_remove_a_note_in_an_existing_fanout(void)
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);
+}