diff --git a/tests/mod.nu b/tests/mod.nu index c79a60a5..b76fa9f7 100644 --- a/tests/mod.nu +++ b/tests/mod.nu @@ -8,6 +8,8 @@ use ../src/nu-git-manager/fs/cache.nu [ ] use ../src/nu-git-manager/fs/path.nu "path sanitize" +use ../src/nu-git-manager/ * + export def path-sanitization [] { assert equal ('\foo\bar' | path sanitize) "/foo/bar" } @@ -235,3 +237,43 @@ export def install-package [] { rm --recursive --force --verbose $env.NUPM_HOME } } + +def run-with-env [code: closure, --prepare-cache] { + # NOTE: for the CI to run, the repos need to live inside `HOME` + let TEST_ENV_BASE = ($nu.home-path | path join "nu-git-manager/tests" (random uuid)) + + let TEST_ENV = { + GIT_REPOS_HOME: ($TEST_ENV_BASE | path join "repos/"), + GIT_REPOS_CACHE: ($TEST_ENV_BASE | path join "repos.cache"), + } + + for target in ($TEST_ENV | values) { + if ($target | path exists) { rm --recursive --force --verbose $target } + } + + if $prepare_cache { + with-env $TEST_ENV { gm update-cache } + } + + with-env $TEST_ENV $code +} + +export def gm-error-with-empty-store [] { + run-with-env { + assert error { gm list } + } +} + +export def gm-cache-update [] { + run-with-env { + gm update-cache + assert equal (gm list) [] + } +} + +export def gm-clone [] { + run-with-env --prepare-cache { + gm clone https://github.com/amtoine/nu-git-manager --depth 1 + assert equal (gm list) ["github.com/amtoine/nu-git-manager"] + } +}