Skip to content

Commit

Permalink
e2e: test 'endpoint hash' command
Browse files Browse the repository at this point in the history
Signed-off-by: Gyu-Ho Lee <[email protected]>
  • Loading branch information
gyuho committed Aug 2, 2017
1 parent e977734 commit bba3f69
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions e2e/ctl_v3_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
}

0 comments on commit bba3f69

Please sign in to comment.