reqs2reqs ¶
リクエストを変換します。
head¶
リクエストの先頭部分を抽出します。
Config¶
Definitions¶
| Key | Type | Description | Example | Default |
|---|---|---|---|---|
| size | int | 抽出するリクエストの数 | 10 |
Examples¶
先頭の10リクエストを抽出する¶
reqs2reqs:
- name: head
config:
size: 10
filter¶
条件に一致するリクエストのみを抽出します。
Config¶
Definitions¶
Root¶
| Key | Type | Description | Example | Default |
|---|---|---|---|---|
| when | str | 条件式 | "qs.id.0 == 1" |
Examples¶
pathにokが含まれ かつ nameにOKが含まれるリクエストのみ抽出する¶
res2res:
- name: filter
config:
when: ('ok' in path) and ('OK' in name)
add¶
先頭または末尾にリクエストを追加します。
Config¶
Definitions¶
root¶
| Key | Type | Description | Example | Default |
|---|---|---|---|---|
| reqs | Request[] | 本設定を反映させるRequestの条件 | ||
| location | (Location) | 先頭と末尾どちらに追加するか | tail | head |
Location¶
| Name | Description |
|---|---|
| head | 先頭 |
| tail | 末尾 |
Examples¶
末尾に/rest/sample?word=hogeというリクエストを追加する¶
reqs2reqs:
- name: add
config:
reqs:
- path: /rest/sample
qs: {word: [hoge]}
location: tail
replace¶
条件に一致するリクエストを置換します。
Config¶
Definitions¶
Root¶
| Key | Type | Description | Example | Default |
|---|---|---|---|---|
| items | Replacer[] | 置換設定のリスト |
Replacer¶
| Key | Type | Description | Example | Default |
|---|---|---|---|---|
| when | (str) | 条件式 | "qs.id.0 == 1" |
|
| queries | dict[str[]]) | 置換するクエリ | {"a": [1], "b": [2, 3]} |
|
| headers | dict[str] | 置換するヘッダ | {"header1": 1, "header2": 2} |
queriesで使える$DATETIMEマクロについて
値に$DATETIMEマクロを使うと現在時刻からの相対時刻に任意のフォーマットで置換できます。
- フォーマットは
$DATETIME(フォーマット)(相対秒) - 現在時刻が2021年4月18日20時52分00秒のとき
$DATETIME(%Y-%m-%dT%H:%M:%S)(3600)で2021-04-18T21:52:00になる$DATETIME(%Y/%m/%d)(-86400)で2021/04/17になる
queriesとheadersについて
リクエストに存在しないクエリやヘッダの場合は、設定した値が追加されます
Examples¶
pathが/targetと一致するリクエストのクエリを置換する (id=dummay_id, time=dummy_date)¶
reqs2reqs:
- name: replace
config:
items:
- when: "path == /target"
queries:
id: ["dummy_id"]
time: ["dummy_date"]
queryにtimeが含まれるとき、現在時刻1時間後の%Y-%m-%dT%H:%M:%Sフォーマットで上書きする¶
reqs2reqs:
- name: replace
config:
items:
- when: 'time' in qs
queries:
time: ["$DATETIME(%Y-%m-%dT%H:%M:%S)(3600)"]
shuffle¶
リクエストの順序をシャッフルします。
Config¶
Definitions¶
Config設定はありません。
Examples¶
リクエストをシャッフルする¶
reqs2reqs:
- name: shuffle
repeat¶
リクエスト全体を指定回数だけ複製します。
Config¶
Definitions¶
| Key | Type | Description | Example | Default |
|---|---|---|---|---|
| times | int | 複製する数 | 10 |
Examples¶
リクエスト全体を10回複製する¶
reqs2reqs:
- name: repeat
config:
times: 10
empty_guard¶
リクエストが空の場合に処理を中断します。
Prerequirements¶
指定したnotifierのtypeによっては環境変数の設定が必要になります。
Config¶
Definitions¶
root¶
| Key | Type | Description | Example | Default |
|---|---|---|---|---|
| notifies | (Notify[]) | 処理を中断する時の通知設定 |
Notify¶
| Key | Type | Description | Example | Default |
|---|---|---|---|---|
| notifier | string | 使用する通知設定の名前 | jumeaux | |
| message | string | 送信するメッセージ | {{ title }}を中断しました |
notifierについて
通知設定の例は config/examples を参考にしてください。定義は notifier の通りです。
messageついて
Template表記に対応しています。
プロパティはConfigurationで定義されたものを使用できます。
Examples¶
リクエストが空の場合に処理を中断する¶
reqs2reqs:
- name: empty_guard
リクエストが空の場合にnotifier jumeauxを使用して通知 および 処理の中断をする¶
reqs2reqs:
- name: empty_guard
config:
notifies:
- notifier: jumeaux
message: "{{ title }} notify!"
notifier: jumeauxについて
Jumeauxのconfigに以下のような設定が必要です。
notifiers:
jumeaux:
type: slack
channel: "#jumeaux"
username: jumeaux
icon_emoji: "jumeaux"
rename¶
条件に一致するリクエストの名称を変更します。
Config¶
Definitions¶
Root¶
| Key | Type | Description | Example | Default |
|---|---|---|---|---|
| conditions | Condition[] | 変更値と条件 |
Condition¶
| Key | Type | Description | Example | Default |
|---|---|---|---|---|
| name | str | 変更後の名称 | {{ name }} ({{ path }}) |
|
| when | str | 条件式 | "qs.id.0 == 1" |
nameおよびwhenについて
jinja2の表現を利用できます。
プロパティはrequestで定義されたものを使用できます。
nameはテンプレート部分を{{ }}で囲む必要があります。
一方、whenは式であるため{{ }}で囲む必要はありませんが、代わりに文字列はクォートで囲って下さい。
Examples¶
pathにtargetという文字列が含まれる場合にrenamedへ名称を変更する¶
reqs2reqs:
- name: rename
config:
conditions:
- name: renamed
when: "'target' in path"
複雑な条件¶
- pathが小文字のアルファベット3文字である場合は
GOODへ名称を変更する - 1に該当せず
idが1つだけ指定されており、かつ2より大きい場合は<クエリのid>: <元の名称>へ名称を変更する
2-1. 例えばid=4で名称がhogeのとき、新しい名称は4: hogeとなる - 1と2に該当しない場合は名称を変更しない
reqs2reqs:
- name: rename
config:
conditions:
- name: "GOOD"
when: "path|reg('[a-z]{3}')"
- name: "{{ qs.id.0 }}: {{ name }}"
when: "qs.id|length == 1 and qs.id.0|int > 2"