Skip to content

Commit

Permalink
filetree: Marshal file and dir names to YAML
Browse files Browse the repository at this point in the history
Will deal with content next.
  • Loading branch information
dcarley committed Jun 15, 2018
1 parent bbd819a commit 2ff4a59
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions filetree/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ type Node struct {
Parent *Node `json:"-"`
}

func (n Node) MarshalYAML() (interface{}, error) {
tree := map[string]interface{}{}
for _, child := range n.Children {
c, err := child.MarshalYAML()
if err != nil {
return tree, err
}
tree[child.Info.Name()] = c
}

return tree, nil
}

// Helper function that returns true if a path exists in excludes array
func excluded(exclude []string, path string) bool {
for _, n := range exclude {
Expand Down
13 changes: 13 additions & 0 deletions filetree/filetree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
yaml "gopkg.in/yaml.v2"

"github.com/circleci/circleci-cli/filetree"
)
Expand Down Expand Up @@ -61,6 +62,18 @@ var _ = Describe("filetree", func() {
Expect(tree.Children[1].Children[0].Info.Name()).To(Equal("sub_dir_file"))
Expect(tree.Children[1].Children[0].FullPath).To(Equal(subDirFile))
})

It("renders to YAML", func() {
tree, err := filetree.NewTree(tempRoot)
Expect(err).ToNot(HaveOccurred())

out, err := yaml.Marshal(tree)
Expect(err).ToNot(HaveOccurred())
Expect(out).To(MatchYAML(`root_file: {}
sub_dir:
sub_dir_file: {}
`))
})
})
})

Expand Down

0 comments on commit 2ff4a59

Please sign in to comment.