Add test library cleanup by name and documentation
Problem: - Libraries are universal (not user-owned) and persist in database - Tests create libraries via API but don't clean them up - Libraries accumulate between test runs Solution: - Delete test libraries (names containing "test") during cleanup - Uses case-insensitive matching to catch "Test", "TEST", "test", etc. - Preserves user-created libraries without "test" in name Changes: 1. cmd/server/tests/test_helpers.go: - Added library cleanup in setupTestServer() after user cleanup - Lists all libraries and deletes those with "test" in name - Includes warning comment about naming convention 2. docs/contributing/development.md: - Added "Test Library Naming Convention" section - Documents that "test" in library names triggers deletion - Recommends alternative names for persistent test libraries Note: Users should NOT use "test" in library names if they want to keep them.
This commit is contained in:
@@ -529,6 +529,16 @@ func setupTestServer(t *testing.T) *TestServerSetup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete test libraries (names containing "test" - case insensitive)
|
||||||
|
// This cleans up libraries created by tests while preserving user-created libraries
|
||||||
|
// NOTE: Do not use "test" in library names if you want to keep them!
|
||||||
|
allLibs, _ := queries.ListLibraries(ctx)
|
||||||
|
for _, lib := range allLibs {
|
||||||
|
if strings.Contains(strings.ToLower(lib.Name), "test") {
|
||||||
|
queries.DeleteLibrary(ctx, lib.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create fresh admin test user
|
// Create fresh admin test user
|
||||||
passwordHash := "$2a$10$JjAtK7PPa1WexQC3AUGe8OXLeuseZ/haN1Mz7emMo6CfOvMiTVXWq"
|
passwordHash := "$2a$10$JjAtK7PPa1WexQC3AUGe8OXLeuseZ/haN1Mz7emMo6CfOvMiTVXWq"
|
||||||
adminUser, err := queries.CreateUser(ctx, database.CreateUserParams{
|
adminUser, err := queries.CreateUser(ctx, database.CreateUserParams{
|
||||||
|
|||||||
@@ -279,6 +279,15 @@ Environment variables for testing:
|
|||||||
|
|
||||||
**⚠️ WARNING**: Never enable these in production!
|
**⚠️ WARNING**: Never enable these in production!
|
||||||
|
|
||||||
|
### Test Library Naming Convention
|
||||||
|
|
||||||
|
Integration tests automatically clean up libraries with "test" in the name (case-insensitive).
|
||||||
|
|
||||||
|
**⚠️ IMPORTANT**: Do not use "test" in library names if you want to keep them!
|
||||||
|
- Libraries containing "test" (e.g., "My Test Library", "Test Library 1") will be deleted by test cleanup
|
||||||
|
- Use names like "Development Library", "Staging Books", or "Personal" for libraries you want to keep
|
||||||
|
- This ensures your manual test data persists between test runs
|
||||||
|
|
||||||
## 📝 Code Style Guidelines
|
## 📝 Code Style Guidelines
|
||||||
|
|
||||||
### Go Code
|
### Go Code
|
||||||
|
|||||||
Reference in New Issue
Block a user