evalCmp executes the given comparison between some field of a key-value pair stored in mockKV and a provided value. The field may be the value stored or one of the various version numbers associated with it.
(cmp clientv3.Cmp)
| 395 | // pair stored in mockKV and a provided value. The field may be the value |
| 396 | // stored or one of the various version numbers associated with it. |
| 397 | func (m *mockKV) evalCmp(cmp clientv3.Cmp) bool { |
| 398 | // Note that we're not checking if there was an existing entry for this |
| 399 | // key/value pair since we'll get one with all zero values in that case. |
| 400 | // This allows transactions to compare a '0' version so that they can be |
| 401 | // used to only create an entry if there previously was none. |
| 402 | entry := m.values[string(cmp.KeyBytes())] |
| 403 | |
| 404 | switch cmp.Target { |
| 405 | case etcdserverpb.Compare_VALUE: |
| 406 | v, _ := cmp.TargetUnion.(*etcdserverpb.Compare_Value) |
| 407 | return m.evalEntryBytes(entry.Value, v.Value, cmp) |
| 408 | case etcdserverpb.Compare_CREATE: |
| 409 | v, _ := cmp.TargetUnion.(*etcdserverpb.Compare_CreateRevision) |
| 410 | return m.evalEntryInt64(entry.CreateRevision, v.CreateRevision, cmp) |
| 411 | case etcdserverpb.Compare_LEASE: |
| 412 | v, _ := cmp.TargetUnion.(*etcdserverpb.Compare_Lease) |
| 413 | return m.evalEntryInt64(entry.Lease, v.Lease, cmp) |
| 414 | case etcdserverpb.Compare_VERSION: |
| 415 | v, _ := cmp.TargetUnion.(*etcdserverpb.Compare_Version) |
| 416 | return m.evalEntryInt64(entry.Version, v.Version, cmp) |
| 417 | case etcdserverpb.Compare_MOD: |
| 418 | v, _ := cmp.TargetUnion.(*etcdserverpb.Compare_ModRevision) |
| 419 | return m.evalEntryInt64(entry.ModRevision, v.ModRevision, cmp) |
| 420 | default: |
| 421 | panic(fmt.Sprintf("unsupported target for cmp: %+v", cmp)) |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | // evalEntryBytes returns true if the provided comparison between two |
| 426 | // byte slices is true, false otherwise. This is used to compare values |
no test coverage detected