diff --git a/e2e/ctl_v3_endpoint_test.go b/e2e/ctl_v3_endpoint_test.go index 74a2ebb7a1d0..a593507a8f19 100644 --- a/e2e/ctl_v3_endpoint_test.go +++ b/e2e/ctl_v3_endpoint_test.go @@ -15,12 +15,18 @@ package e2e import ( + "context" + "fmt" "net/url" "testing" + "time" + + "github.com/coreos/etcd/clientv3" ) func TestCtlV3EndpointHealth(t *testing.T) { testCtl(t, endpointHealthTest, withQuorum()) } func TestCtlV3EndpointStatus(t *testing.T) { testCtl(t, endpointStatusTest, withQuorum()) } +func TestCtlV3EndpointHash(t *testing.T) { testCtl(t, endpointHashTest, withQuorum()) } func endpointHealthTest(cx ctlCtx) { if err := ctlV3EndpointHealth(cx); err != nil { @@ -52,3 +58,35 @@ func ctlV3EndpointStatus(cx ctlCtx) error { } return spawnWithExpects(cmdArgs, eps...) } + +func endpointHashTest(cx ctlCtx) { + if err := ctlV3EndpointHash(cx); err != nil { + cx.t.Fatalf("endpointHashTest ctlV3EndpointHash error (%v)", err) + } +} + +func ctlV3EndpointHash(cx ctlCtx) error { + eps := cx.epc.EndpointsV3() + + // get latest hash to compare + cli, err := clientv3.New(clientv3.Config{ + Endpoints: eps, + DialTimeout: 3 * time.Second, + }) + if err != nil { + cx.t.Fatal(err) + } + defer cli.Close() + hresp, err := cli.HashKV(context.TODO(), eps[0], 0) + if err != nil { + cx.t.Fatal(err) + } + + cmdArgs := append(cx.PrefixArgs(), "endpoint", "hash") + var ss []string + for _, ep := range cx.epc.EndpointsV3() { + u, _ := url.Parse(ep) + ss = append(ss, fmt.Sprintf("%s, %d", u.Host, hresp.Hash)) + } + return spawnWithExpects(cmdArgs, ss...) +}