2018-09-23 12:40:06 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommentCountBasics(t *testing.T) {
|
|
|
|
failTestOnError(t, setupTestEnv())
|
|
|
|
|
|
|
|
commenterHex, _ := commenterNew("test@example.com", "Test", "undefined", "http://example.com/photo.jpg", "google", "")
|
|
|
|
|
|
|
|
commentNew(commenterHex, "example.com", "/path.html", "root", "**foo**", "approved", time.Now().UTC())
|
|
|
|
commentNew(commenterHex, "example.com", "/path.html", "root", "**bar**", "approved", time.Now().UTC())
|
|
|
|
commentNew(commenterHex, "example.com", "/path.html", "root", "**baz**", "unapproved", time.Now().UTC())
|
|
|
|
|
2019-03-10 21:23:34 +08:00
|
|
|
counts, err := commentCount("example.com", []string{"/path.html"})
|
2018-09-23 12:40:06 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error counting comments: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-05-09 13:28:20 +08:00
|
|
|
if counts["/path.html"] != 3 {
|
|
|
|
t.Errorf("expected count=3 got count=%d", counts["/path.html"])
|
2018-09-23 12:40:06 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommentCountNewPage(t *testing.T) {
|
|
|
|
failTestOnError(t, setupTestEnv())
|
|
|
|
|
2019-03-10 21:23:34 +08:00
|
|
|
counts, err := commentCount("example.com", []string{"/path.html"})
|
2018-09-23 12:40:06 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error counting comments: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-03-10 21:23:34 +08:00
|
|
|
if counts["/path.html"] != 0 {
|
|
|
|
t.Errorf("expected count=0 got count=%d", counts["/path.html"])
|
2018-09-23 12:40:06 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCommentCountEmpty(t *testing.T) {
|
2019-03-10 21:23:34 +08:00
|
|
|
if _, err := commentCount("example.com", []string{""}); err != nil {
|
2018-09-23 12:40:06 +08:00
|
|
|
t.Errorf("unexpected error counting comments on empty path: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-03-10 21:23:34 +08:00
|
|
|
if _, err := commentCount("", []string{""}); err == nil {
|
2018-09-23 12:40:06 +08:00
|
|
|
t.Errorf("expected error not found counting comments with empty everything")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|