mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: Migrate TestCtlV3LeaseRevoke.* to common
This commit is contained in:
parent
ab3353582d
commit
87740f6c7b
@ -259,3 +259,64 @@ func TestLeaseGrantKeepAliveOnce(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLeaseGrantRevoke(t *testing.T) {
|
||||
testRunner.BeforeTest(t)
|
||||
|
||||
tcs := []struct {
|
||||
name string
|
||||
config config.ClusterConfig
|
||||
}{
|
||||
{
|
||||
name: "NoTLS",
|
||||
config: config.ClusterConfig{ClusterSize: 1},
|
||||
},
|
||||
{
|
||||
name: "PeerTLS",
|
||||
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS},
|
||||
},
|
||||
{
|
||||
name: "PeerAutoTLS",
|
||||
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS},
|
||||
},
|
||||
{
|
||||
name: "ClientTLS",
|
||||
config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.ManualTLS},
|
||||
},
|
||||
{
|
||||
name: "ClientAutoTLS",
|
||||
config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.AutoTLS},
|
||||
},
|
||||
}
|
||||
for _, tc := range tcs {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
clus := testRunner.NewCluster(t, tc.config)
|
||||
defer clus.Close()
|
||||
cc := clus.Client()
|
||||
|
||||
testutils.ExecuteWithTimeout(t, 10*time.Second, func() {
|
||||
leaseResp, err := cc.Grant(20)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = cc.Put("foo", "bar", config.PutOptions{LeaseID: leaseResp.ID})
|
||||
require.NoError(t, err)
|
||||
|
||||
getResp, err := cc.Get("foo", config.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(1), getResp.Count)
|
||||
|
||||
_, err = cc.LeaseRevoke(leaseResp.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
ttlResp, err := cc.TimeToLive(leaseResp.ID, config.LeaseOption{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(-1), ttlResp.TTL)
|
||||
|
||||
getResp, err = cc.Get("foo", config.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
// Value should expire with the lease
|
||||
require.Equal(t, int64(0), getResp.Count)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -37,20 +37,6 @@ func TestCtlV3LeaseKeepAlivePeerTLS(t *testing.T) {
|
||||
testCtl(t, leaseTestKeepAlive, withCfg(*e2e.NewConfigPeerTLS()))
|
||||
}
|
||||
|
||||
func TestCtlV3LeaseRevoke(t *testing.T) { testCtl(t, leaseTestRevoked) }
|
||||
func TestCtlV3LeaseRevokeNoTLS(t *testing.T) {
|
||||
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigNoTLS()))
|
||||
}
|
||||
func TestCtlV3LeaseRevokeClientTLS(t *testing.T) {
|
||||
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigClientTLS()))
|
||||
}
|
||||
func TestCtlV3LeaseRevokeClientAutoTLS(t *testing.T) {
|
||||
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigClientAutoTLS()))
|
||||
}
|
||||
func TestCtlV3LeaseRevokePeerTLS(t *testing.T) {
|
||||
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigPeerTLS()))
|
||||
}
|
||||
|
||||
func leaseTestKeepAlive(cx ctlCtx) {
|
||||
// put with TTL 10 seconds and keep-alive
|
||||
leaseID, err := ctlV3LeaseGrant(cx, 10)
|
||||
@ -68,31 +54,6 @@ func leaseTestKeepAlive(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 {
|
||||
return fmt.Errorf("ctlV3LeaseGrant error (%v)", err)
|
||||
}
|
||||
if err := ctlV3Put(cx, "key", "val", leaseID); err != nil {
|
||||
return fmt.Errorf("ctlV3Put error (%v)", err)
|
||||
}
|
||||
if err := ctlV3LeaseRevoke(cx, leaseID); err != nil {
|
||||
return fmt.Errorf("ctlV3LeaseRevoke error (%v)", err)
|
||||
}
|
||||
if err := ctlV3Get(cx, []string{"key"}); err != nil { // expect no output
|
||||
return fmt.Errorf("ctlV3Get error (%v)", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ctlV3LeaseGrant(cx ctlCtx, ttl int) (string, error) {
|
||||
cmdArgs := append(cx.PrefixArgs(), "lease", "grant", strconv.Itoa(ttl))
|
||||
proc, err := e2e.SpawnCmd(cmdArgs, cx.envMap)
|
||||
|
Loading…
x
Reference in New Issue
Block a user