mirror of https://github.com/grpc/grpc-go.git
credentials/google: stub out the oauth package in test (#5118)
This commit is contained in:
parent
13c41bce4a
commit
9353ae3bb4
|
|
@ -50,7 +50,7 @@ func NewDefaultCredentialsWithOptions(opts DefaultCredentialsOptions) credential
|
|||
ctx, cancel := context.WithTimeout(context.Background(), tokenRequestTimeout)
|
||||
defer cancel()
|
||||
var err error
|
||||
opts.PerRPCCreds, err = oauth.NewApplicationDefault(ctx)
|
||||
opts.PerRPCCreds, err = newADC(ctx)
|
||||
if err != nil {
|
||||
logger.Warningf("NewDefaultCredentialsWithOptions: failed to create application oauth: %v", err)
|
||||
}
|
||||
|
|
@ -112,6 +112,9 @@ var (
|
|||
newALTS = func() credentials.TransportCredentials {
|
||||
return alts.NewClientCreds(alts.DefaultClientOptions())
|
||||
}
|
||||
newADC = func(ctx context.Context) (credentials.PerRPCCredentials, error) {
|
||||
return oauth.NewApplicationDefault(ctx)
|
||||
}
|
||||
)
|
||||
|
||||
// NewWithMode should make a copy of Bundle, and switch mode. Modifying the
|
||||
|
|
|
|||
|
|
@ -65,17 +65,24 @@ var (
|
|||
)
|
||||
|
||||
func overrideNewCredsFuncs() func() {
|
||||
oldNewTLS := newTLS
|
||||
origNewTLS := newTLS
|
||||
newTLS = func() credentials.TransportCredentials {
|
||||
return testTLS
|
||||
}
|
||||
oldNewALTS := newALTS
|
||||
origNewALTS := newALTS
|
||||
newALTS = func() credentials.TransportCredentials {
|
||||
return testALTS
|
||||
}
|
||||
origNewADC := newADC
|
||||
newADC = func(context.Context) (credentials.PerRPCCredentials, error) {
|
||||
// We do not use perRPC creds in this test. It is safe to return nil here.
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return func() {
|
||||
newTLS = oldNewTLS
|
||||
newALTS = oldNewALTS
|
||||
newTLS = origNewTLS
|
||||
newALTS = origNewALTS
|
||||
newADC = origNewADC
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue