项目文件夹

文件
Claude 310cee61f9
Run Tests / Unit Tests (push) Has been cancelled
Run Tests / Etcd Integration Tests (push) Has been cancelled
fix: address top 8 developer experience gaps
- Add README for multi-service example explaining modular monolith pattern
- Add pubsub-events example with broker and event streaming demos
- Add grpc-integration example showing gRPC server/client with JSON codec
- Update examples/README.md to replace "Coming Soon" with real examples
- Add tests for core packages: micro.go and service/service.go
- Add micro doctor diagnostic command (Go, registry, ports, NATS, config)
- Fix micro gen templates: replace TODO stubs with real implementation logic
- Add consul and etcd registry support to micro mcp serve/test commands
- Make file watcher configurable: extensions, excludes, go.mod watching
- Add watcher tests

https://claude.ai/code/session_01VwPw7hMaVhFfT69oCE6x1D
2026-03-12 09:16:54 +00:00

71 行
1.5 KiB
Go

package micro
import (
"context"
"testing"
)
func TestNew(t *testing.T) {
svc := New("test-service")
if svc == nil {
t.Fatal("New returned nil")
}
if svc.Name() != "test-service" {
t.Errorf("Name() = %q, want %q", svc.Name(), "test-service")
}
}
func TestNewWithAddress(t *testing.T) {
svc := New("test-service", Address(":0"))
if svc == nil {
t.Fatal("New returned nil")
}
if svc.Name() != "test-service" {
t.Errorf("Name() = %q, want %q", svc.Name(), "test-service")
}
}
func TestNewGroup(t *testing.T) {
svc1 := New("svc1", Address(":0"))
svc2 := New("svc2", Address(":0"))
g := NewGroup(svc1, svc2)
if g == nil {
t.Fatal("NewGroup returned nil")
}
}
func TestNewContext(t *testing.T) {
svc := New("ctx-test")
ctx := NewContext(context.Background(), svc)
got, ok := FromContext(ctx)
if !ok {
t.Fatal("FromContext returned false")
}
if got.Name() != "ctx-test" {
t.Errorf("FromContext Name() = %q, want %q", got.Name(), "ctx-test")
}
}
func TestFromContextEmpty(t *testing.T) {
_, ok := FromContext(context.Background())
if ok {
t.Error("FromContext on empty context should return false")
}
}
func TestNewEvent(t *testing.T) {
ev := NewEvent("test.topic", nil)
if ev == nil {
t.Fatal("NewEvent returned nil")
}
}
func TestRegisterHandler(t *testing.T) {
svc := New("handler-test", Address(":0"))
type Handler struct{}
err := RegisterHandler(svc.Server(), &Handler{})
if err != nil {
t.Fatalf("RegisterHandler failed: %v", err)
}
}