(t *testing.T)
| 30 | type TestResponse struct{} |
| 31 | |
| 32 | func 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 | |
| 75 | func TestNewRpcHandlerAutoExtract(t *testing.T) { |
| 76 | handler := NewRpcHandler(&TestService{}) |
nothing calls this directly
no test coverage detected
searching dependent graphs…