2016-10-31 16:13:42 +00:00
|
|
|
//
|
|
|
|
// test_repo_config.h
|
|
|
|
// c-ipfs
|
|
|
|
//
|
|
|
|
// Created by John Jones on 10/31/16.
|
|
|
|
// Copyright © 2016 JMJAtlanta. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef test_repo_config_h
|
|
|
|
#define test_repo_config_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"
|
|
|
|
#include "ipfs/os/utils.h"
|
2016-10-31 16:13:42 +00:00
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
int test_repo_config_init() {
|
2016-11-17 20:07:59 +00:00
|
|
|
struct RepoConfig* repoConfig;
|
|
|
|
int retVal = ipfs_repo_config_new(&repoConfig);
|
|
|
|
if (retVal == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
retVal = repo_config_init(repoConfig, 2048, "/Users/JohnJones/.ipfs");
|
2016-11-02 18:09:38 +00:00
|
|
|
if (retVal == 0)
|
|
|
|
return 0;
|
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
|
2016-11-17 20:07:59 +00:00
|
|
|
retVal = strncmp(repoConfig->addresses.api, "/ip4/127.0.0.1/tcp/5001", 23);
|
2016-11-02 18:09:38 +00:00
|
|
|
if (retVal != 0)
|
|
|
|
return 0;
|
2016-11-17 20:07:59 +00:00
|
|
|
retVal = strncmp(repoConfig->addresses.gateway, "/ip4/127.0.0.1/tcp/8080", 23);
|
2016-11-02 18:09:38 +00:00
|
|
|
if (retVal != 0)
|
|
|
|
return 0;
|
|
|
|
|
2016-11-17 20:07:59 +00:00
|
|
|
if (repoConfig->addresses.swarm.num_addresses != 2)
|
2016-11-03 04:05:29 +00:00
|
|
|
return 0;
|
|
|
|
|
2016-11-17 20:07:59 +00:00
|
|
|
retVal = strncmp(repoConfig->addresses.swarm.addresses[0], "/ip4/0.0.0.0/tcp/4001", 21);
|
2016-11-03 04:05:29 +00:00
|
|
|
if (retVal != 0)
|
|
|
|
return 0;
|
|
|
|
|
2016-11-17 20:07:59 +00:00
|
|
|
retVal = strncmp(repoConfig->addresses.swarm.addresses[1], "/ip6/::/tcp/4001", 16);
|
2016-11-03 04:05:29 +00:00
|
|
|
if (retVal != 0)
|
|
|
|
return 0;
|
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
// datastore
|
2016-11-17 20:07:59 +00:00
|
|
|
retVal = strncmp(repoConfig->datastore.path, "/Users/JohnJones/.ipfs/datastore", 32);
|
2016-11-02 18:09:38 +00:00
|
|
|
if (retVal != 0)
|
|
|
|
return 0;
|
|
|
|
|
2016-11-17 20:07:59 +00:00
|
|
|
ipfs_repo_config_free(repoConfig);
|
2016-11-02 18:44:56 +00:00
|
|
|
|
2016-11-02 18:09:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
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() {
|
|
|
|
// 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);
|
|
|
|
if (!repo_config_init(repoConfig, 2048, "/tmp/.ipfs")) {
|
|
|
|
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 */
|