Skip to content

Instantly share code, notes, and snippets.

@shykes
Created September 25, 2013 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shykes/6694646 to your computer and use it in GitHub Desktop.
Save shykes/6694646 to your computer and use it in GitHub Desktop.
func TestTree(t *testing.T) {
tree := NewTree("/path/to/db")
// List all root containers
names, _ := tree.List("/")
for _, name := range names {
fullPath := path.Join("/", name)
id, _ := tree.Get(fullPath)
fmt.Printf("%s is a link to %s\n", fullPath, id)
// Fetch the container ID from the graph
}
// Create a new database container and link it as a child of "myapp"
db, _ := docker.CreateContainer() // Out of scope here
tree.Set("/" + db.Id, db.Id) // Create a base entry so that the container is listed under its iD.
tree.Set("/myapp/userdb", db.Id) // Link the database as "userdb" in the application
fmt.Printf("Children of /myapp: %s\n", tree.List("/myapp"))
}
// Set creates a new reference to <id> in the tree,
// accessible at the path <p>.
func (Tree *t) Set(p, id string) error {
}
// Get returns the id referenced by <p>, where <p> is
// a slash-separate path.
func (Tree *t) Get(p string) (id string, err error) {
}
// Del removes the reference at path <p>
func (Tree *t) Del(p string) error {
}
// Rename changes the name of a reference at path <p>
func (Tree *t) Rename(p, name string) {
}
// Refs returns a list of all the references to <id>, in the form of normalized paths.
func (Tree *t) Refs(id string) (paths []string, error) {
}
// List returns a list of the children of the given path
func (Tree *t) List(p string) (names []string, err error) {
}
func (Tree *t) Walk(p string, walkFn WalkFunc) error {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment