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

Improve tests capabilities by using local/fake remote repositories #202

Merged
merged 10 commits into from
Jan 15, 2021

Conversation

neomilium
Copy link
Contributor

During the writing of #199 , I needed to refactor some code and would like to be bug-free so I relied on tests.

Behavior tests were pretty rich but lack of capabilities to test repository alteration (ie. commits made by msync).

I started to work in this when I realized they used online repos where we can not push on then test operations.
Some tests were using a local clone of them to operate effectively on it, but still relies on online dummy repos.

This PR provides a new way to test msync operations by faking remote repositories.

It relies on a new class to fake a remote repository of a puppet module.
This class Faker::PuppetModuleRemoteRepo (sorry for the long name), provides some features that helps to test ModuleSync behavior:

  • Fake a remote repository by creating a bare initialization usable using a local remote url (ie. file://)
  • Create basic operations behind the scene using a temporary repo (e.g. write, add and push a file; read a file from a specified branch)
  • Populate the fake remote repo using a basic metadata.json (that can be useful later to test operations like bump)
  • Simulate a read-only repo
  • Change the default branch
  • Count commits between two commit refs
  • Count commits made by an author on all the repo, or a specified branch

Using this, we can now ensure that msync, for example, create a commit or not, depending on excepted behavior.
This PR includes these new expectations on existing tests.

As side effect, all tests are now offline which allow to run them faster, specially when connectivity with GitHub is slow.
For the record, ATM, behind a pretty good connection tests passed in 1m11.826s (using current master branch), while they now run in 0m42.832s (reported by cucumber).

Additionally, this PR replaces cat usage by aruba file matcher, reduces the verbosity of tests to create a basic setup with one puppet module and finally silent down cucumber which promote its online service.

@reviews I tried to split at most this PR with meaningful (I hope so) commit logs; I recommend to review each commit to keep a good track of changes.

Enjoy \o/

Copy link
Member

@bastelfreak bastelfreak left a comment

Choose a reason for hiding this comment

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

this looks very good to me, but I would like to see a review from one of the three requested as well.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

I haven't read through all tests in detail and mainly focused on the Ruby code. Overall I think this is a very good change. The test suite certainly deserved some love.

spec/helpers/faker.rb Outdated Show resolved Hide resolved
spec/helpers/faker/puppet_module_remote_repo.rb Outdated Show resolved Hide resolved
spec/helpers/faker/puppet_module_remote_repo.rb Outdated Show resolved Hide resolved
spec/helpers/faker/puppet_module_remote_repo.rb Outdated Show resolved Hide resolved
spec/helpers/faker/puppet_module_remote_repo.rb Outdated Show resolved Hide resolved
spec/helpers/faker/puppet_module_remote_repo.rb Outdated Show resolved Hide resolved
features/hook.feature Show resolved Hide resolved
features/cli.feature Outdated Show resolved Hide resolved
Copy link
Member

@alexjfisher alexjfisher left a comment

Choose a reason for hiding this comment

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

Huge thanks for this. It looks really good! Some minor nitpicks on the English grammar.

features/step_definitions/git_steps.rb Outdated Show resolved Hide resolved
features/step_definitions/git_steps.rb Outdated Show resolved Hide resolved
features/step_definitions/git_steps.rb Outdated Show resolved Hide resolved
features/step_definitions/git_steps.rb Outdated Show resolved Hide resolved
features/step_definitions/git_steps.rb Outdated Show resolved Hide resolved
features/update.feature Outdated Show resolved Hide resolved
features/update.feature Outdated Show resolved Hide resolved
features/update.feature Outdated Show resolved Hide resolved
features/update.feature Outdated Show resolved Hide resolved
features/update.feature Outdated Show resolved Hide resolved
@neomilium
Copy link
Contributor Author

@ekohl , @raphink and @alexjfisher Its now ready for a new review.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Mostly 👍 but in particular the test needs to change if I read it correct.

spec/helpers/faker/puppet_module_remote_repo.rb Outdated Show resolved Hide resolved
spec/helpers/faker/puppet_module_remote_repo.rb Outdated Show resolved Hide resolved
spec/helpers/faker/puppet_module_remote_repo.rb Outdated Show resolved Hide resolved
features/support/env.rb Outdated Show resolved Hide resolved
features/cli.feature Outdated Show resolved Hide resolved
This commit provides a new helper class Faker::PuppetModuleRemoteRepo to ease the write of tests when tested operations should (or not) operate on the git repository of a puppet module.

This class provides following features:
 - Fake a remote repository by creating a bare initialization usable using a local remote url (ie. file://)
 - Create basic operations behind the scene using a temporary repo (e.g. write, add and push a file; read a file from a specified branch)
 - Populate the fake remote repo using a basic metadata.json
 - Simulate a read-only repo
 - Change the default branch
 - Count commits between two commit refs
 - Count commits made by an author on all the repo, or a specified branch

Note: All operations are made using "Faker <faker@example.com>" as author and committer.

This commit comes with a tiny Faker module to hold the config (ie. the working directory)
This commit changes to global git config used by Aruba during behavior tests in order to make tests more readable when counting commits made by an author
…po faker

This commit replaces the use of dummy remote repo hosted on GitHub (ie. puppet-test from maestrodev) by fake repos provided by Faker::PuppetModuleRemoteRepo.
Additonally, this commit adds expectations to ensure the remote is, or not depending the test, altered by the running test.
As msync as a default git_base set to GitHub, we need to be sure that there is no online repo usage anymore.
To do so, we choose an invalid namespace/repo couple that ensure we operate on local (fake) repos.
This commit adds a "basic setup" step in order to reduce scenario verbosity and help to focus on important steps
@neomilium
Copy link
Contributor Author

neomilium commented Jan 5, 2021

@ekohl All requested changes have been pushed. This PR is ready to be (re-)reviewed.
Many thanks to @ekohl and @alexjfisher for your help, it improves the quality of this contribution.

@bastelfreak bastelfreak merged commit 53c9a25 into voxpupuli:master Jan 15, 2021
@neomilium neomilium deleted the improve-tests branch January 15, 2021 10:04
@ekohl
Copy link
Member

ekohl commented Jan 15, 2021

Thanks @neomilium! I know I was a bit slow to review, but I do appreciate the cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants