Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When running specs against the emulator: Ability to reset entire datastore set between tests #11256

Closed
NielsKSchjoedt opened this issue May 5, 2021 · 3 comments
Assignees
Labels
api: datastore Issues related to the Datastore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@NielsKSchjoedt
Copy link

Hi, it would be really convenient to have a teardown or reset command which could be run around each tests case when running specs against the emulator. I know the emulator has a reset capability (as per: googleapis/google-cloud-java#1292 (comment)) It would be really great to have that option instead of having to query and delete all objects in the DB one by one to ensure no leaks happen between test cases.

@quartzmo quartzmo added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. api: datastore Issues related to the Datastore API. labels May 5, 2021
@quartzmo quartzmo self-assigned this May 5, 2021
@quartzmo
Copy link
Member

quartzmo commented May 5, 2021

Hi @NielsKSchjoedt,

Thanks for this suggestion. Can you provide more context about where you would use this feature? Are you referring to tests in this project or your own tests? Where would you expect the command to be?

@NielsKSchjoedt
Copy link
Author

Hi @quartzmo This would most likely be for peoples own projects where they use the google-cloud-datastore gem. A typical ruby example would be that you e.g. have rspec as your test library, but it could essentially be any library. If we take the spec example people will always have a spec_helper.rb for the spec config. It would normally look something like this: https://github.com/rspec/rspec/wiki#specspec_helperrb

Now what most people do (e.g. in a rails project) is that they will have some strategy implemented for clearning the db (or whatever persistence layer they have) between the tests to avoid inserted test data leaking between requests. For datastore it could look something like this inside the spec_helper.rb:

RSpec.configure do |config|
  config.after :example do
    Google::Cloud.datastore("my-todo-project").reset!
  end
end

So reset! or clear! or delete_all! or teardown! or whatever :-)

@quartzmo
Copy link
Member

quartzmo commented May 5, 2021

Thank you, now I understand. I don't think this feature is something that should be included in the google-cloud-datastore library, since it is outside the scope of the Datastore API, and exists only in the emulator. Users of google-cloud-datastore might get confused and think that reset executes an RPC to the Datastore service.

Instead, can you implement your own simple POST request to http://<host>:<port>/reset in Ruby inside your RSpec helper?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants