(t *testing.T)
| 475 | } |
| 476 | |
| 477 | func 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. |
| 512 | func panics(f func()) (b bool) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…