@@ -10,6 +10,7 @@ import (
1010 "github.com/netobserv/netobserv-ebpf-agent/pkg/pbflow"
1111 "github.com/stretchr/testify/assert"
1212 "github.com/stretchr/testify/require"
13+ "google.golang.org/grpc"
1314 "google.golang.org/protobuf/types/known/timestamppb"
1415)
1516
@@ -84,6 +85,40 @@ func TestGRPCCommunication(t *testing.T) {
8485 }
8586}
8687
88+ func TestConstructorOptions (t * testing.T ) {
89+ port , err := test .FreeTCPPort ()
90+ require .NoError (t , err )
91+ intercepted := make (chan struct {})
92+ // Override the default GRPC collector to verify that StartCollector is applying the
93+ // passed options
94+ _ , err = StartCollector (port , make (chan * pbflow.Records ),
95+ WithGRPCServerOptions (grpc .UnaryInterceptor (func (
96+ ctx context.Context ,
97+ req interface {},
98+ info * grpc.UnaryServerInfo ,
99+ handler grpc.UnaryHandler ,
100+ ) (resp interface {}, err error ) {
101+ close (intercepted )
102+ return handler (ctx , req )
103+ })))
104+ require .NoError (t , err )
105+ cc , err := ConnectClient (fmt .Sprintf ("127.0.0.1:%d" , port ))
106+ require .NoError (t , err )
107+ client := cc .Client ()
108+
109+ go func () {
110+ _ , err = client .Send (context .Background (),
111+ & pbflow.Records {Entries : []* pbflow.Record {{EthProtocol : 123 , Bytes : 456 }}})
112+ require .NoError (t , err )
113+ }()
114+
115+ select {
116+ case <- intercepted :
117+ case <- time .After (timeout ):
118+ require .Fail (t , "timeout waiting for unary interceptor to work" )
119+ }
120+ }
121+
87122func BenchmarkGRPCCommunication (b * testing.B ) {
88123 port , err := test .FreeTCPPort ()
89124 require .NoError (b , err )
0 commit comments