This repository has been archived by the owner on Oct 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
NOISSUE - Add property based testing to users service #146
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright (c) Abstract Machines | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: Property Based Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
env: | ||
TOKEN_URL: http://localhost:9002/users/tokens/issue | ||
USER_IDENTITY: [email protected] | ||
USER_SECRET: 12345678 | ||
|
||
jobs: | ||
api-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21.x | ||
cache-dependency-path: "go.sum" | ||
|
||
- name: Build images | ||
run: make all -j $(nproc) && make dockers_dev -j $(nproc) | ||
|
||
- name: Start containers | ||
run: make run up args="-d" && sleep 10 | ||
|
||
- name: Set access token | ||
run: | | ||
export USER_TOKEN=$(curl -sSX POST $TOKEN_URL -H "Content-Type: application/json" -d "{\"identity\": \"$USER_IDENTITY\",\"secret\": \"$USER_SECRET\"}" | jq -r .access_token) | ||
echo "USER_TOKEN=$USER_TOKEN" >> $GITHUB_ENV | ||
- name: Run Users API tests | ||
uses: schemathesis/action@v1 | ||
with: | ||
schema: api/openapi/users.yml | ||
base-url: http://localhost:9002 | ||
checks: all | ||
report: false | ||
args: '--header "Authorization: Bearer ${{ env.USER_TOKEN }}" --contrib-unique-data --contrib-openapi-formats-uuid --hypothesis-suppress-health-check=filter_too_much --stateful=links' | ||
|
||
- name: Stop containers | ||
if: always() | ||
run: make run down args="-v" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,6 @@ tools/provision/mgconn.toml | |
|
||
# coverage files | ||
coverage | ||
|
||
# Schemathesis | ||
.hypothesis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ FILTERED_SERVICES = $(filter-out $(RUN_ADDON_ARGS), $(SERVICES)) | |
|
||
all: $(SERVICES) | ||
|
||
.PHONY: all $(SERVICES) dockers dockers_dev latest release run run_addons grpc_mtls_certs check_mtls check_certs | ||
.PHONY: all $(SERVICES) dockers dockers_dev latest release run run_addons grpc_mtls_certs check_mtls check_certs test_api | ||
|
||
clean: | ||
rm -rf ${BUILD_DIR} | ||
|
@@ -129,6 +129,16 @@ test: mocks | |
done | ||
go test -v --race -count 1 -tags test -coverprofile=coverage/coverage.out $$(go list ./... | grep -v 'consumers\|readers\|postgres\|internal\|opcua\|cmd') | ||
|
||
test_api: | ||
@which st > /dev/null || (echo "schemathesis not found, please install it from https://github.com/schemathesis/schemathesis#getting-started" && exit 1) | ||
st run api/openapi/users.yml \ | ||
--checks all \ | ||
--base-url http://localhost:9002 \ | ||
--header "Authorization: Bearer $(USER_TOKEN)" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be great if we have some kind of automated script which will do task of getting user token and setting to variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It happens only in CI should we change this approach https://github.com/rodneyosodo/magistrala-dev/blob/users-schemathesis/.github/workflows/api-tests.yml#L38C1-L41C55 ? |
||
--contrib-unique-data --contrib-openapi-formats-uuid \ | ||
--hypothesis-suppress-health-check=filter_too_much \ | ||
--stateful=links | ||
|
||
proto: | ||
protoc -I. --go_out=. --go_opt=paths=source_relative pkg/messaging/*.proto | ||
protoc -I. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative ./*.proto | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we are testing one api
users
when I add the next APIthings
I will make this command support different apis