2016-12-30 00:05:44 +00:00
|
|
|
#include "ipfs/importer/resolver.h"
|
2017-01-02 04:48:09 +00:00
|
|
|
#include "ipfs/os/utils.h"
|
2016-12-30 00:05:44 +00:00
|
|
|
|
|
|
|
int test_resolver_get() {
|
|
|
|
// clean out repository
|
2017-01-02 04:48:09 +00:00
|
|
|
const char* ipfs_path = "/tmp/.ipfs";
|
|
|
|
os_utils_setenv("IPFS_PATH", ipfs_path, 1);
|
2016-12-30 00:05:44 +00:00
|
|
|
|
2017-01-02 04:48:09 +00:00
|
|
|
drop_and_build_repository(ipfs_path);
|
|
|
|
|
2017-01-02 05:38:09 +00:00
|
|
|
// this should point to a test directory with files and directories
|
|
|
|
char* home_dir = os_utils_get_homedir();
|
|
|
|
char* test_dir = malloc(strlen(home_dir) + 10);
|
|
|
|
|
|
|
|
os_utils_filepath_join(home_dir, "ipfstest", test_dir, strlen(home_dir) + 10);
|
|
|
|
|
2017-01-02 04:48:09 +00:00
|
|
|
int argc = 4;
|
2016-12-30 00:05:44 +00:00
|
|
|
char* argv[argc];
|
|
|
|
argv[0] = "ipfs";
|
|
|
|
argv[1] = "add";
|
2017-01-02 04:48:09 +00:00
|
|
|
argv[2] = "-r";
|
2017-01-02 05:38:09 +00:00
|
|
|
argv[3] = test_dir;
|
2016-12-30 00:05:44 +00:00
|
|
|
|
|
|
|
ipfs_import_files(argc, (char**)argv);
|
|
|
|
|
|
|
|
struct FSRepo* fs_repo;
|
2017-01-02 04:48:09 +00:00
|
|
|
ipfs_repo_fsrepo_new(ipfs_path, NULL, &fs_repo);
|
2016-12-30 00:05:44 +00:00
|
|
|
ipfs_repo_fsrepo_open(fs_repo);
|
|
|
|
|
|
|
|
// find something that is already in the repository
|
|
|
|
struct Node* result = ipfs_resolver_get("/ipfs/QmbMecmXESf96ZNry7hRuzaRkEBhjqXpoYfPCwgFzVGDzB", NULL, fs_repo);
|
|
|
|
if (result == NULL) {
|
2017-01-02 05:38:09 +00:00
|
|
|
free(test_dir);
|
|
|
|
ipfs_repo_fsrepo_free(fs_repo);
|
2016-12-30 00:05:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipfs_node_free(result);
|
|
|
|
|
|
|
|
// find something by path
|
2017-01-02 04:48:09 +00:00
|
|
|
result = ipfs_resolver_get("/ipfs/QmZBvycPAYScBoPEzm35zXHt6gYYV5t9PyWmr4sksLPNFS/hello_world.txt", NULL, fs_repo);
|
2016-12-30 00:05:44 +00:00
|
|
|
if (result == NULL) {
|
2017-01-02 05:38:09 +00:00
|
|
|
free(test_dir);
|
|
|
|
ipfs_repo_fsrepo_free(fs_repo);
|
2016-12-30 00:05:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-02 05:38:09 +00:00
|
|
|
ipfs_node_free(result);
|
|
|
|
free(test_dir);
|
|
|
|
ipfs_repo_fsrepo_free(fs_repo);
|
|
|
|
|
2016-12-30 00:05:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|