2016-10-31 16:13:42 +00:00
|
|
|
#ifndef test_repo_config_h
|
|
|
|
#define test_repo_config_h
|
2017-01-02 04:48:09 +00:00
|
|
|
#include <sys/stat.h>
|
2016-11-02 18:09:38 +00:00
|
|
|
#include "ipfs/repo/config/config.h"
|
2016-11-03 04:05:29 +00:00
|
|
|
#include "ipfs/repo/fsrepo/fs_repo.h"
|
2017-04-06 14:33:28 +00:00
|
|
|
#include "libp2p/os/utils.h"
|
2016-10-31 16:13:42 +00:00
|
|
|
|
2016-11-28 13:09:00 +00:00
|
|
|
int test_repo_config_new() {
|
|
|
|
struct RepoConfig* repoConfig;
|
|
|
|
int retVal = ipfs_repo_config_new(&repoConfig);
|
|
|
|
if (retVal == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
retVal = ipfs_repo_config_free(repoConfig);
|
|
|
|
if (retVal == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
int test_repo_config_init() {
|
2017-04-27 16:35:26 +00:00
|
|
|
int retVal = 0;
|
|
|
|
struct RepoConfig* repoConfig = NULL;
|
|
|
|
char* config_dir = "/tmp/.ipfs";
|
|
|
|
char* peer_id = NULL;
|
2016-11-17 20:07:59 +00:00
|
|
|
|
2017-04-27 16:35:26 +00:00
|
|
|
if (!drop_repository(config_dir)) {
|
|
|
|
fprintf(stderr, "Unable to delete repository\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ipfs_repo_config_new(&repoConfig)) {
|
|
|
|
fprintf(stderr, "Unable to initialize repo structure\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ipfs_repo_config_init(repoConfig, 2048, config_dir, 4001, NULL)) {
|
|
|
|
fprintf(stderr, "unable to initialize new repo\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
2016-11-02 18:44:56 +00:00
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
// now tear it apart to check for anything broken
|
|
|
|
|
|
|
|
// addresses
|
2017-04-27 16:35:26 +00:00
|
|
|
if (repoConfig->addresses == NULL) {
|
|
|
|
fprintf(stderr, "Addresses is null\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* API not implemented yet
|
|
|
|
if (repoConfig->addresses->api == NULL) {
|
|
|
|
fprintf(stderr, "Addresses->API is null\n");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(repoConfig->addresses->api, "/ip4/127.0.0.1/tcp/5001", 23) != 0)
|
|
|
|
goto exit;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Gateway not implemented yete
|
|
|
|
if (repoConfig->addresses->gateway == NULL)
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
if (strncmp(repoConfig->addresses->gateway, "/ip4/127.0.0.1/tcp/8080", 23) != 0)
|
|
|
|
goto exit;
|
|
|
|
*/
|
2016-11-02 18:09:38 +00:00
|
|
|
|
2017-04-27 16:35:26 +00:00
|
|
|
/* No swarms added yet
|
|
|
|
if (repoConfig->addresses->swarm_head == NULL
|
|
|
|
|| repoConfig->addresses->swarm_head->next == NULL
|
|
|
|
|| repoConfig->addresses->swarm_head->next->next != NULL) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2016-11-03 04:05:29 +00:00
|
|
|
|
2017-04-27 16:35:26 +00:00
|
|
|
if (strcmp((char*)repoConfig->addresses->swarm_head->item, "/ip4/0.0.0.0/tcp/4001") != 0)
|
|
|
|
goto exit;
|
2016-11-03 04:05:29 +00:00
|
|
|
|
2017-04-27 16:35:26 +00:00
|
|
|
if (strcmp((char*)repoConfig->addresses->swarm_head->next->item, "/ip6/::/tcp/4001") != 0)
|
|
|
|
goto exit;
|
|
|
|
*/
|
2016-11-03 04:05:29 +00:00
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
// datastore
|
2017-04-27 16:35:26 +00:00
|
|
|
if (strncmp(repoConfig->datastore->path, "/tmp/.ipfs/datastore", 32) != 0)
|
|
|
|
goto exit;
|
2016-11-28 13:09:00 +00:00
|
|
|
|
2017-04-27 16:35:26 +00:00
|
|
|
retVal = 1;
|
|
|
|
exit:
|
|
|
|
if (repoConfig != NULL)
|
|
|
|
ipfs_repo_config_free(repoConfig);
|
|
|
|
if (peer_id != NULL)
|
|
|
|
free(peer_id);
|
2016-11-02 18:44:56 +00:00
|
|
|
|
2017-04-27 16:35:26 +00:00
|
|
|
return retVal;
|
2016-11-02 18:09:38 +00:00
|
|
|
}
|
2016-10-31 16:13:42 +00:00
|
|
|
|
2016-11-03 04:05:29 +00:00
|
|
|
/***
|
|
|
|
* test the writing of the config file
|
|
|
|
*/
|
|
|
|
int test_repo_config_write() {
|
2017-01-02 04:48:09 +00:00
|
|
|
// make sure the directory is there
|
|
|
|
if (!os_utils_file_exists("/tmp/.ipfs")) {
|
|
|
|
mkdir("/tmp/.ipfs", S_IRWXU);
|
|
|
|
}
|
2016-11-03 04:05:29 +00:00
|
|
|
// first delete the existing one
|
2016-11-17 20:07:59 +00:00
|
|
|
unlink("/tmp/.ipfs/config");
|
2016-11-03 04:05:29 +00:00
|
|
|
|
|
|
|
// now build a new one
|
2016-11-17 20:07:59 +00:00
|
|
|
struct RepoConfig* repoConfig;
|
|
|
|
ipfs_repo_config_new(&repoConfig);
|
2017-04-13 14:31:58 +00:00
|
|
|
if (!ipfs_repo_config_init(repoConfig, 2048, "/tmp/.ipfs", 4001, NULL)) {
|
2016-11-17 20:07:59 +00:00
|
|
|
ipfs_repo_config_free(repoConfig);
|
2016-11-03 04:05:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-17 20:07:59 +00:00
|
|
|
if (!fs_repo_write_config_file("/tmp/.ipfs", repoConfig)) {
|
|
|
|
ipfs_repo_config_free(repoConfig);
|
2016-11-03 04:05:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-11-17 20:07:59 +00:00
|
|
|
ipfs_repo_config_free(repoConfig);
|
2016-11-03 04:05:29 +00:00
|
|
|
|
|
|
|
// check to see if the file exists
|
2016-11-17 20:07:59 +00:00
|
|
|
return os_utils_file_exists("/tmp/.ipfs/config");
|
2016-11-03 04:05:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-31 16:13:42 +00:00
|
|
|
#endif /* test_repo_config_h */
|