github.com/blend/go-sdk@v1.20220411.3/grpcutil/stream_server_chain_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package grpcutil 9 10 import ( 11 "context" 12 "testing" 13 14 "google.golang.org/grpc" 15 16 "github.com/blend/go-sdk/assert" 17 ) 18 19 func TestStreamServerChain(t *testing.T) { 20 assert := assert.New(t) 21 22 var calls []string 23 combined := StreamServerChain( 24 func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { 25 calls = append(calls, "first") 26 return handler(srv, ss) 27 }, 28 func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { 29 calls = append(calls, "second") 30 return handler(srv, ss) 31 }, 32 func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { 33 calls = append(calls, "third") 34 return handler(srv, ss) 35 }, 36 ) 37 38 err := combined(context.Background(), nil, nil, func(isrv interface{}, istream grpc.ServerStream) error { 39 calls = append(calls, "fourth") 40 return nil 41 }) 42 assert.Nil(err) 43 assert.Equal([]string{"third", "second", "first", "fourth"}, calls) 44 }