Add generate-example-tests #45

Merged parmentf merged 29 commits into tdm:master from tdm:add-generate-example-tests on 11 Oct
@parmentf parmentf commented on 2 Oct

Ajoute un moyen de générer des tests automatiques.

Même si cette méthode n'est pas universelle (ne marche pas pour l'envoi de fichiers, ou un séquence de requêtes), on peut quand même écrire les fichiers de test à la main.

On utilise hurl.

@thouveni Comme j'ajoute les tests à chaque instance, j'ai trouvé un problème dans affiliations-tools: la route v1/netscity/expand renvoie une erreur 500.
Je suppose que c'est parce qu'il manque le fichier netscity.csv dans le container.

le service sur netscity peut être supprimé=, il est remplacé par sa version dans loterre et le ws associé

Test de biblio-tools, une erreur est remontée:

Error [ServerError]: Internal Server Error
    at new ServerError (/home/parmentf/prog/web-services/node_modules/rest-cli/dist/src/ServerError.js:20:28)
    at RestRequest.<anonymous> (/home/parmentf/prog/web-services/node_modules/rest-cli/dist/src/RestRequest.js:128:35)
    at step (/home/parmentf/prog/web-services/node_modules/rest-cli/dist/src/RestRequest.js:52:23)
    at Object.next (/home/parmentf/prog/web-services/node_modules/rest-cli/dist/src/RestRequest.js:33:53)
    at fulfilled (/home/parmentf/prog/web-services/node_modules/rest-cli/dist/src/RestRequest.js:24:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  url: 'https://biblio-tools.services.istex.fr/v1/wos/fetch?indent=true',
  status: 500,
  response: Response {
    size: 0,
    timeout: 0,
    [Symbol(Body internals)]: { body: [PassThrough], disturbed: false, error: null },
    [Symbol(Response internals)]: {
      url: 'https://biblio-tools.services.istex.fr/v1/wos/fetch?indent=true',
      status: 500,
      statusText: 'Internal Server Error',
      headers: [Headers],
      counter: 0
    }
  }
}

Les logs de l'instance finissent par ça (mais impossible de savoir si c'est lié, ce n'est pas daté):

Error: item #1 [delegate] <Error: item #2 [expand] <TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object>>
            at new NodeError (internal/errors.js:322:7)
            at Hash.update (internal/crypto/hash.js:84:11)
            at hash (/app/node_modules/cacache/lib/entry-index.js:375:6)
            at hashKey (/app/node_modules/cacache/lib/entry-index.js:363:10)
            at bucketPath (/app/node_modules/cacache/lib/entry-index.js:353:18)
            at Object.find (/app/node_modules/cacache/lib/entry-index.js:182:18)
            at AsyncFunction.info (/app/node_modules/cacache/lib/get.js:197:18)
            at cacheGet (/app/node_modules/@ezs/core/lib/statements/expand.js:40:50)
            at Object.expand (/app/node_modules/@ezs/core/lib/statements/expand.js:206:31)
            at Engine.execWith (/app/node_modules/@ezs/core/lib/engine.js:214:40)
    at Feed.warn (/app/node_modules/@ezs/core/lib/engine.js:181:28)
    at Feed.f [as error] (/app/node_modules/once/once.js:25:25)
    at Feed.stop (/app/node_modules/@ezs/core/lib/feed.js:71:10)
    at Catcher.<anonymous> (/app/node_modules/@ezs/core/lib/feed.js:45:19)
    at Object.onceWrapper (events.js:520:26)
    at Catcher.emit (events.js:412:35)
    at Engine.<anonymous> (/app/node_modules/@ezs/core/lib/SafeTransform.js:13:34)
    at Engine.emit (events.js:412:35)
    at Engine.<anonymous> (/app/node_modules/@ezs/core/lib/SafeTransform.js:13:34)
    at Engine.emit (events.js:412:35)
    at Engine.<anonymous> (/app/node_modules/@ezs/core/lib/SafeTransform.js:13:34)
    at Engine.emit (events.js:412:35)
    at Engine.<anonymous> (/app/node_modules/@ezs/core/lib/SafeTransform.js:13:34)
    at Engine.emit (events.js:412:35)
    at Engine.<anonymous> (/app/node_modules/@ezs/core/lib/SafeTransform.js:13:34)
    at Engine.emit (events.js:412:35)
