Skip to content

Commit c15aa66

Browse files
committed
test(ingest): add FakeIntentProvider and align NewHandler test calls to new signature
- Create FakeIntentProvider test stub implementing IntentProvider interface - Update all 12 NewHandler calls in handler_test.go to include third IntentProvider argument - Fixes typecheck errors: 'not enough arguments in call to NewHandler' - Signature change: NewHandler(validator, outDir) -> NewHandler(validator, outDir, provider) - All tests now compile and pass basic execution
1 parent 2cd8458 commit c15aa66

2 files changed

Lines changed: 85 additions & 12 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package ingest
2+
3+
import (
4+
"context"
5+
)
6+
7+
// FakeIntentProvider is a test implementation of the IntentProvider interface
8+
// that returns deterministic responses for testing purposes.
9+
type FakeIntentProvider struct {
10+
// ParseResult allows customizing the return value of ParseIntent
11+
ParseResult map[string]interface{}
12+
// ParseError allows customizing the error returned by ParseIntent
13+
ParseError error
14+
// ProviderName allows customizing the name returned by Name()
15+
ProviderName string
16+
}
17+
18+
// NewFakeIntentProvider creates a new FakeIntentProvider with default values
19+
func NewFakeIntentProvider() *FakeIntentProvider {
20+
return &FakeIntentProvider{
21+
ParseResult: map[string]interface{}{
22+
"intent_type": "scaling",
23+
"target": "test-deployment",
24+
"namespace": "default",
25+
"replicas": 3,
26+
"source": "test",
27+
},
28+
ParseError: nil,
29+
ProviderName: "fake",
30+
}
31+
}
32+
33+
// ParseIntent implements the IntentProvider interface
34+
// Returns the configured ParseResult and ParseError
35+
func (f *FakeIntentProvider) ParseIntent(ctx context.Context, text string) (map[string]interface{}, error) {
36+
if f.ParseError != nil {
37+
return nil, f.ParseError
38+
}
39+
40+
// Return a copy to avoid accidental modification
41+
result := make(map[string]interface{})
42+
for k, v := range f.ParseResult {
43+
result[k] = v
44+
}
45+
46+
return result, nil
47+
}
48+
49+
// Name implements the IntentProvider interface
50+
func (f *FakeIntentProvider) Name() string {
51+
if f.ProviderName == "" {
52+
return "fake"
53+
}
54+
return f.ProviderName
55+
}
56+
57+
// WithParseResult allows chaining to set custom parse result
58+
func (f *FakeIntentProvider) WithParseResult(result map[string]interface{}) *FakeIntentProvider {
59+
f.ParseResult = result
60+
return f
61+
}
62+
63+
// WithParseError allows chaining to set custom parse error
64+
func (f *FakeIntentProvider) WithParseError(err error) *FakeIntentProvider {
65+
f.ParseError = err
66+
return f
67+
}
68+
69+
// WithName allows chaining to set custom provider name
70+
func (f *FakeIntentProvider) WithName(name string) *FakeIntentProvider {
71+
f.ProviderName = name
72+
return f
73+
}

