mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: migrate TestCtlV3LeaseGrantLeases.* to common
This commit is contained in:
parent
68e6493977
commit
b7beaf9c62
@ -19,6 +19,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
"go.etcd.io/etcd/tests/v3/framework/config"
|
"go.etcd.io/etcd/tests/v3/framework/config"
|
||||||
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
||||||
)
|
)
|
||||||
@ -69,3 +70,80 @@ func TestLeaseGrantTimeToLive(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLeaseGrantAndList(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 {
|
||||||
|
nestedCases := []struct {
|
||||||
|
name string
|
||||||
|
leaseCount int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no_leases",
|
||||||
|
leaseCount: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "one_lease",
|
||||||
|
leaseCount: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "many_leases",
|
||||||
|
leaseCount: 3,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, nc := range nestedCases {
|
||||||
|
t.Run(tc.name+"/"+nc.name, func(t *testing.T) {
|
||||||
|
clus := testRunner.NewCluster(t, tc.config)
|
||||||
|
defer clus.Close()
|
||||||
|
cc := clus.Client()
|
||||||
|
|
||||||
|
testutils.ExecuteWithTimeout(t, 10*time.Second, func() {
|
||||||
|
createdLeases := []clientv3.LeaseID{}
|
||||||
|
for i := 0; i < nc.leaseCount; i++ {
|
||||||
|
leaseResp, err := cc.Grant(10)
|
||||||
|
require.NoError(t, err)
|
||||||
|
createdLeases = append(createdLeases, leaseResp.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := cc.LeaseList()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, resp.Leases, nc.leaseCount)
|
||||||
|
|
||||||
|
returnedLeases := make([]clientv3.LeaseID, 0, nc.leaseCount)
|
||||||
|
for _, status := range resp.Leases {
|
||||||
|
returnedLeases = append(returnedLeases, status.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
require.ElementsMatch(t, createdLeases, returnedLeases)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -862,6 +862,24 @@ func authLeaseTestLeaseGrantLeases(cx ctlCtx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func leaseTestGrantLeasesList(cx ctlCtx) error {
|
||||||
|
id, err := ctlV3LeaseGrant(cx, 10)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ctlV3LeaseGrant error (%v)", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmdArgs := append(cx.PrefixArgs(), "lease", "list")
|
||||||
|
proc, err := e2e.SpawnCmd(cmdArgs, cx.envMap)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("lease list failed (%v)", err)
|
||||||
|
}
|
||||||
|
_, err = proc.Expect(id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("lease id not in returned list (%v)", err)
|
||||||
|
}
|
||||||
|
return proc.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func authLeaseTestLeaseRevoke(cx ctlCtx) {
|
func authLeaseTestLeaseRevoke(cx ctlCtx) {
|
||||||
cx.user, cx.pass = "root", "root"
|
cx.user, cx.pass = "root", "root"
|
||||||
authSetupTestUser(cx)
|
authSetupTestUser(cx)
|
||||||
|
@ -24,20 +24,6 @@ import (
|
|||||||
"go.etcd.io/etcd/tests/v3/framework/e2e"
|
"go.etcd.io/etcd/tests/v3/framework/e2e"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCtlV3LeaseGrantLeases(t *testing.T) { testCtl(t, leaseTestGrantLeaseListed) }
|
|
||||||
func TestCtlV3LeaseGrantLeasesNoTLS(t *testing.T) {
|
|
||||||
testCtl(t, leaseTestGrantLeaseListed, withCfg(*e2e.NewConfigNoTLS()))
|
|
||||||
}
|
|
||||||
func TestCtlV3LeaseGrantLeasesClientTLS(t *testing.T) {
|
|
||||||
testCtl(t, leaseTestGrantLeaseListed, withCfg(*e2e.NewConfigClientTLS()))
|
|
||||||
}
|
|
||||||
func TestCtlV3LeaseGrantLeasesClientAutoTLS(t *testing.T) {
|
|
||||||
testCtl(t, leaseTestGrantLeaseListed, withCfg(*e2e.NewConfigClientAutoTLS()))
|
|
||||||
}
|
|
||||||
func TestCtlV3LeaseGrantLeasesPeerTLS(t *testing.T) {
|
|
||||||
testCtl(t, leaseTestGrantLeaseListed, withCfg(*e2e.NewConfigPeerTLS()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCtlV3LeaseTestTimeToLiveExpired(t *testing.T) { testCtl(t, leaseTestTimeToLiveExpired) }
|
func TestCtlV3LeaseTestTimeToLiveExpired(t *testing.T) { testCtl(t, leaseTestTimeToLiveExpired) }
|
||||||
func TestCtlV3LeaseTestTimeToLiveExpiredNoTLS(t *testing.T) {
|
func TestCtlV3LeaseTestTimeToLiveExpiredNoTLS(t *testing.T) {
|
||||||
testCtl(t, leaseTestTimeToLiveExpired, withCfg(*e2e.NewConfigNoTLS()))
|
testCtl(t, leaseTestTimeToLiveExpired, withCfg(*e2e.NewConfigNoTLS()))
|
||||||
@ -94,31 +80,6 @@ func TestCtlV3LeaseRevokePeerTLS(t *testing.T) {
|
|||||||
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigPeerTLS()))
|
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigPeerTLS()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func leaseTestGrantLeaseListed(cx ctlCtx) {
|
|
||||||
err := leaseTestGrantLeasesList(cx)
|
|
||||||
if err != nil {
|
|
||||||
cx.t.Fatalf("leaseTestGrantLeasesList: (%v)", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func leaseTestGrantLeasesList(cx ctlCtx) error {
|
|
||||||
id, err := ctlV3LeaseGrant(cx, 10)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("ctlV3LeaseGrant error (%v)", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdArgs := append(cx.PrefixArgs(), "lease", "list")
|
|
||||||
proc, err := e2e.SpawnCmd(cmdArgs, cx.envMap)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("lease list failed (%v)", err)
|
|
||||||
}
|
|
||||||
_, err = proc.Expect(id)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("lease id not in returned list (%v)", err)
|
|
||||||
}
|
|
||||||
return proc.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func leaseTestTimeToLiveExpired(cx ctlCtx) {
|
func leaseTestTimeToLiveExpired(cx ctlCtx) {
|
||||||
err := leaseTestTimeToLiveExpire(cx, 3)
|
err := leaseTestTimeToLiveExpire(cx, 3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user