Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

NOISSUE - Add property based testing to users service #146

Closed
wants to merge 1 commit into from

Conversation

rodneyosodo
Copy link
Member

What type of PR is this?

This is a feature PR as it adds property-based testing to users API. In addition it is a refactor to error handling on the API

What does this do?

Adds schemathesis to users service

Which issue(s) does this PR fix/relate to?

  • Related Issue #
  • Resolves #

Have you included tests for your changes?

Yes, I have included tests for my changes.

Did you document any new/modified feature?

No

Notes

@rodneyosodo rodneyosodo force-pushed the users-schemathesis branch 14 times, most recently from c01a30f to 5d8d612 Compare December 14, 2023 10:27
@@ -130,6 +130,16 @@ test:
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:
Copy link
Member Author

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 API things I will make this command support different apis

@rodneyosodo rodneyosodo force-pushed the users-schemathesis branch 10 times, most recently from 746f305 to 4fbcccd Compare December 15, 2023 13:52
@rodneyosodo rodneyosodo force-pushed the users-schemathesis branch 4 times, most recently from 128e340 to c9b4482 Compare December 20, 2023 15:54
@rodneyosodo rodneyosodo force-pushed the users-schemathesis branch 4 times, most recently from e896974 to ceebb92 Compare December 27, 2023 13:48
@arvindh123
Copy link
Contributor

arvindh123 commented Jan 3, 2024

@rodneyosodo
make test_api after running this command, I checked in users logs, All the request are having error and warns, there is no single OK logs. even after passing USER_TOKEN .
Is this okay ? or something i'm missing

@rodneyosodo rodneyosodo force-pushed the users-schemathesis branch 2 times, most recently from 82fda87 to 0ed62f9 Compare January 3, 2024 10:12
@rodneyosodo
Copy link
Member Author

Sometimes schemathesis doesn't evaluate links well. This is an example where links have been executed https://github.com/absmach/magistrala/actions/runs/7372122967/job/20060147579?pr=164

When links are used in the swagger file, schemathesis is able to do stateful testing hence there will be OK logs since once an entity has been created it can fuzz the update entity URL using the created entity ID

@rodneyosodo rodneyosodo force-pushed the users-schemathesis branch 2 times, most recently from f8c16fe to 362f287 Compare January 8, 2024 14:53
st run api/openapi/users.yml \
--checks all \
--base-url http://localhost:9002 \
--header "Authorization: Bearer $(USER_TOKEN)" \
Copy link
Contributor

@arvindh123 arvindh123 Jan 9, 2024

Choose a reason for hiding this comment

The 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 USER_TOKEN

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 156 to 159
errors.Contains(err, svcerr.ErrViewEntity),
errors.Contains(err, repoerr.ErrFailedToRetrieveAllGroups),
errors.Contains(err, repoerr.ErrAddPolicies),
errors.Contains(err, repoerr.ErrDeletePolicies),
errors.Contains(err, svcerr.ErrRemoveEntity):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we have only wrap repo error in service layer error and handle only svc error in error encoder?
Because repo errors returns error messages from repo, which is irrevlant to user

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have wrapped the respective repo errors

@rodneyosodo rodneyosodo force-pushed the users-schemathesis branch 7 times, most recently from f2f2513 to ef1423e Compare January 16, 2024 12:40
@rodneyosodo rodneyosodo force-pushed the users-schemathesis branch 3 times, most recently from f56e6b2 to ada324d Compare January 25, 2024 08:44
@rodneyosodo
Copy link
Member Author

Closed in favour of https://github.com/absmach/magistrala/pull/2087

@rodneyosodo rodneyosodo deleted the users-schemathesis branch October 22, 2024 08:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants