Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
aslafy-z authored Mar 6, 2024
1 parent db97e0e commit 09be502
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ to the plugin, please see [these instructions](.github/CONTRIBUTING.md).

Here's the Git urls format, followed by examples:

git+https://[provider.com]/[user]/[repo]@[path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0]]
git+ssh://git@[provider.com]/[user]/[repo]@[path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0]]
git+file://[path/to/repo]@[path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0]]
git+https://[provider.com]/[user]/[repo]@[path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0][&package=0]]
git+ssh://git@[provider.com]/[user]/[repo]@[path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0][&package=0]]
git+file://[path/to/repo]@[path/to/charts][?[ref=git-ref][&sparse=0][&depupdate=0][&package=0]]

git+https://github.com/jetstack/cert-manager@deploy/charts?ref=v0.6.2&sparse=0
git+ssh://[email protected]/jetstack/cert-manager@deploy/charts?ref=v0.6.2&sparse=1
git+ssh://[email protected]/jetstack/cert-manager@deploy/charts?ref=v0.6.2
git+https://github.com/istio/istio@install/kubernetes/helm?ref=1.5.4&sparse=0&depupdate=0
git+https://github.com/bitnami/charts@bitnami/wordpress?depupdate=0?ref=master&sparse=0&depupdate=0&package=0
git+https://github.com/bitnami/charts@bitnami/wordpress?ref=master&sparse=0&depupdate=0&package=0

Add your repository:

Expand Down
18 changes: 7 additions & 11 deletions helm-git-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ git_try() {

#git_fetch_ref(git_repo_path, git_ref)
git_fetch_ref() {
_git_repo_path="${1?Missing git repo path as first parameter}"
_git_ref="${2?Mising git ref as second parameter}"
_git_repo_path="${1?Missing git_repo_path as first parameter}"
_git_ref="${2?Mising git_ref as second parameter}"

# Fetches any kind of ref to its right place, tags, annotated tags, branches and commit refs
GIT_DIR="${_git_repo_path}" git fetch -u --depth=1 origin "refs/*/${_git_ref}:refs/*/${_git_ref}" "${_git_ref}"
Expand Down Expand Up @@ -127,16 +127,12 @@ git_checkout() {
if [ "$_sparse" = "1" ]; then
git config core.sparseCheckout true
[ -n "$_git_path" ] && echo "$_git_path/*" >.git/info/sparse-checkout
{
git_fetch_ref "${PWD}/.git" "${_git_ref}" &&
git checkout --quiet "${_git_ref}"
} >&2 || error "Unable to sparse-checkout. Check your Git ref ($_git_ref) and path ($_git_path)."
else
git fetch --quiet --tags origin >&2 || \
error "Unable to fetch remote. Check your Git url."
git checkout --quiet "$git_ref" >&2 || \
error "Unable to checkout ref. Check your Git ref ($git_ref)."

fi
git_fetch_ref "${PWD}/.git" "${_git_ref}" >&2 || \
error "Unable to fetch remote. Check your Git url."
git checkout --quiet "${_git_ref}" >&2 || \
error "Unable to checkout ref. Check your Git ref ($_git_ref) and path ($_git_path)."
# shellcheck disable=SC2010,SC2012
if [ "$(ls -A | grep -v '^.git$' -c)" = "0" ]; then
error "No files have been checked out. Check your Git ref ($_git_ref) and path ($_git_path)."
Expand Down
11 changes: 11 additions & 0 deletions tests/01-git.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ load 'test-helper'
run stat "$HELM_GIT_OUTPUT/$git_path/existing-file"
[ $status = 0 ]
}

@test "git_checkout succeed with existing path and annotated tag" {
git_sparse=1
git_repo="https://github.com/aslafy-z/helm-git"
git_ref="test-annotated-tag"
git_path="tests/fixtures/existing-dir"
run git_checkout "$git_sparse" "$HELM_GIT_OUTPUT" "$git_repo" "$git_ref" "$git_path"
[ $status = 0 ]
run stat "$HELM_GIT_OUTPUT/$git_path/existing-file"
[ $status = 0 ]
}
6 changes: 3 additions & 3 deletions tests/05-helm-cli.bats
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ load 'test-helper'
[ -n "$output" ]
}

@test "helm_cli repo_add wp-cff9c65 depupdate=0 package=0" {
@test "helm_cli repo_add wp-781987fa4bb120f52cbd74cd61484bf45bfb5daa depupdate=0 package=0" {
helm_v2 && skip
run "$HELM_BIN" plugin install "$HELM_GIT_DIRNAME"
[ $status = 0 ]
run "$HELM_BIN" repo add wp-cff9c65 'git+https://github.com/bitnami/charts@bitnami/wordpress?ref=cff9c65&sparse=0&depupdate=0&package=0'
run "$HELM_BIN" repo add wp-781987fa4bb120f52cbd74cd61484bf45bfb5daa 'git+https://github.com/bitnami/charts@bitnami/wordpress?ref=781987fa4bb120f52cbd74cd61484bf45bfb5daa&sparse=0&depupdate=0&package=0'
[ $status = 0 ]
run grep wp-cff9c65 "$HELM_HOME/repository/repositories.yaml"
run grep wp-781987fa4bb120f52cbd74cd61484bf45bfb5daa "$HELM_HOME/repository/repositories.yaml"
[ -n "$output" ]
}

Expand Down
4 changes: 2 additions & 2 deletions tests/06-helm-git-cache.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ load 'test-helper'
[ $status = 0 ]
run "$HELM_BIN" plugin install "$HELM_GIT_DIRNAME"
[ $status = 0 ]
run time "$HELM_BIN" fetch -d "$HELM_GIT_OUTPUT" "git+https://github.com/jetstack/cert-manager@contrib/charts/index.yaml?ref=v0.5.2"
run "$HELM_BIN" fetch -d "$HELM_GIT_OUTPUT" "git+https://github.com/jetstack/cert-manager@contrib/charts/index.yaml?ref=v0.5.2"
[ $status = 0 ]
echo "$output" | grep "First time I see https://github.com/jetstack/cert-manager"
run time "$HELM_BIN" fetch -d "$HELM_GIT_OUTPUT" "git+https://github.com/jetstack/cert-manager@contrib/charts/index.yaml?ref=v0.5.2"
run "$HELM_BIN" fetch -d "$HELM_GIT_OUTPUT" "git+https://github.com/jetstack/cert-manager@contrib/charts/index.yaml?ref=v0.5.2"
[ $status = 0 ]
echo "$output" | grep "https://github.com/jetstack/cert-manager exists in cache"
}
Expand Down

0 comments on commit 09be502

Please sign in to comment.