Add tests for hardlink nodes

This commit is contained in:
Nathan Fisher 2023-12-01 16:03:31 -05:00
parent 3cb0883b4a
commit 0132e493e4
2 changed files with 61 additions and 0 deletions

View file

@ -76,6 +76,7 @@ tests += extract_dir_node
tests += extract_fifo_node
tests += extract_file_node
tests += extract_symlink_node
tests += extract_hardlink_node
total != echo $(tests) | wc -w | awk '{ print $$1 }'

View file

@ -0,0 +1,60 @@
#include <errno.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "haggis.h"
#include "mq.h"
int main() {
haggis_node *node0 = NULL, *node1 = NULL;
haggis_linkmap *map = NULL;
haggis_mq mq;
haggis_msg *msg;
char *orig = "Makefile";
char *lnk = "output/Makefile";
int ret = 0;
map = haggis_linkmap_init();
assert(map != NULL);
if (haggis_mq_init(&mq))
return errno;
unlink(lnk);
ret = link(orig, lnk);
node0 = haggis_create_node(orig, sha256, map, &mq);
assert(node0 != NULL);
assert(node0->filetype.tag == normal);
assert(memcmp(node0->name.name, orig, 8) == 0);
if (ret) return ret;
node1 = haggis_create_node(lnk, sha256, map, &mq);
assert(node1 != NULL);
assert(node1->filetype.tag == hardlink);
assert(memcmp(node1->name.name, lnk, 15) == 0);
ret = haggis_extract_node("output/extracted", node0, &mq);
assert(ret == 0);
haggis_node_deinit(node0);
ret = haggis_extract_node("output/extracted", node1, &mq);
assert(ret == 0);
haggis_node_deinit(node1);
msg = haggis_mq_pop(&mq);
assert(msg->tag == NodeCreated);
assert(memcmp(msg->body.f_name, orig, 8) == 0);
haggis_msg_deinit(msg);
msg = haggis_mq_pop(&mq);
assert(msg->tag == NodeCreated);
assert(memcmp(msg->body.f_name, lnk, 15) == 0);
haggis_msg_deinit(msg);
msg = haggis_mq_pop(&mq);
assert(msg->tag == NodeExtracted);
assert(memcmp(msg->body.f_name, orig, 8) == 0);
haggis_msg_deinit(msg);
msg = haggis_mq_pop(&mq);
assert(msg->tag == NodeExtracted);
assert(memcmp(msg->body.f_name, lnk, 15) == 0);
haggis_msg_deinit(msg);
haggis_linkmap_deinit(map);
return 0;
}