Repository: grpc/grpc-go
File: clientconn_parsed_target_test.go (Go)

Code before:
// Resets the default scheme as though it was never set by the user.
func resetInitialResolverState() {
	resolver.SetDefaultScheme("passthrough")
	internal.UserSetDefaultScheme = false
}

type testResolverForParser struct {
	resolver.Resolver
}

func (testResolverForParser) Build(resolver.Target, resolver.ClientConn, resolver.BuildOptions) (resolver.Resolver, error) {
	return testResolverForParser{}, nil
}

func (testResolverForParser) Close() {}

func (testResolverForParser) Scheme() string {
	return "testresolverforparser"
}

func init() { resolver.Register(testResolverForParser{}) }

func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) {
	tests := []struct {
		target             string
		wantNewClientParse resolver.Target
		wantCustomParse    resolver.Target
	}{
		// No scheme is specified.
		{
			target:             "://a/b",
			wantNewClientParse: generateTarget("dns:///://a/b"),
			wantCustomParse:    generateTarget("testresolverforparser:///://a/b"),
		},
		{
			target:             "a//b",
			wantNewClientParse: generateTarget("dns:///a//b"),
			wantCustomParse:    generateTarget("testresolverforparser:///a//b"),
		},

		// An unregistered scheme is specified.
		{
			target:             "a:///",
			wantNewClientParse: generateTarget("dns:///a:///"),
			wantCustomParse:    generateTarget("testresolverforparser:///a:///"),
		},
		{
			target:             "a:b",
			wantNewClientParse: generateTarget("dns:///a:b"),
			wantCustomParse:    generateTarget("testresolverforparser:///a:b"),
		},

Review comment (suggestion):
Please keep this test param and related assertions. We need to keep tests that test `Dial` specifically, since `Dial` will be supported for gRPC Go 1.x. We only need to replace `Dial` in tests which are not intended to verify the behaviour of `Dial`.

Code after:

// Resets the default scheme as though it was never set by the user.
func resetInitialResolverState() {
	resolver.SetDefaultScheme("passthrough")
	internal.UserSetDefaultScheme = false
}

type testResolverForParser struct {
	resolver.Resolver
}

func (testResolverForParser) Build(resolver.Target, resolver.ClientConn, resolver.BuildOptions) (resolver.Resolver, error) {
	return testResolverForParser{}, nil
}

func (testResolverForParser) Close() {}

func (testResolverForParser) Scheme() string {
	return "testresolverforparser"
}

func init() { resolver.Register(testResolverForParser{}) }

func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) {
	tests := []struct {
		target             string
		wantDialParse      resolver.Target
		wantNewClientParse resolver.Target
		wantCustomParse    resolver.Target
	}{
		// No scheme is specified.
		{
			target:             "://a/b",
			wantDialParse:      generateTarget("passthrough:///://a/b"),
			wantNewClientParse: generateTarget("dns:///://a/b"),
			wantCustomParse:    generateTarget("testresolverforparser:///://a/b"),
		},
		{
			target:             "a//b",
			wantDialParse:      generateTarget("passthrough:///a//b"),
			wantNewClientParse: generateTarget("dns:///a//b"),
			wantCustomParse:    generateTarget("testresolverforparser:///a//b"),
		},

		// An unregistered scheme is specified.
		{
			target:             "a:///",
			wantDialParse:      generateTarget("passthrough:///a:///"),
			wantNewClientParse: generateTarget("dns:///a:///"),
			wantCustomParse:    generateTarget("testresolverforparser:///a:///"),
		},