Add test for fifo node extraction

This commit is contained in:
Nathan Fisher 2023-10-05 10:40:12 -04:00
parent ba69c2b8e9
commit ccb742e80e
3 changed files with 42 additions and 0 deletions

View file

@ -663,6 +663,9 @@ haggis_node* haggis_create_node(
return node;
}
}
body.f_name = strndup(file, PATH_MAX);
msg = haggis_msg_init(NodeCreated, body);
haggis_mq_push(mq, msg);
} else if (S_ISLNK(st.st_mode)) {
node->filetype.tag = softlink;
ssize_t res = readlink(file, pathbuf, PATH_MAX);

View file

@ -73,6 +73,7 @@ tests += create_file_node
tests += mq_push_pop
tests += extract_dev_node
tests += extract_dir_node
tests += extract_fifo_node
total != echo $(tests) | wc -w | awk '{ print $$1 }'

38
test/extract_fifo_node.c Normal file
View file

@ -0,0 +1,38 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "haggis.h"
#include "mq.h"
int main() {
haggis_node *node = NULL;
haggis_linkmap *map = NULL;
haggis_mq mq;
haggis_msg *msg = NULL;
char *path = "output/fifo";
int ret = 0;
map = haggis_linkmap_init();
assert(map != NULL);
assert(haggis_mq_init(&mq) == 0);
node = haggis_create_node(path, skip, map, &mq);
assert(node != NULL);
assert(node->filetype.tag == fifo);
assert(memcmp(node->name.name, path, 11) == 0);
ret = haggis_extract_node("output/extracted", node, &mq);
assert(ret == 0);
msg = haggis_mq_pop(&mq);
assert(msg->tag == NodeCreated);
assert(memcmp(msg->body.f_name, path, 11) == 0);
haggis_msg_deinit(msg);
msg = haggis_mq_pop(&mq);
assert(msg->tag == NodeExtracted);
assert(memcmp(msg->body.f_name, path, 11) == 0);
assert(mq.head == NULL);
assert(mq.tail == NULL);
haggis_msg_deinit(msg);
haggis_node_deinit(node);
haggis_linkmap_deinit(map);
return 0;
}