aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-09-11 00:24:32 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2019-09-11 00:46:34 +0200
commit4e27be9b6cd3ada3ed920781d1b8cd0eb50b2417 (patch)
tree93aa2afc3e369689bb4a54083fbda679aaa6914a
parentef98a68ffaa9117aac8b12ef3663e284a01217b8 (diff)
downloadexchange-4e27be9b6cd3ada3ed920781d1b8cd0eb50b2417.tar.gz
exchange-4e27be9b6cd3ada3ed920781d1b8cd0eb50b2417.zip
Unify "twisted" tests.
-rw-r--r--src/bank-lib/Makefile.am18
-rw-r--r--src/bank-lib/test_bank_api_twisted.c172
-rw-r--r--src/bank-lib/test_bank_api_twisted_NEW.c (renamed from src/bank-lib/test_bank_api_with_fakebank_twisted.c)83
3 files changed, 80 insertions, 193 deletions
diff --git a/src/bank-lib/Makefile.am b/src/bank-lib/Makefile.am
index 8cdd7824e..8b5d59a6e 100644
--- a/src/bank-lib/Makefile.am
+++ b/src/bank-lib/Makefile.am
@@ -103,12 +103,13 @@ check_PROGRAMS = \
103 103
104if HAVE_TWISTER 104if HAVE_TWISTER
105check_PROGRAMS += \ 105check_PROGRAMS += \
106 test_bank_api_twisted \ 106 test_bank_api_with_pybank_twisted \
107 test_bank_api_with_fakebank_twisted 107 test_bank_api_with_fakebank_twisted
108 108
109test_bank_api_with_fakebank_twisted_SOURCES = \ 109
110 test_bank_api_with_fakebank_twisted.c 110test_bank_api_with_pybank_twisted_SOURCES = \
111test_bank_api_with_fakebank_twisted_LDADD = \ 111 test_bank_api_twisted_NEW.c
112test_bank_api_with_pybank_twisted_LDADD = \
112 $(top_builddir)/src/lib/libtalertesting.la \ 113 $(top_builddir)/src/lib/libtalertesting.la \
113 libtalerbank.la \ 114 libtalerbank.la \
114 libtalerbanktesting.la \ 115 libtalerbanktesting.la \
@@ -120,11 +121,11 @@ test_bank_api_with_fakebank_twisted_LDADD = \
120 -lgnunetcurl \ 121 -lgnunetcurl \
121 -lgnunetutil \ 122 -lgnunetutil \
122 -ljansson 123 -ljansson
123endif
124 124
125test_bank_api_twisted_SOURCES = \ 125
126 test_bank_api_twisted.c 126test_bank_api_with_fakebank_twisted_SOURCES = \
127test_bank_api_twisted_LDADD = \ 127 test_bank_api_twisted_NEW.c
128test_bank_api_with_fakebank_twisted_LDADD = \
128 $(top_builddir)/src/lib/libtalertesting.la \ 129 $(top_builddir)/src/lib/libtalertesting.la \
129 libtalerbank.la \ 130 libtalerbank.la \
130 libtalerbanktesting.la \ 131 libtalerbanktesting.la \
@@ -136,6 +137,7 @@ test_bank_api_twisted_LDADD = \
136 -lgnunetcurl \ 137 -lgnunetcurl \
137 -lgnunetutil \ 138 -lgnunetutil \
138 -ljansson 139 -ljansson
140endif
139 141
140TESTS = \ 142TESTS = \
141 $(check_PROGRAMS) 143 $(check_PROGRAMS)
diff --git a/src/bank-lib/test_bank_api_twisted.c b/src/bank-lib/test_bank_api_twisted.c
deleted file mode 100644
index a8f60c5eb..000000000
--- a/src/bank-lib/test_bank_api_twisted.c
+++ /dev/null
@@ -1,172 +0,0 @@
1/*
2 This file is part of TALER
3 Copyright (C) 2014-2019 Taler Systems SA
4
5 TALER is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 3, or
8 (at your option) any later version.
9
10 TALER is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with TALER; see the file COPYING. If not, see
17 <http://www.gnu.org/licenses/>
18*/
19/**
20 * @file exchange/test_exchange_api_twister.c
21 * @brief testcase to test exchange's HTTP API interface
22 * @author Marcello Stanisci
23 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "taler_util.h"
28#include "taler_signatures.h"
29#include "taler_exchange_service.h"
30#include "taler_json_lib.h"
31#include <gnunet/gnunet_util_lib.h>
32#include <microhttpd.h>
33#include "taler_bank_service.h"
34#include "taler_fakebank_lib.h"
35#include "taler_testing_lib.h"
36#include <taler/taler_twister_testing_lib.h>
37#include "taler_testing_bank_lib.h"
38#include <taler/taler_twister_service.h>
39
40/**
41 * Configuration file we use. One (big) configuration is used
42 * for the various components for this test.
43 */
44#define CONFIG_FILE "bank_twisted.conf"
45
46/**
47 * (real) Twister URL. Used at startup time to check if it runs.
48 */
49static char *twister_url;
50
51/**
52 * URL of the twister where all the connections to the
53 * bank that have to be proxied should be addressed to.
54 */
55#define TWISTED_BANK_URL twister_url
56
57/**
58 * URL of the bank.
59 */
60static char *bank_url;
61
62/**
63 * Bank process.
64 */
65static struct GNUNET_OS_Process *bankd;
66
67/**
68 * Twister process.
69 */
70static struct GNUNET_OS_Process *twisterd;
71
72/**
73 * Main function that will tell
74 * the interpreter what commands to run.
75 *
76 * @param cls closure
77 */
78static void
79run (void *cls,
80 struct TALER_TESTING_Interpreter *is)
81{
82 struct TALER_TESTING_Command commands[] = {
83
84 TALER_TESTING_cmd_wait_service ("wait-service",
85 "http://localhost:8888/"),
86
87 TALER_TESTING_cmd_bank_history ("history-0",
88 TWISTED_BANK_URL,
89 EXCHANGE_ACCOUNT_NUMBER,
90 TALER_BANK_DIRECTION_BOTH,
91 GNUNET_NO,
92 NULL,
93 5),
94 TALER_TESTING_cmd_end ()
95 };
96
97 TALER_TESTING_run (is,
98 commands);
99}
100
101/**
102 * Kill, wait, and destroy convenience function.
103 *
104 * @param process process to purge.
105 */
106static void
107purge_process (struct GNUNET_OS_Process *process)
108{
109 GNUNET_OS_process_kill (process,
110 SIGINT);
111 GNUNET_OS_process_wait (process);
112 GNUNET_OS_process_destroy (process);
113}
114
115
116int
117main (int argc,
118 char *const *argv)
119{
120 unsigned int ret;
121 /* These environment variables get in the way... */
122 unsetenv ("XDG_DATA_HOME");
123 unsetenv ("XDG_CONFIG_HOME");
124
125 GNUNET_log_setup ("test-bank-api-twisted",
126 "DEBUG",
127 NULL);
128
129 if (NULL == (bank_url = TALER_TESTING_prepare_bank
130 (CONFIG_FILE)))
131 return 77;
132
133 if (NULL == (bankd = TALER_TESTING_run_bank
134 (CONFIG_FILE,
135 bank_url)))
136 {
137 GNUNET_free (bank_url);
138 return 77;
139 }
140
141 if (NULL == (twister_url = TALER_TESTING_prepare_twister
142 (CONFIG_FILE)))
143 {
144 purge_process (bankd);
145 GNUNET_free (bank_url);
146 return 77;
147 }
148
149 if (NULL == (twisterd = TALER_TESTING_run_twister (CONFIG_FILE)))
150 {
151 GNUNET_free (twister_url);
152 purge_process (bankd);
153 GNUNET_free (bank_url);
154 return 77;
155 }
156 ret = TALER_TESTING_setup (&run,
157 NULL,
158 CONFIG_FILE,
159 NULL,
160 GNUNET_NO);
161 purge_process (twisterd);
162 GNUNET_free (twister_url);
163 purge_process (bankd);
164 GNUNET_free (bank_url);
165
166 if (GNUNET_OK == ret)
167 return 0;
168
169 return 1;
170}
171
172/* end of test_bank_api_twisted.c */
diff --git a/src/bank-lib/test_bank_api_with_fakebank_twisted.c b/src/bank-lib/test_bank_api_twisted_NEW.c
index 8c5b90a1a..e971584f6 100644
--- a/src/bank-lib/test_bank_api_with_fakebank_twisted.c
+++ b/src/bank-lib/test_bank_api_twisted_NEW.c
@@ -43,6 +43,11 @@
43#define CONFIG_FILE "bank_twisted.conf" 43#define CONFIG_FILE "bank_twisted.conf"
44 44
45/** 45/**
46 * True when the test runs against Fakebank.
47 */
48static int WITH_FAKEBANK;
49
50/**
46 * (real) Twister URL. Used at startup time to check if it runs. 51 * (real) Twister URL. Used at startup time to check if it runs.
47 */ 52 */
48static char *twister_url; 53static char *twister_url;
@@ -56,7 +61,7 @@ static char *twister_url;
56/** 61/**
57 * URL of the bank. 62 * URL of the bank.
58 */ 63 */
59static char *fakebank_url; 64static char *bank_url;
60 65
61/** 66/**
62 * Twister process. 67 * Twister process.
@@ -64,6 +69,11 @@ static char *fakebank_url;
64static struct GNUNET_OS_Process *twisterd; 69static struct GNUNET_OS_Process *twisterd;
65 70
66/** 71/**
72 * Python bank process handle.
73 */
74static struct GNUNET_OS_Process *bankd;
75
76/**
67 * Main function that will tell 77 * Main function that will tell
68 * the interpreter what commands to run. 78 * the interpreter what commands to run.
69 * 79 *
@@ -93,9 +103,13 @@ run (void *cls,
93 TALER_TESTING_cmd_end () 103 TALER_TESTING_cmd_end ()
94 }; 104 };
95 105
96 TALER_TESTING_run_with_fakebank (is, 106 if (GNUNET_YES == WITH_FAKEBANK)
97 commands, 107 TALER_TESTING_run_with_fakebank (is,
98 fakebank_url); 108 commands,
109 bank_url);
110 else
111 TALER_TESTING_run (is,
112 commands);
99} 113}
100 114
101 115
@@ -123,35 +137,78 @@ main (int argc,
123 unsetenv ("XDG_DATA_HOME"); 137 unsetenv ("XDG_DATA_HOME");
124 unsetenv ("XDG_CONFIG_HOME"); 138 unsetenv ("XDG_CONFIG_HOME");
125 139
126 GNUNET_log_setup ("test-bank-api-with-fakebank-twisted", 140 GNUNET_log_setup ("test-bank-api-with-(fake)bank-twisted",
127 "DEBUG", 141 "DEBUG",
128 NULL); 142 NULL);
129 143
130 if (NULL == (fakebank_url = TALER_TESTING_prepare_fakebank
131 (CONFIG_FILE,
132 "account-1")))
133 return 77;
134
135 if (NULL == (twister_url = TALER_TESTING_prepare_twister 144 if (NULL == (twister_url = TALER_TESTING_prepare_twister
136 (CONFIG_FILE))) 145 (CONFIG_FILE)))
137 { 146 {
138 GNUNET_free (fakebank_url); 147 GNUNET_break (0);
139 return 77; 148 return 77;
140 } 149 }
141 if (NULL == (twisterd = TALER_TESTING_run_twister (CONFIG_FILE))) 150 if (NULL == (twisterd = TALER_TESTING_run_twister (CONFIG_FILE)))
142 { 151 {
152 GNUNET_break (0);
143 GNUNET_free (twister_url); 153 GNUNET_free (twister_url);
144 GNUNET_free (fakebank_url);
145 return 77; 154 return 77;
146 } 155 }
156
157 WITH_FAKEBANK = TALER_TESTING_has_in_name (argv[0],
158 "_with_fakebank");
159
160 if (GNUNET_YES == WITH_FAKEBANK)
161 {
162 TALER_LOG_DEBUG ("Running against the Fakebank.\n");
163 if (NULL == (bank_url = TALER_TESTING_prepare_fakebank
164 (CONFIG_FILE,
165 "account-1")))
166 {
167 GNUNET_break (0);
168 GNUNET_free (twister_url);
169 return 77;
170 }
171 }
172 else
173 {
174 TALER_LOG_DEBUG ("Running against the Pybank.\n");
175 if (NULL == (bank_url = TALER_TESTING_prepare_bank
176 (CONFIG_FILE)))
177 {
178 GNUNET_break (0);
179 GNUNET_free (twister_url);
180 return 77;
181 }
182
183 if (NULL == (bankd = TALER_TESTING_run_bank
184 (CONFIG_FILE,
185 bank_url)))
186 {
187 GNUNET_break (0);
188 GNUNET_free (twister_url);
189 GNUNET_free (bank_url);
190 return 77;
191 }
192 }
193
147 ret = TALER_TESTING_setup (&run, 194 ret = TALER_TESTING_setup (&run,
148 NULL, 195 NULL,
149 CONFIG_FILE, 196 CONFIG_FILE,
150 NULL, 197 NULL,
151 GNUNET_NO); 198 GNUNET_NO);
152 purge_process (twisterd); 199 purge_process (twisterd);
200
201 if (GNUNET_NO == WITH_FAKEBANK)
202 {
203 GNUNET_OS_process_kill (bankd,
204 SIGKILL);
205 GNUNET_OS_process_wait (bankd);
206 GNUNET_OS_process_destroy (bankd);
207 GNUNET_free (bank_url);
208 }
209
153 GNUNET_free (twister_url); 210 GNUNET_free (twister_url);
154 GNUNET_free (fakebank_url); 211 GNUNET_free (bank_url);
155 212
156 if (GNUNET_OK == ret) 213 if (GNUNET_OK == ret)
157 return 0; 214 return 0;