eykrehbein / strest

⚡️ CI-ready tests for REST APIs configured in YAML
MIT License
1.74k stars 59 forks source link

For Loop #114

Open jgroom33 opened 5 years ago

jgroom33 commented 5 years ago

Possible implementation:

version: 2

requests:
  call1:
    request:
      url: https://postman-echo.com/time/now
      method: GET
  call2:
    request:
      url: https://jsonplaceholder.typicode.com/posts
      method: POST
      postData:
        mimeType: application/json
        text:
          foo: 2
  repeat_until:
    until:
      jsonpath: call1.content
      expect: <$ Env("STREST_GMT_DATE") $>
      else_goto: call1 # when false
      goto: call3 # when true
  call3:
    request:
      url: https://jsonplaceholder.typicode.com/posts
      method: POST
      postData:
        mimeType: application/json
        text:
          foo: 2
jgroom33 commented 5 years ago

Another possible implementation:

version: 2

requests:
  call1:
    request:
      url: https://jsonplaceholder.typicode.com/posts
      method: GET
  call1Looper:
    loop: call1.content   # This is an array response from call1
    request:
      url: https://jsonplaceholder.typicode.com/posts/<$ this.id $>
      method: GET

This would be implemented similar to:

https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#standard-loops

jgroom33 commented 5 years ago

third option:

version: 2

requests:
  call1:
    request:
      url: https://jsonplaceholder.typicode.com/posts
      method: GET
  call1.content.forEach(item):
    request:
      url: https://jsonplaceholder.typicode.com/posts/<$ item.id $>
      method: GET