package config import ( "os" "path/filepath" "testing" "github.com/fsnotify/fsnotify" "github.com/spf13/viper" "github.com/stretchr/testify/assert" ) func TestLoad_Cov3(t *testing.T) { tmpDir := t.TempDir() configContent := ` app: name: test env: test database: host: localhost port: 5432 name: test_db user: postgres password: postgres redis: host: localhost port: 6379 ` configPath := filepath.Join(tmpDir, "config.yaml") assert.NoError(t, os.WriteFile(configPath, []byte(configContent), 0644)) oldDir, _ := os.Getwd() assert.NoError(t, os.Chdir(tmpDir)) defer os.Chdir(oldDir) cfg, err := Load() if err != nil { t.Skip("Load requires full config") } _ = cfg } func TestLoadDotEnvEnvironment_Cov3(t *testing.T) { LoadDotEnvEnvironment() } func TestLoadDotEnvEnvironment_WithFile_Cov3(t *testing.T) { tmpDir := t.TempDir() envContent := "TEST_KEY=test_value\n# comment\nEMPTY_LINE=" envPath := filepath.Join(tmpDir, ".env") assert.NoError(t, os.WriteFile(envPath, []byte(envContent), 0644)) oldDir, _ := os.Getwd() assert.NoError(t, os.Chdir(tmpDir)) defer os.Chdir(oldDir) LoadDotEnvEnvironment() assert.Equal(t, "test_value", os.Getenv("TEST_KEY")) os.Unsetenv("TEST_KEY") } func TestLoadDotEnv_Cov3(t *testing.T) { tmpDir := t.TempDir() envContent := "GOCHAT_TEST_KEY=test_value\n# comment\n" envPath := filepath.Join(tmpDir, ".env") assert.NoError(t, os.WriteFile(envPath, []byte(envContent), 0644)) oldDir, _ := os.Getwd() assert.NoError(t, os.Chdir(tmpDir)) defer os.Chdir(oldDir) v := viper.New() envBindings := map[string]string{"GOCHAT_TEST_KEY": "test.key"} loadDotEnv(v, envBindings) } func TestLoadDotEnv_NoFile_Cov3(t *testing.T) { tmpDir := t.TempDir() oldDir, _ := os.Getwd() assert.NoError(t, os.Chdir(tmpDir)) defer os.Chdir(oldDir) v := viper.New() loadDotEnv(v, map[string]string{}) } func TestLoadWithEnv_Cov3(t *testing.T) { cfg, err := LoadWithEnv("test") if err != nil { t.Skip("LoadWithEnv requires config files") } _ = cfg } func TestHandleConfigChange_Cov3(t *testing.T) { defer func() { _ = recover() }() r := &ConfigReloader{} r.handleConfigChange(fsnotify.Event{}) }