mirror of https://github.com/perkeep/perkeep.git
pkg/client: make Describe use a POST request to the server
Otherwise it can't send Describe Rules. Also in this commit: a bunch of new tests from when I thought I was going crazy and trying to debug the search system, before I realized the problem was that the client was doing a GET request and dropping most of my DescribeRequest. Change-Id: I4ea9bed80f0d7d6b86814527b63acc3586ac1d06
This commit is contained in:
parent
bfb325c96f
commit
a16c015f32
|
@ -475,8 +475,12 @@ func (c *Client) Describe(req *search.DescribeRequest) (*search.DescribeResponse
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
url := sr + req.URLSuffix()
|
||||
hreq := c.newRequest("GET", url)
|
||||
url := sr + req.URLSuffixPost()
|
||||
body, err := json.MarshalIndent(req, "", "\t")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hreq := c.newRequest("POST", url, bytes.NewReader(body))
|
||||
hres, err := c.expect2XX(hreq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -249,6 +249,13 @@ func (m MetaMap) Get(br blob.Ref) *DescribedBlob {
|
|||
return m[br.String()]
|
||||
}
|
||||
|
||||
// URLSuffixPost returns the URL suffix for POST requests.
|
||||
func (r *DescribeRequest) URLSuffixPost() string {
|
||||
return "camli/search/describe"
|
||||
}
|
||||
|
||||
// URLSuffix returns the URL suffix for GET requests.
|
||||
// This is deprecated.
|
||||
func (r *DescribeRequest) URLSuffix() string {
|
||||
var buf bytes.Buffer
|
||||
fmt.Fprintf(&buf, "camli/search/describe?depth=%d&maxdirchildren=%d",
|
||||
|
|
|
@ -74,6 +74,12 @@ func searchDescribeSetup(fi *test.FakeIndex) index.Interface {
|
|||
addPermanode(fi, "somevenuepic-0",
|
||||
"foo", "bar",
|
||||
)
|
||||
addPermanode(fi, "venuepic-2",
|
||||
"camliContent", "somevenuepic-2",
|
||||
)
|
||||
addPermanode(fi, "somevenuepic-2",
|
||||
"foo", "baz",
|
||||
)
|
||||
|
||||
addPermanode(fi, "homedir-0",
|
||||
"camliPath:subdir.1", "homedir-1",
|
||||
|
@ -85,6 +91,11 @@ func searchDescribeSetup(fi *test.FakeIndex) index.Interface {
|
|||
"foo", "bar",
|
||||
)
|
||||
|
||||
addPermanode(fi, "set-0",
|
||||
"camliMember", "venuepic-1",
|
||||
"camliMember", "venuepic-2",
|
||||
)
|
||||
|
||||
return fi
|
||||
}
|
||||
|
||||
|
@ -206,6 +217,23 @@ var searchDescribeTests = []handlerTest{
|
|||
}),
|
||||
wantDescribed: []string{"homedir-0", "homedir-1", "homedir-2"},
|
||||
},
|
||||
|
||||
{
|
||||
name: "find members",
|
||||
postBody: marshalJSON(&search.DescribeRequest{
|
||||
BlobRef: blob.MustParse("set-0"),
|
||||
Rules: []*search.DescribeRule{
|
||||
{
|
||||
IfResultRoot: true,
|
||||
Attrs: []string{"camliMember"},
|
||||
Rules: []*search.DescribeRule{
|
||||
{Attrs: []string{"camliContent"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
wantDescribed: []string{"set-0", "venuepic-1", "venuepic-2", "somevenuepic-0", "somevenuepic-2"},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
Loading…
Reference in New Issue