This commit is contained in:
Bel LaPointe
2022-02-16 07:58:34 -07:00
parent 552a3f46ff
commit 63caf9ed03
8 changed files with 199 additions and 211 deletions

View File

@@ -31,11 +31,11 @@ func TestServerRoutes(t *testing.T) {
ensureAndWrite(server.diskMediaPath("delid"), []byte("hi"))
tree := server.tree()
if err := tree.Put([]string{"getfid"}, Leaf{Title: "", Content: "getfid body"}); err != nil {
if err := tree.Put(ID("getfid"), Leaf{Title: "", Content: "getfid body"}); err != nil {
t.Fatal(err)
}
tree.Put([]string{"putfid"}, Leaf{Title: "putfid title", Content: "initial putfid body"})
tree.Put([]string{"delfid"}, Leaf{Title: "delfid title", Content: "delfid body"})
tree.Put(ID("putfid"), Leaf{Title: "putfid title", Content: "initial putfid body"})
tree.Put(ID("delfid"), Leaf{Title: "delfid title", Content: "delfid body"})
t.Log(tree.GetRoot())
ensureAndWrite(path.Join(server.root, "index.html"), []byte("mom"))
@@ -151,7 +151,7 @@ func TestServerPutTreeGetFile(t *testing.T) {
if err := server.Routes(); err != nil {
t.Fatal(err)
}
server.tree().Put([]string{"my pid"}, Leaf{})
server.tree().Put(ID("my pid"), Leaf{})
var id string
t.Run("put to create an id", func(t *testing.T) {
r := httptest.NewRequest(http.MethodPut, "/my%20pid/my-put-id", strings.NewReader("body"))
@@ -210,6 +210,23 @@ func TestServerPutTreeGetFile(t *testing.T) {
if !bytes.Contains(w.Body.Bytes(), []byte(`{"Title":"my title","Deleted":false,"Content":"`)) {
t.Fatal(w)
}
var branch Branch
if err := json.NewDecoder(w.Body).Decode(&branch); err != nil {
t.Fatal(err)
}
t.Logf("TODO: %+v", branch)
if branch.Leaf != (Leaf{}) {
t.Error(branch.Leaf)
}
if parent, ok := branch.Branches["my pid"]; !ok {
t.Error(ok, branch)
} else if parent.Leaf.Title != "Untitled" {
t.Error(parent.Leaf)
} else if child, ok := parent.Branches[NewID(id)]; !ok {
t.Error(ok, NewID("my pid").Push(id), parent)
} else if child.Leaf.Title != "my title" {
t.Error(child.Leaf)
}
})
t.Run("get", func(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/"+url.PathEscape(id), nil)