diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-23 23:32:53 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-23 23:32:53 -0400 |
commit | 4ce3a78d0071035a66cfb889c23fe9a9d731086f (patch) | |
tree | adb9f8507ab6fcbbafb52ba8c3d1837d94a10e47 /src/testing/testing_api_cmd_get_reserves.c | |
parent | d34f954dcaf6d064931d47f0c90576f3b1dbf648 (diff) | |
download | merchant-4ce3a78d0071035a66cfb889c23fe9a9d731086f.tar.gz merchant-4ce3a78d0071035a66cfb889c23fe9a9d731086f.tar.bz2 merchant-4ce3a78d0071035a66cfb889c23fe9a9d731086f.zip |
deeper checks on GET /private/orders
Diffstat (limited to 'src/testing/testing_api_cmd_get_reserves.c')
-rw-r--r-- | src/testing/testing_api_cmd_get_reserves.c | 90 |
1 files changed, 40 insertions, 50 deletions
diff --git a/src/testing/testing_api_cmd_get_reserves.c b/src/testing/testing_api_cmd_get_reserves.c index 068d7e6e..2c543b64 100644 --- a/src/testing/testing_api_cmd_get_reserves.c +++ b/src/testing/testing_api_cmd_get_reserves.c @@ -45,14 +45,14 @@ struct GetReservesState struct TALER_TESTING_Interpreter *is; /** - * Whether to compare the reserves that were found. + * A list of reserves to compare with. */ - bool cmp_reserves; + const char **reserves; /** - * A list of reserves to compare with. + * Length of @e reserve_refs. */ - const char **reserve_refs; + unsigned int reserves_length; /** * Base URL of the merchant serving the request. @@ -89,24 +89,21 @@ get_reserves_cb (void *cls, switch (hr->http_status) { case MHD_HTTP_OK: + if (reserves_length != grs->reserves_length) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Length of reserves found does not match\n"); + TALER_TESTING_interpreter_fail (grs->is); + return; + } // FIXME: check if the data returned matches that from the POST / PATCH - if (! grs->cmp_reserves) - break; for (unsigned int i = 0; i < reserves_length; ++i) { - if (NULL == grs->reserve_refs[i]) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Number of reserves found does not match\n"); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - const struct TALER_TESTING_Command *reserve_cmd; reserve_cmd = TALER_TESTING_interpreter_lookup_command ( grs->is, - grs->reserve_refs[i]); + grs->reserves[i]); { const struct TALER_ReservePublicKeyP *reserve_pub; @@ -114,7 +111,12 @@ get_reserves_cb (void *cls, TALER_TESTING_get_trait_reserve_pub (reserve_cmd, 0, &reserve_pub)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch reserve public key\n"); TALER_TESTING_interpreter_fail (grs->is); + return; + } if (0 != GNUNET_memcmp (&reserves[i].reserve_pub, reserve_pub)) { @@ -131,7 +133,12 @@ get_reserves_cb (void *cls, TALER_TESTING_get_trait_amount_obj (reserve_cmd, 0, &initial)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch reserve initial balance\n"); TALER_TESTING_interpreter_fail (grs->is); + return; + } if ((GNUNET_OK != TALER_amount_cmp_currency ( &reserves[i].merchant_initial_amount, initial)) || @@ -200,6 +207,9 @@ get_reserves_cleanup (void *cls, "GET /private/reserves operation did not complete\n"); TALER_MERCHANT_reserves_get_cancel (grs->rgh); } + GNUNET_array_grow (grs->reserves, + grs->reserves_length, + 0); GNUNET_free (grs); } @@ -210,54 +220,34 @@ get_reserves_cleanup (void *cls, * @param label command label. * @param merchant_url url to the merchant. * @param http_status expected HTTP response code. + * @param ... NULL-terminated list of labels (const char *) of + * reserve (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_reserves (const char *label, const char *merchant_url, - unsigned int http_status) + unsigned int http_status, + ...) { struct GetReservesState *grs; grs = GNUNET_new (struct GetReservesState); grs->merchant_url = merchant_url; - grs->cmp_reserves = false; grs->http_status = http_status; { - struct TALER_TESTING_Command cmd = { - .cls = grs, - .label = label, - .run = &get_reserves_run, - .cleanup = &get_reserves_cleanup - }; + const char *clabel; + va_list ap; - return cmd; + va_start (ap, http_status); + while (NULL != (clabel = va_arg (ap, const char *))) + { + GNUNET_array_append (grs->reserves, + grs->reserves_length, + clabel); + } + va_end (ap); } -} - - -/** - * Define a "GET /reserves" CMD - * - * @param label command label. - * @param merchant_url url to the merchant. - * @param reserve_refs a NULL-terminated list of references to - * commands that created reserves. - * @param http_status expected HTTP response code. - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_get_reserves_with_reserves (const char *label, - const char *merchant_url, - const char *reserve_refs - [], - unsigned int http_status) -{ - struct GetReservesState *grs; - - grs = GNUNET_new (struct GetReservesState); - grs->merchant_url = merchant_url; - grs->cmp_reserves = true; - grs->reserve_refs = reserve_refs; - grs->http_status = http_status; { struct TALER_TESTING_Command cmd = { .cls = grs, |