Skip to content

Commit

Permalink
Merge pull request #9312 from hexfusion/e2e_w2
Browse files Browse the repository at this point in the history
e2e: improve Watch test coverage
  • Loading branch information
hexfusion authored Feb 13, 2018
2 parents aab8b5e + f65f988 commit cb5d089
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 27 deletions.
22 changes: 21 additions & 1 deletion e2e/ctl_v3_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func TestCtlV3AuthAndWatch(t *testing.T) { testCtl(t, authTestWatch) }

func TestCtlV3AuthLeaseTestKeepAlive(t *testing.T) { testCtl(t, authLeaseTestKeepAlive) }
func TestCtlV3AuthLeaseTestTimeToLiveExpired(t *testing.T) { testCtl(t, authLeaseTestTimeToLiveExpired) }
func TestCtlV3AuthLeaseGrantLeases(t *testing.T) { testCtl(t, authLeaseTestLeaseGrantLeases) }
func TestCtlV3AuthLeaseRevoke(t *testing.T) { testCtl(t, authLeaseTestLeaseRevoke) }

func TestCtlV3AuthRoleGet(t *testing.T) { testCtl(t, authTestRoleGet) }
func TestCtlV3AuthUserGet(t *testing.T) { testCtl(t, authTestUserGet) }
Expand Down Expand Up @@ -759,7 +761,25 @@ func authLeaseTestTimeToLiveExpired(cx ctlCtx) {

ttl := 3
if err := leaseTestTimeToLiveExpire(cx, ttl); err != nil {
cx.t.Fatal(err)
cx.t.Fatalf("leaseTestTimeToLiveExpire: error (%v)", err)
}
}

func authLeaseTestLeaseGrantLeases(cx ctlCtx) {
cx.user, cx.pass = "root", "root"
authSetupTestUser(cx)

if err := leaseTestGrantLeasesList(cx); err != nil {
cx.t.Fatalf("authLeaseTestLeaseGrantLeases: error (%v)", err)
}
}

func authLeaseTestLeaseRevoke(cx ctlCtx) {
cx.user, cx.pass = "root", "root"
authSetupTestUser(cx)

if err := leaseTestRevoke(cx); err != nil {
cx.t.Fatalf("authLeaseTestLeaseRevoke: error (%v)", err)
}
}

Expand Down
139 changes: 113 additions & 26 deletions e2e/ctl_v3_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,84 +22,163 @@ import (
"time"
)

func TestCtlV3LeaseGrantTimeToLive(t *testing.T) { testCtl(t, leaseTestGrantTimeToLive) }
func TestCtlV3LeaseGrantLeases(t *testing.T) { testCtl(t, leaseTestGrantLeasesList) }
func TestCtlV3LeaseGrantTimeToLive(t *testing.T) { testCtl(t, leaseTestGrantTimeToLive) }
func TestCtlV3LeaseGrantTimeToLiveNoTLS(t *testing.T) {
testCtl(t, leaseTestGrantTimeToLive, withCfg(configNoTLS))
}
func TestCtlV3LeaseGrantTimeToLiveClientTLS(t *testing.T) {
testCtl(t, leaseTestGrantTimeToLive, withCfg(configClientTLS))
}
func TestCtlV3LeaseGrantTimeToLiveClientAutoTLS(t *testing.T) {
testCtl(t, leaseTestGrantTimeToLive, withCfg(configClientAutoTLS))
}
func TestCtlV3LeaseGrantTimeToLivePeerTLS(t *testing.T) {
testCtl(t, leaseTestGrantTimeToLive, withCfg(configPeerTLS))
}

func TestCtlV3LeaseGrantLeases(t *testing.T) { testCtl(t, leaseTestGrantLeaseListed) }
func TestCtlV3LeaseGrantLeasesNoTLS(t *testing.T) {
testCtl(t, leaseTestGrantLeaseListed, withCfg(configNoTLS))
}
func TestCtlV3LeaseGrantLeasesClientTLS(t *testing.T) {
testCtl(t, leaseTestGrantLeaseListed, withCfg(configClientTLS))
}
func TestCtlV3LeaseGrantLeasesClientAutoTLS(t *testing.T) {
testCtl(t, leaseTestGrantLeaseListed, withCfg(configClientAutoTLS))
}
func TestCtlV3LeaseGrantLeasesPeerTLS(t *testing.T) {
testCtl(t, leaseTestGrantLeaseListed, withCfg(configPeerTLS))
}

