|
|
|
@ -4,7 +4,12 @@ import ( |
|
|
|
|
"io/ioutil" |
|
|
|
|
"os" |
|
|
|
|
"os/exec" |
|
|
|
|
"path" |
|
|
|
|
"sync" |
|
|
|
|
"testing" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"git.stephensearles.com/stephen/acedoc" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type World struct { |
|
|
|
@ -38,10 +43,53 @@ func NewWorld(t *testing.T) World { |
|
|
|
|
return w |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestDoc(t *testing.T) { |
|
|
|
|
func TestEdits(t *testing.T) { |
|
|
|
|
w := NewWorld(t) |
|
|
|
|
defer w.Clean() |
|
|
|
|
|
|
|
|
|
const title = "sometitle" |
|
|
|
|
w.CH.NewContent(title, "") |
|
|
|
|
|
|
|
|
|
send := []acedoc.Delta{ |
|
|
|
|
acedoc.Insert(0, 0, "hello"), |
|
|
|
|
acedoc.Insert(0, 5, " world"), |
|
|
|
|
acedoc.Insert(0, 11, " world"), |
|
|
|
|
} |
|
|
|
|
var mtx sync.Mutex |
|
|
|
|
received := []acedoc.Delta{} |
|
|
|
|
|
|
|
|
|
doc, err := w.CH.client(title + ".md") |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal("error creating document client:", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
doc.doc.Client(acedoc.DeltaHandlerFunc(func(ds []acedoc.Delta) error { |
|
|
|
|
// receive some deltas...
|
|
|
|
|
mtx.Lock() |
|
|
|
|
defer mtx.Unlock() |
|
|
|
|
received = append(received, ds...) |
|
|
|
|
return nil |
|
|
|
|
})) |
|
|
|
|
|
|
|
|
|
_, ok := w.CH.hasdocref(title + ".md") |
|
|
|
|
if !ok { |
|
|
|
|
t.Fatal("expected there to be an established client") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
doc.doc.Apply(send...) |
|
|
|
|
|
|
|
|
|
<-time.After(5 * time.Second) |
|
|
|
|
if len(received) != len(send) { |
|
|
|
|
t.Errorf("expected %d deltas, received %d; expected: %v, received: %v", len(send), len(received), send, received) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestPagesInPagesOut(t *testing.T) { |
|
|
|
|
w := NewWorld(t) |
|
|
|
|
defer w.Clean() |
|
|
|
|
|
|
|
|
|
// check there's no content at first
|
|
|
|
|
c, err := GetContent(w.BlogFolder, w.CH.HugoSites) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("couldn't get content from a blank test environment: %v", err) |
|
|
|
@ -50,21 +98,46 @@ func TestDoc(t *testing.T) { |
|
|
|
|
t.Fatalf("expected a blank test environment, but saw %d pages", len(c)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
w.CH.NewContent("test1", "") |
|
|
|
|
titles := []string{ |
|
|
|
|
"test1", |
|
|
|
|
"TEST 2!!", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
found := map[string]bool{} |
|
|
|
|
|
|
|
|
|
// create some known content
|
|
|
|
|
for i, title := range titles { |
|
|
|
|
w.CH.NewContent(title, "") |
|
|
|
|
c, err = GetContent(w.BlogFolder, w.CH.HugoSites) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("couldn't get content from the test environment: %v", err) |
|
|
|
|
} |
|
|
|
|
if len(c) != 1 { |
|
|
|
|
t.Fatalf("expected 1 page, but saw %d pages", len(c)) |
|
|
|
|
if len(c)-1 != i { |
|
|
|
|
t.Fatalf("expected %d page, but saw %d pages", i-1, len(c)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
w.CH.NewContent("TEST 2!!", "") |
|
|
|
|
// make sure we get the content out that we just created
|
|
|
|
|
c, err = GetContent(w.BlogFolder, w.CH.HugoSites) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("couldn't get content from the test environment: %v", err) |
|
|
|
|
} |
|
|
|
|
if len(c) != 2 { |
|
|
|
|
t.Fatalf("expected 2 pages, but saw %d pages", len(c)) |
|
|
|
|
|
|
|
|
|
for _, content := range c { |
|
|
|
|
found[content.Filename] = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var missingSomething bool |
|
|
|
|
for _, title := range titles { |
|
|
|
|
adjusted := path.Join("content", docname(title)+".md") |
|
|
|
|
if !found[adjusted] { |
|
|
|
|
missingSomething = true |
|
|
|
|
t.Errorf("expected to find title %q, but didn't see it", adjusted) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if missingSomething { |
|
|
|
|
t.Logf("found titles: %v", found) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|