internal/ingest/handler_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestNewHandler(t *testing.T) {
3636
outDir := filepath.Join(tempDir, "handoff")
3737

3838
mockValidator := &MockValidator{}
39-
handler := NewHandler(mockValidator, outDir)
39+
handler := NewHandler(mockValidator, outDir, NewFakeIntentProvider())
4040

4141
if handler == nil {
4242
t.Fatal("Expected non-nil handler")
@@ -59,7 +59,7 @@ func TestNewHandler(t *testing.T) {
5959
func TestHandleIntent_MethodNotAllowed(t *testing.T) {
6060
tempDir := t.TempDir()
6161
mockValidator := &MockValidator{}
62-
handler := NewHandler(mockValidator, tempDir)
62+
handler := NewHandler(mockValidator, tempDir, NewFakeIntentProvider())
6363

6464
methods := []string{"GET", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"}
6565

@@ -80,7 +80,7 @@ func TestHandleIntent_MethodNotAllowed(t *testing.T) {
8080
func TestHandleIntent_JSONInput_Success(t *testing.T) {
8181
tempDir := t.TempDir()
8282
mockValidator := &MockValidator{}
83-
handler := NewHandler(mockValidator, tempDir)
83+
handler := NewHandler(mockValidator, tempDir, NewFakeIntentProvider())
8484

8585
tests := []struct {
8686
name string
@@ -210,7 +210,7 @@ func TestHandleIntent_JSONInput_Success(t *testing.T) {
210210
func TestHandleIntent_PlainTextInput_Success(t *testing.T) {
211211
tempDir := t.TempDir()
212212
mockValidator := &MockValidator{}
213-
handler := NewHandler(mockValidator, tempDir)
213+
handler := NewHandler(mockValidator, tempDir, NewFakeIntentProvider())
214214

215215
tests := []struct {
216216
name string
@@ -306,7 +306,7 @@ func TestHandleIntent_PlainTextInput_Success(t *testing.T) {
306306
func TestHandleIntent_PlainTextInput_BadFormat(t *testing.T) {
307307
tempDir := t.TempDir()
308308
mockValidator := &MockValidator{}
309-
handler := NewHandler(mockValidator, tempDir)
309+
handler := NewHandler(mockValidator, tempDir, NewFakeIntentProvider())
310310

311311
tests := []struct {
312312
name string
@@ -366,7 +366,7 @@ func TestHandleIntent_PlainTextInput_BadFormat(t *testing.T) {
366366
func TestHandleIntent_UnsupportedContentType(t *testing.T) {
367367
tempDir := t.TempDir()
368368
mockValidator := &MockValidator{}
369-
handler := NewHandler(mockValidator, tempDir)
369+
handler := NewHandler(mockValidator, tempDir, NewFakeIntentProvider())
370370

371371
tests := []struct {
372372
name string
@@ -402,7 +402,7 @@ func TestHandleIntent_UnsupportedContentType(t *testing.T) {
402402
func TestHandleIntent_ValidationError(t *testing.T) {
403403
tempDir := t.TempDir()
404404
mockValidator := &MockValidator{}
405-
handler := NewHandler(mockValidator, tempDir)
405+
handler := NewHandler(mockValidator, tempDir, NewFakeIntentProvider())
406406

407407
tests := []struct {
408408
name string
@@ -472,7 +472,7 @@ func TestHandleIntent_FileWriteError(t *testing.T) {
472472
os.MkdirAll(readOnlyDir, 0o444) // Create read-only directory
473473

474474
mockValidator := &MockValidator{}
475-
handler := NewHandler(mockValidator, readOnlyDir)
475+
handler := NewHandler(mockValidator, readOnlyDir, NewFakeIntentProvider())
476476

477477
// Mock successful validation
478478
mockValidator.ValidateBytesFunc = func(b []byte) (*Intent, error) {
@@ -505,7 +505,7 @@ func TestHandleIntent_FileWriteError(t *testing.T) {
505505
func TestHandleIntent_FileCreation(t *testing.T) {
506506
tempDir := t.TempDir()
507507
mockValidator := &MockValidator{}
508-
handler := NewHandler(mockValidator, tempDir)
508+
handler := NewHandler(mockValidator, tempDir, NewFakeIntentProvider())
509509

510510
payload := `{"intent_type": "scaling", "target": "test-deployment", "namespace": "default", "replicas": 3}`
511511

@@ -563,7 +563,7 @@ func TestHandleIntent_FileCreation(t *testing.T) {
563563
func TestHandleIntent_ConcurrentRequests(t *testing.T) {
564564
tempDir := t.TempDir()
565565
mockValidator := &MockValidator{}
566-
handler := NewHandler(mockValidator, tempDir)
566+
handler := NewHandler(mockValidator, tempDir, NewFakeIntentProvider())
567567

568568
const numRequests = 5 // Reduced to minimize timestamp collisions
569569
results := make(chan int, numRequests)
@@ -620,7 +620,7 @@ func TestHandleIntent_ConcurrentRequests(t *testing.T) {
620620
func TestHandleIntent_CorrelationIdPassthrough(t *testing.T) {
621621
tempDir := t.TempDir()
622622
mockValidator := &MockValidator{}
623-
handler := NewHandler(mockValidator, tempDir)
623+
handler := NewHandler(mockValidator, tempDir, NewFakeIntentProvider())
624624

625625
correlationID := "test-correlation-123"
626626
payload := fmt.Sprintf(`{
@@ -667,7 +667,7 @@ func TestHandleIntent_CorrelationIdPassthrough(t *testing.T) {
667667
func TestHandleIntent_EdgeCases(t *testing.T) {
668668
tempDir := t.TempDir()
669669
mockValidator := &MockValidator{}
670-
handler := NewHandler(mockValidator, tempDir)
670+
handler := NewHandler(mockValidator, tempDir, NewFakeIntentProvider())
671671

672672
tests := []struct {
673673
name string

0 commit comments

Comments
 (0)