|
29 | 29 | #include "journal-authenticate.h" |
30 | 30 | #include "journal-vacuum.h" |
31 | 31 |
|
32 | | -int main(int argc, char *argv[]) { |
| 32 | +static bool arg_keep = false; |
| 33 | + |
| 34 | +static void test_non_empty(void) { |
33 | 35 | dual_timestamp ts; |
34 | 36 | JournalFile *f; |
35 | 37 | struct iovec iovec; |
@@ -119,11 +121,61 @@ int main(int argc, char *argv[]) { |
119 | 121 |
|
120 | 122 | journal_file_close(f); |
121 | 123 |
|
122 | | - journal_directory_vacuum(".", 3000000, 0, 0, NULL); |
| 124 | + log_info("Done..."); |
| 125 | + |
| 126 | + if (arg_keep) |
| 127 | + log_info("Not removing %s", t); |
| 128 | + else { |
| 129 | + journal_directory_vacuum(".", 3000000, 0, 0, NULL); |
| 130 | + |
| 131 | + assert_se(rm_rf_dangerous(t, false, true, false) >= 0); |
| 132 | + } |
| 133 | + |
| 134 | + puts("------------------------------------------------------------"); |
| 135 | +} |
| 136 | + |
| 137 | +static void test_empty(void) { |
| 138 | + JournalFile *f1, *f2, *f3, *f4; |
| 139 | + char t[] = "/tmp/journal-XXXXXX"; |
| 140 | + |
| 141 | + log_set_max_level(LOG_DEBUG); |
123 | 142 |
|
124 | | - log_error("Exiting..."); |
| 143 | + assert_se(mkdtemp(t)); |
| 144 | + assert_se(chdir(t) >= 0); |
| 145 | + |
| 146 | + assert_se(journal_file_open("test.journal", O_RDWR|O_CREAT, 0666, false, false, NULL, NULL, NULL, &f1) == 0); |
| 147 | + |
| 148 | + assert_se(journal_file_open("test-compress.journal", O_RDWR|O_CREAT, 0666, true, false, NULL, NULL, NULL, &f2) == 0); |
| 149 | + |
| 150 | + assert_se(journal_file_open("test-seal.journal", O_RDWR|O_CREAT, 0666, false, true, NULL, NULL, NULL, &f3) == 0); |
| 151 | + |
| 152 | + assert_se(journal_file_open("test-seal-compress.journal", O_RDWR|O_CREAT, 0666, true, true, NULL, NULL, NULL, &f4) == 0); |
| 153 | + |
| 154 | + journal_file_print_header(f1); |
| 155 | + puts(""); |
| 156 | + journal_file_print_header(f2); |
| 157 | + puts(""); |
| 158 | + journal_file_print_header(f3); |
| 159 | + puts(""); |
| 160 | + journal_file_print_header(f4); |
| 161 | + puts(""); |
| 162 | + |
| 163 | + log_info("Done..."); |
| 164 | + |
| 165 | + if (arg_keep) |
| 166 | + log_info("Not removing %s", t); |
| 167 | + else { |
| 168 | + journal_directory_vacuum(".", 3000000, 0, 0, NULL); |
| 169 | + |
| 170 | + assert_se(rm_rf_dangerous(t, false, true, false) >= 0); |
| 171 | + } |
| 172 | +} |
| 173 | + |
| 174 | +int main(int argc, char *argv[]) { |
| 175 | + arg_keep = argc > 1; |
125 | 176 |
|
126 | | - assert_se(rm_rf_dangerous(t, false, true, false) >= 0); |
| 177 | + test_non_empty(); |
| 178 | + test_empty(); |
127 | 179 |
|
128 | 180 | return 0; |
129 | 181 | } |
0 commit comments