MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / TestHashIncrbyfloat

Function TestHashIncrbyfloat

IceFireDB-PubSub/test/cmd_hash_test.go:422–493  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

420}
421
422func TestHashIncrbyfloat(t *testing.T) {
423 server.Clear()
424
425 c, err := proto.Dial(server.Addr())
426 ok(t, err)
427 defer c.Close()
428
429 // Existing key
430 {
431 directDo(t, c, "HSET", "hash", "field", "12")
432 mustDo(t, c,
433 "HINCRBYFLOAT", "hash", "field", "400.12",
434 proto.String("412.12"),
435 )
436 equals(t, "412.12", directDoString(t, c, "HGET", "hash", "field"))
437 }
438
439 // Existing key, not a number
440 {
441 directDo(t, c, "HSET", "hash", "field", "noint")
442 mustDo(t, c,
443 "HINCRBYFLOAT", "hash", "field", "400",
444 proto.Error("ERR value is not a valid float"),
445 )
446 }
447
448 // New key
449 {
450 mustDo(t, c,
451 "HINCRBYFLOAT", "hash", "newfield", "40.33",
452 proto.String("40.33"),
453 )
454 equals(t, "40.33", directDoString(t, c, "HGET", "hash", "newfield"))
455 }
456
457 t.Run("direct", func(t *testing.T) {
458 directDo(t, c, "HSET", "hash", "field", "500.1")
459 equals(t, "500.1", directDoString(t, c, "HGET", "hash", "field"))
460 // f, err := s.HIncrfloat("hash", "field", 12)
461 f, err := directDoFloatErr(t, c, "HINCRBYFLOAT", "hash", "field", "12")
462 ok(t, err)
463 equalFloat(t, 512.1, f)
464 })
465
466 t.Run("errors", func(t *testing.T) {
467 directDoString(t, c, "SET", "wrong", "type")
468 mustDo(t, c,
469 "HINCRBYFLOAT", "wrong", "type", "400",
470 proto.Error(msgWrongType),
471 )
472 mustDo(t, c,
473 "HINCRBYFLOAT",
474 proto.Error(errWrongNumber("HINCRBYFLOAT")),
475 )
476 mustDo(t, c,
477 "HINCRBYFLOAT", "wrong",
478 proto.Error(errWrongNumber("HINCRBYFLOAT")),
479 )

Callers

nothing calls this directly

Calls 15

ClearFunction · 0.92
DialFunction · 0.92
AddrFunction · 0.92
StringFunction · 0.92
ErrorFunction · 0.92
okFunction · 0.70
directDoFunction · 0.70
mustDoFunction · 0.70
equalsFunction · 0.70
directDoStringFunction · 0.70
directDoFloatErrFunction · 0.70
equalFloatFunction · 0.70

Tested by

no test coverage detected