Skip to content

Commit

Permalink
feature: negated few steps, added new step, updated workflow and rela…
Browse files Browse the repository at this point in the history
…ted files
  • Loading branch information
pawel.chmielewski committed Apr 6, 2022
1 parent a88529e commit cf86dad
Show file tree
Hide file tree
Showing 25 changed files with 185 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up GoLang
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18

- name: Turn on backend
working-directory: assets
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env:
# download-dependencies download go packages and godog binary
download-dependencies:
go mod download
go install github.com/cucumber/godog/cmd/godog@v0.12.4
go install github.com/cucumber/godog/cmd/godog@v0.12.5

# clean removes directories with binaries, git repository, github actions workflow and test suite
clean:
Expand Down
18 changes: 12 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Feature: Adding new user
This section runs before every Scenario. Its main purpose is to generate random user data
and save it under provided key in scenario cache.
Given I generate a random word having from "5" to "10" of "polish" characters and save it as "RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "10" of "ASCII" characters and save it as "RANDOM_FIRST_NAME"
Given I generate a random word having from "3" to "7" of "UNICODE" characters and save it as "RANDOM_LAST_NAME"
Given I generate a random sentence having from "3" to "4" of "english" words and save it as "RANDOM_DESCRIPTION"
Given I generate a random "int" in the range from "18" to "48" and save it as "RANDOM_AGE"
Expand All @@ -53,7 +53,7 @@ Feature: Adding new user
# We send HTTP(s) request using pre-generated data to create new user.
# Accessing saved data from scenario cache is done through template syntax from text/template package.
# Docstring may be in YAML or JSON format and should have "body" and "headers" keys.
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 @@ -68,10 +68,13 @@ Feature: Adding new user
}
}
"""
Then the response status code should be 201
And the response should have header "Content-Length"
Then the response status code should not be 200
But the response status code should be 201
And the response should not have header "Set-Cookie"
But the response should have header "Content-Length"
And the response should have header "Content-Type" of value "{{.CONTENT_TYPE_JSON}}; charset=UTF-8"
And the response body should have format "JSON"
And the response body should not have format "plain text"
But the response body should have format "JSON"
And time between last request and response should be less than or equal to "2s"
# uncommenting next line will print last HTTP(s) response body to console
Expand Down Expand Up @@ -112,7 +115,10 @@ Feature: Adding new user
# here is used oliveagle "json-path" syntax to find JSON node
And the "JSON" node "$.lastName" should be "string" of value "doe-{{.RANDOM_LAST_NAME}}"
# here is used regExp acceptable by standard go package "regExp"
And the "JSON" node "lastName" should match regExp "doe-.*"
And the "JSON" node "lastName" should not match regExp "smith-.*"
But the "JSON" node "lastName" should match regExp "doe-.*"
And the "JSON" node "age" should not be "string"
But the "JSON" node "$.age" should be "int"
And the "JSON" node "age" should be "int" of value "{{.RANDOM_AGE}}"
And the "JSON" node "description" should be "string" of value "{{.RANDOM_DESCRIPTION}}"
# here date is formatted according to one of available formats from standard go package "time"
Expand Down
166 changes: 98 additions & 68 deletions defs/scenario.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions features/test_server/json/avatar.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ 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 word having from "5" to "10" of "ASCII" characters and save it as "RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "15" of "polish" 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"
Given I generate a random sentence having from "2" to "4" of "english" words and save it as "RANDOM_DESCRIPTION"
Given I generate current time and travel "backward" "240h" in time and save it as "MEET_DATE"
Expand Down
19 changes: 13 additions & 6 deletions features/test_server/json/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Adding new user
This section runs before every Scenario. Its main purpose is to generate random user data
and save it under provided key in scenario cache.

Given I generate a random word having from "5" to "10" of "polish" characters and save it as "RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "10" of "ASCII" characters and save it as "RANDOM_FIRST_NAME"
Given I generate a random word having from "3" to "7" of "UNICODE" characters and save it as "RANDOM_LAST_NAME"
Given I generate a random sentence having from "3" to "4" of "english" words and save it as "RANDOM_DESCRIPTION"
Given I generate a random "int" in the range from "18" to "48" and save it as "RANDOM_AGE"
Expand Down Expand Up @@ -41,10 +41,13 @@ Feature: Adding new user
}
}
"""
Then the response status code should be 201
And the response should have header "Content-Length"
Then the response status code should not be 200
But the response status code should be 201
And the response should not have header "Set-Cookie"
But the response should have header "Content-Length"
And the response should have header "Content-Type" of value "{{.CONTENT_TYPE_JSON}}; charset=UTF-8"
And the response body should have format "JSON"
And the response body should not have format "plain text"
But the response body should have format "JSON"
And time between last request and response should be less than or equal to "2s"

