mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-14 04:07:46 +00:00
Cleanup tests.
This commit is contained in:
@@ -76,24 +76,3 @@ func TestCache_SetMaxSize(t *testing.T) {
|
|||||||
t.Error("Expected oldest item 'keyA' to be evicted, but it still exists")
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -16,12 +16,6 @@ func TestCircuitBreaker(t *testing.T) {
|
|||||||
|
|
||||||
cb := NewCircuitBreaker(config, logger)
|
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) {
|
t.Run("Successful execution", func(t *testing.T) {
|
||||||
err := cb.Execute(func() error {
|
err := cb.Execute(func() error {
|
||||||
return nil
|
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
|
// Mock network error for testing
|
||||||
type mockNetError struct {
|
type mockNetError struct {
|
||||||
timeout bool
|
timeout bool
|
||||||
|
|||||||
@@ -7,22 +7,6 @@ import (
|
|||||||
"time"
|
"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) {
|
func TestCleanup(t *testing.T) {
|
||||||
pm := &ProviderMetadata{}
|
pm := &ProviderMetadata{}
|
||||||
mc := &MetadataCache{
|
mc := &MetadataCache{
|
||||||
|
|||||||
@@ -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) {
|
func TestConfigValidate(t *testing.T) {
|
||||||
|
|||||||
@@ -14,4 +14,4 @@ func generateRandomString(length int) string {
|
|||||||
return "random-string-fallback"
|
return "random-string-fallback"
|
||||||
}
|
}
|
||||||
return hex.EncodeToString(bytes)
|
return hex.EncodeToString(bytes)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user