@@ -2,6 +2,8 @@ package registry_test
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
6
+ "io"
5
7
"net/http"
6
8
"net/http/httptest"
7
9
"testing"
@@ -493,6 +495,43 @@ func TestClient_IsRegistered(t *testing.T) {
493
495
assert .Equal (t , `["null","string","int"]` , schema .String ())
494
496
}
495
497
498
+ func TestClient_IsRegisteredWithRefs (t * testing.T ) {
499
+ s := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
500
+ assert .Equal (t , "POST" , r .Method )
501
+ assert .Equal (t , "/subjects/test" , r .URL .Path )
502
+ body , _ := io .ReadAll (r .Body )
503
+ var decoded map [string ]interface {}
504
+ _ = json .Unmarshal (body , & decoded )
505
+ assert .Contains (t , decoded , "references" )
506
+ refs , ok := decoded ["references" ].([]interface {})
507
+ assert .Equal (t , ok , true )
508
+ assert .Len (t , refs , 1 )
509
+ ref , ok := refs [0 ].(map [string ]interface {})
510
+ assert .Equal (t , true , ok )
511
+ assert .Equal (t , "some_schema" , ref ["name" ].(string ))
512
+ assert .Equal (t , "some_subject" , ref ["subject" ].(string ))
513
+ assert .Equal (t , float64 (3 ), ref ["version" ].(float64 ))
514
+ _ , _ = w .Write ([]byte (`{"id":10}` ))
515
+ }))
516
+ defer s .Close ()
517
+ client , _ := registry .NewClient (s .URL )
518
+
519
+ id , schema , err := client .IsRegisteredWithRefs (
520
+ context .Background (),
521
+ "test" ,
522
+ "[\" null\" ,\" string\" ,\" int\" ]" ,
523
+ registry.SchemaReference {
524
+ Name : "some_schema" ,
525
+ Subject : "some_subject" ,
526
+ Version : 3 ,
527
+ },
528
+ )
529
+
530
+ require .NoError (t , err )
531
+ assert .Equal (t , 10 , id )
532
+ assert .Equal (t , `["null","string","int"]` , schema .String ())
533
+ }
534
+
496
535
func TestClient_IsRegisteredRequestError (t * testing.T ) {
497
536
s := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
498
537
w .WriteHeader (500 )
0 commit comments