mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: migrate TestCtlV3LeaseGrantTimeToLive.* to common
This commit is contained in:
71
tests/common/lease_test.go
Normal file
71
tests/common/lease_test.go
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright 2022 The etcd Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.etcd.io/etcd/tests/v3/framework/config"
|
||||
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
||||
)
|
||||
|
||||
func TestLeaseGrantTimeToLive(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() {
|
||||
ttl := int64(10)
|
||||
leaseResp, err := cc.Grant(ttl)
|
||||
require.NoError(t, err)
|
||||
|
||||
ttlResp, err := cc.TimeToLive(leaseResp.ID, config.LeaseOption{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, ttl, ttlResp.GrantedTTL)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -24,20 +24,6 @@ import (
|
||||
"go.etcd.io/etcd/tests/v3/framework/e2e"
|
||||
)
|
||||
|
||||
func TestCtlV3LeaseGrantTimeToLive(t *testing.T) { testCtl(t, leaseTestGrantTimeToLive) }
|
||||
func TestCtlV3LeaseGrantTimeToLiveNoTLS(t *testing.T) {
|
||||
testCtl(t, leaseTestGrantTimeToLive, withCfg(*e2e.NewConfigNoTLS()))
|
||||
}
|
||||
func TestCtlV3LeaseGrantTimeToLiveClientTLS(t *testing.T) {
|
||||
testCtl(t, leaseTestGrantTimeToLive, withCfg(*e2e.NewConfigClientTLS()))
|
||||
}
|
||||
func TestCtlV3LeaseGrantTimeToLiveClientAutoTLS(t *testing.T) {
|
||||
testCtl(t, leaseTestGrantTimeToLive, withCfg(*e2e.NewConfigClientAutoTLS()))
|
||||
}
|
||||
func TestCtlV3LeaseGrantTimeToLivePeerTLS(t *testing.T) {
|
||||
testCtl(t, leaseTestGrantTimeToLive, withCfg(*e2e.NewConfigPeerTLS()))
|
||||
}
|
||||
|
||||
func TestCtlV3LeaseGrantLeases(t *testing.T) { testCtl(t, leaseTestGrantLeaseListed) }
|
||||
func TestCtlV3LeaseGrantLeasesNoTLS(t *testing.T) {
|
||||
testCtl(t, leaseTestGrantLeaseListed, withCfg(*e2e.NewConfigNoTLS()))
|
||||
@@ -108,32 +94,6 @@ func TestCtlV3LeaseRevokePeerTLS(t *testing.T) {
|
||||
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigPeerTLS()))
|
||||
}
|
||||
|
||||
func leaseTestGrantTimeToLive(cx ctlCtx) {
|
||||
id, err := ctlV3LeaseGrant(cx, 10)
|
||||
if err != nil {
|
||||
cx.t.Fatalf("leaseTestGrantTimeToLive: ctlV3LeaseGrant error (%v)", err)
|
||||
}
|
||||
|
||||
cmdArgs := append(cx.PrefixArgs(), "lease", "timetolive", id, "--keys")
|
||||
proc, err := e2e.SpawnCmd(cmdArgs, cx.envMap)
|
||||
if err != nil {
|
||||
cx.t.Fatalf("leaseTestGrantTimeToLive: error (%v)", err)
|
||||
}
|
||||
line, err := proc.Expect(" granted with TTL(")
|
||||
if err != nil {
|
||||
cx.t.Fatalf("leaseTestGrantTimeToLive: error (%v)", err)
|
||||
}
|
||||
if err = proc.Close(); err != nil {
|
||||
cx.t.Fatalf("leaseTestGrantTimeToLive: error (%v)", err)
|
||||
}
|
||||
if !strings.Contains(line, ", attached keys") {
|
||||
cx.t.Fatalf("leaseTestGrantTimeToLive: expected 'attached keys', got %q", line)
|
||||
}
|
||||
if !strings.Contains(line, id) {
|
||||
cx.t.Fatalf("leaseTestGrantTimeToLive: expected leaseID %q, got %q", id, line)
|
||||
}
|
||||
}
|
||||
|
||||
func leaseTestGrantLeaseListed(cx ctlCtx) {
|
||||
err := leaseTestGrantLeasesList(cx)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user