MCPcopy
hub / github.com/hashicorp/go-memdb / TestIntFieldIndex_FromObject

Function TestIntFieldIndex_FromObject

index_test.go:611–685  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

609}
610
611func TestIntFieldIndex_FromObject(t *testing.T) {
612 obj := testObj()
613
614 eint := make([]byte, 8)
615 eint8 := make([]byte, 1)
616 eint16 := make([]byte, 2)
617 eint32 := make([]byte, 4)
618 eint64 := make([]byte, 8)
619 binary.BigEndian.PutUint64(eint, 1<<63+1)
620 eint8[0] = 0
621 binary.BigEndian.PutUint16(eint16, 0)
622 binary.BigEndian.PutUint32(eint32, 0)
623 binary.BigEndian.PutUint64(eint64, 0)
624
625 cases := []struct {
626 Field string
627 Expected []byte
628 ErrorContains string
629 }{
630 {
631 Field: "Int",
632 Expected: eint,
633 },
634 {
635 Field: "Int8",
636 Expected: eint8,
637 },
638 {
639 Field: "Int16",
640 Expected: eint16,
641 },
642 {
643 Field: "Int32",
644 Expected: eint32,
645 },
646 {
647 Field: "Int64",
648 Expected: eint64,
649 },
650 {
651 Field: "IntGarbage",
652 ErrorContains: "is invalid",
653 },
654 {
655 Field: "ID",
656 ErrorContains: "want an int",
657 },
658 }
659
660 for _, c := range cases {
661 t.Run(c.Field, func(t *testing.T) {
662 indexer := IntFieldIndex{c.Field}
663 ok, val, err := indexer.FromObject(obj)
664 if err != nil {
665 if ok {
666 t.Fatalf("okay and error")
667 }
668

Callers

nothing calls this directly

Calls 2

FromObjectMethod · 0.95
testObjFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…