(node:283) UnhandledPromiseRejectionWarning: Error: item #3 [expand] <TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object>
        at new NodeError (internal/errors.js:322:7)
        at Hash.update (internal/crypto/hash.js:84:11)
        at hash (/app/node_modules/cacache/lib/entry-index.js:375:6)
        at hashKey (/app/node_modules/cacache/lib/entry-index.js:363:10)
        at bucketPath (/app/node_modules/cacache/lib/entry-index.js:353:18)
        at Object.find (/app/node_modules/cacache/lib/entry-index.js:182:18)
        at AsyncFunction.info (/app/node_modules/cacache/lib/get.js:197:18)
        at cacheGet (/app/node_modules/@ezs/core/lib/statements/expand.js:40:50)
        at Object.expand (/app/node_modules/@ezs/core/lib/statements/expand.js:206:31)
        at Engine.execWith (/app/node_modules/@ezs/core/lib/engine.js:214:40)
    at /app/node_modules/@ezs/core/lib/engine.js:216:28
(node:283) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 308)

Et voici la requête envoyée:

###

# wos/fecth
POST {{baseUrl}}/v1/wos/fetch?indent=true HTTP/1.1
Content-Type: application/json

[
  {
    "query": "0",
    "value": "XX"
  },
  {
    "query" :"I",
    "value": {
      "databaseId": "WOK",
      "usrQuery": "TS=(cadmium)",
      "count": "5",
      "firstRecord": "1"
    }
  },
  {
    "query" :"II",
    "value": {
      "databaseId": "WOK",
      "usrQuery": "TS=(cadmium)",
      "count": "5",
      "firstRecord": "6"
    }
  }
]

Je ne relève là que les erreurs évidentes (les non-réponses).
Mais il faudra une relecture des résultats obtenus, qui ne sont pas forcément ceux attendus (je ne génère ces tests qu'à partir de ce que les services retournent en ce moment).

En voulant tester data-computer, j'ai écrit ça:

# WARNING: This file was not generated, but manually written.
# DON'T OVERWRITE IT

POST https://data-computer.services.istex.fr/v1/tree-segment
content-type: application/x-tar
x-hook: https://webhook.site/69300b22-a251-4c16-9905-f7ba218ae7e9
file,example-json.tar.gz;

HTTP 200
# Capture the computing token
[Captures]
computing_token: jsonpath "$[0].value"
[Asserts]
variable "computing_token" exists

# There should be a waiting time, representing the time taken to process data.
# Fortunately, as the data is sparse, and the computing time is small,
# the need is small.

POST https://data-computer.services.istex.fr/v1/retrieve
content-type: application/json
```
[
    {
        "value":"{{computing_token}}"
    }
]
```

HTTP 200
Content-Type: application/x-tar

Mais il semble que le Content-Type retourné par retrieve soit application/json, et pas application/x-tar, comme je m'y attendais.

$ px hurl --test data-computer/tests.hurl
data-computer/tests.hurl: Running [1/1]
error: Assert header value
  --> data-computer/tests.hurl:31:15
   |
31 | Content-Type: application/x-tar
   |               ^^^^^^^^^^^^^^^^^ actual value is <application/json>
   |

data-computer/tests.hurl: Failure (2 request(s) in 750 ms)
--------------------------------------------------------------------------------
Executed files:  1
Succeeded files: 0 (0.0%)
Failed files:    1 (100.0%)
Duration:        753 ms

Pourtant le fichier retourné est bien un .tar.gz...

Je ne touche pas ce Content-Type, parce que je me dis que peut-être lodex en a besoin tel quel.
@thouveni tu en penses quoi ?

j'ai modifié le content-type, j'ai également ajouté une option pour récupérer les données directement sans passer par un zip

Le répertoire domains-classifier ne contient ni swagger.json ni examples.http.
Il y a pourtant bien un domains-classifier-2 sur la machine de production.

Dans geo-tagger, que je renomme en ner-tagger, il manque l'URL du service sur ISTEX (et donc il n'est pas encore publié en .services.istex.fr).

Il y manque aussi un exemple pour astroTagger.

Au passage, les routes ne sont pas cohérentes:

  • v1/geoTagger/geoTagger
  • v1/perseeBaipTagger/tagger

astroTagger n'a pas (encore?) de route (pas de .ini).

@parmentf parmentf referenced the pull request on 11 Oct

Merged by user

@parmentf parmentf merged commit de43518 into master from add-generate-example-tests on 11 Oct
@parmentf parmentf closed this pull request on 11 Oct
@parmentf parmentf deleted the add-generate-example-tests branch on 11 Oct
@parmentf parmentf referenced the pull request on 12 Oct
Labels

Priority
default
Milestone
No milestone
Assignee
@parmentf parmentf
2 participants
@parmentf @thouveni