All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Add auth-svc /validate endpoint for token checking Add chat-svc with auth client and Redis task queue Add worker-svc chat handler for task processing Co-Authored-By: Claude Code <claude@anthropic.com>
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package taskqueue
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"testing"
|
|
|
|
"git.threesix.ai/jordan/sp4-debug-1770477266/pkg/logging"
|
|
"git.threesix.ai/jordan/sp4-debug-1770477266/pkg/queue"
|
|
)
|
|
|
|
// mockProducer implements queue.Producer for testing.
|
|
type mockProducer struct {
|
|
mu sync.Mutex
|
|
jobs []queue.Job
|
|
}
|
|
|
|
func (m *mockProducer) Enqueue(ctx context.Context, jobType string, payload map[string]any) (string, error) {
|
|
return m.EnqueueWithOptions(ctx, queue.Job{
|
|
Type: jobType,
|
|
Payload: payload,
|
|
})
|
|
}
|
|
|
|
func (m *mockProducer) EnqueueWithOptions(ctx context.Context, job queue.Job) (string, error) {
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
job.ID = "test-job-id"
|
|
m.jobs = append(m.jobs, job)
|
|
return job.ID, nil
|
|
}
|
|
|
|
func TestProducer_EnqueueChatProcess(t *testing.T) {
|
|
mock := &mockProducer{}
|
|
producer := NewProducer(mock, logging.Nop())
|
|
|
|
jobID, err := producer.EnqueueChatProcess(context.Background(), "user-123", "Hello world")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if jobID != "test-job-id" {
|
|
t.Errorf("expected job ID 'test-job-id', got '%s'", jobID)
|
|
}
|
|
|
|
if len(mock.jobs) != 1 {
|
|
t.Fatalf("expected 1 job, got %d", len(mock.jobs))
|
|
}
|
|
|
|
job := mock.jobs[0]
|
|
if job.Type != JobTypeChatProcess {
|
|
t.Errorf("expected job type '%s', got '%s'", JobTypeChatProcess, job.Type)
|
|
}
|
|
if job.Payload["user_id"] != "user-123" {
|
|
t.Errorf("expected user_id 'user-123', got '%v'", job.Payload["user_id"])
|
|
}
|
|
if job.Payload["message"] != "Hello world" {
|
|
t.Errorf("expected message 'Hello world', got '%v'", job.Payload["message"])
|
|
}
|
|
}
|