@@ -176,6 +176,26 @@ func TestAPIServerInvokeAPIRouteStream(t *testing.T) {
176176 assert .Equal (t , "a stream!" , string (res .Body ()))
177177}
178178
179+ func TestAPIServerInvokeAPIRouteLiveness (t * testing.T ) {
180+ _ , as , done := newTestAPIServer (t , true )
181+ defer done ()
182+
183+ <- as .Started ()
184+
185+ res , err := resty .New ().R ().Get (fmt .Sprintf ("%s/livez" , as .MonitoringPublicURL ()))
186+ assert .NoError (t , err )
187+ assert .Equal (t , 200 , res .StatusCode ()) // note this should really be 204, but not changing as would change behavior
188+ }
189+
190+ func TestAPIServerPanicsMisConfig (t * testing.T ) {
191+ assert .Panics (t , func () {
192+ _ = NewAPIServer (context .Background (), APIServerOptions [any ]{})
193+ })
194+ assert .Panics (t , func () {
195+ _ = NewAPIServer (context .Background (), APIServerOptions [any ]{APIConfig : config .RootSection ("any" )})
196+ })
197+ }
198+
179199func TestAPIServerInvokeAPIRouteJSON (t * testing.T ) {
180200 um , as , done := newTestAPIServer (t , true )
181201 defer done ()
@@ -342,6 +362,19 @@ func TestAPIServerInvokeEnrichFailForm(t *testing.T) {
342362 assert .Equal (t , 500 , res .StatusCode ())
343363}
344364
365+ func TestAPIServerInvokeEnrichFailStream (t * testing.T ) {
366+ um , as , done := newTestAPIServer (t , true )
367+ defer done ()
368+
369+ um .mockEnrichErr = fmt .Errorf ("pop" )
370+ <- as .Started ()
371+
372+ res , err := resty .New ().R ().
373+ Get (fmt .Sprintf ("%s/api/v1/ut/utresource/id12345/getit" , as .APIPublicURL ()))
374+ assert .NoError (t , err )
375+ assert .Equal (t , 500 , res .StatusCode ())
376+ }
377+
345378func TestAPIServer404 (t * testing.T ) {
346379 _ , as , done := newTestAPIServer (t , true )
347380 defer done ()
@@ -397,6 +430,45 @@ func TestAPIServerFailServeMonitoring(t *testing.T) {
397430
398431}
399432
433+ func TestAPIServerFailServeMonitoringBadRouteSlash (t * testing.T ) {
434+ _ , as , done := newTestAPIServer (t , false )
435+ defer done ()
436+
437+ as .MonitoringConfig .Set (httpserver .HTTPConfAddress , "127.0.0.1:0" )
438+ as .MonitoringRoutes = []* Route {
439+ {Path : "right" , Extensions : & APIServerRouteExt [* utManager ]{}},
440+ {Path : "/wrong" },
441+ }
442+ err := as .Serve (context .Background ())
443+ assert .Regexp (t , "FF00255" , err )
444+
445+ // Check we still closed the started channel
446+ <- as .Started ()
447+
448+ }
449+
450+ func TestAPIServerFailServeBadRouteSlash (t * testing.T ) {
451+ _ , as , done := newTestAPIServer (t , false )
452+ defer done ()
453+
454+ as .Routes = []* Route {
455+ {
456+ Path : "/wrong" ,
457+ Extensions : & APIServerRouteExt [* utManager ]{
458+ JSONHandler : func (a * APIRequest , um * utManager ) (output interface {}, err error ) {
459+ return nil , nil
460+ },
461+ },
462+ },
463+ }
464+ err := as .Serve (context .Background ())
465+ assert .Regexp (t , "FF00255" , err )
466+
467+ // Check we still closed the started channel
468+ <- as .Started ()
469+
470+ }
471+
400472func TestWaitForServerStop (t * testing.T ) {
401473 _ , as , done := newTestAPIServer (t , false )
402474 defer done ()
@@ -611,6 +683,7 @@ func TestVersionedAPIInitErrors(t *testing.T) {
611683 err = as .Serve (ctx )
612684 assert .Error (t , err )
613685 assert .Regexp (t , "FF00253" , err )
686+
614687 as = NewAPIServer (ctx , APIServerOptions [* utManager ]{
615688 MetricsRegistry : metric .NewPrometheusMetricsRegistry ("ut" ),
616689 VersionedAPIs : & VersionedAPIs {
@@ -633,4 +706,32 @@ func TestVersionedAPIInitErrors(t *testing.T) {
633706 assert .Error (t , err )
634707 assert .Regexp (t , "FF00254" , err )
635708
709+ as = NewAPIServer (ctx , APIServerOptions [* utManager ]{
710+ MetricsRegistry : metric .NewPrometheusMetricsRegistry ("ut" ),
711+ VersionedAPIs : & VersionedAPIs {
712+ DefaultVersion : "unknown" ,
713+ APIVersions : map [string ]* APIVersion {
714+ "v1" : {
715+ Routes : []* Route {
716+ {
717+ Path : "/wrong" ,
718+ Extensions : & APIServerRouteExt [* utManager ]{
719+ JSONHandler : func (r * APIRequest , um * utManager ) (output interface {}, err error ) {
720+ return nil , nil
721+ },
722+ },
723+ },
724+ },
725+ },
726+ },
727+ },
728+ Description : "unit testing" ,
729+ APIConfig : apiConfig ,
730+ MonitoringConfig : monitoringConfig ,
731+ })
732+
733+ err = as .Serve (ctx )
734+ assert .Error (t , err )
735+ assert .Regexp (t , "FF00255" , err )
736+
636737}
0 commit comments