|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package statusreporterextension |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +func TestConfigValidation(t *testing.T) { |
| 11 | + // Test with default config |
| 12 | + cfg := createDefaultConfig().(*Config) |
| 13 | + if cfg.MetricsEndpoint != "http://localhost:8888/metrics" { |
| 14 | + t.Errorf("Expected default MetricsEndpoint to be http://localhost:8888/metrics, got %s", cfg.MetricsEndpoint) |
| 15 | + } |
| 16 | + |
| 17 | + // Test with custom values |
| 18 | + cfg.MetricsEndpoint = "http://custom:9090/metrics" |
| 19 | + cfg.StaleThreshold = 600 |
| 20 | + cfg.EngineID = "custom-engine" |
| 21 | + cfg.PodName = "custom-pod" |
| 22 | + cfg.Port = 9000 |
| 23 | + cfg.AuthEnabled = true |
| 24 | + cfg.SecretValue = "custom-secret" |
| 25 | + |
| 26 | + // Verify custom values |
| 27 | + if cfg.MetricsEndpoint != "http://custom:9090/metrics" { |
| 28 | + t.Errorf("Failed to set custom MetricsEndpoint") |
| 29 | + } |
| 30 | + |
| 31 | + if cfg.StaleThreshold != 600 { |
| 32 | + t.Errorf("Failed to set custom StaleThreshold") |
| 33 | + } |
| 34 | + |
| 35 | + if cfg.EngineID != "custom-engine" { |
| 36 | + t.Errorf("Failed to set custom EngineID") |
| 37 | + } |
| 38 | + |
| 39 | + if cfg.PodName != "custom-pod" { |
| 40 | + t.Errorf("Failed to set custom PodName") |
| 41 | + } |
| 42 | + |
| 43 | + if cfg.Port != 9000 { |
| 44 | + t.Errorf("Failed to set custom Port") |
| 45 | + } |
| 46 | + |
| 47 | + if !cfg.AuthEnabled { |
| 48 | + t.Errorf("Failed to set custom AuthEnabled") |
| 49 | + } |
| 50 | + |
| 51 | + if cfg.SecretValue != "custom-secret" { |
| 52 | + t.Errorf("Failed to set custom SecretValue") |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +func TestConfigEdgeCases(t *testing.T) { |
| 57 | + cfg := createDefaultConfig().(*Config) |
| 58 | + |
| 59 | + // Test with empty metrics endpoint |
| 60 | + cfg.MetricsEndpoint = "" |
| 61 | + // This should be allowed, as the extension will use a default value |
| 62 | + |
| 63 | + // Test with negative stale threshold |
| 64 | + cfg.StaleThreshold = -1 |
| 65 | + // This should be allowed, though it might not be practical |
| 66 | + |
| 67 | + // Test with zero port (should use system-assigned port) |
| 68 | + cfg.Port = 0 |
| 69 | + // This should be allowed, as the HTTP server can use a system-assigned port |
| 70 | + |
| 71 | + // Test with empty engine ID |
| 72 | + cfg.EngineID = "" |
| 73 | + // This should be allowed, though it might not be useful |
| 74 | + |
| 75 | + // Test with empty pod name |
| 76 | + cfg.PodName = "" |
| 77 | + // This should be allowed, though it might not be useful |
| 78 | + |
| 79 | + // Test with auth enabled but empty secret |
| 80 | + cfg.AuthEnabled = true |
| 81 | + cfg.SecretValue = "" |
| 82 | + // This should be allowed, as the secret might be provided via environment variable |
| 83 | +} |
| 84 | + |
0 commit comments