@@ -373,6 +373,42 @@ func TestServerCapabilities(t *testing.T) {
373373 }
374374}
375375
376+ func TestServerAddResourceTemplate (t * testing.T ) {
377+ tests := []struct {
378+ name string
379+ template string
380+ expectPanic bool
381+ }{
382+ {"ValidFileTemplate" , "file:///{a}/{b}" , false },
383+ {"ValidCustomScheme" , "myproto:///{a}" , false },
384+ {"MissingScheme1" , "://example.com/{path}" , true },
385+ {"MissingScheme2" , "/api/v1/users/{id}" , true },
386+ {"EmptyVariable" , "file:///{}/{b}" , true },
387+ {"UnclosedVariable" , "file:///{a" , true },
388+ }
389+
390+ for _ , tt := range tests {
391+ t .Run (tt .name , func (t * testing.T ) {
392+ rt := ResourceTemplate {URITemplate : tt .template }
393+
394+ defer func () {
395+ if r := recover (); r != nil {
396+ if ! tt .expectPanic {
397+ t .Errorf ("%s: unexpected panic: %v" , tt .name , r )
398+ }
399+ } else {
400+ if tt .expectPanic {
401+ t .Errorf ("%s: expected panic but did not panic" , tt .name )
402+ }
403+ }
404+ }()
405+
406+ s := NewServer (testImpl , nil )
407+ s .AddResourceTemplate (& rt , nil )
408+ })
409+ }
410+ }
411+
376412// TestServerSessionkeepaliveCancelOverwritten is to verify that `ServerSession.keepaliveCancel` is assigned exactly once,
377413// ensuring that only a single goroutine is responsible for the session's keepalive ping mechanism.
378414func TestServerSessionkeepaliveCancelOverwritten (t * testing.T ) {
0 commit comments