chore: refactor httpx.SetOkHandler (#3373)

This commit is contained in:
Kevin Wan
2023-06-26 00:27:26 +08:00
committed by GitHub
parent 92e5819e91
commit 40e7a4cd07
2 changed files with 27 additions and 27 deletions

View File

@@ -141,16 +141,16 @@ func TestOkJson(t *testing.T) {
})
t.Run("with handler", func(t *testing.T) {
respLock.RLock()
prev := respHandler
respLock.RUnlock()
okLock.RLock()
prev := okHandler
okLock.RUnlock()
t.Cleanup(func() {
respLock.Lock()
respHandler = prev
respLock.Unlock()
okLock.Lock()
okHandler = prev
okLock.Unlock()
})
SetResponseHandler(func(_ context.Context, v interface{}) any {
SetOkHandler(func(_ context.Context, v interface{}) any {
return fmt.Sprintf("hello %s", v.(message).Name)
})
w := tracedResponseWriter{
@@ -175,16 +175,16 @@ func TestOkJsonCtx(t *testing.T) {
})
t.Run("with handler", func(t *testing.T) {
respLock.RLock()
prev := respHandler
respLock.RUnlock()
okLock.RLock()
prev := okHandler
okLock.RUnlock()
t.Cleanup(func() {
respLock.Lock()
respHandler = prev
respLock.Unlock()
okLock.Lock()
okHandler = prev
okLock.Unlock()
})
SetResponseHandler(func(_ context.Context, v interface{}) any {
SetOkHandler(func(_ context.Context, v interface{}) any {
return fmt.Sprintf("hello %s", v.(message).Name)
})
w := tracedResponseWriter{