Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,55 @@ 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:
go-version: ${{ matrix.go-version }}

- 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
24 changes: 23 additions & 1 deletion database/model_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package database

import "testing"
import (
"strings"
"testing"
)

func TestIsValidTable(t *testing.T) {
if !isValidTable("users") {
Expand All @@ -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)
}
}
}
Comment on lines +17 to +34
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Test logic misalignment with actual implementation.

The test assumes isValidTable performs string validation (checking for special characters, case sensitivity, length limits, etc.), but based on the implementation in database/model.go, the function only checks if the input exists in the schemaTables slice using slices.Contains.

This test will pass if none of these edge case strings are present in schemaTables, but it's not actually testing string validation logic - it's testing slice membership. The test name and structure suggest it's meant to validate input format rules, which don't exist in the current implementation.

Consider either:

  1. Updating the test to reflect the actual behavior (slice membership testing)
  2. Implementing proper string validation in isValidTable if that's the intended behavior

Let me verify what's actually in the schemaTables slice to understand the expected behavior:


🏁 Script executed:

#!/bin/bash
# Description: Find the schemaTables definition to understand what valid table names are expected
# Expected: Find the slice definition and its contents

ast-grep --pattern 'schemaTables = $_'

Length of output: 40


🏁 Script executed:

#!/bin/bash
set -e
# Locate isValidTable implementation with context
rg -n "func isValidTable" -C5

# Locate schemaTables definition or assignment with context
rg -n "schemaTables" -C5

Length of output: 1451


Align test behavior with isValidTable or extend isValidTable functionality

The test TestIsValidTableEdgeCases in database/model_internal_test.go (lines 17–34) currently only verifies that arbitrary strings aren’t present in schemaTables, but does not exercise any format or character‐set rules. Meanwhile, isValidTable in database/model.go (lines 22–24) simply returns slices.Contains(schemaTables, seed) without any additional validation. To resolve this misalignment, choose one of the following:

  • Update the test to reflect membership‐only behavior:
    • Rename it (e.g. TestIsValidTableNonexistentTables).
    • Add positive cases using GetSchemaTables() to assert that known valid names return true.
  • Enhance isValidTable to enforce format rules:
    • Add regex or character checks for allowed characters (lowercase letters, underscores, numeric).
    • Enforce length limits (e.g. 1–255 characters) and reject leading/trailing whitespace.
    • Then update tests to cover both membership and format validations.
🤖 Prompt for AI Agents
In database/model_internal_test.go lines 17 to 34, the test currently checks
only if table names exist in schemaTables without validating format rules, while
isValidTable in database/model.go lines 22 to 24 only checks membership. To fix
this, either rename and adjust the test to verify only membership by adding
positive cases from GetSchemaTables, or enhance isValidTable to include format
validation such as regex for allowed characters, length limits, and whitespace
checks, then update the test to cover these new validations accordingly.

Loading