f3abd42f17
CI Main / Config load (push) Successful in 23s
CI Gitea Reports Main / Config load (push) Successful in 23s
CI Gitea Reports Main / Latest version (push) Successful in 20s
CI Main / Latest versio (push) Successful in 21s
ci-helm-build-push Helm push 0.2.1
CI Gitea Reports Main / Build & Push Helm chart (push) Successful in 41s
unit-tests Bats test report
acc-tests Cucumber test report
CI Gitea Reports Main / Report Summary (push) Successful in 3s
ci-docker-build-push Docker push 0.2.36
CI Main / Build & Push Docker (push) Successful in 32s
CI Main / Report Summary (push) Successful in 3s
CI Main / Move provider version tag (push) Successful in 10s
gitops/gitea-ci-library/gitea-reports GitOps: gitea-reports 0.2.1
CI Gitea Reports Main / GitOps (push) Successful in 33s
CI Main / Cucumber tests (push) Successful in 1m25s
CI Main / Bats tests (push) Successful in 1m26s
gitops/gitea-ci-library GitOps: 0.2.36
CI Main / GitOps (push) Successful in 32s
Co-authored-by: moilanik <niko.moilanen@tietoevry.com> Reviewed-on: #49
100 lines
2.6 KiB
Bash
100 lines
2.6 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
setup() {
|
|
source tests/helpers/mock-api.sh
|
|
export GITEA_API_URL="http://localhost:18080"
|
|
export GIT_PAGES_URL="http://localhost:18080"
|
|
export REPORTS_PUBLISH_TOKEN="publish-token-abc"
|
|
export GITHUB_REPOSITORY="test-owner/test-repo"
|
|
export GITHUB_SHA="abc123def456789012345678901234567890abcd"
|
|
export GITHUB_REF_NAME="main"
|
|
|
|
mkdir -p "unit-tests"
|
|
echo "<html>test</html>" > "unit-tests/index.html"
|
|
}
|
|
|
|
teardown() {
|
|
mock_stop
|
|
rm -rf "unit-tests" "sub" "empty-suite"
|
|
}
|
|
|
|
@test "missing suite_path argument → exit 1" {
|
|
run bash scripts/publish-git-pages.sh ""
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"ERROR"* ]]
|
|
}
|
|
|
|
@test "missing GITHUB_REF_NAME → exit 1" {
|
|
unset GITHUB_REF_NAME
|
|
run bash scripts/publish-git-pages.sh "unit-tests"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"GITHUB_REF_NAME"* ]]
|
|
}
|
|
|
|
@test "missing GIT_PAGES_URL → exit 1" {
|
|
unset GIT_PAGES_URL
|
|
run bash scripts/publish-git-pages.sh "unit-tests"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"GIT_PAGES_URL"* ]]
|
|
}
|
|
|
|
@test "missing REPORTS_PUBLISH_TOKEN → exit 1" {
|
|
unset REPORTS_PUBLISH_TOKEN
|
|
run bash scripts/publish-git-pages.sh "unit-tests"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"REPORTS_PUBLISH_TOKEN"* ]]
|
|
}
|
|
|
|
@test "missing GITHUB_REPOSITORY → exit 1" {
|
|
unset GITHUB_REPOSITORY
|
|
run bash scripts/publish-git-pages.sh "unit-tests"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"GITHUB_REPOSITORY"* ]]
|
|
}
|
|
|
|
@test "suite path is not a directory → exit 1" {
|
|
run bash scripts/publish-git-pages.sh "nonexistent"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"not a directory"* ]]
|
|
}
|
|
|
|
@test "empty directory → exit 1" {
|
|
mkdir -p "empty-suite"
|
|
run bash scripts/publish-git-pages.sh "empty-suite"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"no files to publish"* ]]
|
|
rm -rf "empty-suite"
|
|
}
|
|
|
|
@test "valid publish returns report base URL" {
|
|
mock_set_sequence '[
|
|
{"code":200,"body":"published"}
|
|
]'
|
|
mock_start
|
|
run bash scripts/publish-git-pages.sh "unit-tests"
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == "http://localhost:18080/test-owner/test-repo/main/abc123de/unit-tests/" ]]
|
|
}
|
|
|
|
@test "publish with suite subpath" {
|
|
mkdir -p "sub/suite"
|
|
echo "sub" > "sub/suite/result.html"
|
|
mock_set_sequence '[
|
|
{"code":200,"body":"published"}
|
|
]'
|
|
mock_start
|
|
run bash scripts/publish-git-pages.sh "sub/suite"
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == "http://localhost:18080/test-owner/test-repo/main/abc123de/sub/suite/" ]]
|
|
}
|
|
|
|
@test "git-pages returns HTTP 500 → exit 1" {
|
|
mock_set_sequence '[
|
|
{"code":500,"body":"internal error"}
|
|
]'
|
|
mock_start
|
|
run bash scripts/publish-git-pages.sh "unit-tests"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"500"* ]]
|
|
}
|