fixup! fixup! fixup! fixup! Weekend fun with further optimisations.

This commit is contained in:
2025-09-14 23:47:16 +01:00
parent f411273fa2
commit cc6d6693e0
93 changed files with 10178 additions and 37059 deletions
+22 -10
View File
@@ -1,20 +1,14 @@
package traefikoidc
import (
"context"
"encoding/json"
"log"
"net/http"
"net/http/httptest"
"sync"
"testing"
"time"
"github.com/google/uuid"
"golang.org/x/time/rate"
)
// testWriter is an io.Writer that writes to test log
// lint:ignore U1000 Kept for potential future use
/*
type testWriter struct {
t *testing.T
}
@@ -23,10 +17,13 @@ func (w *testWriter) Write(p []byte) (n int, err error) {
w.t.Log(string(p))
return len(p), nil
}
*/
// Test helper adapters for the new test files
// resetGlobalState resets all global singletons to prevent test interference
// nolint:unused // Kept for potential future use in integration tests
/*
func resetGlobalState() {
// Reset global task registry first to stop all background tasks
ResetGlobalTaskRegistry()
@@ -46,6 +43,7 @@ func resetGlobalState() {
// The universal cache manager is a singleton that persists across tests
// Don't reset it as it causes issues
}
*/
// testCleanup provides comprehensive cleanup for tests to prevent goroutine leaks
type testCleanup struct {
@@ -91,6 +89,8 @@ func (tc *testCleanup) addTokenCache(c *TokenCache) *TokenCache {
}
// addOIDC registers a TraefikOidc instance for cleanup
//
//lint:ignore U1000 Kept for potential future use
func (tc *testCleanup) addOIDC(o *TraefikOidc) *TraefikOidc {
tc.mu.Lock()
defer tc.mu.Unlock()
@@ -132,11 +132,13 @@ func (tc *testCleanup) cleanupAll() {
}
}
// Reset global state
resetGlobalState()
// Reset global state - commented out as resetGlobalState is unused
// resetGlobalState()
}
// createTestConfig creates a config with all required fields populated for testing
// nolint:unused // Kept for potential future use in integration tests
/*
func createTestConfig() *Config {
config := CreateConfig()
config.ProviderURL = "https://test-provider.com"
@@ -146,8 +148,11 @@ func createTestConfig() *Config {
config.CallbackURL = "/oauth2/callback"
return config
}
*/
// setupTestOIDCMiddleware creates a test OIDC middleware instance with mock servers
// nolint:unused // Kept for potential future use in integration tests
/*
func setupTestOIDCMiddleware(t *testing.T, config *Config) (*TraefikOidc, *httptest.Server) {
// Reset global state to ensure test isolation
resetGlobalState()
@@ -330,11 +335,15 @@ func setupTestOIDCMiddleware(t *testing.T, config *Config) (*TraefikOidc, *httpt
return oidc, server
}
*/
// createMockJWT creates a mock JWT token for testing - adapter for existing tests
// nolint:unused // Kept for potential future use in integration tests
/*
func createMockJWT(t *testing.T, sub, email string) string {
return ValidIDToken
}
*/
// createTestSession creates a properly initialized SessionData for testing
func createTestSession() *SessionData {
@@ -351,6 +360,8 @@ func createTestSession() *SessionData {
}
// injectSessionIntoRequest saves the session and adds the resulting cookies to the request
// nolint:unused // Kept for potential future use in integration tests
/*
func injectSessionIntoRequest(t *testing.T, req *http.Request, session *SessionData) {
// Create a response recorder to capture cookies
rec := httptest.NewRecorder()
@@ -365,3 +376,4 @@ func injectSessionIntoRequest(t *testing.T, req *http.Request, session *SessionD
req.AddCookie(cookie)
}
}
*/