repo_writer_tests.c (1781B)
1 #include "writer/html/repo_writer.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/repo.h" 10 #include "utest.h" 11 12 struct html_repo_writer { 13 int dummy; 14 }; 15 16 UTEST_F_SETUP(html_repo_writer) { 17 inmemory_fs_clear(); 18 } 19 20 UTEST_F_TEARDOWN(html_repo_writer) {} 21 22 UTEST_F(html_repo_writer, orchestration) { 23 GitRepo repo = { 24 .name = "test-repo.git", 25 .short_name = "test-repo", 26 .description = "A test repository", 27 .owner = "Test Owner", 28 .clone_url = "git://example.com/test-repo.git", 29 }; 30 HtmlRepoWriter* writer = html_repowriter_create(&repo, g_fs_inmemory); 31 ASSERT_NE(NULL, writer); 32 33 GitCommit commit = { 34 .oid = "sha123", 35 .parentoid = "", 36 .summary = "Test commit", 37 .message = "Detailed message.", 38 .author_name = "User", 39 .author_email = "user@example.com", 40 }; 41 42 html_repowriter_begin(writer); 43 html_repowriter_add_commit(writer, &commit); 44 html_repowriter_end(writer); 45 html_repowriter_free(writer); 46 47 /* Verify orchestration by checking multiple output files. */ 48 49 /* 1. Log file exists and contains the commit message. */ 50 const char* log_buf = inmemory_fs_get_buffer("log.html"); 51 ASSERT_NE(NULL, log_buf); 52 EXPECT_NE(NULL, strstr(log_buf, "Test commit")); 53 54 /* 2. Atom feed exists and contains the commit entry. */ 55 const char* atom_buf = inmemory_fs_get_buffer("atom.xml"); 56 ASSERT_NE(NULL, atom_buf); 57 EXPECT_NE(NULL, strstr(atom_buf, "<title>Test commit</title>")); 58 59 /* 3. Individual commit page exists. */ 60 const char* commit_buf = inmemory_fs_get_buffer("commit/sha123.html"); 61 ASSERT_NE(NULL, commit_buf); 62 EXPECT_NE(NULL, strstr(commit_buf, "Test commit")); 63 EXPECT_NE(NULL, strstr(commit_buf, "sha123")); 64 }