| 765 | } |
| 766 | |
| 767 | func PathsOfSignerTarget(t *testing.T, initIdx func() *index.Index) { |
| 768 | ctx := context.Background() |
| 769 | id := NewIndexDeps(initIdx()) |
| 770 | id.Fataler = t |
| 771 | defer id.DumpIndex(t) |
| 772 | signer := id.SignerBlobRef |
| 773 | pn := id.NewPermanode() |
| 774 | t.Logf("uploaded permanode %q", pn) |
| 775 | |
| 776 | claim1 := id.SetAttribute(pn, "camliPath:somedir", "targ-123") |
| 777 | claim1Time := id.LastTime().UTC() |
| 778 | claim2 := id.SetAttribute(pn, "camliPath:with|pipe", "targ-124") |
| 779 | claim2Time := id.LastTime().UTC() |
| 780 | t.Logf("made path claims %q and %q", claim1, claim2) |
| 781 | |
| 782 | type test struct { |
| 783 | blobref string |
| 784 | want int |
| 785 | } |
| 786 | tests := []test{ |
| 787 | {"targ-123", 1}, |
| 788 | {"targ-124", 1}, |
| 789 | {"targ-125", 0}, |
| 790 | } |
| 791 | for _, tt := range tests { |
| 792 | paths, err := id.Index.PathsOfSignerTarget(ctx, signer, blob.ParseOrZero(tt.blobref)) |
| 793 | if err != nil { |
| 794 | t.Fatalf("PathsOfSignerTarget(%q): %v", tt.blobref, err) |
| 795 | } |
| 796 | if len(paths) != tt.want { |
| 797 | t.Fatalf("PathsOfSignerTarget(%q) got %d results; want %d", |
| 798 | tt.blobref, len(paths), tt.want) |
| 799 | } |
| 800 | if tt.blobref == "targ-123" { |
| 801 | p := paths[0] |
| 802 | want := fmt.Sprintf( |
| 803 | "Path{Claim: %s, %v; Base: %s + Suffix \"somedir\" => Target targ-123}", |
| 804 | claim1, claim1Time, pn) |
| 805 | if g := p.String(); g != want { |
| 806 | t.Errorf("claim wrong.\n got: %s\nwant: %s", g, want) |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | tests = []test{ |
| 811 | {"somedir", 1}, |
| 812 | {"with|pipe", 1}, |
| 813 | {"void", 0}, |
| 814 | } |
| 815 | for _, tt := range tests { |
| 816 | paths, err := id.Index.PathsLookup(ctx, id.SignerBlobRef, pn, tt.blobref) |
| 817 | if err != nil { |
| 818 | t.Fatalf("PathsLookup(%q): %v", tt.blobref, err) |
| 819 | } |
| 820 | if len(paths) != tt.want { |
| 821 | t.Fatalf("PathsLookup(%q) got %d results; want %d", |
| 822 | tt.blobref, len(paths), tt.want) |
| 823 | } |
| 824 | if tt.blobref == "with|pipe" { |