test title not changed if presented

This commit is contained in:
Umputun
2019-01-05 20:58:34 -06:00
parent ad6491ff14
commit 4096302a06
3 changed files with 12 additions and 1 deletions
+1
View File
@@ -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) {
+3 -1
View File
@@ -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{}