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

extract cache logic out of gm itself #44

Merged
merged 12 commits into from
Oct 28, 2023
Merged

Conversation

amtoine
Copy link
Owner

@amtoine amtoine commented Oct 27, 2023

as explained in #24 (comment), i encountered a cache bug when working on #39 => because the cache path can now be fully set by the user with $env.GIT_REPOS_CACHE, it does not have the .nuon extension in general and thus we cannot assume open $env.GIT_REPOS_CACHE to open the file as NUON data...

description

in order to allow testing more of the internals of the gm commands, i propose in this PR to move the cache logic as much as possible from gm itself to a new internal fs/cache.nu module.

Important
this might sounds like clean code, e.g. where you put all the code in nested oneliners...
i would argue it's not the goal of this PR and the fact that the resulting commands are quite small is simply because they are doing quite simple stuff!
the goal here is to move the internal logic out of the public gm which exposes the main API to allow testing as much as possible without require to gm clone actual repositories or gm remove in an interactive manner 😋

changelog

  • move get-repo-store-cache-path and check-cache-file to a new fs/cache.nu module
  • move most of the cache logic to commands in fs/cache.nu
  • adds tests for the cache functionalities

tests

a new cache-manipulation test in tests/mod.nu.

@amtoine amtoine mentioned this pull request Oct 27, 2023
4 tasks
@amtoine amtoine added the tests Something related to the tests of the library label Oct 27, 2023
@amtoine
Copy link
Owner Author

amtoine commented Oct 27, 2023

@melMass
do you think this should address the last task of #24 and thus close the issue?
or do you think we need real integration / end-to-end tests where the CI runs gm clone, gm remove, ..., for real?

this commit defines a tool `assert cache` to check the content of the
cache and keep the test as readable as possible.
this commit remove the `pwd` from the paths in the actual cache and expected
content to hopefully make the output of a failing test easier to read
:crossed_fingers:

sample output
```
Test "tests cache-manipulation" failed with exit code 1:
Error:   × Assertion failed.
     ╭─[/home/amtoine/documents/repos/github.com/amtoine/nu-git-manager/tests/mod.nu:172:1]
 172 │             | str trim --left --char '/'
 173 │         assert equal $actual $expected
     ·                      ────────┬────────
     ·                              ╰── These are not equal.
        Left  : '[bar, foo]'
        Right : '[bar, fo]'
 174 │     }
     ╰────

Ran 7 tests. 6 succeeded, 1 failed.
Error:   × some tests failed
```
@amtoine amtoine marked this pull request as ready for review October 27, 2023 11:00
@amtoine
Copy link
Owner Author

amtoine commented Oct 27, 2023

Note

  • d44e4e0 makes the output of failed tests easier to read
  • 99af26d and 67350aa sanitize PWD and paths added to / removed from cache to fix the tests on Windows

@melMass
Copy link
Collaborator

melMass commented Oct 27, 2023

@melMass do you think this should address the last task of #24 and thus close the issue? or do you think we need real integration / end-to-end tests where the CI runs gm clone, gm remove, ..., for real?

What is the link between the two? Sorry I don't see it.

melMass and others added 2 commits October 28, 2023 01:16
@amtoine amtoine merged commit f9464f3 into main Oct 28, 2023
3 checks passed
@amtoine amtoine deleted the extract-cache-logic-from-gm branch October 28, 2023 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Something related to the tests of the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants