commit_tests.c (1316B)
1 #include "writer/gemini/commit.h" 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 7 #include "fs_inmemory.h" 8 #include "git/commit.h" 9 #include "git/delta.h" 10 #include "git/repo.h" 11 #include "test_utils.h" 12 #include "utest.h" 13 14 struct gemini_commit { 15 int dummy; 16 }; 17 18 UTEST_F_SETUP(gemini_commit) { 19 inmemory_fs_clear(); 20 } 21 22 UTEST_F_TEARDOWN(gemini_commit) {} 23 24 UTEST_F(gemini_commit, basic) { 25 GitRepo repo = {.short_name = "test-repo"}; 26 GeminiCommit* commit_writer = 27 gemini_commit_create(&repo, g_fs_inmemory, "sha123", "Commit Title"); 28 ASSERT_NE(NULL, commit_writer); 29 30 GitCommit commit = { 31 .oid = "sha123", 32 .parentoid = "parent456", 33 .summary = "Fix a bug", 34 .message = "Detailed description.", 35 .author_name = "Author Name", 36 .author_email = "author@example.com", 37 .author_time = 1702031400, 38 .author_timezone_offset = 0, 39 }; 40 41 gemini_commit_begin(commit_writer); 42 gemini_commit_add_commit(commit_writer, &commit); 43 gemini_commit_end(commit_writer); 44 gemini_commit_free(commit_writer); 45 46 const char* buf = inmemory_fs_get_buffer("commit/sha123.gmi"); 47 ASSERT_NE(NULL, buf); 48 49 EXPECT_STR_SEQUENCE(buf, "Commit Title", 50 "=> ../commit/sha123.gmi commit sha123", "Author Name", 51 "Detailed description."); 52 }