refactor: use assert

Signed-off-by: wafuwafu13 <mariobaske@i.softbank.jp>
This commit is contained in:
wafuwafu13 2022-12-19 22:02:46 +09:00
parent 1c00d46b83
commit 77e4e87ee7

View File

@ -17,12 +17,15 @@ package clientv3
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"io" "io"
"net" "net"
"sync" "sync"
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"go.etcd.io/etcd/api/v3/etcdserverpb" "go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes" "go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
"go.etcd.io/etcd/client/pkg/v3/testutil" "go.etcd.io/etcd/client/pkg/v3/testutil"
@ -152,23 +155,33 @@ func TestDialNoTimeout(t *testing.T) {
} }
func TestIsHaltErr(t *testing.T) { func TestIsHaltErr(t *testing.T) {
if !isHaltErr(context.TODO(), errors.New("etcdserver: some etcdserver error")) { assert.Equal(t,
t.Errorf(`error prefixed with "etcdserver: " should be Halted by default`) isHaltErr(context.TODO(), errors.New("etcdserver: some etcdserver error")),
} true,
if isHaltErr(context.TODO(), rpctypes.ErrGRPCStopped) { `error prefixed with "etcdserver: " should be Halted by default`,
t.Errorf("error %v should not halt", rpctypes.ErrGRPCStopped) )
} assert.Equal(t,
if isHaltErr(context.TODO(), rpctypes.ErrGRPCNoLeader) { isHaltErr(context.TODO(), rpctypes.ErrGRPCStopped),
t.Errorf("error %v should not halt", rpctypes.ErrGRPCNoLeader) false,
} fmt.Sprintf("error %v should not halt", rpctypes.ErrGRPCStopped),
)
assert.Equal(t,
isHaltErr(context.TODO(), rpctypes.ErrGRPCNoLeader),
false,
fmt.Sprintf("error %v should not halt", rpctypes.ErrGRPCNoLeader),
)
ctx, cancel := context.WithCancel(context.TODO()) ctx, cancel := context.WithCancel(context.TODO())
if isHaltErr(ctx, nil) { assert.Equal(t,
t.Errorf("no error and active context should not be Halted") isHaltErr(ctx, nil),
} false,
"no error and active context should not be Halted",
)
cancel() cancel()
if !isHaltErr(ctx, nil) { assert.Equal(t,
t.Errorf("cancel on context should be Halted") isHaltErr(ctx, nil),
} true,
"cancel on context should be Halted",
)
} }
func TestCloseCtxClient(t *testing.T) { func TestCloseCtxClient(t *testing.T) {