tests/framework: Add PutOptions
Put can take a leaseid to associate a value with a lease. This adds the ability for tests to make use of this.
This commit is contained in:
@ -47,7 +47,7 @@ func TestCompact(t *testing.T) {
|
||||
testutils.ExecuteWithTimeout(t, 10*time.Second, func() {
|
||||
var kvs = []testutils.KV{{Key: "key", Val: "val1"}, {Key: "key", Val: "val2"}, {Key: "key", Val: "val3"}}
|
||||
for i := range kvs {
|
||||
if err := clus.Client().Put(kvs[i].Key, kvs[i].Val); err != nil {
|
||||
if err := clus.Client().Put(kvs[i].Key, kvs[i].Val, config.PutOptions{}); err != nil {
|
||||
t.Fatalf("compactTest #%d: put kv error (%v)", i, err)
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ func TestDefragOnline(t *testing.T) {
|
||||
defer clus.Close()
|
||||
var kvs = []testutils.KV{{Key: "key", Val: "val1"}, {Key: "key", Val: "val2"}, {Key: "key", Val: "val3"}}
|
||||
for i := range kvs {
|
||||
if err := clus.Client().Put(kvs[i].Key, kvs[i].Val); err != nil {
|
||||
if err := clus.Client().Put(kvs[i].Key, kvs[i].Val, config.PutOptions{}); err != nil {
|
||||
t.Fatalf("compactTest #%d: put kv error (%v)", i, err)
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func TestKVPut(t *testing.T) {
|
||||
testutils.ExecuteWithTimeout(t, 10*time.Second, func() {
|
||||
key, value := "foo", "bar"
|
||||
|
||||
if err := cc.Put(key, value); err != nil {
|
||||
if err := cc.Put(key, value, config.PutOptions{}); err != nil {
|
||||
t.Fatalf("count not put key %q, err: %s", key, err)
|
||||
}
|
||||
resp, err := cc.Get(key, config.GetOptions{Serializable: true})
|
||||
@ -123,7 +123,7 @@ func TestKVGet(t *testing.T) {
|
||||
)
|
||||
|
||||
for i := range kvs {
|
||||
if err := cc.Put(kvs[i], "bar"); err != nil {
|
||||
if err := cc.Put(kvs[i], "bar", config.PutOptions{}); err != nil {
|
||||
t.Fatalf("count not put key %q, err: %s", kvs[i], err)
|
||||
}
|
||||
}
|
||||
@ -246,7 +246,7 @@ func TestKVDelete(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
for i := range kvs {
|
||||
if err := cc.Put(kvs[i], "bar"); err != nil {
|
||||
if err := cc.Put(kvs[i], "bar", config.PutOptions{}); err != nil {
|
||||
t.Fatalf("count not put key %q, err: %s", kvs[i], err)
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.etcd.io/etcd/tests/v3/framework/config"
|
||||
"go.etcd.io/etcd/tests/v3/framework/e2e"
|
||||
"go.etcd.io/etcd/tests/v3/framework/testutils"
|
||||
)
|
||||
@ -100,7 +101,7 @@ func TestAuthority(t *testing.T) {
|
||||
endpoints := templateEndpoints(t, tc.clientURLPattern, epc)
|
||||
|
||||
client := e2e.NewEtcdctl(cfg, endpoints)
|
||||
err = client.Put("foo", "bar")
|
||||
err = client.Put("foo", "bar", config.PutOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -32,6 +32,10 @@ type GetOptions struct {
|
||||
SortBy clientv3.SortTarget
|
||||
}
|
||||
|
||||
type PutOptions struct {
|
||||
LeaseID clientv3.LeaseID
|
||||
}
|
||||
|
||||
type DeleteOptions struct {
|
||||
Prefix bool
|
||||
FromKey bool
|
||||
|
@ -107,8 +107,13 @@ func (ctl *EtcdctlV3) Get(key string, o config.GetOptions) (*clientv3.GetRespons
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
func (ctl *EtcdctlV3) Put(key, value string) error {
|
||||
return SpawnWithExpect(ctl.cmdArgs("put", key, value), "OK")
|
||||
func (ctl *EtcdctlV3) Put(key, value string, opts config.PutOptions) error {
|
||||
args := ctl.cmdArgs()
|
||||
args = append(args, "put", key, value)
|
||||
if opts.LeaseID != 0 {
|
||||
args = append(args, "--lease", strconv.FormatInt(int64(opts.LeaseID), 16))
|
||||
}
|
||||
return SpawnWithExpect(args, "OK")
|
||||
}
|
||||
|
||||
func (ctl *EtcdctlV3) Delete(key string, o config.DeleteOptions) (*clientv3.DeleteResponse, error) {
|
||||
|
@ -126,8 +126,12 @@ func (c integrationClient) Get(key string, o config.GetOptions) (*clientv3.GetRe
|
||||
return c.Client.Get(context.Background(), key, clientOpts...)
|
||||
}
|
||||
|
||||
func (c integrationClient) Put(key, value string) error {
|
||||
_, err := c.Client.Put(context.Background(), key, value)
|
||||
func (c integrationClient) Put(key, value string, opts config.PutOptions) error {
|
||||
clientOpts := []clientv3.OpOption{}
|
||||
if opts.LeaseID != 0 {
|
||||
clientOpts = append(clientOpts, clientv3.WithLease(opts.LeaseID))
|
||||
}
|
||||
_, err := c.Client.Put(context.Background(), key, value, clientOpts...)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ type Cluster interface {
|
||||
}
|
||||
|
||||
type Client interface {
|
||||
Put(key, value string) error
|
||||
Put(key, value string, opts config.PutOptions) error
|
||||
Get(key string, opts config.GetOptions) (*clientv3.GetResponse, error)
|
||||
Delete(key string, opts config.DeleteOptions) (*clientv3.DeleteResponse, error)
|
||||
Compact(rev int64, opts config.CompactOption) (*clientv3.CompactResponse, error)
|
||||
|
Reference in New Issue
Block a user