mirror of https://github.com/status-im/consul.git
De-nests the KV output structure (removes DirEnt member).
This commit is contained in:
parent
960b9d6fb6
commit
4882a9fe43
|
@ -286,7 +286,7 @@ type TxnOps []*TxnOp
|
|||
|
||||
// TxnResult is the internal format we receive from Consul.
|
||||
type TxnResult struct {
|
||||
KV *struct{ DirEnt *KVPair }
|
||||
KV *KVPair
|
||||
}
|
||||
|
||||
// TxnResults is a list of TxnResult objects.
|
||||
|
@ -373,11 +373,7 @@ func (k *KV) Txn(txn KVTxnOps, q *WriteOptions) (bool, *KVTxnResponse, *WriteMet
|
|||
Errors: txnResp.Errors,
|
||||
}
|
||||
for _, result := range txnResp.Results {
|
||||
var entry *KVPair
|
||||
if result.KV != nil {
|
||||
entry = result.KV.DirEnt
|
||||
}
|
||||
kvResp.Results = append(kvResp.Results, entry)
|
||||
kvResp.Results = append(kvResp.Results, result.KV)
|
||||
}
|
||||
return resp.StatusCode == http.StatusOK, &kvResp, wm, nil
|
||||
}
|
||||
|
|
|
@ -126,36 +126,32 @@ func TestTxnEndpoint_KV_Actions(t *testing.T) {
|
|||
if len(txnResp.Results) != 2 {
|
||||
t.Fatalf("bad: %v", txnResp)
|
||||
}
|
||||
index = txnResp.Results[0].KV.DirEnt.ModifyIndex
|
||||
index = txnResp.Results[0].KV.ModifyIndex
|
||||
expected := structs.TxnResponse{
|
||||
Results: structs.TxnResults{
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "key",
|
||||
Value: nil,
|
||||
Flags: 23,
|
||||
Session: id,
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: index,
|
||||
ModifyIndex: index,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "key",
|
||||
Value: nil,
|
||||
Flags: 23,
|
||||
Session: id,
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: index,
|
||||
ModifyIndex: index,
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "key",
|
||||
Value: []byte("hello world"),
|
||||
Flags: 23,
|
||||
Session: id,
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: index,
|
||||
ModifyIndex: index,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "key",
|
||||
Value: []byte("hello world"),
|
||||
Flags: 23,
|
||||
Session: id,
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: index,
|
||||
ModifyIndex: index,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -208,32 +204,28 @@ func TestTxnEndpoint_KV_Actions(t *testing.T) {
|
|||
if len(txnResp.Results) != 2 {
|
||||
t.Fatalf("bad: %v", txnResp)
|
||||
}
|
||||
modIndex := txnResp.Results[0].KV.DirEnt.ModifyIndex
|
||||
modIndex := txnResp.Results[0].KV.ModifyIndex
|
||||
expected := structs.TxnResponse{
|
||||
Results: structs.TxnResults{
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "key",
|
||||
Value: nil,
|
||||
Session: id,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: index,
|
||||
ModifyIndex: modIndex,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "key",
|
||||
Value: nil,
|
||||
Session: id,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: index,
|
||||
ModifyIndex: modIndex,
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "key",
|
||||
Value: []byte("goodbye world"),
|
||||
Session: id,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: index,
|
||||
ModifyIndex: modIndex,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "key",
|
||||
Value: []byte("goodbye world"),
|
||||
Session: id,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: index,
|
||||
ModifyIndex: modIndex,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github.com/hashicorp/go-memdb"
|
||||
)
|
||||
|
||||
func (s *StateStore) txnKVS(tx *memdb.Txn, idx uint64, op *structs.TxnKVOp) (*structs.TxnKVResult, error) {
|
||||
func (s *StateStore) txnKVS(tx *memdb.Txn, idx uint64, op *structs.TxnKVOp) (structs.TxnKVResult, error) {
|
||||
var entry *structs.DirEntry
|
||||
var err error
|
||||
|
||||
|
@ -74,12 +74,12 @@ func (s *StateStore) txnKVS(tx *memdb.Txn, idx uint64, op *structs.TxnKVOp) (*st
|
|||
// the state store).
|
||||
if entry != nil {
|
||||
if op.Verb == structs.KVSGet {
|
||||
return &structs.TxnKVResult{entry}, nil
|
||||
return entry, nil
|
||||
}
|
||||
|
||||
clone := entry.Clone()
|
||||
clone.Value = nil
|
||||
return &structs.TxnKVResult{clone}, nil
|
||||
return clone, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
|
|
@ -177,13 +177,11 @@ func TestStateStore_Txn_KVS(t *testing.T) {
|
|||
// Make sure the response looks as expected.
|
||||
expected := structs.TxnResults{
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "foo/new",
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 8,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "foo/new",
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 8,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -191,112 +189,94 @@ func TestStateStore_Txn_KVS(t *testing.T) {
|
|||
&structs.TxnResult{}, // delete tree
|
||||
&structs.TxnResult{}, // delete CAS
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "foo/update",
|
||||
Value: []byte("stale"),
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 5,
|
||||
ModifyIndex: 5,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "foo/update",
|
||||
Value: []byte("stale"),
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 5,
|
||||
ModifyIndex: 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
KV: &structs.DirEntry{
|
||||
|
||||
Key: "foo/update",
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 5,
|
||||
ModifyIndex: 5,
|
||||
},
|
||||
Key: "foo/update",
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 5,
|
||||
ModifyIndex: 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "foo/update",
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 5,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "foo/update",
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 5,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "foo/update",
|
||||
Value: []byte("new"),
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 5,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "foo/update",
|
||||
Value: []byte("new"),
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 5,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{}, // get on not/there
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "foo/update",
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 5,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "foo/update",
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 5,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{}, // get on foo/lock before it's created
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "foo/lock",
|
||||
Session: session,
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 8,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "foo/lock",
|
||||
Session: session,
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 8,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "foo/lock",
|
||||
Session: session,
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 8,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "foo/lock",
|
||||
Session: session,
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 8,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "foo/lock",
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 8,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "foo/lock",
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 8,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "foo/lock",
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 8,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "foo/lock",
|
||||
LockIndex: 1,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: 8,
|
||||
ModifyIndex: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -13,9 +13,7 @@ type TxnKVOp struct {
|
|||
|
||||
// TxnKVResult is used to define the result of a single operation on the KVS
|
||||
// inside a transaction.
|
||||
type TxnKVResult struct {
|
||||
DirEnt *DirEntry
|
||||
}
|
||||
type TxnKVResult *DirEntry
|
||||
|
||||
// TxnOp is used to define a single operation inside a transaction. Only one
|
||||
// of the types should be filled out per entry.
|
||||
|
@ -56,7 +54,7 @@ type TxnErrors []*TxnError
|
|||
// TxnResult is used to define the result of a given operation inside a
|
||||
// transaction. Only one of the types should be filled out per entry.
|
||||
type TxnResult struct {
|
||||
KV *TxnKVResult
|
||||
KV TxnKVResult
|
||||
}
|
||||
|
||||
// TxnResults is a list of TxnResult entries.
|
||||
|
|
|
@ -71,28 +71,24 @@ func TestTxn_Apply(t *testing.T) {
|
|||
expected := structs.TxnResponse{
|
||||
Results: structs.TxnResults{
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "test",
|
||||
Flags: 42,
|
||||
Value: nil,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: d.CreateIndex,
|
||||
ModifyIndex: d.ModifyIndex,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "test",
|
||||
Flags: 42,
|
||||
Value: nil,
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: d.CreateIndex,
|
||||
ModifyIndex: d.ModifyIndex,
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{
|
||||
KV: &structs.TxnKVResult{
|
||||
DirEnt: &structs.DirEntry{
|
||||
Key: "test",
|
||||
Flags: 42,
|
||||
Value: []byte("test"),
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: d.CreateIndex,
|
||||
ModifyIndex: d.ModifyIndex,
|
||||
},
|
||||
KV: &structs.DirEntry{
|
||||
Key: "test",
|
||||
Flags: 42,
|
||||
Value: []byte("test"),
|
||||
RaftIndex: structs.RaftIndex{
|
||||
CreateIndex: d.CreateIndex,
|
||||
ModifyIndex: d.ModifyIndex,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -315,7 +311,7 @@ func TestTxn_Apply_LockDelay(t *testing.T) {
|
|||
}
|
||||
if len(out.Results) != 1 ||
|
||||
len(out.Errors) != 0 ||
|
||||
out.Results[0].KV.DirEnt.LockIndex != 2 {
|
||||
out.Results[0].KV.LockIndex != 2 {
|
||||
t.Fatalf("bad: %v", out)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue