forked from wgroeneveld/go-jamming
fix non-pointer author pic change
This commit is contained in:
parent
d54fe42ec7
commit
ceabec241a
|
@ -31,6 +31,8 @@ func (wm Mention) Domain() string {
|
|||
return rest.Domain(wm.Target)
|
||||
}
|
||||
|
||||
// Key returns a unique string representation of the mention for use in storage.
|
||||
// TODO Profiling indicated that md5() consumes a lot of CPU power, so this could be replaced with db migration.
|
||||
func (wm Mention) Key() string {
|
||||
return fmt.Sprintf("%x", md5.Sum([]byte("source="+wm.Source+",target="+wm.Target)))
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ type IndiewebAuthor struct {
|
|||
Picture string `json:"picture"`
|
||||
}
|
||||
|
||||
func (ia IndiewebAuthor) Anonymize() {
|
||||
func (ia *IndiewebAuthor) Anonymize() {
|
||||
ia.Picture = fmt.Sprintf("/pictures/%s", Anonymous)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package webmention
|
||||
|
||||
import (
|
||||
"brainbaking.com/go-jamming/common"
|
||||
"brainbaking.com/go-jamming/db"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func postWm(source string, target string) url.Values {
|
||||
values := url.Values{}
|
||||
values.Set("source", source)
|
||||
values.Set("target", target)
|
||||
return values
|
||||
}
|
||||
|
||||
var (
|
||||
cnf = common.Configure()
|
||||
repo db.MentionRepo
|
||||
)
|
||||
|
||||
func init() {
|
||||
cnf.ConString = ":memory:"
|
||||
repo = db.NewMentionRepo(cnf)
|
||||
}
|
||||
|
||||
func TestHandlePostWithInvalidUrlsShouldReturnBadRequest(t *testing.T) {
|
||||
ts := httptest.NewServer(HandlePost(cnf, repo))
|
||||
defer ts.Close()
|
||||
res, err := http.PostForm(ts.URL, postWm("https://haha.be/woof/said/the/dog.txt", "https://pussies.nl/mycatjustthrewup/gottacleanup.html"))
|
||||
assert.NoError(t, err)
|
||||
|
||||
content, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, string(content), "Bad Request")
|
||||
}
|
||||
|
||||
// Explicitly tests using actual live data, so this could fail if URLs are unreachable.
|
||||
func TestHandlePostWithTestServer_Parallel(t *testing.T) {
|
||||
ts := httptest.NewServer(HandlePost(cnf, repo))
|
||||
defer ts.Close()
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
res, err := http.PostForm(ts.URL, postWm("https://jefklakscodex.com/articles/retrospectives/raven-shield-17-years-later/", "https://brainbaking.com/post/2020/10/building-a-core2duo-winxp-retro-pc/"))
|
||||
assert.NoError(t, err)
|
||||
|
||||
content, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, string(content), "Thanks, bro. Will process this soon, pinky swear")
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
|
@ -76,7 +76,7 @@ func TestSaveAuthorPictureLocally(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func BenchmarkReceive(b *testing.B) {
|
||||
func BenchmarkReceiveWithoutRestCalls(b *testing.B) {
|
||||
origLog := zerolog.GlobalLevel()
|
||||
zerolog.SetGlobalLevel(zerolog.Disabled)
|
||||
defer zerolog.SetGlobalLevel(origLog)
|
||||
|
|
Loading…
Reference in New Issue