Pulse/internal/config/persistence_alerts_extra_test.go
rcourtman ed78509f92 Fix flaky tests and improve coverage across alerts, api, and config packages
- Fix deadlock and race conditions in internal/alerts
- Add comprehensive error path tests for internal/config
- Fix 401 handling in internal/api
- Fix Docker Swarm task filtering test logic
2026-01-03 18:36:17 +00:00

38 lines
839 B
Go

package config
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLoadAlertConfig_ReadError(t *testing.T) {
if os.Getuid() == 0 {
t.Skip("Skipping as root")
}
tempDir := t.TempDir()
cp := NewConfigPersistence(tempDir)
// Create unreadable alerts.json
path := filepath.Join(tempDir, "alerts.json")
require.NoError(t, os.WriteFile(path, []byte("{}"), 0000))
cfg, err := cp.LoadAlertConfig()
assert.Error(t, err)
assert.Nil(t, cfg)
}
func TestLoadAlertConfig_UnmarshalError(t *testing.T) {
tempDir := t.TempDir()
cp := NewConfigPersistence(tempDir)
path := filepath.Join(tempDir, "alerts.json")
require.NoError(t, os.WriteFile(path, []byte("{invalid"), 0644))
cfg, err := cp.LoadAlertConfig()
assert.Error(t, err)
assert.Nil(t, cfg)
}