No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

60 líneas
1.6 KiB

  1. package config
  2. import (
  3. "os"
  4. "testing"
  5. "github.com/AFASystems/presence/internal/pkg/config"
  6. )
  7. func TestConfig_Constants(t *testing.T) {
  8. if config.SMALL_CHANNEL_SIZE != 200 {
  9. t.Errorf("Expected SMALL_CHANNEL_SIZE 200, got %d", config.SMALL_CHANNEL_SIZE)
  10. }
  11. if config.MEDIUM_CHANNEL_SIZE != 500 {
  12. t.Errorf("Expected MEDIUM_CHANNEL_SIZE 500, got %d", config.MEDIUM_CHANNEL_SIZE)
  13. }
  14. if config.LARGE_CHANNEL_SIZE != 2000 {
  15. t.Errorf("Expected LARGE_CHANNEL_SIZE 2000, got %d", config.LARGE_CHANNEL_SIZE)
  16. }
  17. }
  18. func TestConfig_Load_WithEnv(t *testing.T) {
  19. // Set required env vars to avoid panic
  20. os.Setenv("MQTT_USERNAME", "testuser")
  21. os.Setenv("MQTT_PASSWORD", "testpass")
  22. os.Setenv("MQTT_CLIENT_ID", "testclient")
  23. os.Setenv("DBUser", "testdbuser")
  24. os.Setenv("DBPass", "testdbpass")
  25. os.Setenv("DBName", "testdb")
  26. os.Setenv("HTTPClientID", "testclient")
  27. os.Setenv("ClientSecret", "testsecret")
  28. os.Setenv("HTTPUsername", "testuser")
  29. os.Setenv("HTTPPassword", "testpass")
  30. os.Setenv("HTTPAudience", "testaudience")
  31. defer func() {
  32. os.Unsetenv("MQTT_USERNAME")
  33. os.Unsetenv("MQTT_PASSWORD")
  34. os.Unsetenv("MQTT_CLIENT_ID")
  35. os.Unsetenv("DBUser")
  36. os.Unsetenv("DBPass")
  37. os.Unsetenv("DBName")
  38. os.Unsetenv("HTTPClientID")
  39. os.Unsetenv("ClientSecret")
  40. os.Unsetenv("HTTPUsername")
  41. os.Unsetenv("HTTPPassword")
  42. os.Unsetenv("HTTPAudience")
  43. }()
  44. cfg := config.Load()
  45. if cfg == nil {
  46. t.Fatal("Load returned nil")
  47. }
  48. if cfg.MQTTUser != "testuser" {
  49. t.Errorf("Expected MQTTUser testuser, got %s", cfg.MQTTUser)
  50. }
  51. if cfg.HTTPAddr != "0.0.0.0:1902" {
  52. t.Errorf("Expected default HTTPAddr, got %s", cfg.HTTPAddr)
  53. }
  54. }