func TestCtlV3LeaseTestTimeToLiveExpired(t *testing.T) { testCtl(t, leaseTestTimeToLiveExpired) }
func TestCtlV3LeaseKeepAlive(t *testing.T) { testCtl(t, leaseTestKeepAlive) }
func TestCtlV3LeaseKeepAliveOnce(t *testing.T) { testCtl(t, leaseTestKeepAliveOnce) }
func TestCtlV3LeaseRevoke(t *testing.T) { testCtl(t, leaseTestRevoke) }
func TestCtlV3LeaseTestTimeToLiveExpiredNoTLS(t *testing.T) {
testCtl(t, leaseTestTimeToLiveExpired, withCfg(configNoTLS))
}
func TestCtlV3LeaseTestTimeToLiveExpiredClientTLS(t *testing.T) {
testCtl(t, leaseTestTimeToLiveExpired, withCfg(configClientTLS))
}
func TestCtlV3LeaseTestTimeToLiveExpiredClientAutoTLS(t *testing.T) {
testCtl(t, leaseTestTimeToLiveExpired, withCfg(configClientAutoTLS))
}
func TestCtlV3LeaseTestTimeToLiveExpiredPeerTLS(t *testing.T) {
testCtl(t, leaseTestTimeToLiveExpired, withCfg(configPeerTLS))
}

func TestCtlV3LeaseKeepAlive(t *testing.T) { testCtl(t, leaseTestKeepAlive) }
func TestCtlV3LeaseKeepAliveNoTLS(t *testing.T) { testCtl(t, leaseTestKeepAlive, withCfg(configNoTLS)) }
func TestCtlV3LeaseKeepAliveClientTLS(t *testing.T) {
testCtl(t, leaseTestKeepAlive, withCfg(configClientTLS))
}
func TestCtlV3LeaseKeepAliveClientAutoTLS(t *testing.T) {
testCtl(t, leaseTestKeepAlive, withCfg(configClientAutoTLS))
}
func TestCtlV3LeaseKeepAlivePeerTLS(t *testing.T) {
testCtl(t, leaseTestKeepAlive, withCfg(configPeerTLS))
}

func TestCtlV3LeaseKeepAliveOnce(t *testing.T) { testCtl(t, leaseTestKeepAliveOnce) }
func TestCtlV3LeaseKeepAliveOnceNoTLS(t *testing.T) {
testCtl(t, leaseTestKeepAliveOnce, withCfg(configNoTLS))
}
func TestCtlV3LeaseKeepAliveOnceClientTLS(t *testing.T) {
testCtl(t, leaseTestKeepAliveOnce, withCfg(configClientTLS))
}
func TestCtlV3LeaseKeepAliveOnceClientAutoTLS(t *testing.T) {
testCtl(t, leaseTestKeepAliveOnce, withCfg(configClientAutoTLS))
}
func TestCtlV3LeaseKeepAliveOncePeerTLS(t *testing.T) {
testCtl(t, leaseTestKeepAliveOnce, withCfg(configPeerTLS))
}

func TestCtlV3LeaseRevoke(t *testing.T) { testCtl(t, leaseTestRevoked) }
func TestCtlV3LeaseRevokeNoTLS(t *testing.T) { testCtl(t, leaseTestRevoked, withCfg(configNoTLS)) }
func TestCtlV3LeaseRevokeClientTLS(t *testing.T) {
testCtl(t, leaseTestRevoked, withCfg(configClientTLS))
}
func TestCtlV3LeaseRevokeClientAutoTLS(t *testing.T) {
testCtl(t, leaseTestRevoked, withCfg(configClientAutoTLS))
}
func TestCtlV3LeaseRevokePeerTLS(t *testing.T) { testCtl(t, leaseTestRevoked, withCfg(configPeerTLS)) }

func leaseTestGrantTimeToLive(cx ctlCtx) {
id, err := ctlV3LeaseGrant(cx, 10)
if err != nil {
cx.t.Fatal(err)
cx.t.Fatalf("leaseTestGrantTimeToLive: ctlV3LeaseGrant error (%v)", err)
}

cmdArgs := append(cx.PrefixArgs(), "lease", "timetolive", id, "--keys")
proc, err := spawnCmd(cmdArgs)
if err != nil {
cx.t.Fatal(err)
cx.t.Fatalf("leaseTestGrantTimeToLive: error (%v)", err)
}
line, err := proc.Expect(" granted with TTL(")
if err != nil {
cx.t.Fatal(err)
cx.t.Fatalf("leaseTestGrantTimeToLive: error (%v)", err)
}
if err = proc.Close(); err != nil {
cx.t.Fatal(err)
cx.t.Fatalf("leaseTestGrantTimeToLive: error (%v)", err)
}
if !strings.Contains(line, ", attached keys") {
cx.t.Fatalf("expected 'attached keys', got %q", line)
cx.t.Fatalf("leaseTestGrantTimeToLive: expected 'attached keys', got %q", line)
}
if !strings.Contains(line, id) {
cx.t.Fatalf("expected leaseID %q, got %q", id, line)
cx.t.Fatalf("leaseTestGrantTimeToLive: expected leaseID %q, got %q", id, line)
}
}

