Files
gochat/backend/internal/config/coverage3_test.go
T
Rogeeandrogee 2b182f9956 H-300: wire Captain Skills into Web runtime (#48)
* H-300: wire Captain Skills into Web runtime

* H-300: enforce effective model and conservative skill budget

* H-300: fix CI gosec step

* ci: extend golangci-lint timeout

* fix lint findings across backend

* fix(push): resolve delivery protocol blockers

* test(repository): close SQLite test databases

* test(repository): reuse SQLite schema per package

* H-307: restore backend Go cache in CI

* H-307: prefetch modules before cold lint

* H-307: resolve govulncheck security gate

* H-307: build lint with patched Go toolchain

* H-307: clear remaining security scan findings

---------

Co-authored-by: Rogee <rogee@ipao.vip>
2026-08-19 07:08:14 +08:00

93 lines
2.3 KiB
Go

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))
t.Cleanup(func() { assert.NoError(t, 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))
t.Cleanup(func() { assert.NoError(t, 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))
t.Cleanup(func() { assert.NoError(t, 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))
t.Cleanup(func() { assert.NoError(t, 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{})
}