Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package cmd
import (
"crypto/sha512"
"strings"
"testing"
)
func TestInit(t *testing.T) {
dsn = "root:RootkitPassword@tcp(qcloud:3306)/work"
defer Init().Close()
}
func TestUpsert(t *testing.T) {
dsn = "root:RootkitPassword@tcp(qcloud:3306)/work"
defer Init().Close()
name := "a/b/c/d"
paths := strings.Split(name, "/")
depth := len(paths)
node := paths[depth-1]
nodeHash := sha512.Sum512([]byte(node))
var ancestorHash [64]byte
var ancestorName, hash string
for dep := 0; dep < depth; dep++ {
ancestorName = paths[depth-1-dep]
hash = strings.Join(paths[:depth-dep], "/")
t.Log(node, ancestorName, hash, dep)
ancestorHash = sha512.Sum512([]byte(hash))
if err := Upsert(
nodeHash[:], // const
ancestorHash[:],
ancestorName,
dep,
); err != nil {
t.Fatal(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.