Skip to content

Commit aea8830

Browse files
chmouelzakisk
authored andcommitted
feat: check E2E test naming convention with linter
Introduced a new script, `hack/check-e2e-test-naming.sh`, to enforce a naming convention for end-to-end tests. This script validates that test function names start with specific prefixes (e.g., `TestGithub*`, `TestGitlab*`) or include "Concurrency" to ensure they can be correctly categorized and executed by CI jobs. The Makefile was updated to include this new linting step, and the GitHub Actions workflow configuration (`.github/workflows/e2e.yaml`) was adjusted to correctly pass necessary secrets and variables for testing against Bitbucket Cloud and GitHub. A minor adjustment was also made to the `github_second_controller` test selection in `hack/gh-workflow-ci.sh` to include "Others" tests. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent 58c9cde commit aea8830

File tree

4 files changed

+61
-6
lines changed

4 files changed

+61
-6
lines changed

.github/workflows/e2e.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
TARGET_TEAM_SLUGS: "pipeline-as-code,pipeline-as-code-contributors"
6262
TEST_BITBUCKET_CLOUD_API_URL: https://api.bitbucket.org/2.0
6363
TEST_BITBUCKET_CLOUD_E2E_REPOSITORY: cboudjna/pac-e2e-tests
64+
TEST_BITBUCKET_CLOUD_TOKEN: ${{ secrets.BITBUCKET_CLOUD_TOKEN }}
6465
TEST_BITBUCKET_CLOUD_USER: cboudjna
6566
TEST_BITBUCKET_SERVER_API_URL: ${{ secrets.BITBUCKET_SERVER_API_URL }}
6667
TEST_BITBUCKET_SERVER_E2E_REPOSITORY: PAC/pac-e2e-tests
@@ -77,18 +78,17 @@ jobs:
7778
TEST_GITHUB_API_URL: api.github.com
7879
TEST_GITHUB_PRIVATE_TASK_NAME: task-remote
7980
TEST_GITHUB_PRIVATE_TASK_URL: https://github.com/openshift-pipelines/pipelines-as-code-e2e-tests-private/blob/main/remote_task.yaml
81+
TEST_GITHUB_REPO_INSTALLATION_ID: ${{ vars.INSTALLATION_ID }}
8082
TEST_GITHUB_REPO_OWNER_GITHUBAPP: openshift-pipelines/pipelines-as-code-e2e-tests
8183
TEST_GITHUB_REPO_OWNER_WEBHOOK: openshift-pipelines/pipelines-as-code-e2e-tests-webhook
8284
TEST_GITHUB_SECOND_API_URL: ghe.pipelinesascode.com
8385
TEST_GITHUB_SECOND_EL_URL: http://ghe.paac-127-0-0-1.nip.io
8486
TEST_GITHUB_SECOND_REPO_INSTALLATION_ID: 1
8587
TEST_GITHUB_SECOND_REPO_OWNER_GITHUBAPP: pipelines-as-code/e2e
88+
TEST_GITHUB_SECOND_TOKEN: ${{ secrets.TEST_GITHUB_SECOND_TOKEN }}
89+
TEST_GITHUB_TOKEN: ${{ secrets.GH_APPS_TOKEN }}
8690
TEST_GITLAB_API_URL: https://gitlab.com
8791
TEST_GITLAB_PROJECT_ID: ${{ vars.TEST_GITLAB_PROJECT_ID }}
88-
TEST_BITBUCKET_CLOUD_TOKEN: ${{ secrets.BITBUCKET_CLOUD_TOKEN }}
89-
TEST_GITHUB_REPO_INSTALLATION_ID: ${{ vars.INSTALLATION_ID }}
90-
TEST_GITHUB_TOKEN: ${{ secrets.GH_APPS_TOKEN }}
91-
TEST_GITHUB_SECOND_TOKEN: ${{ secrets.TEST_GITHUB_SECOND_TOKEN }}
9292
TEST_GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
9393
steps:
9494
- uses: actions/checkout@v6

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ html-coverage: ## generate html coverage
8383

8484
##@ Linting
8585
.PHONY: lint
86-
lint: lint-go lint-yaml lint-md lint-python lint-shell ## run all linters
86+
lint: lint-go lint-yaml lint-md lint-python lint-shell lint-e2e-naming ## run all linters
87+
88+
.PHONY: lint-e2e-naming
89+
lint-e2e-naming: ## check e2e test naming conventions
90+
@echo "Checking E2E test naming conventions..."
91+
@./hack/check-e2e-test-naming.sh
8792

8893
.PHONY: lint-go
8994
lint-go: ## runs go linter on all go files

hack/check-e2e-test-naming.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
# Validates that all E2E test functions follow the naming convention so they
3+
# can be properly partitioned into CI jobs by hack/gh-workflow-ci.sh.
4+
#
5+
# Valid prefixes: TestGithub*, TestGitea*, TestGitlab*, TestBitbucket*, TestOthers*
6+
# Concurrency tests (any name containing "Concurrency") are also allowed.
7+
set -euo pipefail
8+
9+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
11+
12+
# Find all test files in the test directory (excluding subdirectories)
13+
mapfile -t testfiles < <(find "${REPO_ROOT}/test/" -maxdepth 1 -name '*_test.go' 2>/dev/null)
14+
15+
if [[ ${#testfiles[@]} -eq 0 ]]; then
16+
echo "No test files found in ${REPO_ROOT}/test/"
17+
exit 0
18+
fi
19+
20+
# Extract all Test* function names
21+
all_tests=$(grep -hE '^func[[:space:]]+Test[[:alnum:]_]+' "${testfiles[@]}" | sed -E 's/^func[[:space:]]+([[:alnum:]_]+).*/\1/')
22+
23+
# Valid patterns: TestGithub*, TestGitea*, TestGitlab*, TestBitbucket*, TestOthers*, or *Concurrency*
24+
valid_pattern='^Test(Github|Gitea|Gitlab|Bitbucket|Others)|Concurrency'
25+
26+
orphaned_tests=()
27+
while IFS= read -r test; do
28+
[[ -z "${test}" ]] && continue
29+
if ! echo "${test}" | grep -qE "${valid_pattern}"; then
30+
orphaned_tests+=("${test}")
31+
fi
32+
done <<< "${all_tests}"
33+
34+
if [[ ${#orphaned_tests[@]} -gt 0 ]]; then
35+
echo "ERROR: The following E2E tests do not follow the naming convention:"
36+
echo ""
37+
for test in "${orphaned_tests[@]}"; do
38+
# Find which file contains this test
39+
file=$(grep -l "func ${test}" "${testfiles[@]}" 2>/dev/null | head -1)
40+
echo " - ${test} (in ${file:-unknown})"
41+
done
42+
echo ""
43+
echo "Tests must start with one of: TestGithub*, TestGitea*, TestGitlab*, TestBitbucket*, TestOthers*"
44+
echo "Or contain 'Concurrency' in the name for concurrency tests."
45+
echo ""
46+
echo "This ensures tests are properly assigned to CI jobs in hack/gh-workflow-ci.sh"
47+
exit 1
48+
fi
49+
50+
echo "All E2E tests follow the naming convention."

hack/gh-workflow-ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ get_tests() {
118118
fi
119119
;;
120120
github_second_controller)
121-
printf '%s\n' "${all_tests}" | grep -iP 'GithubSecond' | grep -ivP 'Concurrency'
121+
printf '%s\n' "${all_tests}" | grep -iP 'GithubSecond|Others' | grep -ivP 'Concurrency'
122122
;;
123123
gitlab_bitbucket)
124124
printf '%s\n' "${all_tests}" | grep -iP 'Gitlab|Bitbucket' | grep -ivP 'Concurrency'

0 commit comments

Comments
 (0)