MCPcopy
hub / github.com/gofiber/fiber / Test_LBClientTransport_StreamResponseBody

Function Test_LBClientTransport_StreamResponseBody

client/transport_test.go:411–466  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

409}
410
411func Test_LBClientTransport_StreamResponseBody(t *testing.T) {
412 t.Parallel()
413
414 t.Run("empty clients", func(t *testing.T) {
415 t.Parallel()
416 lbClient := &fasthttp.LBClient{
417 Clients: []fasthttp.BalancingClient{},
418 }
419 transport := newLBClientTransport(lbClient)
420 require.False(t, transport.StreamResponseBody())
421 })
422
423 t.Run("single host client", func(t *testing.T) {
424 t.Parallel()
425 hostClient := &fasthttp.HostClient{Addr: "example.com:80"}
426 lbClient := &fasthttp.LBClient{
427 Clients: []fasthttp.BalancingClient{hostClient},
428 }
429 transport := newLBClientTransport(lbClient)
430
431 // Test default
432 require.False(t, transport.StreamResponseBody())
433
434 // Enable streaming
435 transport.SetStreamResponseBody(true)
436 require.True(t, transport.StreamResponseBody())
437 require.True(t, hostClient.StreamResponseBody)
438
439 // Disable streaming
440 transport.SetStreamResponseBody(false)
441 require.False(t, transport.StreamResponseBody())
442 require.False(t, hostClient.StreamResponseBody)
443 })
444
445 t.Run("multiple host clients", func(t *testing.T) {
446 t.Parallel()
447 hostClient1 := &fasthttp.HostClient{Addr: "example1.com:80"}
448 hostClient2 := &fasthttp.HostClient{Addr: "example2.com:80"}
449 lbClient := &fasthttp.LBClient{
450 Clients: []fasthttp.BalancingClient{hostClient1, hostClient2},
451 }
452 transport := newLBClientTransport(lbClient)
453
454 // Enable streaming on all clients
455 transport.SetStreamResponseBody(true)
456 require.True(t, transport.StreamResponseBody())
457 require.True(t, hostClient1.StreamResponseBody)
458 require.True(t, hostClient2.StreamResponseBody)
459
460 // Disable streaming on all clients
461 transport.SetStreamResponseBody(false)
462 require.False(t, transport.StreamResponseBody())
463 require.False(t, hostClient1.StreamResponseBody)
464 require.False(t, hostClient2.StreamResponseBody)
465 })
466}
467
468func Test_httpClientTransport_Interface(t *testing.T) {

Callers

nothing calls this directly

Calls 3

newLBClientTransportFunction · 0.85
StreamResponseBodyMethod · 0.65
SetStreamResponseBodyMethod · 0.65

Tested by

no test coverage detected