Deadcode-verified removals (RTA reachability from main, cross-checked with -test and textual xrefs): Go server: - whole files: middleware/transaction.go, middleware/error_handler.go, middleware/password_validator.go (live registration machinery kept), handlers/sync.go, sync/offline.go - unrouted endpoints: auth UpdateUsername/UpdateEmail, timezone settings handler, OPDS RegisterOPDS, Kobo LibrarySync handler, ReaderHandler.ShowReader, JSON-data twins on collections/library - duplicate book-matching handlers (book_matching.go Handler twins, matching.go MatchingHandler twins), superseded helpers (router.parseUUID, handlers.ValidateDeviceToken, normalizePath, userExists, generateLockID) Templ/client: - never-routed pages: api_explorer.templ, queue.templ and their client modules api-explorer.ts, api-explorer-docs.ts, queue.ts - fully orphaned wrapper modules events.ts, dom.ts - broken clearSyncQueue (called a nonexistent endpoint) and the hidden, never-populated sync-queue section on the devices page - 166+ unused exports demoted to private (knip-verified); ~85 truly dead declarations removed via tsc noUnusedLocals fixpoint - stale 'interactive API Explorer' claims dropped from docs The docs drift-gate package (internal/docs), templ-bound modules (dashboard, stats, header, index, login, profile*, bookshelf, collections, toast-error), sqlc-generated code, and web/static are intentionally untouched.
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// Helper functions for database verification and test utilities
|
|
// These functions reduce code duplication and ensure consistent database state verification
|
|
|
|
// createTestLibraryWithFolder creates a test library with optional folder
|
|
func createTestLibraryWithFolder(t *testing.T, ts *httptest.Server, token, name string, withFolder bool) string {
|
|
libReq := map[string]interface{}{
|
|
"name": name,
|
|
"type": "ebooks",
|
|
}
|
|
libBody, _ := json.Marshal(libReq)
|
|
|
|
libHTTP, _ := http.NewRequest("POST", ts.URL+"/api/libraries", bytes.NewBuffer(libBody))
|
|
libHTTP.Header.Set("Content-Type", "application/json")
|
|
libHTTP.Header.Set("Authorization", "Bearer "+token)
|
|
|
|
client := &http.Client{}
|
|
resp, err := client.Do(libHTTP)
|
|
require.NoError(t, err)
|
|
defer func(Body io.ReadCloser) {
|
|
_ = Body.Close()
|
|
}(resp.Body)
|
|
require.Equal(t, http.StatusCreated, resp.StatusCode, "Library creation should succeed")
|
|
|
|
var libResponse map[string]interface{}
|
|
err = json.NewDecoder(resp.Body).Decode(&libResponse)
|
|
require.NoError(t, err)
|
|
libraryID := libResponse["id"].(string)
|
|
|
|
// Every library a test creates must not outlive that test — delete
|
|
// it on cleanup so runs leave no residue in the dev database.
|
|
t.Cleanup(func() {
|
|
delHTTP, _ := http.NewRequest("DELETE", fmt.Sprintf("%s/api/libraries/%s", ts.URL, libraryID), nil)
|
|
delHTTP.Header.Set("Authorization", "Bearer "+token)
|
|
delResp, err := client.Do(delHTTP)
|
|
if err == nil {
|
|
_, _ = io.Copy(io.Discard, delResp.Body)
|
|
_ = delResp.Body.Close()
|
|
}
|
|
})
|
|
|
|
if withFolder {
|
|
folderReq := map[string]interface{}{
|
|
"folder_path": "/app/uploads",
|
|
}
|
|
folderBody, _ := json.Marshal(folderReq)
|
|
|
|
folderHTTP, _ := http.NewRequest("POST", fmt.Sprintf("%s/api/libraries/%s/folders", ts.URL, libraryID), bytes.NewBuffer(folderBody))
|
|
folderHTTP.Header.Set("Content-Type", "application/json")
|
|
folderHTTP.Header.Set("Authorization", "Bearer "+token)
|
|
|
|
folderResp, err := client.Do(folderHTTP)
|
|
require.NoError(t, err)
|
|
defer func(Body io.ReadCloser) {
|
|
_ = Body.Close()
|
|
}(folderResp.Body)
|
|
require.Equal(t, http.StatusCreated, folderResp.StatusCode, "Folder creation should succeed")
|
|
}
|
|
|
|
return libraryID
|
|
}
|