feat(09-01): add Engine with parallel fanout and ExampleSource
- Engine.Register/List/SweepAll with ants pool fanout - ExampleSource emits two deterministic findings (SourceType=recon:example) - Tests cover Register/List idempotency, SweepAll aggregation, empty-registry, and Enabled() filtering
This commit is contained in:
57
pkg/recon/engine_test.go
Normal file
57
pkg/recon/engine_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package recon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRegisterList(t *testing.T) {
|
||||
e := NewEngine()
|
||||
require.Empty(t, e.List())
|
||||
|
||||
e.Register(ExampleSource{})
|
||||
require.Equal(t, []string{"example"}, e.List())
|
||||
|
||||
// Re-registering the same name is idempotent.
|
||||
e.Register(ExampleSource{})
|
||||
require.Equal(t, []string{"example"}, e.List())
|
||||
}
|
||||
|
||||
func TestSweepAll(t *testing.T) {
|
||||
e := NewEngine()
|
||||
e.Register(ExampleSource{})
|
||||
|
||||
findings, err := e.SweepAll(context.Background(), Config{Query: "ignored"})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, findings, 2, "ExampleSource should emit exactly 2 deterministic findings")
|
||||
|
||||
for _, f := range findings {
|
||||
require.Equal(t, "recon:example", f.SourceType)
|
||||
require.NotEmpty(t, f.ProviderName)
|
||||
require.NotEmpty(t, f.KeyMasked)
|
||||
require.NotEmpty(t, f.Source)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSweepAll_NoSources(t *testing.T) {
|
||||
e := NewEngine()
|
||||
findings, err := e.SweepAll(context.Background(), Config{})
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, findings)
|
||||
}
|
||||
|
||||
// disabledSource tests that Enabled() filtering works.
|
||||
type disabledSource struct{ ExampleSource }
|
||||
|
||||
func (disabledSource) Name() string { return "disabled" }
|
||||
func (disabledSource) Enabled(Config) bool { return false }
|
||||
|
||||
func TestSweepAll_FiltersDisabled(t *testing.T) {
|
||||
e := NewEngine()
|
||||
e.Register(disabledSource{})
|
||||
findings, err := e.SweepAll(context.Background(), Config{})
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, findings)
|
||||
}
|
||||
Reference in New Issue
Block a user