diff --git a/api/kv_test.go b/api/kv_test.go index bd432194b8..7e8b4cc181 100644 --- a/api/kv_test.go +++ b/api/kv_test.go @@ -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]) } diff --git a/consul/state/txn.go b/consul/state/txn.go index f324831cd0..11662d129c 100644 --- a/consul/state/txn.go +++ b/consul/state/txn.go @@ -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) diff --git a/consul/state/txn_test.go b/consul/state/txn_test.go index dd459bc523..9e8f88234d 100644 --- a/consul/state/txn_test.go +++ b/consul/state/txn_test.go @@ -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",