Pulse/internal/config/persistence_suppressions_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

34 lines
813 B
Go

package config
import (
"errors"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoadEnvTokenSuppressions_Branches(t *testing.T) {
tempDir := t.TempDir()
cp := NewConfigPersistence(tempDir)
suppFile := filepath.Join(tempDir, "env_token_suppressions.json")
// 1. ReadFile error
mfs := &mockFSError{FileSystem: defaultFileSystem{}, readError: errors.New("read error")}
cp.SetFileSystem(mfs)
_, err := cp.LoadEnvTokenSuppressions()
assert.Error(t, err)
mfs.readError = nil
// 2. Empty data
os.WriteFile(suppFile, []byte(""), 0600)
hashes, err := cp.LoadEnvTokenSuppressions()
assert.NoError(t, err)
assert.Empty(t, hashes)
// 3. Unmarshal error
os.WriteFile(suppFile, []byte("not-json"), 0600)
_, err = cp.LoadEnvTokenSuppressions()
assert.Error(t, err)
}