openfisca / country-template

Start modelling the tax and benefit system of your country in a few minutes.
https://legislation.demo.openfisca.org
GNU Affero General Public License v3.0
31 stars 15 forks source link

Web API smoke test #113

Closed HAEKADI closed 3 years ago

HAEKADI commented 3 years ago

Closes #112.

HAEKADI commented 3 years ago

@MattiSG I have an issue with the last commit. I could use some help :) When I ran the following test_api script:

#! /usr/bin/env bash

apt-get update
apt-get install -y jq

make serve-local &

PORT=5000
ENDPOINT=spec

set -e 
response=$(curl --retry-connrefused --retry 10 --retry-delay 5 --fail http://127.0.0.1:$PORT/$ENDPOINT | jq -e)

I got an error:

curl: (23) Failed writing body (0 != 15248)

I tried :

response=$(curl --retry-connrefused --retry 10 --retry-delay 5 --fail http://127.0.0.1:$PORT/$ENDPOINT | tac | tac | jq -e)

And I got the same error.

The following command runs with no issues:

curl --retry-connrefused --retry 10 --retry-delay 5 --fail http://127.0.0.1:$PORT/$ENDPOINT | jq -e

Do you have any idea why that is?

MattiSG commented 3 years ago

No, I don't know why that happens. This makes me suspect jq is not happy being piped streaming data and expects all contents at once. Let's just use an intermediary variable as suggested earlier 🙂

HAEKADI commented 3 years ago

jq remains problematic even after adding an intermediary variable; rendering the following error, which I could not fix:

jq: error: syntax error, unexpected $end, expecting QQSTRING_TEXT or QQSTRING_INTERP_START or QQSTRING_END (Unix shell quoting issues?) at <top-level>

So I switched to python -m json.tool which works, and as a bonus there is no need to add a jqdependency.

HAEKADI commented 3 years ago

@MattiSG Il faudra rajouter test_api comme required dans les status checks avant le merge, non ?

MattiSG commented 3 years ago

Good point! Done now :)