Merge pull request #19589 from mmorel-35/usetesting/client
client: address Go 1.24 usetesting issues
This commit is contained in:
commit
ce5620760b
@ -131,7 +131,7 @@ func TestSimpleHTTPClientDoSuccess(t *testing.T) {
|
||||
Body: io.NopCloser(strings.NewReader("foo")),
|
||||
}
|
||||
|
||||
resp, body, err := c.Do(context.Background(), &fakeAction{})
|
||||
resp, body, err := c.Do(t.Context(), &fakeAction{})
|
||||
require.NoErrorf(t, err, "incorrect error value")
|
||||
wantCode := http.StatusTeapot
|
||||
require.Equalf(t, wantCode, resp.StatusCode, "invalid response code: want=%d got=%d", wantCode, resp.StatusCode)
|
||||
@ -146,7 +146,7 @@ func TestSimpleHTTPClientDoError(t *testing.T) {
|
||||
|
||||
tr.errchan <- errors.New("fixture")
|
||||
|
||||
_, _, err := c.Do(context.Background(), &fakeAction{})
|
||||
_, _, err := c.Do(t.Context(), &fakeAction{})
|
||||
assert.Errorf(t, err, "expected non-nil error, got nil")
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ func TestSimpleHTTPClientDoNilRequest(t *testing.T) {
|
||||
|
||||
tr.errchan <- errors.New("fixture")
|
||||
|
||||
_, _, err := c.Do(context.Background(), &nilAction{})
|
||||
_, _, err := c.Do(t.Context(), &nilAction{})
|
||||
require.ErrorIsf(t, err, ErrNoRequest, "expected non-nil error, got nil")
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ func TestSimpleHTTPClientDoCancelContext(t *testing.T) {
|
||||
tr.startCancel <- struct{}{}
|
||||
tr.finishCancel <- struct{}{}
|
||||
|
||||
_, _, err := c.Do(context.Background(), &fakeAction{})
|
||||
_, _, err := c.Do(t.Context(), &fakeAction{})
|
||||
assert.Errorf(t, err, "expected non-nil error, got nil")
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ func TestSimpleHTTPClientDoCancelContextResponseBodyClosed(t *testing.T) {
|
||||
c := &simpleHTTPClient{transport: tr}
|
||||
|
||||
// create an already-cancelled context
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
cancel()
|
||||
|
||||
body := &checkableReadCloser{ReadCloser: io.NopCloser(strings.NewReader("foo"))}
|
||||
@ -232,7 +232,7 @@ func TestSimpleHTTPClientDoCancelContextResponseBodyClosedWithBlockingBody(t *te
|
||||
tr := newFakeTransport()
|
||||
c := &simpleHTTPClient{transport: tr}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
body := &checkableReadCloser{ReadCloser: &blockingBody{c: make(chan struct{})}}
|
||||
go func() {
|
||||
tr.respchan <- &http.Response{Body: body}
|
||||
@ -252,7 +252,7 @@ func TestSimpleHTTPClientDoCancelContextWaitForRoundTrip(t *testing.T) {
|
||||
c := &simpleHTTPClient{transport: tr}
|
||||
|
||||
donechan := make(chan struct{})
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
go func() {
|
||||
c.Do(ctx, &fakeAction{})
|
||||
close(donechan)
|
||||
@ -285,7 +285,7 @@ func TestSimpleHTTPClientDoHeaderTimeout(t *testing.T) {
|
||||
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
_, _, err := c.Do(context.Background(), &fakeAction{})
|
||||
_, _, err := c.Do(t.Context(), &fakeAction{})
|
||||
errc <- err
|
||||
}()
|
||||
|
||||
@ -407,7 +407,7 @@ func TestHTTPClusterClientDo(t *testing.T) {
|
||||
),
|
||||
rand: rand.New(rand.NewSource(0)),
|
||||
},
|
||||
ctx: context.WithValue(context.Background(), &oneShotCtxValue, &oneShotCtxValue),
|
||||
ctx: context.WithValue(t.Context(), &oneShotCtxValue, &oneShotCtxValue),
|
||||
wantErr: errors.New("client: etcd member returns server error [Bad Gateway]"),
|
||||
wantPinned: 1,
|
||||
},
|
||||
@ -415,7 +415,7 @@ func TestHTTPClusterClientDo(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
if tt.ctx == nil {
|
||||
tt.ctx = context.Background()
|
||||
tt.ctx = t.Context()
|
||||
}
|
||||
resp, _, err := tt.client.Do(tt.ctx, nil)
|
||||
if (tt.wantErr == nil && !errors.Is(err, tt.wantErr)) || (tt.wantErr != nil && tt.wantErr.Error() != err.Error()) {
|
||||
@ -450,7 +450,7 @@ func TestHTTPClusterClientDoDeadlineExceedContext(t *testing.T) {
|
||||
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), time.Millisecond)
|
||||
defer cancel()
|
||||
_, _, err := c.Do(ctx, &fakeAction{})
|
||||
errc <- err
|
||||
@ -722,7 +722,7 @@ func TestRedirectFollowingHTTPClient(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
client := &redirectFollowingHTTPClient{client: tt.client, checkRedirect: tt.checkRedirect}
|
||||
resp, _, err := client.Do(context.Background(), nil)
|
||||
resp, _, err := client.Do(t.Context(), nil)
|
||||
if (tt.wantErr == nil && !errors.Is(err, tt.wantErr)) || (tt.wantErr != nil && tt.wantErr.Error() != err.Error()) {
|
||||
t.Errorf("#%d: got err=%v, want=%v", i, err, tt.wantErr)
|
||||
continue
|
||||
@ -781,7 +781,7 @@ func TestHTTPClusterClientSync(t *testing.T) {
|
||||
got := hc.Endpoints()
|
||||
require.Truef(t, reflect.DeepEqual(want, got), "incorrect endpoints: want=%#v got=%#v", want, got)
|
||||
|
||||
err = hc.Sync(context.Background())
|
||||
err = hc.Sync(t.Context())
|
||||
require.NoErrorf(t, err, "unexpected error during Sync: %#v", err)
|
||||
|
||||
want = []string{"http://127.0.0.1:2379", "http://127.0.0.1:4001", "http://127.0.0.1:4002", "http://127.0.0.1:4003"}
|
||||
@ -813,7 +813,7 @@ func TestHTTPClusterClientSyncFail(t *testing.T) {
|
||||
got := hc.Endpoints()
|
||||
require.Truef(t, reflect.DeepEqual(want, got), "incorrect endpoints: want=%#v got=%#v", want, got)
|
||||
|
||||
err = hc.Sync(context.Background())
|
||||
err = hc.Sync(t.Context())
|
||||
require.Errorf(t, err, "got nil error during Sync")
|
||||
|
||||
got = hc.Endpoints()
|
||||
@ -835,7 +835,7 @@ func TestHTTPClusterClientAutoSyncCancelContext(t *testing.T) {
|
||||
err := hc.SetEndpoints([]string{"http://127.0.0.1:2379"})
|
||||
require.NoErrorf(t, err, "unexpected error during setup")
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
cancel()
|
||||
|
||||
err = hc.AutoSync(ctx, time.Hour)
|
||||
@ -854,7 +854,7 @@ func TestHTTPClusterClientAutoSyncFail(t *testing.T) {
|
||||
err := hc.SetEndpoints([]string{"http://127.0.0.1:2379"})
|
||||
require.NoErrorf(t, err, "unexpected error during setup")
|
||||
|
||||
err = hc.AutoSync(context.Background(), time.Hour)
|
||||
err = hc.AutoSync(t.Context(), time.Hour)
|
||||
require.Truef(t, strings.HasPrefix(err.Error(), ErrClusterUnavailable.Error()), "incorrect error value: want=%v got=%v", ErrClusterUnavailable, err)
|
||||
}
|
||||
|
||||
@ -874,7 +874,7 @@ func TestHTTPClusterClientGetVersion(t *testing.T) {
|
||||
err := hc.SetEndpoints([]string{"http://127.0.0.1:4003", "http://127.0.0.1:2379", "http://127.0.0.1:4001", "http://127.0.0.1:4002"})
|
||||
require.NoErrorf(t, err, "unexpected error during setup")
|
||||
|
||||
actual, err := hc.GetVersion(context.Background())
|
||||
actual, err := hc.GetVersion(t.Context())
|
||||
if err != nil {
|
||||
t.Errorf("non-nil error: %#v", err)
|
||||
}
|
||||
@ -911,7 +911,7 @@ func TestHTTPClusterClientSyncPinEndpoint(t *testing.T) {
|
||||
pinnedEndpoint := hc.endpoints[hc.pinned]
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
err = hc.Sync(context.Background())
|
||||
err = hc.Sync(t.Context())
|
||||
require.NoErrorf(t, err, "#%d: unexpected error during Sync", i)
|
||||
|
||||
if g := hc.endpoints[hc.pinned]; g != pinnedEndpoint {
|
||||
@ -947,7 +947,7 @@ func TestHTTPClusterClientSyncUnpinEndpoint(t *testing.T) {
|
||||
wants := []string{"http://127.0.0.1:2379", "http://127.0.0.1:4001", "http://127.0.0.1:4002"}
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
err = hc.Sync(context.Background())
|
||||
err = hc.Sync(t.Context())
|
||||
require.NoErrorf(t, err, "#%d: unexpected error during Sync", i)
|
||||
|
||||
if g := hc.endpoints[hc.pinned]; g.String() != wants[i] {
|
||||
@ -988,7 +988,7 @@ func TestHTTPClusterClientSyncPinLeaderEndpoint(t *testing.T) {
|
||||
wants := []string{"http://127.0.0.1:4003", "http://127.0.0.1:4002"}
|
||||
|
||||
for i, want := range wants {
|
||||
err := hc.Sync(context.Background())
|
||||
err := hc.Sync(t.Context())
|
||||
require.NoErrorf(t, err, "#%d: unexpected error during Sync", i)
|
||||
|
||||
pinned := hc.endpoints[hc.pinned].String()
|
||||
|
@ -15,7 +15,6 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -875,7 +874,7 @@ func TestHTTPWatcherNextWaitAction(t *testing.T) {
|
||||
nextWait: initAction,
|
||||
}
|
||||
|
||||
resp, err := watcher.Next(context.Background())
|
||||
resp, err := watcher.Next(t.Context())
|
||||
if err != nil {
|
||||
t.Errorf("non-nil error: %#v", err)
|
||||
}
|
||||
@ -925,7 +924,7 @@ func TestHTTPWatcherNextFail(t *testing.T) {
|
||||
nextWait: act,
|
||||
}
|
||||
|
||||
resp, err := watcher.Next(context.Background())
|
||||
resp, err := watcher.Next(t.Context())
|
||||
if err == nil {
|
||||
t.Errorf("#%d: expected non-nil error", i)
|
||||
}
|
||||
@ -1073,7 +1072,7 @@ func TestHTTPKeysAPISetAction(t *testing.T) {
|
||||
for i, tt := range tests {
|
||||
client := &actionAssertingHTTPClient{t: t, num: i, act: tt.wantAction}
|
||||
kAPI := httpKeysAPI{client: client}
|
||||
kAPI.Set(context.Background(), tt.key, tt.value, tt.opts)
|
||||
kAPI.Set(t.Context(), tt.key, tt.value, tt.opts)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1102,7 +1101,7 @@ func TestHTTPKeysAPISetError(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
kAPI := httpKeysAPI{client: tt}
|
||||
resp, err := kAPI.Set(context.Background(), "/foo", "bar", nil)
|
||||
resp, err := kAPI.Set(t.Context(), "/foo", "bar", nil)
|
||||
if err == nil {
|
||||
t.Errorf("#%d: received nil error", i)
|
||||
}
|
||||
@ -1129,7 +1128,7 @@ func TestHTTPKeysAPISetResponse(t *testing.T) {
|
||||
}
|
||||
|
||||
kAPI := &httpKeysAPI{client: client, prefix: "/pants"}
|
||||
resp, err := kAPI.Set(context.Background(), "/foo/bar/baz", "snarf", nil)
|
||||
resp, err := kAPI.Set(t.Context(), "/foo/bar/baz", "snarf", nil)
|
||||
if err != nil {
|
||||
t.Errorf("non-nil error: %#v", err)
|
||||
}
|
||||
@ -1184,7 +1183,7 @@ func TestHTTPKeysAPIGetAction(t *testing.T) {
|
||||
for i, tt := range tests {
|
||||
client := &actionAssertingHTTPClient{t: t, num: i, act: tt.wantAction}
|
||||
kAPI := httpKeysAPI{client: client}
|
||||
kAPI.Get(context.Background(), tt.key, tt.opts)
|
||||
kAPI.Get(t.Context(), tt.key, tt.opts)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1213,7 +1212,7 @@ func TestHTTPKeysAPIGetError(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
kAPI := httpKeysAPI{client: tt}
|
||||
resp, err := kAPI.Get(context.Background(), "/foo", nil)
|
||||
resp, err := kAPI.Get(t.Context(), "/foo", nil)
|
||||
if err == nil {
|
||||
t.Errorf("#%d: received nil error", i)
|
||||
}
|
||||
@ -1246,7 +1245,7 @@ func TestHTTPKeysAPIGetResponse(t *testing.T) {
|
||||
}
|
||||
|
||||
kAPI := &httpKeysAPI{client: client, prefix: "/pants"}
|
||||
resp, err := kAPI.Get(context.Background(), "/foo/bar", &GetOptions{Recursive: true})
|
||||
resp, err := kAPI.Get(t.Context(), "/foo/bar", &GetOptions{Recursive: true})
|
||||
if err != nil {
|
||||
t.Errorf("non-nil error: %#v", err)
|
||||
}
|
||||
@ -1303,7 +1302,7 @@ func TestHTTPKeysAPIDeleteAction(t *testing.T) {
|
||||
for i, tt := range tests {
|
||||
client := &actionAssertingHTTPClient{t: t, num: i, act: tt.wantAction}
|
||||
kAPI := httpKeysAPI{client: client}
|
||||
kAPI.Delete(context.Background(), tt.key, tt.opts)
|
||||
kAPI.Delete(t.Context(), tt.key, tt.opts)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1332,7 +1331,7 @@ func TestHTTPKeysAPIDeleteError(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
kAPI := httpKeysAPI{client: tt}
|
||||
resp, err := kAPI.Delete(context.Background(), "/foo", nil)
|
||||
resp, err := kAPI.Delete(t.Context(), "/foo", nil)
|
||||
if err == nil {
|
||||
t.Errorf("#%d: received nil error", i)
|
||||
}
|
||||
@ -1359,7 +1358,7 @@ func TestHTTPKeysAPIDeleteResponse(t *testing.T) {
|
||||
}
|
||||
|
||||
kAPI := &httpKeysAPI{client: client, prefix: "/pants"}
|
||||
resp, err := kAPI.Delete(context.Background(), "/foo/bar/baz", nil)
|
||||
resp, err := kAPI.Delete(t.Context(), "/foo/bar/baz", nil)
|
||||
if err != nil {
|
||||
t.Errorf("non-nil error: %#v", err)
|
||||
}
|
||||
@ -1379,7 +1378,7 @@ func TestHTTPKeysAPICreateAction(t *testing.T) {
|
||||
}
|
||||
|
||||
kAPI := httpKeysAPI{client: &actionAssertingHTTPClient{t: t, act: act}}
|
||||
kAPI.Create(context.Background(), "/foo", "bar")
|
||||
kAPI.Create(t.Context(), "/foo", "bar")
|
||||
}
|
||||
|
||||
func TestHTTPKeysAPICreateInOrderAction(t *testing.T) {
|
||||
@ -1389,7 +1388,7 @@ func TestHTTPKeysAPICreateInOrderAction(t *testing.T) {
|
||||
TTL: 0,
|
||||
}
|
||||
kAPI := httpKeysAPI{client: &actionAssertingHTTPClient{t: t, act: act}}
|
||||
kAPI.CreateInOrder(context.Background(), "/foo", "bar", nil)
|
||||
kAPI.CreateInOrder(t.Context(), "/foo", "bar", nil)
|
||||
}
|
||||
|
||||
func TestHTTPKeysAPIUpdateAction(t *testing.T) {
|
||||
@ -1403,7 +1402,7 @@ func TestHTTPKeysAPIUpdateAction(t *testing.T) {
|
||||
}
|
||||
|
||||
kAPI := httpKeysAPI{client: &actionAssertingHTTPClient{t: t, act: act}}
|
||||
kAPI.Update(context.Background(), "/foo", "bar")
|
||||
kAPI.Update(t.Context(), "/foo", "bar")
|
||||
}
|
||||
|
||||
func TestNodeTTLDuration(t *testing.T) {
|
||||
|
@ -15,7 +15,6 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
@ -340,7 +339,7 @@ func TestHTTPMembersAPIAddSuccess(t *testing.T) {
|
||||
PeerURLs: []string{"http://127.0.0.1:7002"},
|
||||
}
|
||||
|
||||
m, err := mAPI.Add(context.Background(), "http://127.0.0.1:7002")
|
||||
m, err := mAPI.Add(t.Context(), "http://127.0.0.1:7002")
|
||||
if err != nil {
|
||||
t.Errorf("got non-nil err: %#v", err)
|
||||
}
|
||||
@ -415,7 +414,7 @@ func TestHTTPMembersAPIAddError(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
mAPI := &httpMembersAPI{client: tt.client}
|
||||
m, err := mAPI.Add(context.Background(), tt.peerURL)
|
||||
m, err := mAPI.Add(t.Context(), tt.peerURL)
|
||||
if err == nil {
|
||||
t.Errorf("#%d: got nil err", i)
|
||||
}
|
||||
@ -443,7 +442,7 @@ func TestHTTPMembersAPIRemoveSuccess(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
if err := mAPI.Remove(context.Background(), "94088180e21eb87b"); err != nil {
|
||||
if err := mAPI.Remove(t.Context(), "94088180e21eb87b"); err != nil {
|
||||
t.Errorf("got non-nil err: %#v", err)
|
||||
}
|
||||
}
|
||||
@ -465,7 +464,7 @@ func TestHTTPMembersAPIRemoveFail(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
mAPI := &httpMembersAPI{client: tt}
|
||||
if err := mAPI.Remove(context.Background(), "94088180e21eb87b"); err == nil {
|
||||
if err := mAPI.Remove(t.Context(), "94088180e21eb87b"); err == nil {
|
||||
t.Errorf("#%d: got nil err", i)
|
||||
}
|
||||
}
|
||||
@ -493,7 +492,7 @@ func TestHTTPMembersAPIListSuccess(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
m, err := mAPI.List(context.Background())
|
||||
m, err := mAPI.List(t.Context())
|
||||
if err != nil {
|
||||
t.Errorf("got non-nil err: %#v", err)
|
||||
}
|
||||
@ -523,7 +522,7 @@ func TestHTTPMembersAPIListError(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
mAPI := &httpMembersAPI{client: tt}
|
||||
ms, err := mAPI.List(context.Background())
|
||||
ms, err := mAPI.List(t.Context())
|
||||
if err == nil {
|
||||
t.Errorf("#%d: got nil err", i)
|
||||
}
|
||||
@ -553,7 +552,7 @@ func TestHTTPMembersAPILeaderSuccess(t *testing.T) {
|
||||
ClientURLs: []string{"http://127.0.0.1:4002"},
|
||||
}
|
||||
|
||||
m, err := mAPI.Leader(context.Background())
|
||||
m, err := mAPI.Leader(t.Context())
|
||||
if err != nil {
|
||||
t.Errorf("err = %v, want %v", err, nil)
|
||||
}
|
||||
@ -583,7 +582,7 @@ func TestHTTPMembersAPILeaderError(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
mAPI := &httpMembersAPI{client: tt}
|
||||
m, err := mAPI.Leader(context.Background())
|
||||
m, err := mAPI.Leader(t.Context())
|
||||
if err == nil {
|
||||
t.Errorf("#%d: err = nil, want not nil", i)
|
||||
}
|
||||
|
@ -196,18 +196,18 @@ func TestBackoffJitterFraction(t *testing.T) {
|
||||
|
||||
func TestIsHaltErr(t *testing.T) {
|
||||
assert.Truef(t,
|
||||
isHaltErr(context.TODO(), errors.New("etcdserver: some etcdserver error")),
|
||||
isHaltErr(t.Context(), errors.New("etcdserver: some etcdserver error")),
|
||||
"error created by errors.New should be unavailable error",
|
||||
)
|
||||
assert.Falsef(t,
|
||||
isHaltErr(context.TODO(), rpctypes.ErrGRPCStopped),
|
||||
isHaltErr(t.Context(), rpctypes.ErrGRPCStopped),
|
||||
`error "%v" should not be halt error`, rpctypes.ErrGRPCStopped,
|
||||
)
|
||||
assert.Falsef(t,
|
||||
isHaltErr(context.TODO(), rpctypes.ErrGRPCNoLeader),
|
||||
isHaltErr(t.Context(), rpctypes.ErrGRPCNoLeader),
|
||||
`error "%v" should not be halt error`, rpctypes.ErrGRPCNoLeader,
|
||||
)
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
assert.Falsef(t,
|
||||
isHaltErr(ctx, nil),
|
||||
"no error and active context should be halt error",
|
||||
@ -221,18 +221,18 @@ func TestIsHaltErr(t *testing.T) {
|
||||
|
||||
func TestIsUnavailableErr(t *testing.T) {
|
||||
assert.Falsef(t,
|
||||
isUnavailableErr(context.TODO(), errors.New("etcdserver: some etcdserver error")),
|
||||
isUnavailableErr(t.Context(), errors.New("etcdserver: some etcdserver error")),
|
||||
"error created by errors.New should not be unavailable error",
|
||||
)
|
||||
assert.Truef(t,
|
||||
isUnavailableErr(context.TODO(), rpctypes.ErrGRPCStopped),
|
||||
isUnavailableErr(t.Context(), rpctypes.ErrGRPCStopped),
|
||||
`error "%v" should be unavailable error`, rpctypes.ErrGRPCStopped,
|
||||
)
|
||||
assert.Falsef(t,
|
||||
isUnavailableErr(context.TODO(), rpctypes.ErrGRPCNotCapable),
|
||||
isUnavailableErr(t.Context(), rpctypes.ErrGRPCNotCapable),
|
||||
"error %v should not be unavailable error", rpctypes.ErrGRPCNotCapable,
|
||||
)
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
assert.Falsef(t,
|
||||
isUnavailableErr(ctx, nil),
|
||||
"no error and active context should not be unavailable error",
|
||||
@ -245,7 +245,7 @@ func TestIsUnavailableErr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCloseCtxClient(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
c := NewCtxClient(ctx)
|
||||
err := c.Close()
|
||||
// Close returns ctx.toErr, a nil error means an open Done channel
|
||||
@ -255,7 +255,7 @@ func TestCloseCtxClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithLogger(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
c := NewCtxClient(ctx)
|
||||
if c.lg == nil {
|
||||
t.Errorf("unexpected nil in *zap.Logger")
|
||||
@ -268,7 +268,7 @@ func TestWithLogger(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestZapWithLogger(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
lg := zap.NewNop()
|
||||
c := NewCtxClient(ctx, WithZapLogger(lg))
|
||||
|
||||
@ -327,7 +327,7 @@ func TestSyncFiltersMembers(t *testing.T) {
|
||||
{ID: 2, Name: "isStartedAndNotLearner", ClientURLs: []string{"http://254.0.0.3:12345"}, IsLearner: false},
|
||||
},
|
||||
}
|
||||
c.Sync(context.Background())
|
||||
c.Sync(t.Context())
|
||||
|
||||
endpoints := c.Endpoints()
|
||||
if len(endpoints) != 1 || endpoints[0] != "http://254.0.0.3:12345" {
|
||||
@ -421,7 +421,7 @@ func TestClientRejectOldCluster(t *testing.T) {
|
||||
endpointToVersion[tt.endpoints[j]] = tt.versions[j]
|
||||
}
|
||||
c := &Client{
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
endpoints: tt.endpoints,
|
||||
epMu: new(sync.RWMutex),
|
||||
Maintenance: &mockMaintenance{
|
||||
|
@ -15,7 +15,6 @@
|
||||
package credentials
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -25,7 +24,7 @@ import (
|
||||
|
||||
func TestUpdateAuthToken(t *testing.T) {
|
||||
bundle := NewPerRPCCredentialBundle()
|
||||
ctx := context.TODO()
|
||||
ctx := t.Context()
|
||||
|
||||
metadataBeforeUpdate, _ := bundle.PerRPCCredentials().GetRequestMetadata(ctx)
|
||||
assert.Empty(t, metadataBeforeUpdate)
|
||||
|
@ -15,7 +15,6 @@
|
||||
package clientv3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@ -27,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMetadataWithRequireLeader(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
ctx := t.Context()
|
||||
_, ok := metadata.FromOutgoingContext(ctx)
|
||||
require.Falsef(t, ok, "expected no outgoing metadata ctx key")
|
||||
|
||||
@ -48,7 +47,7 @@ func TestMetadataWithRequireLeader(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMetadataWithClientAPIVersion(t *testing.T) {
|
||||
ctx := withVersion(WithRequireLeader(context.TODO()))
|
||||
ctx := withVersion(WithRequireLeader(t.Context()))
|
||||
|
||||
md, ok := metadata.FromOutgoingContext(ctx)
|
||||
require.Truef(t, ok, "expected outgoing metadata ctx key")
|
||||
|
@ -76,7 +76,7 @@ func TestKvOrdering(t *testing.T) {
|
||||
tt.prevRev,
|
||||
sync.RWMutex{},
|
||||
}
|
||||
res, err := kv.Get(context.TODO(), "mockKey")
|
||||
res, err := kv.Get(t.Context(), "mockKey")
|
||||
if err != nil {
|
||||
t.Errorf("#%d: expected response %+v, got error %+v", i, tt.response, err)
|
||||
}
|
||||
@ -131,9 +131,9 @@ func TestTxnOrdering(t *testing.T) {
|
||||
sync.RWMutex{},
|
||||
}
|
||||
txn := &txnOrdering{
|
||||
kv.Txn(context.Background()),
|
||||
kv.Txn(t.Context()),
|
||||
kv,
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
sync.Mutex{},
|
||||
[]clientv3.Cmp{},
|
||||
[]clientv3.Op{},
|
||||
|
@ -15,7 +15,6 @@
|
||||
package clientv3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -44,7 +43,7 @@ func TestTxnPanics(t *testing.T) {
|
||||
{
|
||||
f: func(errc chan string) {
|
||||
defer df(errc)
|
||||
kv.Txn(context.TODO()).If(cmp).If(cmp)
|
||||
kv.Txn(t.Context()).If(cmp).If(cmp)
|
||||
},
|
||||
|
||||
err: "cannot call If twice!",
|
||||
@ -52,7 +51,7 @@ func TestTxnPanics(t *testing.T) {
|
||||
{
|
||||
f: func(errc chan string) {
|
||||
defer df(errc)
|
||||
kv.Txn(context.TODO()).Then(op).If(cmp)
|
||||
kv.Txn(t.Context()).Then(op).If(cmp)
|
||||
},
|
||||
|
||||
err: "cannot call If after Then!",
|
||||
@ -60,7 +59,7 @@ func TestTxnPanics(t *testing.T) {
|
||||
{
|
||||
f: func(errc chan string) {
|
||||
defer df(errc)
|
||||
kv.Txn(context.TODO()).Else(op).If(cmp)
|
||||
kv.Txn(t.Context()).Else(op).If(cmp)
|
||||
},
|
||||
|
||||
err: "cannot call If after Else!",
|
||||
@ -68,7 +67,7 @@ func TestTxnPanics(t *testing.T) {
|
||||
{
|
||||
f: func(errc chan string) {
|
||||
defer df(errc)
|
||||
kv.Txn(context.TODO()).Then(op).Then(op)
|
||||
kv.Txn(t.Context()).Then(op).Then(op)
|
||||
},
|
||||
|
||||
err: "cannot call Then twice!",
|
||||
@ -76,7 +75,7 @@ func TestTxnPanics(t *testing.T) {
|
||||
{
|
||||
f: func(errc chan string) {
|
||||
defer df(errc)
|
||||
kv.Txn(context.TODO()).Else(op).Then(op)
|
||||
kv.Txn(t.Context()).Else(op).Then(op)
|
||||
},
|
||||
|
||||
err: "cannot call Then after Else!",
|
||||
@ -84,7 +83,7 @@ func TestTxnPanics(t *testing.T) {
|
||||
{
|
||||
f: func(errc chan string) {
|
||||
defer df(errc)
|
||||
kv.Txn(context.TODO()).Else(op).Else(op)
|
||||
kv.Txn(t.Context()).Else(op).Else(op)
|
||||
},
|
||||
|
||||
err: "cannot call Else twice!",
|
||||
|
@ -72,7 +72,7 @@ func TestStreamKeyFromCtx(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "multiple keys",
|
||||
ctx: metadata.NewOutgoingContext(context.Background(), metadata.MD{
|
||||
ctx: metadata.NewOutgoingContext(t.Context(), metadata.MD{
|
||||
"key1": []string{"value1"},
|
||||
"key2": []string{"value2a", "value2b"},
|
||||
}),
|
||||
@ -80,19 +80,19 @@ func TestStreamKeyFromCtx(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "no keys",
|
||||
ctx: metadata.NewOutgoingContext(context.Background(), metadata.MD{}),
|
||||
ctx: metadata.NewOutgoingContext(t.Context(), metadata.MD{}),
|
||||
expected: "map[]",
|
||||
},
|
||||
{
|
||||
name: "only one key",
|
||||
ctx: metadata.NewOutgoingContext(context.Background(), metadata.MD{
|
||||
ctx: metadata.NewOutgoingContext(t.Context(), metadata.MD{
|
||||
"key1": []string{"value1", "value1a"},
|
||||
}),
|
||||
expected: "map[key1:[value1 value1a]]",
|
||||
},
|
||||
{
|
||||
name: "no metadata",
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
expected: "",
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user