mirror of https://github.com/status-im/consul.git
Makes get fail a transaction if the key doesn't exist.
This commit is contained in:
parent
4882a9fe43
commit
04d99cd702
|
@ -484,11 +484,12 @@ func TestClient_Txn(t *testing.T) {
|
|||
t.Fatalf("transaction should have failed")
|
||||
}
|
||||
|
||||
if ret == nil || len(ret.Errors) != 1 || len(ret.Results) != 0 {
|
||||
if ret == nil || len(ret.Errors) != 2 || len(ret.Results) != 0 {
|
||||
t.Fatalf("bad: %v", ret)
|
||||
}
|
||||
if ret.Errors[0].OpIndex != 0 ||
|
||||
!strings.Contains(ret.Errors[0].What, "missing session") {
|
||||
!strings.Contains(ret.Errors[0].What, "missing session") ||
|
||||
!strings.Contains(ret.Errors[1].What, "doesn't exist") {
|
||||
t.Fatalf("bad: %v", ret.Errors[0])
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,9 @@ func (s *StateStore) txnKVS(tx *memdb.Txn, idx uint64, op *structs.TxnKVOp) (str
|
|||
|
||||
case structs.KVSGet:
|
||||
_, entry, err = s.kvsGetTxn(tx, op.DirEnt.Key)
|
||||
if entry == nil && err == nil {
|
||||
err = fmt.Errorf("key %q doesn't exist", op.DirEnt.Key)
|
||||
}
|
||||
|
||||
case structs.KVSCheckSession:
|
||||
entry, err = s.kvsCheckSessionTxn(tx, op.DirEnt.Key, op.DirEnt.Session)
|
||||
|
|
|
@ -102,14 +102,6 @@ func TestStateStore_Txn_KVS(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnOp{
|
||||
KV: &structs.TxnKVOp{
|
||||
Verb: structs.KVSGet,
|
||||
DirEnt: structs.DirEntry{
|
||||
Key: "not/there",
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnOp{
|
||||
KV: &structs.TxnKVOp{
|
||||
Verb: structs.KVSCheckIndex,
|
||||
|
@ -121,14 +113,6 @@ func TestStateStore_Txn_KVS(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnOp{
|
||||
KV: &structs.TxnKVOp{
|
||||
Verb: structs.KVSGet,
|
||||
DirEnt: structs.DirEntry{
|
||||
Key: "foo/lock",
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnOp{
|
||||
KV: &structs.TxnKVOp{
|
||||
Verb: structs.KVSLock,
|
||||
|
@ -227,7 +211,6 @@ func TestStateStore_Txn_KVS(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{}, // get on not/there
|
||||
&structs.TxnResult{
|
||||
KV: &structs.DirEntry{
|
||||
Key: "foo/update",
|
||||
|
@ -237,7 +220,6 @@ func TestStateStore_Txn_KVS(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnResult{}, // get on foo/lock before it's created
|
||||
&structs.TxnResult{
|
||||
KV: &structs.DirEntry{
|
||||
Key: "foo/lock",
|
||||
|
@ -449,6 +431,14 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnOp{
|
||||
KV: &structs.TxnKVOp{
|
||||
Verb: structs.KVSGet,
|
||||
DirEnt: structs.DirEntry{
|
||||
Key: "nope",
|
||||
},
|
||||
},
|
||||
},
|
||||
&structs.TxnOp{
|
||||
KV: &structs.TxnKVOp{
|
||||
Verb: structs.KVSCheckSession,
|
||||
|
@ -505,6 +495,7 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) {
|
|||
"lock isn't held, or is held by another session",
|
||||
"current session",
|
||||
`key "nope" doesn't exist`,
|
||||
`key "nope" doesn't exist`,
|
||||
"current modify index",
|
||||
`key "nope" doesn't exist`,
|
||||
"unknown KV verb",
|
||||
|
|
Loading…
Reference in New Issue