@@ -808,15 +808,44 @@ func (s) TestMethodConfigDefaultService(t *testing.T) {
808808 }
809809}
810810
811- func (s ) TestGetClientConnTarget (t * testing.T ) {
812- addr := "nonexist:///non.existent"
813- cc , err := Dial (addr , WithTransportCredentials (insecure .NewCredentials ()))
814- if err != nil {
815- t .Fatalf ("Dial(%s, _) = _, %v, want _, <nil>" , addr , err )
811+ func (s ) TestClientConn_Target (t * testing.T ) {
812+ tests := []struct {
813+ name string
814+ addr string
815+ targetWant string
816+ }{
817+ {
818+ name : "normal-case" ,
819+ addr : "dns://a.server.com/google.com" ,
820+ targetWant : "dns://a.server.com/google.com" ,
821+ },
822+ {
823+ name : "canonical-target-not-specified" ,
824+ addr : "no.scheme" ,
825+ targetWant : "passthrough:///no.scheme" ,
826+ },
827+ {
828+ name : "canonical-target-nonexistent" ,
829+ addr : "nonexist:///non.existent" ,
830+ targetWant : "passthrough:///nonexist:///non.existent" ,
831+ },
832+ {
833+ name : "canonical-target-add-colon-slash" ,
834+ addr : "dns:hostname:port" ,
835+ targetWant : "dns:///hostname:port" ,
836+ },
816837 }
817- defer cc .Close ()
818- if cc .Target () != addr {
819- t .Fatalf ("Target() = %s, want %s" , cc .Target (), addr )
838+ for _ , test := range tests {
839+ t .Run (test .name , func (t * testing.T ) {
840+ cc , err := Dial (test .addr , WithTransportCredentials (insecure .NewCredentials ()))
841+ if err != nil {
842+ t .Fatalf ("Dial(%s, _) = _, %v, want _, <nil>" , test .addr , err )
843+ }
844+ defer cc .Close ()
845+ if cc .Target () != test .targetWant {
846+ t .Fatalf ("Target() = %s, want %s" , cc .Target (), test .targetWant )
847+ }
848+ })
820849 }
821850}
822851
0 commit comments