diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-23 17:08:28 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-23 17:08:28 -0400 |
commit | d34f954dcaf6d064931d47f0c90576f3b1dbf648 (patch) | |
tree | 90b74e39bee371213d93286eeb5f8a10dc2c3e28 /src/testing/testing_api_cmd_get_instances.c | |
parent | d52356b4ac66bc22f3c7195490ff713668f340b1 (diff) | |
download | merchant-d34f954dcaf6d064931d47f0c90576f3b1dbf648.tar.gz merchant-d34f954dcaf6d064931d47f0c90576f3b1dbf648.tar.bz2 merchant-d34f954dcaf6d064931d47f0c90576f3b1dbf648.zip |
harder tests for GET /private/instances, GET /private/products
Diffstat (limited to 'src/testing/testing_api_cmd_get_instances.c')
-rw-r--r-- | src/testing/testing_api_cmd_get_instances.c | 98 |
1 files changed, 93 insertions, 5 deletions
diff --git a/src/testing/testing_api_cmd_get_instances.c b/src/testing/testing_api_cmd_get_instances.c index 3c93d0ed..5a7c55cb 100644 --- a/src/testing/testing_api_cmd_get_instances.c +++ b/src/testing/testing_api_cmd_get_instances.c @@ -54,6 +54,16 @@ struct GetInstancesState */ unsigned int http_status; + /** + * The list of instance references to compare to. + */ + const char **instances; + + /** + * The length of @e instances. + */ + unsigned int instances_length; + }; @@ -68,7 +78,6 @@ get_instances_cb (void *cls, unsigned int iis_length, const struct TALER_MERCHANT_InstanceInformation iis[]) { - /* FIXME, deeper checks should be implemented here. */ struct GetInstancesState *gis = cls; gis->igh = NULL; @@ -85,8 +94,67 @@ get_instances_cb (void *cls, switch (hr->http_status) { case MHD_HTTP_OK: - // FIXME: use gis->instance_reference here to - // check if the data returned matches that from the POST / PATCH + if (iis_length != gis->instances_length) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Length of instances found does not match\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + for (unsigned int i = 0; i < iis_length; ++i) + { + const struct TALER_TESTING_Command *instance_cmd; + + instance_cmd = TALER_TESTING_interpreter_lookup_command ( + gis->is, + gis->instances[i]); + + { + const char *name; + if (GNUNET_OK != + TALER_TESTING_get_trait_string (instance_cmd, + 0, + &name)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch instance name\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + if (0 != strcmp (iis[i].name, + name)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Instance name does not match\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + } + + { + const char *id; + if (GNUNET_OK != + TALER_TESTING_get_trait_string (instance_cmd, + 1, + &id)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch instance id\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + if (0 != strcmp (iis[i].id, + id)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Instance id does not match\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + } + } + + // FIXME: compare payment_targets break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -136,9 +204,12 @@ get_instances_cleanup (void *cls, if (NULL != gis->igh) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "GET /instances/$ID operation did not complete\n"); + "GET /instances operation did not complete\n"); TALER_MERCHANT_instances_get_cancel (gis->igh); } + GNUNET_array_grow (gis->instances, + gis->instances_length, + 0); GNUNET_free (gis); } @@ -150,12 +221,16 @@ get_instances_cleanup (void *cls, * @param merchant_url base URL of the merchant serving the * GET /instances request. * @param http_status expected HTTP response code. + * @param ... NULL-terminated list of labels (const char *) of + * product (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) * @return the command. */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_instances (const char *label, const char *merchant_url, - unsigned int http_status) + unsigned int http_status, + ...) { struct GetInstancesState *gis; @@ -163,6 +238,19 @@ TALER_TESTING_cmd_merchant_get_instances (const char *label, gis->merchant_url = merchant_url; gis->http_status = http_status; { + const char *clabel; + va_list ap; + + va_start (ap, http_status); + while (NULL != (clabel = va_arg (ap, const char *))) + { + GNUNET_array_append (gis->instances, + gis->instances_length, + clabel); + } + va_end (ap); + } + { struct TALER_TESTING_Command cmd = { .cls = gis, .label = label, |