2016-10-27 01:14:07 +00:00
|
|
|
/**
|
|
|
|
* Testing of cmd/ipfs/init
|
|
|
|
*/
|
|
|
|
#ifndef __TEST_INIT_H__
|
|
|
|
#define __TEST_INIT_H__
|
|
|
|
|
2016-12-05 11:13:20 +00:00
|
|
|
#include <stdlib.h>
|
2016-12-05 11:54:21 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
//#include <string.h>
|
2017-09-20 17:39:26 +00:00
|
|
|
#include <pthread.h>
|
2016-12-05 11:13:20 +00:00
|
|
|
|
2016-10-31 16:13:42 +00:00
|
|
|
#include "ipfs/cmd/ipfs/init.h"
|
|
|
|
#include "ipfs/commands/argument.h"
|
2016-11-10 13:28:51 +00:00
|
|
|
#include "ipfs/commands/request.h"
|
|
|
|
#include "ipfs/commands/command.h"
|
2017-04-06 14:33:28 +00:00
|
|
|
#include "libp2p/os/utils.h"
|
2016-10-27 01:14:07 +00:00
|
|
|
|
|
|
|
|
2016-11-10 13:28:51 +00:00
|
|
|
int test_init_new_installation() {
|
2016-11-17 20:07:59 +00:00
|
|
|
unlink("/tmp/.ipfs/config");
|
2016-11-10 13:28:51 +00:00
|
|
|
// do the minimum to get the .ipfs directory structure and config file built
|
|
|
|
struct Request request;
|
|
|
|
int retVal = ipfs_cmd_ipfs_init_command_new( &request.cmd );
|
|
|
|
if (retVal == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// build a request so it builds the repository in the /tmp directory
|
|
|
|
request.invoc_context = (struct Context*)malloc(sizeof(struct Context));
|
|
|
|
request.invoc_context->config_root = "/tmp/.ipfs";
|
|
|
|
|
|
|
|
// run the methods
|
|
|
|
|
|
|
|
retVal = request.cmd.pre_run(&request);
|
2016-11-28 13:09:00 +00:00
|
|
|
if (retVal == 0) {
|
|
|
|
free(request.invoc_context);
|
|
|
|
ipfs_cmd_ipfs_init_command_free(&request.cmd);
|
2016-11-10 13:28:51 +00:00
|
|
|
return 0;
|
2016-11-28 13:09:00 +00:00
|
|
|
}
|
2016-11-10 13:28:51 +00:00
|
|
|
|
|
|
|
retVal = request.cmd.run(&request);
|
2016-11-28 13:09:00 +00:00
|
|
|
if (retVal == 0) {
|
|
|
|
free(request.invoc_context);
|
|
|
|
ipfs_cmd_ipfs_init_command_free(&request.cmd);
|
2016-11-10 13:28:51 +00:00
|
|
|
return 0;
|
2016-11-28 13:09:00 +00:00
|
|
|
}
|
2016-11-10 13:28:51 +00:00
|
|
|
|
|
|
|
retVal = request.cmd.post_run(&request);
|
2016-11-28 13:09:00 +00:00
|
|
|
if (retVal == 0) {
|
|
|
|
free(request.invoc_context);
|
|
|
|
ipfs_cmd_ipfs_init_command_free(&request.cmd);
|
2016-11-10 13:28:51 +00:00
|
|
|
return 0;
|
2016-11-28 13:09:00 +00:00
|
|
|
}
|
2016-11-10 13:28:51 +00:00
|
|
|
|
|
|
|
// clean up
|
|
|
|
ipfs_cmd_ipfs_init_command_free( &request.cmd );
|
2016-11-28 13:09:00 +00:00
|
|
|
free(request.invoc_context);
|
2016-11-10 13:28:51 +00:00
|
|
|
|
|
|
|
// make sure the repository exists
|
|
|
|
retVal = os_utils_file_exists("/tmp/.ipfs/config");
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* This is used for the command line interpreter, which is still in development
|
|
|
|
*/
|
2016-10-27 01:14:07 +00:00
|
|
|
int test_get_init_command() {
|
2016-10-27 18:11:34 +00:00
|
|
|
struct Command cmd = { 0 };
|
2016-10-27 02:13:32 +00:00
|
|
|
int retVal = 1;
|
2016-10-27 01:14:07 +00:00
|
|
|
// make sure its empty
|
|
|
|
if (cmd.help_text.tagline != NULL) {
|
|
|
|
fprintf(stderr, "short description should be null\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// grab the stuff
|
2016-11-10 13:28:51 +00:00
|
|
|
retVal = ipfs_cmd_ipfs_init_command_new(&cmd);
|
2016-10-27 01:14:07 +00:00
|
|
|
|
2016-10-27 02:13:32 +00:00
|
|
|
if (!retVal) {
|
|
|
|
fprintf(stderr, "Function call to get_init_command not successful. Return was %d\n", retVal);
|
|
|
|
return retVal;
|
|
|
|
}
|
2016-10-27 01:14:07 +00:00
|
|
|
// make sure its right
|
|
|
|
if (cmd.help_text.tagline == NULL) {
|
|
|
|
fprintf(stderr, "short description is null\n");
|
2016-10-27 02:13:32 +00:00
|
|
|
retVal = 0;
|
|
|
|
} else if (strcmp(cmd.help_text.tagline, "Initializes IPFS config file.") != 0) {
|
2016-10-27 01:14:07 +00:00
|
|
|
fprintf(stderr, "short description is not null\n");
|
2016-10-27 02:13:32 +00:00
|
|
|
retVal = 0;
|
|
|
|
} else if (cmd.argument_count != 1) {
|
|
|
|
fprintf(stderr, "argument count should be 1");
|
|
|
|
retVal = 0;
|
|
|
|
} else {
|
2016-10-27 18:11:34 +00:00
|
|
|
struct Argument arg1 = *(cmd.arguments[0]);
|
2016-10-27 02:13:32 +00:00
|
|
|
if (strncmp(arg1.name, "default-config", 14) != 0) {
|
|
|
|
fprintf(stderr, "arg1 wrong name. Expected %s but got %s\n", "default_config", arg1.name);
|
|
|
|
retVal = 0;
|
|
|
|
}
|
2016-10-27 01:14:07 +00:00
|
|
|
}
|
2016-11-10 13:28:51 +00:00
|
|
|
ipfs_cmd_ipfs_init_command_free(&cmd);
|
2016-10-27 02:13:32 +00:00
|
|
|
return retVal;
|
2016-10-27 01:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|