@@ -23,6 +23,7 @@ import (
2323 "errors"
2424 "fmt"
2525 "net"
26+ "strings"
2627 "testing"
2728 "time"
2829
@@ -185,6 +186,8 @@ func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) {
185186}
186187
187188func (s ) TestParsedTarget_Failure_WithoutCustomDialer (t * testing.T ) {
189+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
190+ defer cancel ()
188191 targets := []string {
189192 "" ,
190193 "unix://a/b/c" ,
@@ -195,9 +198,16 @@ func (s) TestParsedTarget_Failure_WithoutCustomDialer(t *testing.T) {
195198
196199 for _ , target := range targets {
197200 t .Run (target , func (t * testing.T ) {
198- if cc , err := Dial (target , WithTransportCredentials (insecure .NewCredentials ())); err == nil {
199- defer cc .Close ()
200- t .Fatalf ("Dial(%q) succeeded cc.parsedTarget = %+v, expected to fail" , target , cc .parsedTarget )
201+ cc , err := NewClient (target , WithTransportCredentials (insecure .NewCredentials ()))
202+ if err != nil {
203+ t .Fatalf ("NewClient(%q) failed: %v" , target , err )
204+ }
205+ defer cc .Close ()
206+ wantErrSubstr := "failed to exit idle mode"
207+ if _ , err := cc .NewStream (ctx , & StreamDesc {}, "/my.service.v1.MyService/UnaryCall" ); err == nil {
208+ t .Fatalf ("NewStream() succeeded with target = %q, cc.parsedTarget = %+v, expected to fail" , target , cc .parsedTarget )
209+ } else if ! strings .Contains (err .Error (), wantErrSubstr ) {
210+ t .Fatalf ("NewStream() with target = %q returned unexpected error: got %v, want substring %q" , target , err , wantErrSubstr )
201211 }
202212 })
203213 }
0 commit comments