fvm icon indicating copy to clipboard operation
fvm copied to clipboard

[Feature Request] Tests: Mock system calls & expectations instead of using on local repo

Open ened opened this issue 3 years ago • 7 comments

Is your feature request related to a problem? Please describe.

Running the test suite currently causes actual downloads & install commands.

Describe the solution you'd like

The test suite should run the commands against a mock shell / mock environment. Commands & their responses could be recorded, mocked & evaluated.

Additional context

This implies a bit of refactor in how fvm runs the commands. This probably has to go through a PlatformExecutor class or similar.

That class needs a test, but it will probably suffice to test echo 123 or similar.

ened avatar Apr 19 '21 20:04 ened

@ened I have a local reference flutter repo that I use as "mock" and makes things run much faster. Passing the local flutter repo as an env var FVM_GIT_CACHE. The tests run much quicker.

leoafarias avatar Apr 19 '21 20:04 leoafarias

@leoafarias Understood you have a local test repo. Will this work on CI? Is this picked up simply by running flutter test?

Does the unit test actually need a repository? Wouldn't the commands be enough?

ened avatar Apr 19 '21 21:04 ened

On the CI I run without the local cache since the time is not a priority. I implemented an AppContext in order to control them a bit more the tests as I get the coverage a bit higher. I do plan on creating a MockContext, that automatically creates/updates and uses a local referenced repo.

However, I am not if mocking so you don't need the repo is a good option. FVM does not work without a flutter repository. Would have to mock all flutter and git tools which are critical pieces.

leoafarias avatar Apr 19 '21 22:04 leoafarias

@leoafarias agree you'd had to mock all of the interfaces with the file system & tools underneath. This would document the tool invocations and any expectations as well.

ened avatar Apr 20 '21 05:04 ened

@ened I am not opposed to have a better documented interface. However it seems that this was not the purpose of the initial issue.

  • Quicker tests
  • Download on every test run

These are addressed by the local reference in the mock local repo.

Do you want to update the goals of the issue, I think I can get aligned on the problem with you.

leoafarias avatar Apr 20 '21 11:04 leoafarias

@leoafarias ok updated the title, hope that is sufficient to move on.

ened avatar Apr 20 '21 12:04 ened

For future ticket reference:

  • I currently implemented AppContext in order to allow for some overrides, and better mocking.
  • Create abstractions mock services especially FlutterTools and GitTools

leoafarias avatar Apr 20 '21 12:04 leoafarias

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 02 '22 20:12 stale[bot]