test(config): add comprehensive tests for config loading path
All checks were successful
check / check (push) Successful in 43s
All checks were successful
check / check (push) Successful in 43s
Add tests covering the main configuration loading path which was previously untested (only ClassifyTargets and PSL logic had tests). New test coverage: - New() constructor with default values, env overrides, and error cases - buildConfig() interval parsing with fallback to defaults on invalid input - setupViper() env prefix binding and default value registration - parseCSV() edge cases: whitespace, trailing/leading commas, empty segments - configureDebugLogging() debug mode activation - StatePath() path construction with various DataDir values - ErrNoTargets sentinel error for missing/empty targets - PORT env without DNSWATCHER_ prefix (compatibility) - Target classification into domains vs hostnames via PSL - Invalid targets (public suffixes) rejected with clear error Coverage for internal/config increased from 23% to 92.5%.
This commit is contained in:
44
internal/config/parsecsv_test.go
Normal file
44
internal/config/parsecsv_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"sneak.berlin/go/dnswatcher/internal/config"
|
||||
)
|
||||
|
||||
func TestParseCSV(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want []string
|
||||
}{
|
||||
{"empty string", "", nil},
|
||||
{"single value", "a", []string{"a"}},
|
||||
{"multiple values", "a,b,c", []string{"a", "b", "c"}},
|
||||
{"whitespace trimmed", " a , b ", []string{"a", "b"}},
|
||||
{"trailing comma", "a,b,", []string{"a", "b"}},
|
||||
{"leading comma", ",a,b", []string{"a", "b"}},
|
||||
{"consecutive commas", "a,,b", []string{"a", "b"}},
|
||||
{"all empty segments", ",,,", nil},
|
||||
{"whitespace only", " , , ", nil},
|
||||
{"tabs", "\ta\t,\tb\t", []string{"a", "b"}},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
got := config.ParseCSVForTest(tt.input)
|
||||
require.Len(t, got, len(tt.want))
|
||||
|
||||
for i, w := range tt.want {
|
||||
assert.Equal(t, w, got[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user