gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-exchange] branch master updated (049e9c89 -> 6aa8ade


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated (049e9c89 -> 6aa8aded)
Date: Mon, 09 Sep 2019 23:47:28 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a change to branch master
in repository exchange.

    from 049e9c89 update Makefile.am
     new cb6aab59 Provide method to launch Fakebank withOUT running tests.
     new 447d1d78 Importing the "has_in_name" logic from MHD.
     new e6dc2ce6 one source two binaries for testing.
     new 6aa8aded fix makefile

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/bank-lib/Makefile.am                           |  15 +-
 ...api_with_fakebank_new.c => test_bank_api_NEW.c} | 171 ++++++++++++++-------
 src/bank-lib/testing_api_helpers.c                 |  66 ++++++++
 src/include/taler_testing_bank_lib.h               |  21 +++
 4 files changed, 213 insertions(+), 60 deletions(-)
 rename src/bank-lib/{test_bank_api_with_fakebank_new.c => test_bank_api_NEW.c} 
(62%)

diff --git a/src/bank-lib/Makefile.am b/src/bank-lib/Makefile.am
index 2678884b..8cdd7824 100644
--- a/src/bank-lib/Makefile.am
+++ b/src/bank-lib/Makefile.am
@@ -98,7 +98,8 @@ check_PROGRAMS = \
   test_bank_api \
   test_bank_api_new \
   test_bank_api_with_fakebank \
-  test_bank_api_with_fakebank_new
+  test_bank_api_with_fakebank_new \
+  test_bank_api_with_pybank_new
 
 if HAVE_TWISTER
 check_PROGRAMS += \
@@ -172,8 +173,18 @@ test_bank_api_with_fakebank_LDADD = \
   -lgnunetutil \
   -ljansson
 
+test_bank_api_with_pybank_new_SOURCES = \
+  test_bank_api_NEW.c
+
+test_bank_api_with_pybank_new_LDADD = \
+  $(top_builddir)/src/lib/libtalertesting.la \
+  libtalerbanktesting.la \
+  -ltalerexchange \
+  -lgnunetutil \
+  libtalerbank.la
+
 test_bank_api_with_fakebank_new_SOURCES = \
-  test_bank_api_with_fakebank_new.c
+  test_bank_api_NEW.c
 
 test_bank_api_with_fakebank_new_LDADD = \
   $(top_builddir)/src/lib/libtalertesting.la \
diff --git a/src/bank-lib/test_bank_api_with_fakebank_new.c 
b/src/bank-lib/test_bank_api_NEW.c
similarity index 62%
rename from src/bank-lib/test_bank_api_with_fakebank_new.c
rename to src/bank-lib/test_bank_api_NEW.c
index 046248ad..a2f77623 100644
--- a/src/bank-lib/test_bank_api_with_fakebank_new.c
+++ b/src/bank-lib/test_bank_api_NEW.c
@@ -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,
@@ -76,17 +86,17 @@ run (void *cls,
      * the parameters, although it was always set as '200 OK' */
     TALER_TESTING_cmd_fakebank_transfer_with_subject
       ("debit-1",
-      "KUDOS:5.01",
-      fakebank_url,
-      EXCHANGE_ACCOUNT_NUMBER,
-      BANK_ACCOUNT_NUMBER,
-      AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
-      AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password,
-      "subject 1",
-      "http://exchange.com/";),
+       "KUDOS:5.01",
+       bank_url,
+       EXCHANGE_ACCOUNT_NUMBER,
+       BANK_ACCOUNT_NUMBER,
+       AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
+       AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password,
+       "subject 1",
+       "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,
@@ -103,28 +113,28 @@ run (void *cls,
 
     TALER_TESTING_cmd_fakebank_transfer_with_subject
       ("debit-2",
-      "KUDOS:3.21",
-      fakebank_url,
-      EXCHANGE_ACCOUNT_NUMBER,  // debit account.
-      USER_ACCOUNT_NUMBER,
-      AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
-      AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password,
-      "subject 2",
-      "http://exchange.org/";),
+       "KUDOS:3.21",
+       bank_url,
+       EXCHANGE_ACCOUNT_NUMBER,  // debit account.
+       USER_ACCOUNT_NUMBER,
+       AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.username,
+       AUTHS[EXCHANGE_ACCOUNT_NUMBER - 1].details.basic.password,
+       "subject 2",
+       "http://exchange.org/";),
 
     TALER_TESTING_cmd_fakebank_transfer_with_subject
       ("credit-2",
-      "KUDOS:3.22",
-      fakebank_url,
-      USER_ACCOUNT_NUMBER,  // debit account.
-      EXCHANGE_ACCOUNT_NUMBER,
-      AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.username,
-      AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.password,
-      "credit 2",
-      "http://exchange.org/";),
+       "KUDOS:3.22",
+       bank_url,
+       USER_ACCOUNT_NUMBER,  // debit account.
+       EXCHANGE_ACCOUNT_NUMBER,
+       AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.username,
+       AUTHS[USER_ACCOUNT_NUMBER - 1].details.basic.password,
+       "credit 2",
+       "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,
@@ -152,21 +162,21 @@ run (void *cls,
 
     TALER_TESTING_cmd_fakebank_transfer_with_subject
       ("credit-for-reject-1",
-      "KUDOS:5.01",
-      fakebank_url,
-      BANK_ACCOUNT_NUMBER,
-      EXCHANGE_ACCOUNT_NUMBER,
-      AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.username,
-      AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.password,
-      "subject 3",
-      "http://exchange.net/";),
+       "KUDOS:5.01",
+       bank_url,
+       BANK_ACCOUNT_NUMBER,
+       EXCHANGE_ACCOUNT_NUMBER,
+       AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.username,
+       AUTHS[BANK_ACCOUNT_NUMBER - 1].details.basic.password,
+       "subject 3",
+       "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,
@@ -184,7 +194,7 @@ run (void *cls,
 
     TALER_TESTING_cmd_check_bank_transfer_with_ref
       ("expect-credit-reject-1",
-      "credit-for-reject-1"),
+       "credit-for-reject-1"),
 
     TALER_TESTING_cmd_check_bank_empty ("expect-empty-2"),
 
@@ -195,31 +205,76 @@ run (void *cls,
     TALER_TESTING_cmd_end ()
   };
 
-  TALER_TESTING_run_with_fakebank (is,
-                                   commands,
-                                   fakebank_url);
+  if (GNUNET_YES == WITH_FAKEBANK)
+    TALER_TESTING_run_with_fakebank (is,
+                                     commands,
+                                     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,
-                                            NULL,
-                                            CONFIG_FILE,
-                                            NULL,
-                                            GNUNET_NO)) ? 0 : 1;
+
+  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;
 }
 
 
