Files
ntfy-discord/internal/config/fuzz_test.go
Billy D. 1c1a9cc35f
Some checks failed
CI / Lint (push) Successful in 58s
CI / Test (push) Successful in 1m15s
CI / Release (push) Successful in 6s
CI / Docker Build & Push (push) Failing after 23s
CI / Notify (push) Successful in 1s
fix: add golangci-lint config and fix all lint errors
- Add .golangci.yml with v2 config (errcheck, govet, staticcheck, misspell, etc.)
- Fix 32 errcheck issues across config, discord, ntfy, server packages
- Fix misspelling: cancelled → canceled
- Fix staticcheck: use append(slice...) instead of loop
- Fix staticcheck: remove empty error branch
- Use t.Setenv instead of os.Setenv/Unsetenv in tests
- Update CI workflow: add lint job, release tagging, ntfy notifications
2026-02-14 09:15:01 -05:00

70 lines
1.3 KiB
Go

package config
import (
"testing"
)
// FuzzParseTopics tests topic parsing doesn't panic on arbitrary input
func FuzzParseTopics(f *testing.F) {
// Normal cases
f.Add("alerts")
f.Add("alerts,updates")
f.Add("alerts, updates, notifications")
f.Add("")
// Edge cases
f.Add(",,,")
f.Add(" , , ")
f.Add("a]topic-with-special_chars.123")
f.Add("\x00\x00\x00")
f.Add("topic\nwith\nnewlines")
f.Fuzz(func(t *testing.T, input string) {
// Simulate topic parsing logic
if input == "" {
return
}
topics := append([]string{}, splitAndTrim(input)...)
// Accessing results should not panic
_ = len(topics)
})
}
// splitAndTrim mimics the topic parsing in Load()
func splitAndTrim(s string) []string {
if s == "" {
return nil
}
var result []string
start := 0
for i := 0; i < len(s); i++ {
if s[i] == ',' {
part := trimSpace(s[start:i])
if part != "" {
result = append(result, part)
}
start = i + 1
}
}
// Last part
part := trimSpace(s[start:])
if part != "" {
result = append(result, part)
}
return result
}
func trimSpace(s string) string {
start := 0
end := len(s)
for start < end && (s[start] == ' ' || s[start] == '\t' || s[start] == '\n' || s[start] == '\r') {
start++
}
for end > start && (s[end-1] == ' ' || s[end-1] == '\t' || s[end-1] == '\n' || s[end-1] == '\r') {
end--
}
return s[start:end]
}