Skip to content

Commit

Permalink
Add check to prevent focused tests being committed. (#1466)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsomething committed Dec 5, 2023
1 parent 09fe618 commit d7e4a2e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,31 @@ jobs:
matrix:
go-version: [ 1.20.x, 1.21.x ]
os: [ ubuntu-latest, macos-latest, windows-latest ]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Ensure code is formatted with gofmt
run: make gofmt_check
if: matrix.os == 'ubuntu-latest'

- name: Install and run shellcheck
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install shellcheck && make shellcheck

- name: Run unit tests
run: make test_unit

- name: Ensure integration test not focused
run: make check_focused

- name: Run integration tests
run: make test_integration
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ gofmt_check:
echo "gofmt checking failed:\n"; echo "$${GOFMT} \n"; exit 1; \
fi

.PHONY: check_focused
check_focused:
@scripts/check_focused_test.sh

.PHONY: snap_image
snap_image:
@echo "==> build docker image for releasing snap"
Expand Down
14 changes: 14 additions & 0 deletions scripts/check_focused_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# When an integration test is focused, no other test is run.
# This can be useful in development, but allowing a test to be
# checked in to main while focused means other tests are not
# actually run in CI.

set -o pipefail

FOCUSED=$(grep -rn "\.Focus" integration/)
if [ -n "${FOCUSED}" ]; then
echo -e "Focused tests should not be checked in:\n\n${FOCUSED}"
exit 1
fi

0 comments on commit d7e4a2e

Please sign in to comment.