簡體   English   中英

對同一個補丁請求端點使用多個 stubby 響應

[英]using stubby multiple responses for the same patch request endpoint

這是我在 data.yaml 中的補丁請求映射

request:
    url: ^/api/test
    method: PATCH
    headers:
      Content-Type: application/json 

  response:
    headers:
      Content-Type: application/json
    status: 200
    file: response/test-1.json

api 路徑 api/test 是一個 PATCH 請求,它在其主體 {testVar: "1111"} 中接受單個請求參數

我需要實現的是當請求參數為 {testVar: "1111"} -> 當請求參數為 {testVar: "2222"} 時調用 response/test-1.json -> 調用 response/test-2.json

如何實施?

我嘗試了查詢參數、請求參數等,但沒有成功

閱讀:

  1. https://stubby4j.com/#dynamic-token-replacement-in-stubbed-response 更具體地說,以下部分在何處指定模板
  2. 另外,請查看以下 YAML,它是我的功能測試套件的一部分: https : //github.com/azagniotov/stubby4j/blob/master/src/functional-test/resources/yaml/include-regex-dynamic -tokens-templated-stubs.yaml#L13

這里的想法是:

在您的POST / PATCH請求負載中,您可以將參數之一指定為正則表達式,例如: {"testVar": "(.*)"} 匹配后的正則表達式標記(即: (.*)的值(.*)可用作response配置的替換標記。 換句話說,您應該能夠根據需要加載相應的 JSON 文件。

但是,為了讓您更輕松,請嘗試以下 YAML 配置:

- request:
    method: PATCH
    url: ^/api/test
    headers:
      content-type: application/json
    post: >
      {"testVar": "(.*)"}

  response:
    headers:
      content-type: application/json
    status: 200
    file: response/test-<% post.1 %>.json

讓我知道以上是否適合您。 作為參考,我在以下 PR 中測試了上述配置: https : //github.com/azagniotov/stubby4j/pull/280

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM