Skip to content

Commit d7e4a2e

Browse files
Add check to prevent focused tests being committed. (#1466)
1 parent 09fe618 commit d7e4a2e

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,31 @@ jobs:
1414
matrix:
1515
go-version: [ 1.20.x, 1.21.x ]
1616
os: [ ubuntu-latest, macos-latest, windows-latest ]
17+
1718
runs-on: ${{ matrix.os }}
19+
1820
steps:
1921
- name: Checkout code
2022
uses: actions/checkout@v4
23+
2124
- name: Install Go
2225
uses: actions/setup-go@v4
2326
with:
2427
go-version: ${{ matrix.go-version }}
28+
2529
- name: Ensure code is formatted with gofmt
2630
run: make gofmt_check
2731
if: matrix.os == 'ubuntu-latest'
32+
2833
- name: Install and run shellcheck
2934
if: matrix.os == 'ubuntu-latest'
3035
run: sudo apt-get install shellcheck && make shellcheck
36+
3137
- name: Run unit tests
3238
run: make test_unit
39+
40+
- name: Ensure integration test not focused
41+
run: make check_focused
42+
3343
- name: Run integration tests
3444
run: make test_integration

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ gofmt_check:
118118
echo "gofmt checking failed:\n"; echo "$${GOFMT} \n"; exit 1; \
119119
fi
120120

121+
.PHONY: check_focused
122+
check_focused:
123+
@scripts/check_focused_test.sh
124+
121125
.PHONY: snap_image
122126
snap_image:
123127
@echo "==> build docker image for releasing snap"

scripts/check_focused_test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# When an integration test is focused, no other test is run.
4+
# This can be useful in development, but allowing a test to be
5+
# checked in to main while focused means other tests are not
6+
# actually run in CI.
7+
8+
set -o pipefail
9+
10+
FOCUSED=$(grep -rn "\.Focus" integration/)
11+
if [ -n "${FOCUSED}" ]; then
12+
echo -e "Focused tests should not be checked in:\n\n${FOCUSED}"
13+
exit 1
14+
fi

0 commit comments

Comments
 (0)