# uncommenting next line will print last HTTP(s) response body to console
Expand Down Expand Up @@ -85,7 +88,10 @@ Feature: Adding new user
# here is used oliveagle "json-path" syntax to find JSON node
And the "JSON" node "$.lastName" should be "string" of value "doe-{{.RANDOM_LAST_NAME}}"
# here is used regExp acceptable by standard go package "regExp"
And the "JSON" node "lastName" should match regExp "doe-.*"
And the "JSON" node "lastName" should not match regExp "smith-.*"
But the "JSON" node "lastName" should match regExp "doe-.*"
And the "JSON" node "age" should not be "string"
But the "JSON" node "$.age" should be "int"
And the "JSON" node "age" should be "int" of value "{{.RANDOM_AGE}}"
And the "JSON" node "description" should be "string" of value "{{.RANDOM_DESCRIPTION}}"
# here date is formatted according to one of available formats from standard go package "time"
Expand Down Expand Up @@ -172,6 +178,7 @@ Feature: Adding new user
}
}
"""
Then the response status code should be 400
Then the response status code should not be 201
But the response status code should be 400
And the response body should have format "JSON"
And the response body should be valid according to schema "general_error.json"
9 changes: 6 additions & 3 deletions features/test_server/json/delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Feature: Removing user
}
"""
Then the response status code should be 200
But the response status code should not be 404
And the response should have header "Content-Type" of value "application/json; charset=UTF-8"
And the response body should have format "JSON"
And time between last request and response should be less than or equal to "2s"
Expand All @@ -64,7 +65,8 @@ Feature: Removing user
}
}
"""
And the response status code should be 204
Then the response status code should be 204
And the response status code should not be 404


#---------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -98,8 +100,9 @@ Feature: Removing user
}
}
"""
And the response status code should be 400
Then the response body should have format "JSON"
Then the response status code should not be 204
But the response status code should be 400
And the response body should have format "JSON"
And the response body should be valid according to schema "general_error.json"
And the "JSON" response should have node "error"
And the "JSON" node "error" should match regExp "could not find in database user of id .*"
5 changes: 3 additions & 2 deletions features/test_server/json/get_many.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Feature: Fetching many users.

#---------------------------------------------------------------------------------------------------
# We generate second user's data
Given I generate a random word having from "5" to "15" of "ASCII" characters and save it as "RANDOM_FIRST_NAME2"
Given I generate a random word having from "5" to "15" of "UNICODE" characters and save it as "RANDOM_LAST_NAME2"
Given I generate a random word having from "5" to "15" of "english" characters and save it as "RANDOM_FIRST_NAME2"
Given I generate a random word having from "5" to "15" of "polish" characters and save it as "RANDOM_LAST_NAME2"
Given I generate a random "int" in the range from "18" to "48" and save it as "RANDOM_AGE2"
Given I generate a random sentence having from "5" to "10" of "english" words and save it as "RANDOM_DESCRIPTION2"
Given I generate current time and travel "backward" "240h" in time and save it as "MEET_DATE2"
Expand Down Expand Up @@ -84,4 +84,5 @@ Feature: Fetching many users.
And the response body should have format "JSON"
# here we only check only node type, not its exact value
And the "JSON" node "root" should be "slice"
But the "JSON" node "root" should not be slice of length "0"
And the "JSON" node "root" should not be "nil"
3 changes: 2 additions & 1 deletion features/test_server/json/get_one.feature
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Feature: Fetching single user.
}
}
"""
Then the response status code should be 404
Then the response status code should not be 200
But the response status code should be 404
And the response body should have format "JSON"
And the response body should be valid according to schema "general_error.json"
10 changes: 6 additions & 4 deletions features/test_server/json/replace.feature
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ Feature: Replacing single user account.

#---------------------------------------------------------------------------------------------------
# Here, we generate new user data.
Given I generate a random word having from "5" to "15" of "ASCII" characters and save it as "NEW_USER_RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "15" of "UNICODE" characters and save it as "NEW_USER_RANDOM_LAST_NAME"
Given I generate a random word having from "5" to "15" of "english" characters and save it as "NEW_USER_RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "15" of "polish" characters and save it as "NEW_USER_RANDOM_LAST_NAME"
Given I generate a random "int" in the range from "18" to "48" and save it as "NEW_USER_RANDOM_AGE"
Given I generate a random sentence having from "1" to "17" of "english" words and save it as "NEW_USER_RANDOM_DESCRIPTION"
Given I generate current time and travel "backward" "340h" in time and save it as "NEW_USER_MEET_DATE"
Expand Down Expand Up @@ -162,7 +162,8 @@ Feature: Replacing single user account.
}
}
"""
Then the response status code should be 400
Then the response status code should not be 200
But the response status code should be 400
And the response body should have format "JSON"
And the response body should be valid according to schema "general_error.json"

