find out if a file is amongst a dir's progeny (grand-children)
(t *testing.T)
| 966 | |
| 967 | // find out if a file is amongst a dir's progeny (grand-children) |
| 968 | func TestQueryDirProgeny(t *testing.T) { |
| 969 | testQuery(t, func(qt *queryTest) { |
| 970 | id := qt.id |
| 971 | grandchild1, _ := id.UploadFile("grandchild1.txt", "hello", time.Unix(123, 0)) |
| 972 | qt.t.Logf("grandchild1 = %q", grandchild1) |
| 973 | grandchild2, _ := id.UploadFile("grandchild2.txt", "world", time.Unix(456, 0)) |
| 974 | qt.t.Logf("grandchild2 = %q", grandchild2) |
| 975 | parentdir := id.UploadDir("parentdir", []blob.Ref{grandchild1, grandchild2}, time.Unix(789, 0)) |
| 976 | qt.t.Logf("parentdir = %q", parentdir) |
| 977 | grandparentdir := id.UploadDir("grandparentdir", []blob.Ref{parentdir}, time.Unix(101112, 0)) |
| 978 | qt.t.Logf("grandparentdir = %q", grandparentdir) |
| 979 | p1 := id.NewPlannedPermanode("1") |
| 980 | id.SetAttribute(p1, "camliContent", grandparentdir.String()) |
| 981 | |
| 982 | p3 := id.NewPlannedPermanode("3") |
| 983 | id.SetAttribute(p3, "camliContent", parentdir.String()) |
| 984 | |
| 985 | // adding an unrelated directory, to make sure we do _not_ find it as well |
| 986 | fileRef3, _ := id.UploadFile("other-file", "hellooooo", time.Unix(131415, 0)) |
| 987 | qt.t.Logf("fileRef3 = %q", fileRef3) |
| 988 | otherdir := id.UploadDir("otherdir", []blob.Ref{fileRef3}, time.Unix(161718, 0)) |
| 989 | qt.t.Logf("otherdir = %q", otherdir) |
| 990 | p2 := id.NewPlannedPermanode("2") |
| 991 | id.SetAttribute(p2, "camliContent", otherdir.String()) |
| 992 | |
| 993 | sq := &SearchQuery{ |
| 994 | Constraint: &Constraint{ |
| 995 | Permanode: &PermanodeConstraint{ |
| 996 | Attr: "camliContent", |
| 997 | ValueInSet: &Constraint{ |
| 998 | Dir: &DirConstraint{ |
| 999 | RecursiveContains: &Constraint{File: &FileConstraint{ |
| 1000 | FileName: &StringConstraint{ |
| 1001 | Contains: "grandchild1.txt", |
| 1002 | }, |
| 1003 | }}, |
| 1004 | }, |
| 1005 | }, |
| 1006 | }, |
| 1007 | }, |
| 1008 | } |
| 1009 | qt.wantRes(sq, p1, p3) |
| 1010 | |
| 1011 | // make sure that "Contains" only finds the direct parent, and not the grand-parent as well. |
| 1012 | // also this time, skip the permanode layer. |
| 1013 | sq = &SearchQuery{ |
| 1014 | Constraint: &Constraint{ |
| 1015 | Dir: &DirConstraint{ |
| 1016 | Contains: &Constraint{ |
| 1017 | BlobRefPrefix: grandchild1.String(), |
| 1018 | }, |
| 1019 | }, |
| 1020 | }, |
| 1021 | } |
| 1022 | qt.wantRes(sq, parentdir) |
| 1023 | }) |
| 1024 | } |
| 1025 |
nothing calls this directly
no test coverage detected