项目文件夹

文件
Asim Aslam 4311b73361 Enhance ADK vs Go Micro comparison and apply lint fixes (#2994)
* docs: compare Go Micro with Google ADK in the comparison guide

Adds a 'vs Agent Frameworks (Google ADK)' section: ADK builds an agent,
Go Micro builds the distributed system the agent lives in (agents are
services in the mesh). Covers the category difference, a feature table,
when to choose each, and MCP/A2A interoperability.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* docs: replace ADK comparison slogan with concrete explanation

State plainly what each tool provides (ADK builds an agent process; Go Micro
builds the surrounding service mesh) instead of marketing phrasing.

* lint: apply golangci-lint autofixes; exclude ST1003 and demo errcheck

Mechanical, behaviour-preserving fixes applied by 'golangci-lint run --fix':
gofmt, misspell (US spelling), usestdlibvars (http.Method*/Status*), unconvert,
and the auto-fixable staticcheck simplifications (QF*, S1017/S1019/S1023/S1039).

Config: exclude ST1003 (remaining offenders are exported API renames, e.g.
web.Id, which would break compatibility) and skip errcheck for examples/ and
internal/harness/ (demo code where fire-and-forget is intentional).

Build and test compilation verified.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

* lint: WIP cleanup checkpoint (errcheck config + partial fixes)

Checkpoint of an in-progress golangci-lint cleanup (background pass). Builds
cleanly; lint is not yet zero. Follow-up commit will complete the cleanup and
switch CI to a blocking full-tree lint.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmdEY7pYmV5zzwCjNJ4ykL

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-22 17:21:47 +01:00

138 行
3.0 KiB
Go

package web
import (
"bufio"
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
)
func TestSSEBroadcaster_Basic(t *testing.T) {
// Create broadcaster
b := NewSSEBroadcaster()
if err := b.Start(); err != nil {
t.Fatalf("Failed to start broadcaster: %v", err)
}
defer b.Stop()
// Create test server
server := httptest.NewServer(b.Handler())
defer server.Close()
// Connect client
resp, err := http.Get(server.URL)
if err != nil {
t.Fatalf("Failed to connect: %v", err)
}
defer resp.Body.Close()
// Check headers
if ct := resp.Header.Get("Content-Type"); ct != "text/event-stream" {
t.Errorf("Expected Content-Type text/event-stream, got %s", ct)
}
// Read initial connection event
reader := bufio.NewReader(resp.Body)
line, err := reader.ReadString('\n')
if err != nil {
t.Fatalf("Failed to read: %v", err)
}
if !strings.HasPrefix(line, "event: connected") {
t.Errorf("Expected connected event, got: %s", line)
}
}
func TestSSEBroadcaster_BroadcastEvent(t *testing.T) {
b := NewSSEBroadcaster()
if err := b.Start(); err != nil {
t.Fatalf("Failed to start broadcaster: %v", err)
}
defer b.Stop()
server := httptest.NewServer(b.Handler())
defer server.Close()
// Connect client
resp, err := http.Get(server.URL)
if err != nil {
t.Fatalf("Failed to connect: %v", err)
}
defer resp.Body.Close()
// Wait for client to register
time.Sleep(50 * time.Millisecond)
// Broadcast an event
testData := map[string]string{"message": "hello"}
if err := b.BroadcastEvent("test", testData); err != nil {
t.Fatalf("Failed to broadcast: %v", err)
}
// Read and verify
reader := bufio.NewReader(resp.Body)
// Skip connection event
for i := 0; i < 3; i++ {
reader.ReadString('\n')
}
// Read broadcast event
line, _ := reader.ReadString('\n')
if !strings.HasPrefix(line, "data:") {
t.Errorf("Expected data line, got: %s", line)
}
// Parse the data
dataStr := strings.TrimPrefix(line, "data: ")
dataStr = strings.TrimSpace(dataStr)
var event SSEEvent
if err := json.Unmarshal([]byte(dataStr), &event); err != nil {
t.Fatalf("Failed to parse event: %v", err)
}
if event.Event != "test" {
t.Errorf("Expected event type 'test', got '%s'", event.Event)
}
}
func TestSSEBroadcaster_ClientCount(t *testing.T) {
b := NewSSEBroadcaster()
if err := b.Start(); err != nil {
t.Fatalf("Failed to start broadcaster: %v", err)
}
defer b.Stop()
server := httptest.NewServer(b.Handler())
defer server.Close()
if count := b.ClientCount(); count != 0 {
t.Errorf("Expected 0 clients, got %d", count)
}
// Connect a client
resp, err := http.Get(server.URL)
if err != nil {
t.Fatalf("Failed to connect: %v", err)
}
// Wait for registration
time.Sleep(50 * time.Millisecond)
if count := b.ClientCount(); count != 1 {
t.Errorf("Expected 1 client, got %d", count)
}
resp.Body.Close()
// Wait for unregistration
time.Sleep(50 * time.Millisecond)
if count := b.ClientCount(); count != 0 {
t.Errorf("Expected 0 clients after disconnect, got %d", count)
}
}