Skip to content
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
13 changes: 7 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ that implements 🥒[gherkin/cucumber](https://cucumber.io/docs/gherkin/) syntax

## Why ?
**No more** long and time-consuming framework setup. This project **cuts initial time** & allows bootstrap e2e test framework with **plenty of
utility methods** (_for testing HTTP(s) API using JSON/YAML_) in just few steps. Just grab it and write tests right away.
utility methods** (_for testing HTTP(s) API using JSON/YAML/XML_) in just few steps. Just grab it and write tests right away.

Benefits:
* **short time** from **[setup](https://github.com/pawelWritesCode/godog-example-setup/wiki/Set-up#clone-repository) - to writing** actual E2E tests,
* [35+ well-documented, coupled in logical groups steps](https://github.com/pawelWritesCode/godog-example-setup/wiki/Steps) useful for testing HTTP(s) API,
* support for using templated values as in [text/template](https://pkg.go.dev/text/template) package,
* support for querying JSON/YAML tree with different path engines ([oliveagle - JSON](https://github.com/oliveagle/jsonpath), [qjson - JSON](https://github.com/pawelWritesCode/qjson), [go-yaml - YAML](https://github.com/goccy/go-yaml)),
* support for querying nodes with different path engines ([oliveagle](https://github.com/oliveagle/jsonpath), [qjson](https://github.com/pawelWritesCode/qjson) - JSON, [go-yaml](https://github.com/goccy/go-yaml) - YAML, [antchfx](https://github.com/antchfx/xmlquery) - XML),
* support for sending _multipart/form-data_ forms with file in it,
* rich debugging possibilities - various ways to debug tests,
* very customisable (ability to [replace](https://github.com/pawelWritesCode/godog-example-setup/blob/main/main_test.go#L58) internal services with your own implementation),
* friendly for custom [steps development](https://github.com/pawelWritesCode/godog-example-setup/wiki/Steps-development) because of [exported utility services](https://github.com/pawelWritesCode/gdutils/blob/master/state.go#L18).
* customisable - ability to [replace](https://github.com/pawelWritesCode/godog-example-setup/blob/main/main_test.go#L58) utility services with your own implementations,
* supports custom [steps development](https://github.com/pawelWritesCode/godog-example-setup/wiki/Steps-development) through [exported utility services](https://github.com/pawelWritesCode/gdutils/blob/master/state.go#L18).

## Example

#### [Click here 👆 to see more tests](https://github.com/pawelWritesCode/godog-example-setup/blob/main/features/)
#### [Click here 👆 to see more tests using JSON/YAML/XML](https://github.com/pawelWritesCode/godog-example-setup/blob/main/features/test_server)

```cucumber
Feature: Adding new user
Expand Down Expand Up @@ -128,5 +128,6 @@ See project ![hand pointing right](assets/gifs/hand-pointing-right.gif) [wiki](
* [Project structure](https://github.com/pawelWritesCode/godog-example-setup/wiki/Project-structure) - describes repository folder structure,
* [Setup](https://github.com/pawelWritesCode/godog-example-setup/wiki/Set-up) - guide how to bootstrap repository on your machine,
* [Steps](https://github.com/pawelWritesCode/godog-example-setup/wiki/Steps) - describes each available step and how to use it in tests,
* [Steps development](https://github.com/pawelWritesCode/godog-example-setup/wiki/Steps-development) - how to create custom steps using internal services,
* [Steps debugging](https://github.com/pawelWritesCode/godog-example-setup/wiki/Steps-debugging) - how to debug tests,
* [Steps development](https://github.com/pawelWritesCode/godog-example-setup/wiki/Steps-development) - how to create custom steps using utility services,
* [Usage](https://github.com/pawelWritesCode/godog-example-setup/wiki/Usage) - how to run tests.
Binary file modified assets/test_server/bin/darwin/amd64/user_crud
Binary file not shown.
Binary file modified assets/test_server/bin/linux/amd64/user_crud
Binary file not shown.
Binary file modified assets/test_server/bin/windows/amd64/user_crud.exe
Binary file not shown.
173 changes: 172 additions & 1 deletion assets/test_server/doc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
"user"
],
"summary": "Create user",
"parameters": [
{
"name": "format",
"in": "query",
"description": "response body format",
"required": false,
"schema": {
"enum": ["json", "xml", "yaml"]
}
}
],
"description": "Creation of new user.",
"operationId": "create_user",
"requestBody": {
Expand All @@ -52,7 +63,17 @@
"200": {
"description": "Successfully created user",
"content": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GETUser"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/GETUser"
}
},
"application/x-yaml": {
"schema": {
"$ref": "#/components/schemas/GETUser"
}
Expand All @@ -66,6 +87,16 @@
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/general_error_xml"
}
},
"application/x-yaml": {
"schema": {
"$ref": "#/components/schemas/general_error"
}
}
}
}
Expand All @@ -77,6 +108,17 @@
],
"summary": "Get user by user name",
"operationId": "get_users_list",
"parameters": [
{
"name": "format",
"in": "query",
"description": "response body format",
"required": false,
"schema": {
"enum": ["json", "xml", "yaml"]
}
}
],
"responses": {
"200": {
"description": "successful operation",
Expand All @@ -88,6 +130,26 @@
"$ref": "#/components/schemas/GETUser"
}
}
},
"application/xml": {
"schema": {
"type": "array",
"xml": {
"wrapped": true,
"name": "users"
},
"items": {
"$ref": "#/components/schemas/GETUser"
}
}
},
"application/x-yaml": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/GETUser"
}
}
}
}
}
Expand All @@ -110,6 +172,15 @@
"schema": {
"type": "integer"
}
},
{
"name": "format",
"in": "query",
"description": "response body format",
"required": false,
"schema": {
"enum": ["json", "xml", "yaml"]
}
}
],
"responses": {
Expand All @@ -120,6 +191,16 @@
"schema": {
"$ref": "#/components/schemas/GETUser"
}
},
"application/x-yaml": {
"schema": {
"$ref": "#/components/schemas/GETUser"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/GETUser"
}
}
}
},
Expand All @@ -130,6 +211,16 @@
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/x-yaml": {
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/general_error_xml"
}
}
}
}
Expand All @@ -151,6 +242,15 @@
"schema": {
"type": "integer"
}
},
{
"name": "format",
"in": "query",
"description": "response body format",
"required": false,
"schema": {
"enum": ["json", "xml", "yaml"]
}
}
],
"requestBody": {
Expand All @@ -176,6 +276,16 @@
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/x-yaml": {
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/general_error_xml"
}
}
}
}
Expand All @@ -197,6 +307,15 @@
"schema": {
"type": "integer"
}
},
{
"name": "format",
"in": "query",
"description": "response body format",
"required": false,
"schema": {
"enum": ["json", "xml", "yaml"]
}
}
],
"responses": {
Expand All @@ -211,6 +330,16 @@
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/x-yaml": {
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/general_error_xml"
}
}
}
}
Expand All @@ -231,6 +360,15 @@
"schema": {
"type": "integer"
}
},
{
"name": "format",
"in": "query",
"description": "response body format",
"required": false,
"schema": {
"enum": ["json", "xml", "yaml"]
}
}
],
"requestBody": {
Expand Down Expand Up @@ -263,6 +401,16 @@
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/x-yaml": {
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/general_error_xml"
}
}
}
},
Expand All @@ -273,6 +421,16 @@
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/x-yaml": {
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/general_error_xml"
}
}
}
},
Expand All @@ -283,6 +441,16 @@
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/x-yaml": {
"schema": {
"$ref": "#/components/schemas/general_error"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/general_error_xml"
}
}
}
}
Expand All @@ -300,6 +468,9 @@
},
"general_error": {
"$ref": "./schema/general_error.json"
},
"general_error_xml": {
"$ref": "./schema/general_error_xml.json"
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions assets/test_server/doc/schema/general_error_xml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "general error",
"description": "general error",
"type": "object",
"properties": {},
"additionalProperties": false,
"xml": {
"name": "Error"
}
}
3 changes: 3 additions & 0 deletions assets/test_server/doc/schema/user/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"description": "get user",
"type": "object",
"additionalProperties": false,
"xml": {
"name": "user"
},
"properties": {
"id": {
"type": "integer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Feature: Send avatar file using multipart/form-data in HTTP(s) request.

Background:
Given I save "application/json" as "CONTENT_TYPE_JSON"

Given I generate a random word having from "5" to "10" of "russian" characters and save it as "RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "15" of "UNICODE" characters and save it as "RANDOM_LAST_NAME"
Given I generate a random "int" in the range from "18" to "48" and save it as "RANDOM_AGE"
Expand Down Expand Up @@ -56,7 +57,7 @@ Feature: Send avatar file using multipart/form-data in HTTP(s) request.

#-------------------------------------------------------------------------------------------------------------------
# Fetching user, to check whether avatar field appeared and has proper value.
When I send "GET" request to "{{.MY_APP_URL}}/users/{{.USER_ID}}" with body and headers:
When I send "GET" request to "{{.MY_APP_URL}}/users/{{.USER_ID}}?format=json" with body and headers:
"""
{
"body": {},
Expand All @@ -75,7 +76,7 @@ Feature: Send avatar file using multipart/form-data in HTTP(s) request.

#-------------------------------------------------------------------------------------------------------------------
# Create new user using data generated in background section above.
When I send "POST" request to "{{.MY_APP_URL}}/users" with body and headers:
When I send "POST" request to "{{.MY_APP_URL}}/users?format=json" with body and headers:
"""
{
"body": {
Expand All @@ -95,7 +96,7 @@ Feature: Send avatar file using multipart/form-data in HTTP(s) request.
And the response body should have format "JSON"
And I save from the last response "JSON" node "id" as "USER_ID"

Given I prepare new "POST" request to "{{.MY_APP_URL}}/users/{{.USER_ID}}/avatar" and save it as "AVATAR_REQUEST"
Given I prepare new "POST" request to "{{.MY_APP_URL}}/users/{{.USER_ID}}/avatar?format=json" and save it as "AVATAR_REQUEST"

#-------------------------------------------------------------------------------------------------------------------
# This form has invalid name property
Expand Down
Loading