diff --git a/src/bank-lib/testing_api_helpers.c 
b/src/bank-lib/testing_api_helpers.c
index db813df2..411391e5 100644
--- a/src/bank-lib/testing_api_helpers.c
+++ b/src/bank-lib/testing_api_helpers.c
@@ -26,6 +26,7 @@
 #include "platform.h"
 #include <gnunet/gnunet_util_lib.h>
 #include "taler_testing_bank_lib.h"
+#include "taler_fakebank_lib.h"
 
 /* Keep each bank account credentials at index:
  * bank account number - 1 */
@@ -47,6 +48,71 @@ struct TALER_BANK_AuthenticationData AUTHS[] = {
    .details.basic.password = USER_PASSWORD }
 };
 
+
+/**
+ * Runs the Fakebank by guessing / extracting the portnumber
+ * from the base URL.
+ *
+ * @param bank_url bank's base URL.
+ * @return the fakebank process handle, or NULL if any
+ *         error occurs.
+ */
+struct TALER_FAKEBANK_Handle *
+TALER_TESTING_run_fakebank (const char *bank_url)
+{
+  const char *port;
+  long pnum;
+  struct TALER_FAKEBANK_Handle *fakebankd;
+
+  port = strrchr (bank_url,
+                  (unsigned char) ':');
+  if (NULL == port)
+    pnum = 80;
+  else
+    pnum = strtol (port + 1, NULL, 10);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Starting Fakebank on port %u (%s)\n",
+              (unsigned int) pnum,
+              bank_url);
+  fakebankd = TALER_FAKEBANK_start ((uint16_t) pnum);
+  if (NULL == fakebankd)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+  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
diff --git a/src/include/taler_testing_bank_lib.h 
b/src/include/taler_testing_bank_lib.h
index 9948a7f2..72176d44 100644
--- a/src/include/taler_testing_bank_lib.h
+++ b/src/include/taler_testing_bank_lib.h
@@ -68,6 +68,17 @@ TALER_TESTING_run_bank (const char *config_filename,
                         const char *bank_url);
 
 /**
+ * Runs the Fakebank by guessing / extracting the portnumber
+ * from the base URL.
+ *
+ * @param bank_url bank's base URL.
+ * @return the fakebank process handle, or NULL if any
+ *         error occurs.
+ */
+struct TALER_FAKEBANK_Handle *
+TALER_TESTING_run_fakebank (const char *bank_url);
+
+/**
  * Prepare the bank execution.  Check if the port is available
  * and reset database.
  *
@@ -80,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 ************ */
 
 /**

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]