MCPcopy
hub / github.com/perkeep/perkeep / TestQueryFileLocation

Function TestQueryFileLocation

pkg/search/query_test.go:628–689  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

626}
627
628func TestQueryFileLocation(t *testing.T) {
629 testQueryTypes(t, memIndexTypes, func(qt *queryTest) {
630 id := qt.id
631
632 // Upload a basic image
633 srcRoot, err := osutil.PkSourceRoot()
634 if err != nil {
635 panic(fmt.Sprintf("source root folder not found: %v", err))
636 }
637 uploadFile := func(file string, modTime time.Time) blob.Ref {
638 fileName := filepath.Join(srcRoot, "pkg", "search", "testdata", file)
639 contents, err := os.ReadFile(fileName)
640 if err != nil {
641 panic(err)
642 }
643 br, _ := id.UploadFile(file, string(contents), modTime)
644 return br
645 }
646 fileRef := uploadFile("dude-gps.jpg", time.Time{})
647
648 p6 := id.NewPlannedPermanode("photo")
649 id.SetAttribute(p6, "camliContent", fileRef.String())
650
651 sq := &SearchQuery{
652 Constraint: &Constraint{
653 File: &FileConstraint{
654 Location: &LocationConstraint{
655 Any: true,
656 },
657 },
658 },
659 }
660
661 qt.wantRes(sq, fileRef)
662 if qt.res == nil {
663 t.Fatal("No results struct")
664 }
665 if qt.res.LocationArea == nil {
666 t.Fatal("No location area in results")
667 }
668 want := camtypes.LocationBounds{
669 North: 42.45,
670 South: 42.45,
671 West: 18.76,
672 East: 18.76,
673 }
674 if *qt.res.LocationArea != want {
675 t.Fatalf("Wrong location area expansion: wanted %#v, got %#v", want, *qt.res.LocationArea)
676 }
677
678 ExportSetExpandLocationHook(true)
679 qt.wantRes(sq)
680 if qt.res == nil {
681 t.Fatal("No results struct")
682 }
683 if qt.res.LocationArea != nil {
684 t.Fatalf("Location area should not have been expanded")
685 }

Callers

nothing calls this directly

Calls 11

PkSourceRootFunction · 0.92
testQueryTypesFunction · 0.85
NewPlannedPermanodeMethod · 0.80
SetAttributeMethod · 0.80
wantResMethod · 0.80
FatalMethod · 0.80
FatalfMethod · 0.65
uploadFileFunction · 0.50
UploadFileMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected