Skip to content

Commit

Permalink
Exclude start path from returned RQL result
Browse files Browse the repository at this point in the history
This commit also removes rqlQuery.go as that file isn't being used.

Signed-off-by: Enis Inan <[email protected]>
  • Loading branch information
ekinanp committed Mar 7, 2020
1 parent d61ff3f commit 7560829
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
5 changes: 5 additions & 0 deletions api/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/puppetlabs/wash/api/rql"
"github.com/puppetlabs/wash/api/rql/ast"
apitypes "github.com/puppetlabs/wash/api/types"
"github.com/puppetlabs/wash/plugin"
)

// swagger:route GET /fs/find find listEntries
Expand All @@ -36,6 +37,10 @@ var findHandler = handler{fn: func(w http.ResponseWriter, r *http.Request) *erro
return errResp
}

if !plugin.ListAction().IsSupportedOn(entry) {
return unsupportedActionResponse(path, plugin.ListAction())
}

minDepth, hasMinDepth, errResp := getIntParam(r.URL, "mindepth")
if errResp != nil {
return errResp
Expand Down
9 changes: 4 additions & 5 deletions api/rql/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
)

// Find returns all descendants of the start entry that satisfy the given query
// (including the start entry itself). Note that all returned entries' paths
// will start from "", which represents the start path. For example, if "childOne"
// and "childTwo" are the cnames of the start entry's children, then their "Path"
// fields will be set to "childOne" and "childTwo" (where the start entry's path of
// "" is automatically prefixed).
// Note that all returned entries' paths will start from "", which represents the
// start path. For example, if "childOne" and "childTwo" are the cnames of the start
// entry's children, then their "Path" fields will be set to "childOne" and "childTwo"
// (where the start entry's path of "" is automatically prefixed).
//
// Each entry's children are descended in lexicographic order (based on their cnames).
// So given entries "foo", "foo/bar", "foo/baz", "foo/baz/1", the returned entries will
Expand Down
14 changes: 9 additions & 5 deletions api/rql/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ func (w *walkerImpl) Walk(ctx context.Context, start plugin.Entry) ([]Entry, err
func (w *walkerImpl) walk(ctx context.Context, e *Entry, depth int) ([]Entry, error) {
entries := []Entry{}

includeEntry, err := w.visit(ctx, e, depth)
if err != nil {
return nil, err
} else if includeEntry {
entries = append(entries, *e)
isStartEntry := e.Path == ""
if !isStartEntry {
// Visit the entry
includeEntry, err := w.visit(ctx, e, depth)
if err != nil {
return nil, err
} else if includeEntry {
entries = append(entries, *e)
}
}

childDepth := depth + 1
Expand Down
4 changes: 1 addition & 3 deletions api/rql/walker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func (s *WalkerTestSuite) TestWalk_HappyCase() {
entries := s.mustWalk(context.Background(), tree["."])
s.assertEntries(
[]string{
"",
"foo",
"foo/bar",
"foo/bar/1",
Expand Down Expand Up @@ -135,7 +134,6 @@ func (s *WalkerTestSuite) TestWalk_MaxdepthSet() {
entries := s.mustWalk(context.Background(), tree["."])
s.assertEntries(
[]string{
"",
"foo",
"foo/bar",
"foo/baz",
Expand Down Expand Up @@ -174,7 +172,7 @@ func (s *WalkerTestSuite) TestWalk_VisitErrors() {
s.walker.opts.Fullmeta = true

expectedErr := fmt.Errorf("failed to fetch metadata")
tree["."].On("Metadata", mock.Anything).Return(plugin.JSONObject{}, expectedErr)
tree["./foo"].On("Metadata", mock.Anything).Return(plugin.JSONObject{}, expectedErr)

_, err := s.walker.Walk(context.Background(), tree["."])
s.Regexp(`full.*metadata.*failed.*metadata`, err)
Expand Down
3 changes: 0 additions & 3 deletions api/types/rqlQuery.go

This file was deleted.

0 comments on commit 7560829

Please sign in to comment.