MCPcopy
hub / github.com/perkeep/perkeep / TestQueryDirChildrenByNameConstraint

Function TestQueryDirChildrenByNameConstraint

pkg/search/query_test.go:882–924  ·  view source on GitHub ↗

find children of a directory, by name. in practice, one can also get the children with the proper describe rules, but doing so has some limitations that a direct search query has not.

(t *testing.T)

Source from the content-addressed store, hash-verified

880// in practice, one can also get the children with the proper describe rules,
881// but doing so has some limitations that a direct search query has not.
882func TestQueryDirChildrenByNameConstraint(t *testing.T) {
883 testQueryTypes(t, memIndexTypes, func(qt *queryTest) {
884 id := qt.id
885 fileRef1, _ := id.UploadFile("some-stuff.txt", "hello", time.Unix(123, 0))
886 qt.t.Logf("fileRef1 = %q", fileRef1)
887 fileRef2, _ := id.UploadFile("more-stuff.txt", "world", time.Unix(456, 0))
888 qt.t.Logf("fileRef2 = %q", fileRef2)
889 childDirRef := id.UploadDir("childdir", []blob.Ref{}, time.Unix(457, 0))
890 qt.t.Logf("childDirRef = %q", childDirRef)
891 dirRef := id.UploadDir("somedir", []blob.Ref{fileRef1, fileRef2, childDirRef}, time.Unix(789, 0))
892 qt.t.Logf("dirRef = %q", dirRef)
893 p1 := id.NewPlannedPermanode("1")
894 id.SetAttribute(p1, "camliContent", dirRef.String())
895
896 fileRef3, _ := id.UploadFile("other-file", "hellooooo", time.Unix(101112, 0))
897 qt.t.Logf("fileRef3 = %q", fileRef3)
898 p2 := id.NewPlannedPermanode("2")
899 id.SetAttribute(p2, "camliContent", fileRef3.String())
900
901 sq := &SearchQuery{
902 Constraint: &Constraint{
903 Logical: &LogicalConstraint{
904 A: &Constraint{File: &FileConstraint{
905 ParentDir: &DirConstraint{
906 FileName: &StringConstraint{
907 Equals: "somedir",
908 },
909 },
910 }},
911 B: &Constraint{Dir: &DirConstraint{
912 ParentDir: &DirConstraint{
913 FileName: &StringConstraint{
914 Equals: "somedir",
915 },
916 },
917 }},
918 Op: "or",
919 },
920 },
921 }
922 qt.wantRes(sq, fileRef1, fileRef2, childDirRef)
923 })
924}
925
926// find children of a directory, by blobref.
927func TestQueryDirChildrenByRefConstraint(t *testing.T) {

Callers

nothing calls this directly

Calls 8

testQueryTypesFunction · 0.85
LogfMethod · 0.80
UploadDirMethod · 0.80
NewPlannedPermanodeMethod · 0.80
SetAttributeMethod · 0.80
wantResMethod · 0.80
UploadFileMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected