Skip to content

Commit

Permalink
test gm clone and gm cache-update
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Nov 5, 2023
1 parent 8504306 commit 232914f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"]
}
}

0 comments on commit 232914f

Please sign in to comment.