Skip to content

Commit 6eb7a9a

Browse files
committed
tests: add test for empty journal files
The headers are currently not printed properly: some "(null)"s appear.
1 parent ed375be commit 6eb7a9a

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

TODO

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Bugfixes:
1111

1212
* properly handle .mount unit state tracking when two mount points are stacked one on top of another on the exact same mount point.
1313

14+
* fix --header to files without entries (see test-journal output).
15+
1416
Fedora 19:
1517

1618
* external: maybe it is time to patch procps so that "ps" links to

src/journal/test-journal.c

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#include "journal-authenticate.h"
3030
#include "journal-vacuum.h"
3131

32-
int main(int argc, char *argv[]) {
32+
static bool arg_keep = false;
33+
34+
static void test_non_empty(void) {
3335
dual_timestamp ts;
3436
JournalFile *f;
3537
struct iovec iovec;
@@ -119,11 +121,61 @@ int main(int argc, char *argv[]) {
119121

120122
journal_file_close(f);
121123

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);
123142

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;
125176

126-
assert_se(rm_rf_dangerous(t, false, true, false) >= 0);
177+
test_non_empty();
178+
test_empty();
127179

128180
return 0;
129181
}

0 commit comments

Comments
 (0)