Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multipart form request #254

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 115 additions & 43 deletions README-ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,69 @@ Gonkey протестирует ваши сервисы, используя их

## Содержание

- [Использование консольной утилиты](#использование-консольной-утилиты)
- [Использование gonkey как библиотеки](#использование-gonkey-как-библиотеки)
- [Пример тестового сценария](#пример-тестового-сценария)
- [Статус теста](#статус-теста)
- [HTTP-запрос](#http-запрос)
- [HTTP-ответ](#http-ответ)
- [Переменные](#переменные)
- [Способы присвоения](#способы-присвоения)
- [В описании самого теста](#в-описании-самого-теста)
- [Из результатов предыдущего запроса](#из-результатов-предыдущего-запроса)
- [Из результата текущего запроса](#из-результата-текущего-запроса)
- [В переменных окружения или в env-файле](#в-переменных-окружения-или-в-env-файле)
- [В cases](#в-cases)
- [Загрузка файлов](#загрузка-файлов)
- [Фикстуры](#фикстуры)
- [Удаление данных из таблиц](#удаление-данных-из-таблиц)
- [Шаблоны записей](#шаблоны-записей)
- [Наследование записей](#наследование-записей)
- [Связывание записей](#связывание-записей)
- [Выражения](#выражения)
- [Aerospike](#aerospike)
- [Redis](#redis)
- [Моки](#моки)
- [Запуск моков при использовании gonkey как библиотеки](#запуск-моков-при-использовании-gonkey-как-библиотеки)
- [Описание моков в файле с тестом](#описание-моков-в-файле-с-тестом)
- [Проверки запросов (requestConstraints)](#проверки-запросов-requestconstraints)
- [Стратегии ответов (strategy)](#стратегии-ответов-strategy)
- [Подсчет количества вызовов](#подсчет-количества-вызовов)
- [Использование shell скриптов](#использование-shell-скриптов)
- [Описание скрипта](#описание-скрипта)
- [Запуск скрипта с параметризацией](#запуск-скрипта-с-параметризацией)
- [Запрос в Базу данных](#запрос-в-базу-данных)
- [Формат описания запросов](#формат-описания-запросов)
- [Описание запроса](#описание-запроса)
- [Описание ответа на запрос в Базу данных](#описание-ответа-на-запрос-в-базу-данных)
- [Параметризация при запросах в Базу данных](#параметризация-при-запросах-в-базу-данных)
- [Игнорирование порядка записей в ответе на запрос в базу данных](#игнорирование-порядка-записей-в-ответе-на-запрос-в-базу-данных)
- [JSON-schema](#json-schema)
- [Настройка на IDE Jetbrains](#настройка-на-ide-jetbrains)
- [Настройка на IDE VSCode](#настройка-на-ide-vscode)
- [Gonkey: инструмент автоматизации тестирования](#gonkey-инструмент-автоматизации-тестирования)
- [Содержание](#содержание)
- [Использование консольной утилиты](#использование-консольной-утилиты)
- [Использование gonkey как библиотеки](#использование-gonkey-как-библиотеки)
- [Пример тестового сценария](#пример-тестового-сценария)
- [Статус теста](#статус-теста)
- [HTTP-запрос](#http-запрос)
- [HTTP-ответ](#http-ответ)
- [Переменные](#переменные)
- [Способы присвоения](#способы-присвоения)
- [В описании самого теста](#в-описании-самого-теста)
- [Из результатов предыдущего запроса](#из-результатов-предыдущего-запроса)
- [Из результата текущего запроса](#из-результата-текущего-запроса)
- [В переменных окружения или в env-файле](#в-переменных-окружения-или-в-env-файле)
- [В cases](#в-cases)
- [Запросы с multipart/form-data](#запросы-с-multipartform-data)
- [Данные полей формы](#данные-полей-формы)
- [Загрузка файлов](#загрузка-файлов)
- [Фикстуры](#фикстуры)
- [Удаление данных из таблиц](#удаление-данных-из-таблиц)
- [Шаблоны записей](#шаблоны-записей)
- [Наследование записей](#наследование-записей)
- [Связывание записей](#связывание-записей)
- [Выражения](#выражения)
- [Aerospike](#aerospike)
- [Redis](#redis)
- [Моки](#моки)
- [Запуск моков при использовании gonkey как библиотеки](#запуск-моков-при-использовании-gonkey-как-библиотеки)
- [Описание моков в файле с тестом](#описание-моков-в-файле-с-тестом)
- [Проверки запросов (requestConstraints)](#проверки-запросов-requestconstraints)
- [nop](#nop)
- [bodyMatchesJSON](#bodymatchesjson)
- [bodyJSONFieldMatchesJSON](#bodyjsonfieldmatchesjson)
- [pathMatches](#pathmatches)
- [queryMatches](#querymatches)
- [queryMatchesRegexp](#querymatchesregexp)
- [methodIs](#methodis)
- [headerIs](#headeris)
- [bodyMatchesText](#bodymatchestext)
- [bodyMatchesXML](#bodymatchesxml)
- [Стратегии ответов (strategy)](#стратегии-ответов-strategy)
- [nop](#nop-1)
- [file](#file)
- [constant](#constant)
- [template](#template)
- [uriVary](#urivary)
- [methodVary](#methodvary)
- [sequence](#sequence)
- [basedOnRequest](#basedonrequest)
- [dropRequest](#droprequest)
- [Подсчет количества вызовов](#подсчет-количества-вызовов)
- [Использование shell скриптов](#использование-shell-скриптов)
- [Описание скрипта](#описание-скрипта)
- [Запуск скрипта с параметризацией](#запуск-скрипта-с-параметризацией)
- [Запрос в Базу данных](#запрос-в-базу-данных)
- [Формат описания запросов](#формат-описания-запросов)
- [Описание запроса](#описание-запроса)
- [Описание ответа на запрос в Базу данных](#описание-ответа-на-запрос-в-базу-данных)
- [Параметризация при запросах в Базу данных](#параметризация-при-запросах-в-базу-данных)
- [Игнорирование порядка записей в ответе на запрос в базу данных](#игнорирование-порядка-записей-в-ответе-на-запрос-в-базу-данных)
- [JSON-schema](#json-schema)
- [Настройка на IDE Jetbrains](#настройка-на-ide-jetbrains)
- [Настройка на IDE VSCode](#настройка-на-ide-vscode)

## Использование консольной утилиты

Expand Down Expand Up @@ -346,6 +369,7 @@ responseHeaders:
- body для моков
- headers для моков
- requestConstraints для моков
- form для multipart/form-data

Пример использования:

Expand Down Expand Up @@ -487,12 +511,41 @@ env-файл, например, удобно использовать, когд

Такие переменные будут доступны и в других кейсах, если не будут переопределены.

## Загрузка файлов

В тестовом запросе можно загружать файлы. Для этого нужно указать тип запроса - POST и заголовок:
## Запросы с multipart/form-data
Нужно указать тип запроса
- POST

Заголовок (необязательно):
> Content-Type: multipart/form-data

или с указанием _boundary_ (необязательно):
> Content-Type: multipart/form-data; boundary=--some-boundary

### Данные полей формы
Пример:

```yaml
- name: "upload-form"
method: POST
form:
fields:
field_name1: "field_name1 value"
name2: "name2 value"
"custom_struct_field[0]": "custom_struct_field 0"
"custom_struct_field[1]": "custom_struct_field 1"
"custom_struct_field[inner_obj][field]": "inner_obj field value"
headers:
Content-Type: multipart/form-data # case-sensitive, can be omitted
response:
200: |
{
"status": "OK"
}
```

### Загрузка файлов
*по пути с файловой системы

Пример:

```yaml
Expand All @@ -502,6 +555,25 @@ env-файл, например, удобно использовать, когд
files:
file1: "testdata/upload-files/file1.txt"
file2: "testdata/upload-files/file2.log"
headers:
Content-Type: multipart/form-data
response:
200: |
{
"status": "OK"
}
```

с данными формы:
```yaml
- name: "upload-multipart-form-data"
method: POST
form:
fields:
field_name1: "field_name1 value"
files:
file1: "testdata/upload-files/file1.txt"
file2: "testdata/upload-files/file2.log"
headers:
Content-Type: multipart/form-data # case-sensitive, can be omitted
response:
Expand Down
160 changes: 117 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,69 @@ Capabilities:

## Table of contents

- [Using the CLI](#using-the-cli)
- [Using gonkey as a library](#using-gonkey-as-a-library)
- [Test scenario example](#test-scenario-example)
- [Test status](#test-status)
- [HTTP-request](#http-request)
- [HTTP-response](#http-response)
- [Variables](#variables)
- [Assignment](#assignment)
- [In the description of the test](#in-the-description-of-the-test)
- [From the response of the previous test](#from-the-response-of-the-previous-test)
- [From the response of currently running test](#from-the-response-of-currently-running-test)
- [From environment variables or from env-file](#from-environment-variables-or-from-env-file)
- [From cases](#from-cases)
- [Files uploading](#files-uploading)
- [Fixtures](#fixtures)
- [Deleting data from tables](#deleting-data-from-tables)
- [Record templates](#record-templates)
- [Record inheritance](#record-inheritance)
- [Record linking](#record-linking)
- [Expressions](#expressions)
- [Aerospike](#aerospike)
- [Redis](#redis)
- [Mocks](#mocks)
- [Running mocks while using gonkey as a library](#running-mocks-while-using-gonkey-as-a-library)
- [Mocks definition in the test file](#mocks-definition-in-the-test-file)
- [Request constraints (requestConstraints)](#request-constraints-requestconstraints)
- [Response strategies (strategy)](#response-strategies-strategy)
- [Calls count](#calls-count)
- [Shell scripts usage](#shell-scripts-usage)
- [Script definition](#script-definition)
- [Running a script with parameterization](#running-a-script-with-parameterization)
- [A DB query](#a-db-query)
- [Test Format](#test-format)
- [Query definition](#query-definition)
- [Definition of DB request response](#definition-of-db-request-response)
- [DB request parameterization](#db-request-parameterization)
- [Ignoring ordering in DB response](#ignoring-ordering-in-db-response)
- [JSON-schema](#json-schema)
- [Setup in Jetbrains IDE](#setup-in-jetbrains-ide)
- [Setup is VSCode IDE](#setup-is-vscode-ide)
- [Gonkey: testing automation tool](#gonkey-testing-automation-tool)
- [Table of contents](#table-of-contents)
- [Using the CLI](#using-the-cli)
- [Using gonkey as a library](#using-gonkey-as-a-library)
- [Test scenario example](#test-scenario-example)
- [Test status](#test-status)
- [HTTP-request](#http-request)
- [HTTP-response](#http-response)
- [Variables](#variables)
- [Assignment](#assignment)
- [In the description of the test](#in-the-description-of-the-test)
- [From the response of the previous test](#from-the-response-of-the-previous-test)
- [From the response of currently running test](#from-the-response-of-currently-running-test)
- [From environment variables or from env-file](#from-environment-variables-or-from-env-file)
- [From cases](#from-cases)
- [multipart/form-data requests](#multipartform-data-requests)
- [Form](#form)
- [File upload](#file-upload)
- [Fixtures](#fixtures)
- [Deleting data from tables](#deleting-data-from-tables)
- [Record templates](#record-templates)
- [Record inheritance](#record-inheritance)
- [Record linking](#record-linking)
- [Expressions](#expressions)
- [Aerospike](#aerospike)
- [Redis](#redis)
- [Mocks](#mocks)
- [Running mocks while using gonkey as a library](#running-mocks-while-using-gonkey-as-a-library)
- [Mocks definition in the test file](#mocks-definition-in-the-test-file)
- [Request constraints (requestConstraints)](#request-constraints-requestconstraints)
- [nop](#nop)
- [bodyMatchesJSON](#bodymatchesjson)
- [bodyJSONFieldMatchesJSON](#bodyjsonfieldmatchesjson)
- [pathMatches](#pathmatches)
- [queryMatches](#querymatches)
- [queryMatchesRegexp](#querymatchesregexp)
- [methodIs](#methodis)
- [headerIs](#headeris)
- [bodyMatchesText](#bodymatchestext)
- [bodyMatchesXML](#bodymatchesxml)
- [Response strategies (strategy)](#response-strategies-strategy)
- [nop](#nop-1)
- [file](#file)
- [constant](#constant)
- [template](#template)
- [uriVary](#urivary)
- [methodVary](#methodvary)
- [sequence](#sequence)
- [basedOnRequest](#basedonrequest)
- [dropRequest](#droprequest)
- [Calls count](#calls-count)
- [Shell scripts usage](#shell-scripts-usage)
- [Script definition](#script-definition)
- [Running a script with parameterization](#running-a-script-with-parameterization)
- [A DB query](#a-db-query)
- [Test Format](#test-format)
- [Query definition](#query-definition)
- [Definition of DB request response](#definition-of-db-request-response)
- [DB request parameterization](#db-request-parameterization)
- [Ignoring ordering in DB response](#ignoring-ordering-in-db-response)
- [JSON-schema](#json-schema)
- [Setup in Jetbrains IDE](#setup-in-jetbrains-ide)
- [Setup is VSCode IDE](#setup-is-vscode-ide)

## Using the CLI

Expand Down Expand Up @@ -349,6 +372,7 @@ You can use variables in the description of the test, the following fields are s
- mocks body
- mocks headers
- mocks requestConstraints
- form

Example:

Expand Down Expand Up @@ -487,12 +511,43 @@ Example:

Variables like these will be available through another cases if not redefined.

## Files uploading

You can upload files in test request. For this you must specify the type of request - POST and header:
## multipart/form-data requests
You must specify the type of request:
- POST

Header (optional):
> Content-Type: multipart/form-data

with _boundary_ (optional):
> Content-Type: multipart/form-data; boundary=--some-boundary


### Form
Example:

```yaml
- name: "upload-form"
method: POST
form:
fields:
field_name1: "field_name1 value"
name2: "name2 value"
"custom_struct_field[0]": "custom_struct_field 0"
"custom_struct_field[1]": "custom_struct_field 1"
"custom_struct_field[inner_obj][field]": "inner_obj field value"
headers:
Content-Type: multipart/form-data # case-sensitive, can be omitted
response:
200: |
{
"status": "OK"
}
```

### File upload
You can upload files in test request.
Example:

Example:

```yaml
Expand All @@ -502,6 +557,25 @@ Example:
files:
file1: "testdata/upload-files/file1.txt"
file2: "testdata/upload-files/file2.log"
headers:
Content-Type: multipart/form-data
response:
200: |
{
"status": "OK"
}
```

with form:
```yaml
- name: "upload-multipart-form-data"
method: POST
form:
fields:
field_name1: "field_name1 value"
files:
file1: "testdata/upload-files/file1.txt"
file2: "testdata/upload-files/file2.log"
headers:
Content-Type: multipart/form-data # case-sensitive, can be omitted
response:
Expand Down
Loading
Loading