Importing the "has_in_name" logic from MHD.
This commit is contained in:
parent
cb6aab590b
commit
447d1d78ad
@ -40,11 +40,21 @@
|
||||
|
||||
#define CONFIG_FILE "bank.conf"
|
||||
|
||||
|
||||
/**
|
||||
* Fakebank URL.
|
||||
*/
|
||||
char *fakebank_url;
|
||||
static char *bank_url;
|
||||
|
||||
/**
|
||||
* Handle to the Py-bank daemon.
|
||||
*/
|
||||
static struct GNUNET_OS_Process *bankd;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the test is running against the
|
||||
* Fakebank. Set up at runtime.
|
||||
*/
|
||||
static int WITH_FAKEBANK;
|
||||
|
||||
/**
|
||||
* Main function that will tell the interpreter what commands to
|
||||
@ -57,14 +67,14 @@ run (void *cls,
|
||||
struct TALER_TESTING_Interpreter *is)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||
"Fakebank serves at `%s'\n",
|
||||
fakebank_url);
|
||||
"Bank serves at `%s'\n",
|
||||
bank_url);
|
||||
extern struct TALER_BANK_AuthenticationData AUTHS[];
|
||||
|
||||
struct TALER_TESTING_Command commands[] = {
|
||||
|
||||
TALER_TESTING_cmd_bank_history ("history-0",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
BANK_ACCOUNT_NUMBER,
|
||||
TALER_BANK_DIRECTION_BOTH,
|
||||
GNUNET_YES,
|
||||
@ -77,7 +87,7 @@ run (void *cls,
|
||||
TALER_TESTING_cmd_fakebank_transfer_with_subject
|
||||
("debit-1",
|
||||
"KUDOS:5.01",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
EXCHANGE_ACCOUNT_NUMBER,
|
||||
BANK_ACCOUNT_NUMBER,
|
||||
AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
|
||||
@ -86,7 +96,7 @@ run (void *cls,
|
||||
"http://exchange.com/"),
|
||||
|
||||
TALER_TESTING_cmd_bank_history ("history-1c",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
BANK_ACCOUNT_NUMBER,
|
||||
TALER_BANK_DIRECTION_CREDIT,
|
||||
GNUNET_YES,
|
||||
@ -94,7 +104,7 @@ run (void *cls,
|
||||
5),
|
||||
|
||||
TALER_TESTING_cmd_bank_history ("history-1d",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
BANK_ACCOUNT_NUMBER,
|
||||
TALER_BANK_DIRECTION_DEBIT,
|
||||
GNUNET_YES,
|
||||
@ -104,7 +114,7 @@ run (void *cls,
|
||||
TALER_TESTING_cmd_fakebank_transfer_with_subject
|
||||
("debit-2",
|
||||
"KUDOS:3.21",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
EXCHANGE_ACCOUNT_NUMBER, // debit account.
|
||||
USER_ACCOUNT_NUMBER,
|
||||
AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
|
||||
@ -115,7 +125,7 @@ run (void *cls,
|
||||
TALER_TESTING_cmd_fakebank_transfer_with_subject
|
||||
("credit-2",
|
||||
"KUDOS:3.22",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
USER_ACCOUNT_NUMBER, // debit account.
|
||||
EXCHANGE_ACCOUNT_NUMBER,
|
||||
AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.username,
|
||||
@ -124,7 +134,7 @@ run (void *cls,
|
||||
"http://exchange.org/"),
|
||||
|
||||
TALER_TESTING_cmd_bank_history ("history-2b",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
EXCHANGE_ACCOUNT_NUMBER,
|
||||
TALER_BANK_DIRECTION_BOTH,
|
||||
GNUNET_YES,
|
||||
@ -132,7 +142,7 @@ run (void *cls,
|
||||
5),
|
||||
|
||||
TALER_TESTING_cmd_bank_history ("history-2bi",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
EXCHANGE_ACCOUNT_NUMBER,
|
||||
TALER_BANK_DIRECTION_BOTH,
|
||||
GNUNET_YES,
|
||||
@ -153,7 +163,7 @@ run (void *cls,
|
||||
TALER_TESTING_cmd_fakebank_transfer_with_subject
|
||||
("credit-for-reject-1",
|
||||
"KUDOS:5.01",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
BANK_ACCOUNT_NUMBER,
|
||||
EXCHANGE_ACCOUNT_NUMBER,
|
||||
AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.username,
|
||||
@ -162,11 +172,11 @@ run (void *cls,
|
||||
"http://exchange.net/"),
|
||||
|
||||
TALER_TESTING_cmd_bank_reject ("reject-1",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
"credit-for-reject-1"),
|
||||
|
||||
TALER_TESTING_cmd_bank_history ("history-r1",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
BANK_ACCOUNT_NUMBER,
|
||||
TALER_BANK_DIRECTION_BOTH,
|
||||
GNUNET_YES,
|
||||
@ -174,7 +184,7 @@ run (void *cls,
|
||||
5),
|
||||
|
||||
TALER_TESTING_cmd_bank_history ("history-r1c",
|
||||
fakebank_url,
|
||||
bank_url,
|
||||
BANK_ACCOUNT_NUMBER,
|
||||
TALER_BANK_DIRECTION_BOTH
|
||||
| TALER_BANK_DIRECTION_CANCEL,
|
||||
@ -195,31 +205,76 @@ run (void *cls,
|
||||
TALER_TESTING_cmd_end ()
|
||||
};
|
||||
|
||||
if (GNUNET_YES == WITH_FAKEBANK)
|
||||
TALER_TESTING_run_with_fakebank (is,
|
||||
commands,
|
||||
fakebank_url);
|
||||
bank_url);
|
||||
else
|
||||
TALER_TESTING_run (is,
|
||||
commands);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *const *argv)
|
||||
{
|
||||
int rv;
|
||||
|
||||
/* These environment variables get in the way... */
|
||||
unsetenv ("XDG_DATA_HOME");
|
||||
unsetenv ("XDG_CONFIG_HOME");
|
||||
GNUNET_log_setup ("test-bank-api-with-fakebank-new",
|
||||
"DEBUG",
|
||||
NULL);
|
||||
if (NULL ==
|
||||
(fakebank_url = TALER_TESTING_prepare_fakebank (CONFIG_FILE,
|
||||
"account-1")))
|
||||
return 77;
|
||||
|
||||
return (GNUNET_OK == TALER_TESTING_setup (&run,
|
||||
WITH_FAKEBANK = TALER_TESTING_has_in_name (argv[0],
|
||||
"_with_fakebank");
|
||||
|
||||
if (GNUNET_YES == WITH_FAKEBANK)
|
||||
{
|
||||
TALER_LOG_DEBUG ("Running against the Fakebank.\n");
|
||||
if (NULL == (bank_url = TALER_TESTING_prepare_fakebank
|
||||
(CONFIG_FILE,
|
||||
"account-1")))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return 77;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NULL == (bank_url = TALER_TESTING_prepare_bank
|
||||
(CONFIG_FILE)))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return 77;
|
||||
}
|
||||
|
||||
if (NULL == (bankd = TALER_TESTING_run_bank
|
||||
(CONFIG_FILE,
|
||||
bank_url)))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return 77;
|
||||
}
|
||||
}
|
||||
|
||||
rv = (GNUNET_OK == TALER_TESTING_setup (&run,
|
||||
NULL,
|
||||
CONFIG_FILE,
|
||||
NULL,
|
||||
GNUNET_NO)) ? 0 : 1;
|
||||
if (GNUNET_NO == WITH_FAKEBANK)
|
||||
{
|
||||
|
||||
GNUNET_OS_process_kill (bankd,
|
||||
SIGKILL);
|
||||
GNUNET_OS_process_wait (bankd);
|
||||
GNUNET_OS_process_destroy (bankd);
|
||||
GNUNET_free (bank_url);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,6 +83,36 @@ TALER_TESTING_run_fakebank (const char *bank_url)
|
||||
return fakebankd;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Look for substring in a programs' name.
|
||||
*
|
||||
* @param prog program's name to look into
|
||||
* @param marker chunk to find in @a prog
|
||||
*/
|
||||
int
|
||||
TALER_TESTING_has_in_name (const char *prog_name,
|
||||
const char *marker)
|
||||
{
|
||||
size_t name_pos;
|
||||
size_t pos;
|
||||
|
||||
if (!prog_name || !marker)
|
||||
return GNUNET_NO;
|
||||
|
||||
pos = 0;
|
||||
name_pos = 0;
|
||||
while (prog_name[pos])
|
||||
{
|
||||
if ('/' == prog_name[pos])
|
||||
name_pos = pos + 1;
|
||||
pos++;
|
||||
}
|
||||
if (name_pos == pos)
|
||||
return GNUNET_YES;
|
||||
return strstr(prog_name + name_pos, marker) != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the (Python) bank process. Assume the port
|
||||
* is available and the database is clean. Use the "prepare
|
||||
|
@ -91,6 +91,16 @@ char *
|
||||
TALER_TESTING_prepare_bank (const char *config_filename);
|
||||
|
||||
|
||||
/**
|
||||
* Look for substring in a programs' name.
|
||||
*
|
||||
* @param prog program's name to look into
|
||||
* @param marker chunk to find in @a prog
|
||||
*/
|
||||
int
|
||||
TALER_TESTING_has_in_name (const char *prog,
|
||||
const char *marker);
|
||||
|
||||
/* ************** Specific interpreter commands ************ */
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user