Expand Down Expand Up @@ -212,6 +213,7 @@ Feature: Replacing single user account.
}
}
"""
Then the response status code should be 400
Then the response status code should not be 200
But the response status code should be 400
And the response body should have format "JSON"
And the response body should be valid according to schema "general_error.json"
2 changes: 1 addition & 1 deletion features/test_server/xml/avatar.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Send avatar file using multipart/form-data in HTTP(s) request.
Background:
Given I save "application/xml" as "CONTENT_TYPE_XML"
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 word having from "5" to "15" of "polish" 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"
Given I generate a random sentence having from "2" to "4" of "english" words and save it as "RANDOM_DESCRIPTION"
Given I generate current time and travel "backward" "240h" in time and save it as "MEET_DATE"
Expand Down
2 changes: 1 addition & 1 deletion features/test_server/xml/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Feature: Adding new user
and save it under provided key in scenario cache.

Given I generate a random word having from "5" to "10" of "polish" characters and save it as "RANDOM_FIRST_NAME"
Given I generate a random word having from "3" to "7" of "UNICODE" characters and save it as "RANDOM_LAST_NAME"
Given I generate a random word having from "3" to "7" of "polish" characters and save it as "RANDOM_LAST_NAME"
Given I generate a random sentence having from "3" to "4" of "english" words and save it as "RANDOM_DESCRIPTION"
Given I generate a random "int" in the range from "18" to "48" and save it as "RANDOM_AGE"
Given I generate current time and travel "backward" "240h" in time and save it as "MEET_DATE"
Expand Down
4 changes: 2 additions & 2 deletions features/test_server/xml/delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Feature: Removing user
Test from this feature focus on removing user account from app.

Background:
Given I generate a random word having from "5" to "15" of "ASCII" 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 word having from "5" to "15" of "english" characters and save it as "RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "15" of "polish" 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"
Given I generate a random sentence having from "5" to "10" of "english" words and save it as "RANDOM_DESCRIPTION"
Given I generate current time and travel "backward" "240h" in time and save it as "MEET_DATE"
Expand Down
6 changes: 3 additions & 3 deletions features/test_server/xml/get_many.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Feature: Fetching many users.
Tests from this feature focus on fetching many users at once.

Background:
Given I generate a random word having from "5" to "15" of "ASCII" 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 word having from "5" to "15" of "english" characters and save it as "RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "15" of "polish" 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"
Given I generate a random sentence having from "5" to "10" of "english" words and save it as "RANDOM_DESCRIPTION"
Given I generate current time and travel "backward" "240h" in time and save it as "MEET_DATE"
Expand Down Expand Up @@ -38,7 +38,7 @@ Feature: Fetching many users.

#---------------------------------------------------------------------------------------------------
# We generate second user's data
Given I generate a random word having from "5" to "15" of "UNICODE" characters and save it as "RANDOM_LAST_NAME2"
Given I generate a random word having from "5" to "15" of "polish" characters and save it as "RANDOM_LAST_NAME2"
Given I generate a random "int" in the range from "18" to "48" and save it as "RANDOM_AGE2"
Given I generate a random sentence having from "5" to "10" of "english" words and save it as "RANDOM_DESCRIPTION2"
Given I generate current time and travel "backward" "240h" in time and save it as "MEET_DATE2"
Expand Down
4 changes: 2 additions & 2 deletions features/test_server/xml/get_one.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Feature: Fetching single user.
Tests from this feature focus on fetching given user.

Background:
Given I generate a random word having from "5" to "15" of "ASCII" 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 word having from "5" to "15" of "english" characters and save it as "RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "15" of "polish" 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"
Given I generate a random sentence having from "5" to "10" of "english" words and save it as "RANDOM_DESCRIPTION"
Given I generate current time and travel "backward" "240h" in time and save it as "MEET_DATE"
Expand Down
8 changes: 4 additions & 4 deletions features/test_server/xml/replace.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Feature: Replacing single user account.
Tests from this feature focus on replacing existing user account with another.

Background:
Given I generate a random word having from "5" to "15" of "ASCII" 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 word having from "5" to "15" of "english" characters and save it as "RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "15" of "polish" 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"
Given I generate a random sentence having from "5" to "10" of "english" words and save it as "RANDOM_DESCRIPTION"
Given I generate current time and travel "backward" "240h" in time and save it as "MEET_DATE"
Expand Down Expand Up @@ -60,8 +60,8 @@ Feature: Replacing single user account.

#---------------------------------------------------------------------------------------------------
# Here, we generate new user data.
Given I generate a random word having from "5" to "15" of "ASCII" characters and save it as "NEW_USER_RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "15" of "UNICODE" characters and save it as "NEW_USER_RANDOM_LAST_NAME"
Given I generate a random word having from "5" to "15" of "english" characters and save it as "NEW_USER_RANDOM_FIRST_NAME"
Given I generate a random word having from "5" to "15" of "polish" characters and save it as "NEW_USER_RANDOM_LAST_NAME"
Given I generate a random "int" in the range from "18" to "48" and save it as "NEW_USER_RANDOM_AGE"
Given I generate a random sentence having from "1" to "17" of "english" words and save it as "NEW_USER_RANDOM_DESCRIPTION"
Given I generate current time and travel "backward" "340h" in time and save it as "NEW_USER_MEET_DATE"
Expand Down
2 changes: 1 addition & 1 deletion features/test_server/yaml/avatar.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Send avatar file using multipart/form-data in HTTP(s) request.
Background:
Given I save "application/x-yaml" as "CONTENT_TYPE_YAML"
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 word having from "5" to "15" of "polish" 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"
Given I generate a random sentence having from "2" to "4" of "english" words and save it as "RANDOM_DESCRIPTION"
Given I generate current time and travel "backward" "240h" in time and save it as "MEET_DATE"
Expand Down
Loading

0 comments on commit cf86dad

Please # to comment.