snapshot of https://github.com/grpc/grpc-go.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
Testing / vet-proto (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Stale bot / stale (push) Failing after 1s
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
Testing / vet-proto (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Stale bot / stale (push) Failing after 1s
This commit is contained in:
70
internal/testutils/resolver.go
Normal file
70
internal/testutils/resolver.go
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2023 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package testutils
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc/internal"
|
||||
"google.golang.org/grpc/internal/pretty"
|
||||
"google.golang.org/grpc/resolver"
|
||||
"google.golang.org/grpc/serviceconfig"
|
||||
)
|
||||
|
||||
// Logger wraps the logging methods from testing.T.
|
||||
type Logger interface {
|
||||
Log(args ...any)
|
||||
Logf(format string, args ...any)
|
||||
Errorf(format string, args ...any)
|
||||
}
|
||||
|
||||
// ResolverClientConn is a fake implementation of the resolver.ClientConn
|
||||
// interface to be used in tests.
|
||||
type ResolverClientConn struct {
|
||||
resolver.ClientConn // Embedding the interface to avoid implementing deprecated methods.
|
||||
|
||||
Logger Logger // Tests should pass testing.T for this.
|
||||
UpdateStateF func(resolver.State) error // Invoked when resolver pushes a state update.
|
||||
ReportErrorF func(err error) // Invoked when resolver pushes an error.
|
||||
}
|
||||
|
||||
// UpdateState invokes the test specified callback with the update received from
|
||||
// the resolver. If the callback returns a non-nil error, the same will be
|
||||
// propagated to the resolver.
|
||||
func (t *ResolverClientConn) UpdateState(s resolver.State) error {
|
||||
t.Logger.Logf("testutils.ResolverClientConn: UpdateState(%s)", pretty.ToJSON(s))
|
||||
|
||||
if t.UpdateStateF != nil {
|
||||
return t.UpdateStateF(s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReportError pushes the error received from the resolver on to ErrorCh.
|
||||
func (t *ResolverClientConn) ReportError(err error) {
|
||||
t.Logger.Logf("testutils.ResolverClientConn: ReportError(%v)", err)
|
||||
|
||||
if t.ReportErrorF != nil {
|
||||
t.ReportErrorF(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ParseServiceConfig parses the provided service by delegating the work to the
|
||||
// implementation in the grpc package.
|
||||
func (t *ResolverClientConn) ParseServiceConfig(jsonSC string) *serviceconfig.ParseResult {
|
||||
return internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult)(jsonSC)
|
||||
}
|
||||
Reference in New Issue
Block a user