@@ -14,6 +14,7 @@ import (
1414 "google.golang.org/grpc/metadata"
1515 "google.golang.org/protobuf/proto"
1616
17+ "github.com/smartcontractkit/chainlink-common/pkg/chipingress/mocks"
1718 "github.com/smartcontractkit/chainlink-common/pkg/chipingress/pb"
1819)
1920
@@ -56,6 +57,33 @@ func TestClient(t *testing.T) {
5657 assert .NotNil (t , client )
5758 })
5859
60+ t .Run ("NoopClient" , func (t * testing.T ) {
61+ client := & NoopClient {}
62+ assert .NotNil (t , client )
63+
64+ // Test that it implements the Client interface
65+ var _ Client = client
66+
67+ // Test Close returns no error
68+ err := client .Close ()
69+ assert .NoError (t , err )
70+
71+ // Test Ping returns success
72+ pingResp , err := client .Ping (context .Background (), & pb.EmptyRequest {})
73+ assert .NoError (t , err )
74+ assert .NotNil (t , pingResp )
75+ assert .Equal (t , "pong" , pingResp .Message )
76+
77+ // Test RegisterSchemas returns empty map
78+ schemas := []* pb.Schema {
79+ {Subject : "test" , Schema : `{"test":"value"}` , Format : 1 },
80+ }
81+ result , err := client .RegisterSchemas (context .Background (), schemas ... )
82+ assert .NoError (t , err )
83+ assert .NotNil (t , result )
84+ assert .Empty (t , result )
85+ })
86+
5987}
6088
6189func TestNewEvent (t * testing.T ) {
@@ -619,3 +647,62 @@ func TestNewClientWithTLS(t *testing.T) {
619647 assert .NotNil (t , client )
620648 }
621649}
650+
651+ func TestClient_RegisterSchemas (t * testing.T ) {
652+ t .Run ("successfully registers schemas" , func (t * testing.T ) {
653+ mockClient := mocks .NewClient (t )
654+ mockClient .EXPECT ().RegisterSchema (
655+ context .Background (),
656+ & pb.RegisterSchemaRequest {
657+ Schemas : []* pb.Schema {
658+ {Subject : "schema1" , Schema : `{"type":"record","name":"Test","fields":[{"name":"field1"}]}` , Format : 1 },
659+ {Subject : "schema2" , Schema : `{"type":"record","name":"Test2","fields":[{"name":"field2"}]}` , Format : 2 },
660+ },
661+ },
662+ ).Return (& pb.RegisterSchemaResponse {
663+ Registered : []* pb.RegisteredSchema {
664+ {Subject : "schema1" , Version : 1 },
665+ {Subject : "schema2" , Version : 2 },
666+ },
667+ }, nil )
668+
669+ client := & client {
670+ client : mockClient ,
671+ conn : nil ,
672+ }
673+
674+ schemas := []* pb.Schema {
675+ {Subject : "schema1" , Schema : `{"type":"record","name":"Test","fields":[{"name":"field1"}]}` , Format : 1 },
676+ {Subject : "schema2" , Schema : `{"type":"record","name":"Test2","fields":[{"name":"field2"}]}` , Format : 2 },
677+ }
678+
679+ result , err := client .RegisterSchemas (context .Background (), schemas ... )
680+ assert .NoError (t , err )
681+ assert .Equal (t , map [string ]int {"schema1" : 1 , "schema2" : 2 }, result )
682+ })
683+
684+ t .Run ("returns error when registration fails" , func (t * testing.T ) {
685+ mockClient := mocks .NewClient (t )
686+ mockClient .EXPECT ().RegisterSchema (
687+ context .Background (),
688+ & pb.RegisterSchemaRequest {
689+ Schemas : []* pb.Schema {
690+ {Subject : "schema1" , Schema : `{"type":"record","name":"Test","fields":[{"name":"field1"}]}` , Format : 1 },
691+ },
692+ },
693+ ).Return (nil , fmt .Errorf ("registration failed" ))
694+
695+ client := & client {
696+ client : mockClient ,
697+ conn : nil ,
698+ }
699+
700+ schemas := []* pb.Schema {
701+ {Subject : "schema1" , Schema : `{"type":"record","name":"Test","fields":[{"name":"field1"}]}` , Format : 1 },
702+ }
703+
704+ result , err := client .RegisterSchemas (context .Background (), schemas ... )
705+ assert .Nil (t , result )
706+ assert .EqualError (t , err , "failed to register schema: registration failed" )
707+ })
708+ }
0 commit comments