diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-19 02:30:17 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-19 02:30:17 -0400 |
commit | e35244074480faa18f6370e4d5b800ed35d8ef94 (patch) | |
tree | 5a5493a1899ee2ba33077d837966bd288c76f088 /src/testing/testing_api_cmd_get_reserves.c | |
parent | 566408fa02acf56bbf6063c6d17d739e491e27f2 (diff) | |
download | merchant-e35244074480faa18f6370e4d5b800ed35d8ef94.tar.gz merchant-e35244074480faa18f6370e4d5b800ed35d8ef94.tar.bz2 merchant-e35244074480faa18f6370e4d5b800ed35d8ef94.zip |
stricter tests for query reserve(s) methods
Diffstat (limited to 'src/testing/testing_api_cmd_get_reserves.c')
-rw-r--r-- | src/testing/testing_api_cmd_get_reserves.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/testing/testing_api_cmd_get_reserves.c b/src/testing/testing_api_cmd_get_reserves.c index b9909cad..068d7e6e 100644 --- a/src/testing/testing_api_cmd_get_reserves.c +++ b/src/testing/testing_api_cmd_get_reserves.c @@ -45,6 +45,16 @@ struct GetReservesState struct TALER_TESTING_Interpreter *is; /** + * Whether to compare the reserves that were found. + */ + bool cmp_reserves; + + /** + * A list of reserves to compare with. + */ + const char **reserve_refs; + + /** * Base URL of the merchant serving the request. */ const char *merchant_url; @@ -80,6 +90,61 @@ get_reserves_cb (void *cls, { case MHD_HTTP_OK: // 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]); + { + const struct TALER_ReservePublicKeyP *reserve_pub; + + if (GNUNET_OK != + TALER_TESTING_get_trait_reserve_pub (reserve_cmd, + 0, + &reserve_pub)) + TALER_TESTING_interpreter_fail (grs->is); + if (0 != GNUNET_memcmp (&reserves[i].reserve_pub, + reserve_pub)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Reserve public key does not match\n"); + TALER_TESTING_interpreter_fail (grs->is); + return; + } + } + { + const struct TALER_Amount *initial; + + if (GNUNET_OK != + TALER_TESTING_get_trait_amount_obj (reserve_cmd, + 0, + &initial)) + TALER_TESTING_interpreter_fail (grs->is); + if ((GNUNET_OK != TALER_amount_cmp_currency ( + &reserves[i].merchant_initial_amount, + initial)) || + (0 != TALER_amount_cmp (&reserves[i].merchant_initial_amount, + initial))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Reserve initial amount does not match\n"); + TALER_TESTING_interpreter_fail (grs->is); + return; + } + } + } break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -155,6 +220,43 @@ TALER_TESTING_cmd_merchant_get_reserves (const char *label, 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 + }; + + return cmd; + } +} + + +/** + * 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 = { |