MCPcopy
hub / github.com/micro/go-micro / TestExtractHandlerDocs

Function TestExtractHandlerDocs

server/comments_test.go:32–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30type TestResponse struct{}
31
32func TestExtractHandlerDocs(t *testing.T) {
33 handler := &TestService{}
34 docs := extractHandlerDocs(handler)
35
36 // Test GetItem extraction
37 if docs["GetItem"] == nil {
38 t.Fatal("GetItem documentation not extracted")
39 }
40 if docs["GetItem"]["description"] == "" {
41 t.Error("GetItem description is empty")
42 }
43 if docs["GetItem"]["example"] != `{"id": "item-123"}` {
44 t.Errorf("GetItem example = %q, want %q", docs["GetItem"]["example"], `{"id": "item-123"}`)
45 }
46
47 // Test CreateItem extraction
48 if docs["CreateItem"] == nil {
49 t.Fatal("CreateItem documentation not extracted")
50 }
51 if docs["CreateItem"]["description"] == "" {
52 t.Error("CreateItem description is empty")
53 }
54 if docs["CreateItem"]["example"] != `{"name": "New Item", "value": 42}` {
55 t.Errorf("CreateItem example = %q, want %q", docs["CreateItem"]["example"], `{"name": "New Item", "value": 42}`)
56 }
57
58 // Test NoDoc (should have no metadata or only empty metadata)
59 if docs["NoDoc"] != nil && len(docs["NoDoc"]) > 0 {
60 t.Logf("NoDoc metadata: %+v", docs["NoDoc"])
61 // Check if all values are empty
62 allEmpty := true
63 for _, v := range docs["NoDoc"] {
64 if v != "" {
65 allEmpty = false
66 break
67 }
68 }
69 if !allEmpty {
70 t.Error("NoDoc should have no metadata with values")
71 }
72 }
73}
74
75func TestNewRpcHandlerAutoExtract(t *testing.T) {
76 handler := NewRpcHandler(&TestService{})

Callers

nothing calls this directly

Calls 5

extractHandlerDocsFunction · 0.85
FatalMethod · 0.80
ErrorMethod · 0.65
LogfMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…