Feature/gitops (#37)
CI Git-Pages Main / Load git-pages.gitea-env.conf to pipeline env (push) Successful in 34s
CI Main / Check existing artifact (push) Successful in 22s
CI Git-Pages Main / Build & Push Helm chart (push) Successful in 48s
CI Main / Bats tests (push) Successful in 1m34s
acc-tests Cucumber test report
CI Main / Cucumber tests (push) Successful in 1m45s
CI Main / Load example-gitea-env.conf to pipeline env (push) Successful in 34s
CI Git-Pages Main / Check existing artifact (push) Successful in 21s
ci-helm-build-push Helm push 0.1.5
unit-tests Bats test report
CI Git-Pages Main / Update chart to the cluster (push) Failing after 0s
ci-docker-build-push Docker push 0.2.25
CI Git-Pages Main / Report Summary (push) Successful in 7s
CI Main / Build & Push Docker (push) Successful in 44s
CI Main / GitOps (push) Failing after 22s
CI Main / Move provider version tag (push) Has been skipped
CI Main / Report Summary (push) Successful in 6s
CI Git-Pages Main / Load git-pages.gitea-env.conf to pipeline env (push) Successful in 34s
CI Main / Check existing artifact (push) Successful in 22s
CI Git-Pages Main / Build & Push Helm chart (push) Successful in 48s
CI Main / Bats tests (push) Successful in 1m34s
acc-tests Cucumber test report
CI Main / Cucumber tests (push) Successful in 1m45s
CI Main / Load example-gitea-env.conf to pipeline env (push) Successful in 34s
CI Git-Pages Main / Check existing artifact (push) Successful in 21s
ci-helm-build-push Helm push 0.1.5
unit-tests Bats test report
CI Git-Pages Main / Update chart to the cluster (push) Failing after 0s
ci-docker-build-push Docker push 0.2.25
CI Git-Pages Main / Report Summary (push) Successful in 7s
CI Main / Build & Push Docker (push) Successful in 44s
CI Main / GitOps (push) Failing after 22s
CI Main / Move provider version tag (push) Has been skipped
CI Main / Report Summary (push) Successful in 6s
Co-authored-by: moilanik <niko.moilanen@tietoevry.com> Reviewed-on: #37
This commit was merged in pull request #37.
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
setup() {
|
||||
export INPUT_FILE=dev/Chart.yaml
|
||||
export YQ_TPL='version = "{{VERSION}}"'
|
||||
export VERSION=1.0.0
|
||||
export SOURCE_REPO=niko/app
|
||||
export SOURCE_COMMIT=abc123def456
|
||||
export GITOPS_REPO=niko/app-gitops
|
||||
export GITEA_TOKEN=test-token
|
||||
export GITEA_API_URL=http://localhost:18080
|
||||
}
|
||||
|
||||
teardown() {
|
||||
if type mock_stop &>/dev/null 2>&1; then
|
||||
mock_stop 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
@test "missing GITEA_API_URL causes exit 1" {
|
||||
unset GITEA_API_URL
|
||||
run bash scripts/gitops-update.sh
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"GITEA_API_URL"* ]]
|
||||
}
|
||||
|
||||
@test "missing GITEA_TOKEN causes exit 1" {
|
||||
unset GITEA_TOKEN
|
||||
run bash scripts/gitops-update.sh
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"GITEA_TOKEN"* ]]
|
||||
}
|
||||
|
||||
@test "missing INPUT_FILE causes exit 1" {
|
||||
unset INPUT_FILE
|
||||
run bash scripts/gitops-update.sh
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"INPUT_FILE"* ]]
|
||||
}
|
||||
|
||||
@test "missing YQ_TPL causes exit 1" {
|
||||
unset YQ_TPL
|
||||
run bash scripts/gitops-update.sh
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"YQ_TPL"* ]]
|
||||
}
|
||||
|
||||
@test "missing VERSION causes exit 1" {
|
||||
unset VERSION
|
||||
run bash scripts/gitops-update.sh
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"VERSION"* ]]
|
||||
}
|
||||
|
||||
@test "missing SOURCE_REPO causes exit 1" {
|
||||
unset SOURCE_REPO
|
||||
run bash scripts/gitops-update.sh
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"SOURCE_REPO"* ]]
|
||||
}
|
||||
|
||||
@test "missing SOURCE_COMMIT causes exit 1" {
|
||||
unset SOURCE_COMMIT
|
||||
run bash scripts/gitops-update.sh
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"SOURCE_COMMIT"* ]]
|
||||
}
|
||||
|
||||
@test "_gitops_substitute replaces {{VERSION}}" {
|
||||
run bash -c '
|
||||
source scripts/gitops-update.sh >/dev/null 2>&1
|
||||
_gitops_substitute "(.version) = \"{{VERSION}}\"" "0.2.3"
|
||||
'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == '(.version) = "0.2.3"' ]]
|
||||
}
|
||||
|
||||
@test "CLONE_URL is constructed correctly from GITEA_API_URL" {
|
||||
export GITEA_API_URL=https://gitea.app.keskikuja.site
|
||||
export GITEA_TOKEN=secret123
|
||||
export GITOPS_REPO=niko/app-gitops
|
||||
run bash -c '
|
||||
source scripts/gitops-update.sh >/dev/null 2>&1
|
||||
echo "$CLONE_URL"
|
||||
'
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "https://secret123@gitea.app.keskikuja.site/niko/app-gitops.git" ]
|
||||
}
|
||||
|
||||
@test "CLONE_URL works with http:// URL" {
|
||||
export GITEA_API_URL=http://localhost:18080
|
||||
export GITEA_TOKEN=token
|
||||
export GITOPS_REPO=owner/repo
|
||||
run bash -c '
|
||||
source scripts/gitops-update.sh >/dev/null 2>&1
|
||||
echo "$CLONE_URL"
|
||||
'
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "https://token@localhost:18080/owner/repo.git" ]
|
||||
}
|
||||
|
||||
@test "_gitops_substitute handles multiple {{VERSION}} occurrences" {
|
||||
run bash -c '
|
||||
source scripts/gitops-update.sh >/dev/null 2>&1
|
||||
_gitops_substitute "version = \"{{VERSION}}\"; tag = \"v{{VERSION}}\"" "1.2.3"
|
||||
'
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == 'version = "1.2.3"; tag = "v1.2.3"' ]]
|
||||
}
|
||||
|
||||
@test "git flow: clone yq add commit push" {
|
||||
source tests/helpers/mock-api.sh
|
||||
mock_set_sequence '[
|
||||
{"code":201},
|
||||
{"code":201}
|
||||
]'
|
||||
mock_start
|
||||
export GIT_CALLS_FILE=$(mktemp)
|
||||
export YQ_CALLS_FILE=$(mktemp)
|
||||
export PATH="${BATS_TEST_DIRNAME}/helpers:$PATH"
|
||||
export INPUT_FILE=dev/Chart.yaml
|
||||
export YQ_TPL='(.version) = "{{VERSION}}"'
|
||||
export VERSION=0.2.3
|
||||
export SOURCE_REPO=niko/app
|
||||
export SOURCE_COMMIT=abc123def456
|
||||
export GITOPS_REPO=niko/app-gitops
|
||||
export GITEA_API_URL=http://localhost:18080
|
||||
export GITEA_TOKEN=test-token
|
||||
run bash scripts/gitops-update.sh
|
||||
[ "$status" -eq 0 ]
|
||||
git_calls=$(cat "$GIT_CALLS_FILE")
|
||||
[[ "$git_calls" == *"clone"* ]]
|
||||
[[ "$git_calls" == *"add"* ]]
|
||||
[[ "$git_calls" == *"commit"* ]]
|
||||
[[ "$git_calls" == *"push"* ]]
|
||||
yq_calls=$(cat "$YQ_CALLS_FILE")
|
||||
[[ "$yq_calls" == *"eval -i"* ]]
|
||||
rm -f "$GIT_CALLS_FILE" "$YQ_CALLS_FILE"
|
||||
mock_stop
|
||||
}
|
||||
|
||||
@test "one commit-status call: gitops-repo only" {
|
||||
source tests/helpers/mock-api.sh
|
||||
mock_set_sequence '[
|
||||
{"code":201}
|
||||
]'
|
||||
mock_start
|
||||
export GIT_CALLS_FILE=$(mktemp)
|
||||
export YQ_CALLS_FILE=$(mktemp)
|
||||
export PATH="${BATS_TEST_DIRNAME}/helpers:$PATH"
|
||||
export INPUT_FILE=dev/Chart.yaml
|
||||
export YQ_TPL='(.version) = "{{VERSION}}"'
|
||||
export VERSION=0.2.3
|
||||
export SOURCE_REPO=niko/app
|
||||
export SOURCE_COMMIT=abc123def456
|
||||
export GITOPS_REPO=niko/app-gitops
|
||||
export GITEA_API_URL=http://localhost:18080
|
||||
export GITEA_TOKEN=test-token
|
||||
run bash scripts/gitops-update.sh
|
||||
[ "$status" -eq 0 ]
|
||||
path=$(mock_get_first_request_path)
|
||||
body=$(mock_get_first_request_body)
|
||||
[[ "$path" == *"/repos/niko/app-gitops/statuses/"* ]]
|
||||
[[ "$body" == *'"context":"app '* ]]
|
||||
[[ "$body" == *'"description":"Install to dev 0.2.3"'* ]]
|
||||
[[ "$body" == *'"state":"success"'* ]]
|
||||
rm -f "$GIT_CALLS_FILE" "$YQ_CALLS_FILE"
|
||||
mock_stop
|
||||
}
|
||||
|
||||
@test "missing GITOPS_REPO causes exit 1" {
|
||||
unset GITOPS_REPO
|
||||
run bash scripts/gitops-update.sh
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"GITOPS_REPO"* ]]
|
||||
}
|
||||
Reference in New Issue
Block a user