MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / TestServerAddResourceTemplate

Function TestServerAddResourceTemplate

mcp/server_test.go:477–509  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

475}
476
477func TestServerAddResourceTemplate(t *testing.T) {
478 tests := []struct {
479 name string
480 template string
481 expectPanic bool
482 }{
483 {"ValidFileTemplate", "file:///{a}/{b}", false},
484 {"ValidCustomScheme", "myproto:///{a}", false},
485 {"EmptyVariable", "file:///{}/{b}", true},
486 {"UnclosedVariable", "file:///{a", true},
487 }
488
489 for _, tt := range tests {
490 t.Run(tt.name, func(t *testing.T) {
491 rt := ResourceTemplate{URITemplate: tt.template}
492
493 defer func() {
494 if r := recover(); r != nil {
495 if !tt.expectPanic {
496 t.Errorf("%s: unexpected panic: %v", tt.name, r)
497 }
498 } else {
499 if tt.expectPanic {
500 t.Errorf("%s: expected panic but did not panic", tt.name)
501 }
502 }
503 }()
504
505 s := NewServer(testImpl, nil)
506 s.AddResourceTemplate(&rt, nil)
507 })
508 }
509}
510
511// panicks reports whether f() panics.
512func panics(f func()) (b bool) {

Callers

nothing calls this directly

Calls 3

AddResourceTemplateMethod · 0.95
NewServerFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…