|
- package config
-
- import (
- "os"
- "testing"
-
- "github.com/AFASystems/presence/internal/pkg/config"
- )
-
- func TestConfig_Constants(t *testing.T) {
- if config.SMALL_CHANNEL_SIZE != 200 {
- t.Errorf("Expected SMALL_CHANNEL_SIZE 200, got %d", config.SMALL_CHANNEL_SIZE)
- }
- if config.MEDIUM_CHANNEL_SIZE != 500 {
- t.Errorf("Expected MEDIUM_CHANNEL_SIZE 500, got %d", config.MEDIUM_CHANNEL_SIZE)
- }
- if config.LARGE_CHANNEL_SIZE != 2000 {
- t.Errorf("Expected LARGE_CHANNEL_SIZE 2000, got %d", config.LARGE_CHANNEL_SIZE)
- }
- }
-
- func TestConfig_Load_WithEnv(t *testing.T) {
- // Set required env vars to avoid panic
- os.Setenv("MQTT_USERNAME", "testuser")
- os.Setenv("MQTT_PASSWORD", "testpass")
- os.Setenv("MQTT_CLIENT_ID", "testclient")
- os.Setenv("DBUser", "testdbuser")
- os.Setenv("DBPass", "testdbpass")
- os.Setenv("DBName", "testdb")
- os.Setenv("HTTPClientID", "testclient")
- os.Setenv("ClientSecret", "testsecret")
- os.Setenv("HTTPUsername", "testuser")
- os.Setenv("HTTPPassword", "testpass")
- os.Setenv("HTTPAudience", "testaudience")
- defer func() {
- os.Unsetenv("MQTT_USERNAME")
- os.Unsetenv("MQTT_PASSWORD")
- os.Unsetenv("MQTT_CLIENT_ID")
- os.Unsetenv("DBUser")
- os.Unsetenv("DBPass")
- os.Unsetenv("DBName")
- os.Unsetenv("HTTPClientID")
- os.Unsetenv("ClientSecret")
- os.Unsetenv("HTTPUsername")
- os.Unsetenv("HTTPPassword")
- os.Unsetenv("HTTPAudience")
- }()
-
- cfg := config.Load()
- if cfg == nil {
- t.Fatal("Load returned nil")
- }
- if cfg.MQTTUser != "testuser" {
- t.Errorf("Expected MQTTUser testuser, got %s", cfg.MQTTUser)
- }
- if cfg.HTTPAddr != "0.0.0.0:1902" {
- t.Errorf("Expected default HTTPAddr, got %s", cfg.HTTPAddr)
- }
- }
|