func leaseTestGrantLeaseListed(cx ctlCtx) {
err := leaseTestGrantLeasesList(cx)
if err != nil {
cx.t.Fatalf("leaseTestGrantLeasesList: (%v)", err)
}
}

func leaseTestGrantLeasesList(cx ctlCtx) {
func leaseTestGrantLeasesList(cx ctlCtx) error {
id, err := ctlV3LeaseGrant(cx, 10)
if err != nil {
cx.t.Fatal(err)
return fmt.Errorf("ctlV3LeaseGrant error (%v)", err)
}

cmdArgs := append(cx.PrefixArgs(), "lease", "list")
proc, err := spawnCmd(cmdArgs)
if err != nil {
cx.t.Fatal(err)
return fmt.Errorf("lease list failed (%v)", err)
}
_, err = proc.Expect(id)
if err != nil {
cx.t.Fatal(err)
return fmt.Errorf("lease id not in returned list (%v)", err)
}
if err = proc.Close(); err != nil {
cx.t.Fatal(err)
return err
}
return nil
}

func leaseTestTimeToLiveExpired(cx ctlCtx) {
err := leaseTestTimeToLiveExpire(cx, 3)
if err != nil {
cx.t.Fatal(err)
cx.t.Fatalf("leaseTestTimeToLiveExpire: (%v)", err)
}
}

func leaseTestTimeToLiveExpire(cx ctlCtx, ttl int) error {
leaseID, err := ctlV3LeaseGrant(cx, ttl)
if err != nil {
return err
return fmt.Errorf("ctlV3LeaseGrant error (%v)", err)
}

if err = ctlV3Put(cx, "key", "val", leaseID); err != nil {
return fmt.Errorf("leaseTestTimeToLiveExpire: ctlV3Put error (%v)", err)
return fmt.Errorf("ctlV3Put error (%v)", err)
}
// eliminate false positive
time.Sleep(time.Duration(ttl+1) * time.Second)
cmdArgs := append(cx.PrefixArgs(), "lease", "timetolive", leaseID)
exp := fmt.Sprintf("lease %s already expired", leaseID)
if err = spawnWithExpect(cmdArgs, exp); err != nil {
return err
return fmt.Errorf("lease not properly expired: (%v)", err)
}
if err := ctlV3Get(cx, []string{"key"}); err != nil {
return fmt.Errorf("leaseTestTimeToLiveExpire: ctlV3Get error (%v)", err)
return fmt.Errorf("ctlV3Get error (%v)", err)
}
return nil
}
Expand Down Expand Up @@ -138,21 +217,29 @@ func leaseTestKeepAliveOnce(cx ctlCtx) {
}
}

func leaseTestRevoke(cx ctlCtx) {
func leaseTestRevoked(cx ctlCtx) {
err := leaseTestRevoke(cx)
if err != nil {
cx.t.Fatalf("leaseTestRevoke: (%v)", err)
}
}

func leaseTestRevoke(cx ctlCtx) error {
// put with TTL 10 seconds and revoke
leaseID, err := ctlV3LeaseGrant(cx, 10)
if err != nil {
cx.t.Fatalf("leaseTestRevoke: ctlV3LeaseGrant error (%v)", err)
return fmt.Errorf("ctlV3LeaseGrant error (%v)", err)
}
if err := ctlV3Put(cx, "key", "val", leaseID); err != nil {
cx.t.Fatalf("leaseTestRevoke: ctlV3Put error (%v)", err)
return fmt.Errorf("ctlV3Put error (%v)", err)
}
if err := ctlV3LeaseRevoke(cx, leaseID); err != nil {
cx.t.Fatalf("leaseTestRevoke: ctlV3LeaseRevok error (%v)", err)
return fmt.Errorf("ctlV3LeaseRevoke error (%v)", err)
}
if err := ctlV3Get(cx, []string{"key"}); err != nil { // expect no output
cx.t.Fatalf("leaseTestRevoke: ctlV3Get error (%v)", err)
return fmt.Errorf("ctlV3Get error (%v)", err)
}
return nil
}

func ctlV3LeaseGrant(cx ctlCtx, ttl int) (string, error) {
Expand Down

0 comments on commit cb5d089

Please sign in to comment.