Open tonybaloney opened 3 years ago
@Kami or @armab do you know the answer to this?
IIRC, ST2_ACTION_AUTH_TOKEN
was never set for the unit tests and they way to test client / datastore functionality is to use mock datastore client (st2tests.mocks.datastore.MockDatastoreService
).
That method only mocks datastore related API client methods though.
If you need to access other client functionality, we should probably also provide mock version of the Client
class - right now we don't have a good set up for running pack tests end to end so we rely on unit tests + mocked methods (providing end to end test environment wouldn't be so trivial, would be slow and require quite some set up time).
So right now, at least for unit tests probably best option is to mock the Client methods you need to use.
Update - I had a look at https://github.com/StackStorm-Exchange/stackstorm-msexchange/pull/16.
It appears client is only used to manage datastore items - in this case it probably shouldn't be too hard for us to provide initial MockClient
version which offers mocked methods for handling that since we already have MockDatastoreService
abstraction.
Having said that, I noticed that pack code uses client directly.
Is there a specific reason why it uses that and not self.datastore_service
which also allows datastore items management and we also have MockDatastoreService
version of it for unit tests (https://github.com/StackStorm/st2/blob/master/st2tests/st2tests/mocks/datastore.py#L28).
If there is no specific need to use Client
and DatastoreService
can be used instead, this should likely do the trick for tests.
Thanks for contributing to this issue. As it has been 90 days since the last activity, we are automatically marking is as stale. If this issue is not relevant or applicable anymore (problem has been fixed in a new version or similar), please close the issue or let us know so we can close it. On the contrary, if the issue is still relevant, there is nothing you need to do, but if you have any additional details or context which would help us when working on this issue, please include it as a comment to this issue.
I'm trying to write some tests for the
msexchange
pack and hitting some issues with the BaseActionTestCase because the pack uses the st2 client to read and write cache entries...On both CircleCI for the pack and when I test using the Vagrant image, because the
ST2_ACTION_AUTH_TOKEN
is not set on the runner. What is the correct way to get around this?