File tree 4 files changed +54
-0
lines changed 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,9 @@ func (o *Options) validate() error {
96
96
if o == nil {
97
97
return errors .New ("grpctransport: opts required to be non-nil" )
98
98
}
99
+ if o .InternalOptions != nil && o .InternalOptions .SkipValidation {
100
+ return nil
101
+ }
99
102
hasCreds := o .Credentials != nil ||
100
103
(o .DetectOpts != nil && len (o .DetectOpts .CredentialsJSON ) > 0 ) ||
101
104
(o .DetectOpts != nil && o .DetectOpts .CredentialsFile != "" )
@@ -151,6 +154,9 @@ type InternalOptions struct {
151
154
// DefaultScopes specifies the default OAuth2 scopes to be used for a
152
155
// service.
153
156
DefaultScopes []string
157
+ // SkipValidation bypasses validation on Options. It should only be used
158
+ // internally for clients that needs more control over their transport.
159
+ SkipValidation bool
154
160
}
155
161
156
162
// Dial returns a GRPCClientConnPool that can be used to communicate with a
Original file line number Diff line number Diff line change @@ -117,6 +117,27 @@ func TestDial_FailsValidation(t *testing.T) {
117
117
}
118
118
}
119
119
120
+ func TestDial_SkipValidation (t * testing.T ) {
121
+ opts := & Options {
122
+ DisableAuthentication : true ,
123
+ Credentials : auth .NewCredentials (& auth.CredentialsOptions {
124
+ TokenProvider : & staticTP {tok : & auth.Token {Value : "fakeToken" }},
125
+ }),
126
+ }
127
+ t .Run ("invalid opts" , func (t * testing.T ) {
128
+ if err := opts .validate (); err == nil {
129
+ t .Fatalf ("opts.validate() = nil, want error" )
130
+ }
131
+ })
132
+
133
+ t .Run ("skip invalid opts" , func (t * testing.T ) {
134
+ opts .InternalOptions = & InternalOptions {SkipValidation : true }
135
+ if err := opts .validate (); err != nil {
136
+ t .Fatalf ("opts.validate() = %v, want nil" , err )
137
+ }
138
+ })
139
+ }
140
+
120
141
func TestOptions_ResolveDetectOptions (t * testing.T ) {
121
142
tests := []struct {
122
143
name string
Original file line number Diff line number Diff line change @@ -74,6 +74,9 @@ func (o *Options) validate() error {
74
74
if o == nil {
75
75
return errors .New ("httptransport: opts required to be non-nil" )
76
76
}
77
+ if o .InternalOptions != nil && o .InternalOptions .SkipValidation {
78
+ return nil
79
+ }
77
80
hasCreds := o .APIKey != "" ||
78
81
o .Credentials != nil ||
79
82
(o .DetectOpts != nil && len (o .DetectOpts .CredentialsJSON ) > 0 ) ||
@@ -131,6 +134,9 @@ type InternalOptions struct {
131
134
// DefaultScopes specifies the default OAuth2 scopes to be used for a
132
135
// service.
133
136
DefaultScopes []string
137
+ // SkipValidation bypasses validation on Options. It should only be used
138
+ // internally for clients that needs more control over their transport.
139
+ SkipValidation bool
134
140
}
135
141
136
142
// AddAuthorizationMiddleware adds a middleware to the provided client's
Original file line number Diff line number Diff line change @@ -133,6 +133,27 @@ func TestNewClient_FailsValidation(t *testing.T) {
133
133
}
134
134
}
135
135
136
+ func TestDial_SkipValidation (t * testing.T ) {
137
+ opts := & Options {
138
+ DisableAuthentication : true ,
139
+ Credentials : auth .NewCredentials (& auth.CredentialsOptions {
140
+ TokenProvider : staticTP ("fakeToken" ),
141
+ }),
142
+ }
143
+ t .Run ("invalid opts" , func (t * testing.T ) {
144
+ if err := opts .validate (); err == nil {
145
+ t .Fatalf ("opts.validate() = nil, want error" )
146
+ }
147
+ })
148
+
149
+ t .Run ("skip invalid opts" , func (t * testing.T ) {
150
+ opts .InternalOptions = & InternalOptions {SkipValidation : true }
151
+ if err := opts .validate (); err != nil {
152
+ t .Fatalf ("opts.validate() = %v, want nil" , err )
153
+ }
154
+ })
155
+ }
156
+
136
157
func TestOptions_ResolveDetectOptions (t * testing.T ) {
137
158
tests := []struct {
138
159
name string
You can’t perform that action at this time.
0 commit comments