nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: zeromicro/go-zero
Pull request #2485 (2022-10-06 15:31:57)

chore: remove init if possible


Patch:
diff --git a/core/mapping/unmarshaler.go b/core/mapping/unmarshaler.go
index a4cdf3f6..2cd1b93e 100644
--- a/core/mapping/unmarshaler.go
+++ b/core/mapping/unmarshaler.go
@@ -25,9 +25,9 @@ var (
 	errValueNotStruct   = errors.New("value type is not struct")
 	keyUnmarshaler      = NewUnmarshaler(defaultKeyName)
 	durationType        = reflect.TypeOf(time.Duration(0))
-	cacheKeys           map[string][]string
+	cacheKeys           = make(map[string][]string)
 	cacheKeysLock       sync.Mutex
-	defaultCache        map[string]interface{}
+	defaultCache        = make(map[string]interface{})
 	defaultCacheLock    sync.Mutex
 	emptyMap            = map[string]interface{}{}
 	emptyValue          = reflect.ValueOf(lang.Placeholder)
@@ -49,11 +49,6 @@ type (
 	}
 )
 
-func init() {
-	cacheKeys = make(map[string][]string)
-	defaultCache = make(map[string]interface{})
-}
-
 // NewUnmarshaler returns a Unmarshaler.
 func NewUnmarshaler(key string, opts ...UnmarshalOption) *Unmarshaler {
 	unmarshaler := Unmarshaler{
diff --git a/zrpc/internal/rpclogger.go b/zrpc/internal/rpclogger.go
index e7b057bb..e3c3148c 100644
--- a/zrpc/internal/rpclogger.go
+++ b/zrpc/internal/rpclogger.go
@@ -1,8 +1,6 @@
 package internal
 
 import (
-	"sync"
-
 	"github.com/zeromicro/go-zero/core/logx"
 	"google.golang.org/grpc/grpclog"
 )
@@ -10,16 +8,11 @@ import (
 // because grpclog.errorLog is not exported, we need to define our own.
 const errorLevel = 2
 
-var once sync.Once
-
 // A Logger is a rpc logger.
 type Logger struct{}
 
-// InitLogger initializes the rpc logger.
-func InitLogger() {
-	once.Do(func() {
-		grpclog.SetLoggerV2(new(Logger))
-	})
+func init() {
+	grpclog.SetLoggerV2(new(Logger))
 }
 
 // Error logs the given args into error log.
diff --git a/zrpc/internal/rpcserver.go b/zrpc/internal/rpcserver.go
index 36408776..cf9c8ce8 100644
--- a/zrpc/internal/rpcserver.go
+++ b/zrpc/internal/rpcserver.go
@@ -25,10 +25,6 @@ type (
 	}
 )
 
-func init() {
-	InitLogger()
-}
-
 // NewRpcServer returns a Server.
 func NewRpcServer(address string, opts ...ServerOption) Server {
 	var options rpcServerOptions


Test patch:
diff --git a/rest/internal/encoding/parser_test.go b/rest/internal/encoding/parser_test.go
index b04b3f72..2708098c 100644
--- a/rest/internal/encoding/parser_test.go
+++ b/rest/internal/encoding/parser_test.go
@@ -48,4 +48,4 @@ func TestParseHeadersArrayInt(t *testing.T) {
 	r.Header.Add("foo", "2")
 	assert.Nil(t, ParseHeaders(r.Header, &val))
 	assert.Equal(t, []int{1, 2}, val.Foo)
-}
\ No newline at end of file
+}
Repository: zeromicro/go-zero
Pull request #2546 (2022-10-22 15:11:56)

feat: add logger.WithFields


Patch:
diff --git a/core/logx/logger.go b/core/logx/logger.go
index ddb4ada7..a9ea0253 100644
--- a/core/logx/logger.go
+++ b/core/logx/logger.go
@@ -45,4 +45,6 @@ type Logger interface {
 	WithContext(ctx context.Context) Logger
 	// WithDuration returns a new logger with the given duration.
 	WithDuration(d time.Duration) Logger
+	// WithFields returns a new logger with the given fields.
+	WithFields(fields ...LogField) Logger
 }
diff --git a/core/logx/richlogger.go b/core/logx/richlogger.go
index f73fddf9..e88c2f75 100644
--- a/core/logx/richlogger.go
+++ b/core/logx/richlogger.go
@@ -123,6 +123,11 @@ func (l *richLogger) WithDuration(duration time.Duration) Logger {
 	return l
 }
 
+func (l *richLogger) WithFields(fields ...LogField) Logger {
+	l.fields = append(l.fields, fields...)
+	return l
+}
+
 func (l *richLogger) buildFields(fields ...LogField) []LogField {
 	fields = append(l.fields, fields...)
 	fields = append(fields, Field(callerKey, getCaller(callerDepth+l.callerSkip)))


Test patch:
diff --git a/core/logx/richlogger_test.go b/core/logx/richlogger_test.go
index 7cf373a5..b629c537 100644
--- a/core/logx/richlogger_test.go
+++ b/core/logx/richlogger_test.go
@@ -272,6 +272,23 @@ func TestLogWithCallerSkip(t *testing.T) {
 	assert.True(t, w.Contains(fmt.Sprintf("%s:%d", file, line+1)))
 }
 
+func TestLoggerWithFields(t *testing.T) {
+	w := new(mockWriter)
+	old := writer.Swap(w)
+	writer.lock.RLock()
+	defer func() {
+		writer.lock.RUnlock()
+		writer.Store(old)
+	}()
+
+	l := WithContext(context.Background()).WithFields(Field("foo", "bar"))
+	l.Info(testlog)
+
+	var val mockValue
+	assert.Nil(t, json.Unmarshal([]byte(w.String()), &val))
+	assert.Equal(t, "bar", val.Foo)
+}
+
 func validate(t *testing.T, body string, expectedTrace, expectedSpan bool) {
 	var val mockValue
 	dec := json.NewDecoder(strings.NewReader(body))
Repository: zeromicro/go-zero
Pull request #2549 (2022-10-24 00:54:24)

chore(action): enable cache dependency


Patch:
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 7e8ee5db..6ba019ea 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -11,15 +11,17 @@ jobs:
     name: Linux
     runs-on: ubuntu-latest
     steps:
+      - name: Check out code into the Go module directory
+        uses: actions/checkout@v3
+
       - name: Set up Go 1.x
         uses: actions/setup-go@v3
         with:
           go-version: ^1.16
+          check-latest: true
+          cache: true
         id: go
 
-      - name: Check out code into the Go module directory
-        uses: actions/checkout@v3
-
       - name: Get dependencies
         run: |
           go get -v -t -d ./...
@@ -40,13 +42,15 @@ jobs:
     name: Windows
     runs-on: windows-latest
     steps:
+      - name: Checkout codebase
+        uses: actions/checkout@v3
+
       - name: Set up Go 1.x
         uses: actions/setup-go@v3
         with:
           go-version: ^1.16
-
-      - name: Checkout codebase
-        uses: actions/checkout@v3
+          check-latest: true
+          cache: true
 
       - name: Test
         run: |


Test patch:
diff --git a/core/mapping/unmarshaler_test.go b/core/mapping/unmarshaler_test.go
index 97c27890..f445817d 100644
--- a/core/mapping/unmarshaler_test.go
+++ b/core/mapping/unmarshaler_test.go
@@ -10,6 +10,7 @@ import (
 
 	"github.com/google/uuid"
 	"github.com/stretchr/testify/assert"
+
 	"github.com/zeromicro/go-zero/core/stringx"
 )
 
@@ -539,7 +540,7 @@ func TestUnmarshalStringMapFromUnsupportedType(t *testing.T) {
 func TestUnmarshalStringMapFromNotSettableValue(t *testing.T) {
 	var v struct {
 		sort  map[string]string  `key:"sort"`
-		psort *map[string]string `key:"sort"`
+		psort *map[string]string `key:"psort"`
 	}
 	m := map[string]interface{}{
 		"sort":  `{"value":"ascend","emptyStr":""}`,
Repository: zeromicro/go-zero
Pull request #2593 (2022-11-11 16:18:28)

feat: support bool for env tag


Patch:
diff --git a/core/mapping/unmarshaler.go b/core/mapping/unmarshaler.go
index 9fcf1de5..c75bc50c 100644
--- a/core/mapping/unmarshaler.go
+++ b/core/mapping/unmarshaler.go
@@ -6,6 +6,7 @@ import (
 	"errors"
 	"fmt"
 	"reflect"
+	"strconv"
 	"strings"
 	"sync"
 	"time"
@@ -342,6 +343,14 @@ func (u *Unmarshaler) processFieldWithEnvValue(field reflect.StructField, value
 	envVal string, opts *fieldOptionsWithContext, fullName string) error {
 	fieldKind := field.Type.Kind()
 	switch fieldKind {
+	case reflect.Bool:
+		val, err := strconv.ParseBool(envVal)
+		if err != nil {
+			return fmt.Errorf("unmarshal field %q with environment variable, %w", fullName, err)
+		}
+
+		value.SetBool(val)
+		return nil
 	case durationType.Kind():
 		if err := fillDurationValue(fieldKind, value, envVal); err != nil {
 			return fmt.Errorf("unmarshal field %q with environment variable, %w", fullName, err)


Test patch:
diff --git a/core/mapping/unmarshaler_test.go b/core/mapping/unmarshaler_test.go
index 6fdcdaac..f806bfbb 100644
--- a/core/mapping/unmarshaler_test.go
+++ b/core/mapping/unmarshaler_test.go
@@ -3186,6 +3186,47 @@ func TestUnmarshal_EnvFloatOverwrite(t *testing.T) {
 	assert.Equal(t, float32(123.45), v.Age)
 }
 
+func TestUnmarshal_EnvBoolTrue(t *testing.T) {
+	type Value struct {
+		Enable bool `key:"enable,env=TEST_NAME_BOOL_TRUE"`
+	}
+
+	const envName = "TEST_NAME_BOOL_TRUE"
+	os.Setenv(envName, "true")
+	defer os.Unsetenv(envName)
+
+	var v Value
+	assert.NoError(t, UnmarshalKey(emptyMap, &v))
+	assert.True(t, v.Enable)
+}
+
+func TestUnmarshal_EnvBoolFalse(t *testing.T) {
+	type Value struct {
+		Enable bool `key:"enable,env=TEST_NAME_BOOL_FALSE"`
+	}
+
+	const envName = "TEST_NAME_BOOL_FALSE"
+	os.Setenv(envName, "false")
+	defer os.Unsetenv(envName)
+
+	var v Value
+	assert.NoError(t, UnmarshalKey(emptyMap, &v))
+	assert.False(t, v.Enable)
+}
+
+func TestUnmarshal_EnvBoolBad(t *testing.T) {
+	type Value struct {
+		Enable bool `key:"enable,env=TEST_NAME_BOOL_BAD"`
+	}
+
+	const envName = "TEST_NAME_BOOL_BAD"
+	os.Setenv(envName, "bad")
+	defer os.Unsetenv(envName)
+
+	var v Value
+	assert.Error(t, UnmarshalKey(emptyMap, &v))
+}
+
 func TestUnmarshal_EnvDuration(t *testing.T) {
 	type Value struct {
 		Duration time.Duration `key:"duration,env=TEST_NAME_DURATION"`
Repository: zeromicro/go-zero
Pull request #2598 (2022-11-12 12:03:33)

The default port is used when there is no port number for k8s
Target: k8s://namespace/service-rpc-svc:8001
To
Target: k8s://namespace/service-rpc-svc

kevwan: Fix #2636 
Issues-translate-bot:  
> Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿         
----    
Fix #2636  
      

Patch:
diff --git a/zrpc/resolver/internal/kube/targetparser.go b/zrpc/resolver/internal/kube/targetparser.go
index 570ad7d5..d74cfba3 100644
--- a/zrpc/resolver/internal/kube/targetparser.go
+++ b/zrpc/resolver/internal/kube/targetparser.go
@@ -32,18 +32,21 @@ func ParseTarget(target resolver.Target) (Service, error) {
 	}
 
 	endpoints := targets.GetEndpoints(target)
-	segs := strings.SplitN(endpoints, colon, 2)
-	if len(segs) < 2 {
-		return emptyService, fmt.Errorf("bad endpoint: %s", endpoints)
+	if strings.Contains(endpoints, colon) {
+		segs := strings.SplitN(endpoints, colon, 2)
+		if len(segs) < 2 {
+			return emptyService, fmt.Errorf("bad endpoint: %s", endpoints)
+		}
+
+		service.Name = segs[0]
+		port, err := strconv.Atoi(segs[1])
+		if err != nil {
+			return emptyService, err
+		}
+
+		service.Port = port
+	} else {
+		service.Name = endpoints
 	}
-
-	service.Name = segs[0]
-	port, err := strconv.Atoi(segs[1])
-	if err != nil {
-		return emptyService, err
-	}
-
-	service.Port = port
-
 	return service, nil
 }
diff --git a/zrpc/resolver/internal/kubebuilder.go b/zrpc/resolver/internal/kubebuilder.go
index 1a78eda5..38c1f775 100644
--- a/zrpc/resolver/internal/kubebuilder.go
+++ b/zrpc/resolver/internal/kubebuilder.go
@@ -40,6 +40,14 @@ func (b *kubeBuilder) Build(target resolver.Target, cc resolver.ClientConn,
 		return nil, err
 	}
 
+	if svc.Port == 0 {
+		endpoints, err := cs.CoreV1().Endpoints(svc.Namespace).Get(context.Background(), svc.Name, v1.GetOptions{})
+		if err != nil {
+			return nil, err
+		}
+		svc.Port = int(endpoints.Subsets[0].Ports[0].Port)
+	}
+
 	handler := kube.NewEventHandler(func(endpoints []string) {
 		var addrs []resolver.Address
 		for _, val := range subset(endpoints, subsetSize) {
@@ -64,12 +72,10 @@ func (b *kubeBuilder) Build(target resolver.Target, cc resolver.ClientConn,
 	threading.GoSafe(func() {
 		inf.Start(proc.Done())
 	})
-
 	endpoints, err := cs.CoreV1().Endpoints(svc.Namespace).Get(context.Background(), svc.Name, v1.GetOptions{})
 	if err != nil {
 		return nil, err
 	}
-
 	handler.Update(endpoints)
 
 	return &nopResolver{cc: cc}, nil


Test patch:
diff --git a/zrpc/resolver/internal/kube/targetparser_test.go b/zrpc/resolver/internal/kube/targetparser_test.go
index 4dce9e43..ef69053c 100644
--- a/zrpc/resolver/internal/kube/targetparser_test.go
+++ b/zrpc/resolver/internal/kube/targetparser_test.go
@@ -39,9 +39,12 @@ func TestParseTarget(t *testing.T) {
 			hasErr: true,
 		},
 		{
-			name:   "no port, no colon",
-			input:  "k8s://ns1/my-svc",
-			hasErr: true,
+			name:  "no port, no colon",
+			input: "k8s://ns1/my-svc",
+			expect: Service{
+				Namespace: "ns1",
+				Name:      "my-svc",
+			},
 		},
 		{
 			name:   "bad port",
Repository: zeromicro/go-zero
Pull request #2622 (2022-11-20 07:17:01)

feat: add stringx.ToCamelCase


Patch:
diff --git a/core/stringx/strings.go b/core/stringx/strings.go
index c0c4510c..155c8b3e 100644
--- a/core/stringx/strings.go
+++ b/core/stringx/strings.go
@@ -2,6 +2,7 @@ package stringx
 
 import (
 	"errors"
+	"unicode"
 
 	"github.com/zeromicro/go-zero/core/lang"
 )
@@ -168,6 +169,15 @@ func TakeWithPriority(fns ...func() string) string {
 	return ""
 }
 
+// ToCamelCase returns the string that converts the first letter to lowercase.
+func ToCamelCase(s string) string {
+	for i, v := range s {
+		return string(unicode.ToLower(v)) + s[i+1:]
+	}
+
+	return ""
+}
+
 // Union merges the strings in first and second.
 func Union(first, second []string) []string {
 	set := make(map[string]lang.PlaceholderType)


Test patch:
diff --git a/core/stringx/strings_test.go b/core/stringx/strings_test.go
index 6ef8755e..2caffd3e 100644
--- a/core/stringx/strings_test.go
+++ b/core/stringx/strings_test.go
@@ -396,6 +396,61 @@ func TestTakeWithPriority(t *testing.T) {
 	}
 }
 
+func TestToCamelCase(t *testing.T) {
+	tests := []struct {
+		input  string
+		expect string
+	}{
+		{
+			input:  "",
+			expect: "",
+		},
+		{
+			input:  "A",
+			expect: "a",
+		},
+		{
+			input:  "a",
+			expect: "a",
+		},
+		{
+			input:  "hello_world",
+			expect: "hello_world",
+		},
+		{
+			input:  "Hello_world",
+			expect: "hello_world",
+		},
+		{
+			input:  "hello_World",
+			expect: "hello_World",
+		},
+		{
+			input:  "helloWorld",
+			expect: "helloWorld",
+		},
+		{
+			input:  "HelloWorld",
+			expect: "helloWorld",
+		},
+		{
+			input:  "hello World",
+			expect: "hello World",
+		},
+		{
+			input:  "Hello World",
+			expect: "hello World",
+		},
+	}
+
+	for _, test := range tests {
+		test := test
+		t.Run(test.input, func(t *testing.T) {
+			assert.Equal(t, test.expect, ToCamelCase(test.input))
+		})
+	}
+}
+
 func TestUnion(t *testing.T) {
 	first := []string{
 		"one",
Repository: zeromicro/go-zero
Pull request #2704 (2022-12-14 04:24:30)

add ServeHTTP to Server/Engin for doing Httptest
Is similar to gin-gonic , allow developer to do a unit test with all defined router without starting a HTTP Server.
For example:
server := MustNewServer(...)
server.addRoute(...) // router a
server.addRoute(...) // router b
server.addRoute(...) // router c

req, _ := http.NewRequest(...) 
w := httptest.NewRecorder(...)
server.ServeHTTP(w,req)

//TODO : test after response


Patch:
diff --git a/rest/server.go b/rest/server.go
index 4c7a30ff..f3104344 100644
--- a/rest/server.go
+++ b/rest/server.go
@@ -307,3 +307,8 @@ func newCorsRouter(router httpx.Router, headerFn func(http.Header), origins ...s
 func (c *corsRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	c.middleware(c.Router.ServeHTTP)(w, r)
 }
+
+func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+	s.ngin.bindRoutes(s.router)
+	s.router.ServeHTTP(w, r)
+}


Test patch:
diff --git a/rest/server_test.go b/rest/server_test.go
index ad205552..bd215fae 100644
--- a/rest/server_test.go
+++ b/rest/server_test.go
@@ -535,3 +535,91 @@ func TestServer_WithCors(t *testing.T) {
 	cr.ServeHTTP(httptest.NewRecorder(), req)
 	assert.Equal(t, int32(0), atomic.LoadInt32(&called))
 }
+
+func TestServer_ServeHTTP(t *testing.T) {
+	const configYaml = `
+Name: foo
+Port: 54321
+`
+
+	var cnf RestConf
+	assert.Nil(t, conf.LoadFromYamlBytes([]byte(configYaml), &cnf))
+
+	svr, err := NewServer(cnf)
+	assert.Nil(t, err)
+
+	svr.AddRoutes([]Route{
+		{
+			Method: http.MethodGet,
+			Path:   "/foo",
+			Handler: func(writer http.ResponseWriter, request *http.Request) {
+				_, _ = writer.Write([]byte("succeed"))
+				writer.WriteHeader(http.StatusOK)
+			},
+		},
+		{
+			Method: http.MethodGet,
+			Path:   "/bar",
+			Handler: func(writer http.ResponseWriter, request *http.Request) {
+				_, _ = writer.Write([]byte("succeed"))
+				writer.WriteHeader(http.StatusOK)
+			},
+		},
+		{
+			Method: http.MethodGet,
+			Path:   "/user/:name",
+			Handler: func(writer http.ResponseWriter, request *http.Request) {
+
+				var userInfo struct {
+					Name string `path:"name"`
+				}
+
+				err := httpx.Parse(request, &userInfo)
+				if err != nil {
+					_, _ = writer.Write([]byte("failed"))
+					writer.WriteHeader(http.StatusBadRequest)
+					return
+				}
+
+				_, _ = writer.Write([]byte("succeed"))
+				writer.WriteHeader(http.StatusOK)
+			},
+		},
+	})
+
+	testCase := []struct {
+		name string
+		path string
+		code int
+	}{
+		{
+			name: "URI : /foo",
+			path: "/foo",
+			code: http.StatusOK,
+		},
+		{
+			name: "URI : /bar",
+			path: "/bar",
+			code: http.StatusOK,
+		},
+		{
+			name: "URI : undefined path",
+			path: "/test",
+			code: http.StatusNotFound,
+		},
+		{
+			name: "URI : /user/:name",
+			path: "/user/abc",
+			code: http.StatusOK,
+		},
+	}
+
+	for _, test := range testCase {
+		t.Run(test.name, func(t *testing.T) {
+			w := httptest.NewRecorder()
+			req, _ := http.NewRequest("GET", test.path, nil)
+			svr.ServeHTTP(w, req)
+			assert.Equal(t, test.code, w.Code)
+		})
+	}
+}
Repository: zeromicro/go-zero
Pull request #2740 (2023-01-03 03:09:31)

use stat instead of disableStat


Patch:
diff --git a/core/logx/config.go b/core/logx/config.go
index 2d75549c..7d1a4c1e 100644
--- a/core/logx/config.go
+++ b/core/logx/config.go
@@ -9,7 +9,7 @@ type LogConf struct {
 	Path                string `json:",default=logs"`
 	Level               string `json:",default=info,options=[debug,info,error,severe]"`
 	Compress            bool   `json:",optional"`
-	DisableStat         bool   `json:",optional"`
+	Stat                bool   `json:",default=true"`
 	KeepDays            int    `json:",optional"`
 	StackCooldownMillis int    `json:",default=100"`
 	// MaxBackups represents how many backup log files will be kept. 0 means all files will be kept forever.
diff --git a/core/logx/logs.go b/core/logx/logs.go
index 07f200e9..65047d49 100644
--- a/core/logx/logs.go
+++ b/core/logx/logs.go
@@ -229,11 +229,11 @@ func SetUp(c LogConf) (err error) {
 	// Need to wait for the first caller to complete the execution.
 	setupOnce.Do(func() {
 		setupLogLevel(c)
-		
-        if (c.DisableStat){
-		   DisableStat()
+
+		if !c.Stat {
+			DisableStat()
 		}
-		
+
 		if len(c.TimeFormat) > 0 {
 			timeFormat = c.TimeFormat
 		}


Test patch:
diff --git a/core/logx/logs_test.go b/core/logx/logs_test.go
index 415f9d42..e8068a78 100644
--- a/core/logx/logs_test.go
+++ b/core/logx/logs_test.go
@@ -794,11 +794,7 @@ func testSetLevelTwiceWithMode(t *testing.T, mode string, w *mockWriter) {
 		Mode:  mode,
 		Level: "error",
 		Path:  "/dev/null",
-	})
-	SetUp(LogConf{
-		Mode:  mode,
-		Level: "info",
-		Path:  "/dev/null",
+		Stat:  false,
 	})
 	const message = "hello there"
 	Info(message)
Repository: zeromicro/go-zero
Pull request #2754 (2023-01-05 12:26:07)

chore: remove unnecessary code


Patch:
diff --git a/rest/httpc/requests.go b/rest/httpc/requests.go
index a4ae197d..4ddb15a8 100644
--- a/rest/httpc/requests.go
+++ b/rest/httpc/requests.go
@@ -7,7 +7,6 @@ import (
 	"fmt"
 	"io"
 	"net/http"
-	"net/http/httptrace"
 	nurl "net/url"
 	"strings"
 
@@ -176,11 +175,6 @@ func request(r *http.Request, cli client) (*http.Response, error) {
 		respHandlers[i] = h
 	}
 
-	clientTrace := httptrace.ContextClientTrace(ctx)
-	if clientTrace != nil {
-		ctx = httptrace.WithClientTrace(ctx, clientTrace)
-	}
-
 	r = r.WithContext(ctx)
 	propagator.Inject(ctx, propagation.HeaderCarrier(r.Header))
 


Test patch:
diff --git a/rest/httpc/requests_test.go b/rest/httpc/requests_test.go
index b5bf9612..59fdfed5 100644
--- a/rest/httpc/requests_test.go
+++ b/rest/httpc/requests_test.go
@@ -5,6 +5,7 @@ import (
 	"net/http"
 	"net/http/httptest"
 	"net/http/httptrace"
+	"strings"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
@@ -205,12 +206,14 @@ func TestDo_WithClientHttpTrace(t *testing.T) {
 	svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
 	defer svr.Close()
 
+	enter := false
 	_, err := Do(httptrace.WithClientTrace(context.Background(),
 		&httptrace.ClientTrace{
-			DNSStart: func(info httptrace.DNSStartInfo) {
-				assert.Equal(t, "localhost", info.Host)
+			GetConn: func(hostPort string) {
+				assert.Equal(t, "127.0.0.1", strings.Split(hostPort, ":")[0])
+				enter = true
 			},
 		}), http.MethodGet, svr.URL, nil)
 	assert.Nil(t, err)
-
+	assert.True(t, enter)
 }