mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-28 11:30:15 +00:00
- 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
38 lines
839 B
Go
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)
|
|
}
|