From f6b3f9ecab1a4deeb3b77972e86dc82a5f85fedf Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Tue, 22 Jul 2025 10:16:23 +0100 Subject: [PATCH] Cleanup tests. --- cache_test.go | 21 -------- error_recovery_test.go | 73 --------------------------- metadata_cache_test.go | 16 ------ settings_test.go | 25 --------- helpers_test.go => test_utils_test.go | 2 +- 5 files changed, 1 insertion(+), 136 deletions(-) rename helpers_test.go => test_utils_test.go (99%) diff --git a/cache_test.go b/cache_test.go index ce76c6b..0ad4150 100644 --- a/cache_test.go +++ b/cache_test.go @@ -76,24 +76,3 @@ func TestCache_SetMaxSize(t *testing.T) { t.Error("Expected oldest item 'keyA' to be evicted, but it still exists") } } - -func TestJWKCache_WithInternalCache(t *testing.T) { - cache := NewJWKCache() - - // Check that the internal cache is properly initialized - if cache.internalCache == nil { - t.Error("internalCache field was not initialized") - } - - // Test max size configuration - testSize := 50 - cache.SetMaxSize(testSize) - - if cache.maxSize != testSize { - t.Errorf("JWKCache maxSize not updated, expected %d, got %d", testSize, cache.maxSize) - } - - if cache.internalCache.maxSize != testSize { - t.Errorf("internalCache maxSize not updated, expected %d, got %d", testSize, cache.internalCache.maxSize) - } -} diff --git a/error_recovery_test.go b/error_recovery_test.go index 9ff5b25..9580c9f 100644 --- a/error_recovery_test.go +++ b/error_recovery_test.go @@ -16,12 +16,6 @@ func TestCircuitBreaker(t *testing.T) { cb := NewCircuitBreaker(config, logger) - t.Run("Initial state is closed", func(t *testing.T) { - if cb.GetState() != CircuitBreakerClosed { - t.Errorf("Expected initial state to be closed, got %v", cb.GetState()) - } - }) - t.Run("Successful execution", func(t *testing.T) { err := cb.Execute(func() error { return nil @@ -334,73 +328,6 @@ func TestHTTPError(t *testing.T) { } } -func TestHelperFunctions(t *testing.T) { - t.Run("contains function", func(t *testing.T) { - if !contains("hello world", "hello") { - t.Error("Expected contains to find substring at start") - } - if !contains("hello world", "world") { - t.Error("Expected contains to find substring at end") - } - if !contains("hello world", "lo wo") { - t.Error("Expected contains to find substring in middle") - } - if contains("hello world", "xyz") { - t.Error("Expected contains to not find non-existent substring") - } - }) - - t.Run("containsSubstring function", func(t *testing.T) { - if !containsSubstring("hello world", "lo wo") { - t.Error("Expected containsSubstring to find substring") - } - if containsSubstring("hello", "hello world") { - t.Error("Expected containsSubstring to not find longer substring") - } - }) -} - -func TestDefaultConfigs(t *testing.T) { - t.Run("DefaultCircuitBreakerConfig", func(t *testing.T) { - config := DefaultCircuitBreakerConfig() - if config.MaxFailures <= 0 { - t.Error("Expected positive MaxFailures") - } - if config.Timeout <= 0 { - t.Error("Expected positive Timeout") - } - if config.ResetTimeout <= 0 { - t.Error("Expected positive ResetTimeout") - } - }) - - t.Run("DefaultRetryConfig", func(t *testing.T) { - config := DefaultRetryConfig() - if config.MaxAttempts <= 0 { - t.Error("Expected positive MaxAttempts") - } - if config.InitialDelay <= 0 { - t.Error("Expected positive InitialDelay") - } - if config.BackoffFactor <= 1 { - t.Error("Expected BackoffFactor > 1") - } - if len(config.RetryableErrors) == 0 { - t.Error("Expected some retryable errors") - } - }) - - t.Run("DefaultGracefulDegradationConfig", func(t *testing.T) { - config := DefaultGracefulDegradationConfig() - if config.HealthCheckInterval <= 0 { - t.Error("Expected positive HealthCheckInterval") - } - if config.RecoveryTimeout <= 0 { - t.Error("Expected positive RecoveryTimeout") - } - }) -} - // Mock network error for testing type mockNetError struct { timeout bool diff --git a/metadata_cache_test.go b/metadata_cache_test.go index 03bd40f..e73d6e5 100644 --- a/metadata_cache_test.go +++ b/metadata_cache_test.go @@ -7,22 +7,6 @@ import ( "time" ) -func TestIsCacheValid(t *testing.T) { - // Setup with a dummy ProviderMetadata. - pm := &ProviderMetadata{} - mc := &MetadataCache{ - metadata: pm, - expiresAt: time.Now().Add(1 * time.Hour), - } - if !mc.isCacheValid() { - t.Errorf("Expected cache to be valid") - } - mc.expiresAt = time.Now().Add(-1 * time.Hour) - if mc.isCacheValid() { - t.Errorf("Expected cache to be invalid") - } -} - func TestCleanup(t *testing.T) { pm := &ProviderMetadata{} mc := &MetadataCache{ diff --git a/settings_test.go b/settings_test.go index 6758caa..45d771e 100644 --- a/settings_test.go +++ b/settings_test.go @@ -56,31 +56,6 @@ func TestCreateConfig(t *testing.T) { } }) - t.Run("Config Can Hold Custom Values", func(t *testing.T) { - config := CreateConfig() - config.Scopes = []string{"custom_scope"} - config.LogLevel = "debug" - config.RateLimit = 50 - config.ForceHTTPS = false - config.OverrideScopes = true - - // Verify config struct can hold custom values - if len(config.Scopes) != 1 || config.Scopes[0] != "custom_scope" { - t.Error("Config struct cannot hold custom scopes") - } - if config.LogLevel != "debug" { - t.Error("Config struct cannot hold custom log level") - } - if config.RateLimit != 50 { - t.Error("Config struct cannot hold custom rate limit") - } - if config.ForceHTTPS { - t.Error("Config struct cannot hold custom ForceHTTPS value") - } - if !config.OverrideScopes { - t.Error("Config struct cannot hold custom OverrideScopes value") - } - }) } func TestConfigValidate(t *testing.T) { diff --git a/helpers_test.go b/test_utils_test.go similarity index 99% rename from helpers_test.go rename to test_utils_test.go index 84d6ae2..a7e5428 100644 --- a/helpers_test.go +++ b/test_utils_test.go @@ -14,4 +14,4 @@ func generateRandomString(length int) string { return "random-string-fallback" } return hex.EncodeToString(bytes) -} +} \ No newline at end of file