test title not changed if presented
This commit is contained in:
@@ -60,6 +60,7 @@ func (s *DataStore) Create(comment store.Comment) (commentID string, err error)
|
||||
return "", errors.Wrap(err, "failed to prepare comment")
|
||||
}
|
||||
|
||||
// keep input title and set to extracted if missing
|
||||
if s.TitleExtractor != nil && comment.PostTitle == "" {
|
||||
if title, err := s.TitleExtractor.Get(comment.Locator.URL); err == nil {
|
||||
comment.PostTitle = title
|
||||
|
||||
@@ -93,6 +93,14 @@ func TestService_CreateFromPartialWithTitle(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
t.Logf("%+v", res)
|
||||
assert.Equal(t, "Радио-Т 630 - Радио-Т Подкаст", res.PostTitle)
|
||||
|
||||
comment.PostTitle = "post blah"
|
||||
id, err = b.Create(comment)
|
||||
assert.NoError(t, err)
|
||||
res, err = b.Get(store.Locator{URL: "https://radio-t.com/p/2018/12/29/podcast-630/", SiteID: "radio-t"}, id)
|
||||
assert.NoError(t, err)
|
||||
t.Logf("%+v", res)
|
||||
assert.Equal(t, "post blah", res.PostTitle, "keep comment title")
|
||||
}
|
||||
|
||||
func TestService_Vote(t *testing.T) {
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
const teMaxCachedRecs = 1000
|
||||
|
||||
// TitleExtractor gets html title from remote page, cached
|
||||
type TitleExtractor struct {
|
||||
client http.Client
|
||||
@@ -22,7 +24,7 @@ func NewTitleExtractor(client http.Client) *TitleExtractor {
|
||||
client: client,
|
||||
}
|
||||
var err error
|
||||
res.cache, err = cache.NewMemoryCache(cache.MaxKeys(1000))
|
||||
res.cache, err = cache.NewMemoryCache(cache.MaxKeys(teMaxCachedRecs))
|
||||
if err != nil {
|
||||
log.Printf("[WARN] failed to make cache, %v", err)
|
||||
res.cache = &cache.Nop{}
|
||||
|
||||
Reference in New Issue
Block a user