diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3d7988ca..380e5c97 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,11 +6,13 @@ on: jobs: test: - if: github.event.pull_request.draft == false || (github.event.action == 'labeled' && github.event.label.name == 'testing') + if: github.event.pull_request.draft == false || + (github.event.action == 'labeled' && github.event.label.name == 'testing') runs-on: ubuntu-latest strategy: matrix: - go-version: [1.24.x] + go-version: ['1.24.5', '1.24.4'] + steps: - uses: actions/setup-go@v5 with: @@ -18,31 +20,41 @@ jobs: - uses: actions/checkout@v4 - - uses: actions/cache@v4 + - name: Cache Go modules + uses: actions/cache@v4 with: path: | ~/go/pkg/mod ~/.cache/go-build - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('go.sum') }} restore-keys: | - ${{ runner.os }}-go- + ${{ runner.os }}-go-${{ matrix.go-version }}- + + - name: Download Go modules + run: go mod download - name: Run pkg tests run: | - go test ./pkg/... -coverprofile=coverage.out - go tool cover -func=coverage.out | tail -n 1 + go test -coverpkg=./... ./pkg/... -coverprofile=coverage-pkg-${{ matrix.go-version }}.out + go tool cover -func=coverage-pkg-${{ matrix.go-version }}.out | tail -n 1 - name: Run boost & env tests run: | - go test ./boost ./env -coverprofile=coverage.out - go tool cover -func=coverage.out | tail -n 1 + go test -coverpkg=./... ./boost ./env -coverprofile=coverage-boost-env-${{ matrix.go-version }}.out + go tool cover -func=coverage-boost-env-${{ matrix.go-version }}.out | tail -n 1 - name: Run handlers tests run: | - go test ./handler/... -coverprofile=coverage.out - go tool cover -func=coverage.out | tail -n 1 + go test -coverpkg=./... ./handler/... -coverprofile=coverage-handler-${{ matrix.go-version }}.out + go tool cover -func=coverage-handler-${{ matrix.go-version }}.out | tail -n 1 - name: Run database tests run: | - go test ./database/... -coverprofile=coverage.out - go tool cover -func=coverage.out | tail -n 1 + go test -coverpkg=./... ./database/... -coverprofile=coverage-database-${{ matrix.go-version }}.out + go tool cover -func=coverage-database-${{ matrix.go-version }}.out | tail -n 1 + + - name: Merge coverage reports + run: | + echo "mode: set" > coverage-${{ matrix.go-version }}.out + tail -q -n +2 coverage-*-${{ matrix.go-version }}.out >> coverage-${{ matrix.go-version }}.out + go tool cover -func=coverage-${{ matrix.go-version }}.out | tail -n 1 diff --git a/database/model_internal_test.go b/database/model_internal_test.go index 2fabf46b..728cb714 100644 --- a/database/model_internal_test.go +++ b/database/model_internal_test.go @@ -1,6 +1,9 @@ package database -import "testing" +import ( + "strings" + "testing" +) func TestIsValidTable(t *testing.T) { if !isValidTable("users") { @@ -10,3 +13,22 @@ func TestIsValidTable(t *testing.T) { t.Fatalf("unexpected valid table") } } + +func TestIsValidTableEdgeCases(t *testing.T) { + invalid := []string{ + "", + "user!@#", + "user-name", + "Users", + "USERS", + "table123", + strings.Repeat("x", 256), + " ", + } + + for _, name := range invalid { + if isValidTable(name) { + t.Fatalf("%q should be invalid", name) + } + } +}