You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bathyscaphe/internal/indexer/index/elastic_test.go

62 lines
1.1 KiB
Go

package index
import (
"github.com/creekorful/bathyscaphe/internal/event"
"testing"
"time"
)
func TestIndexResource(t *testing.T) {
body := `
<title>Creekorful Inc</title>
This is sparta
<a href="https://google.com/test?test=test#12">
<meta name="Description" content="Zhello world">
<meta property="og:url" content="https://example.org">
`
msg := event.NewResourceEvent{
URL: "https://example.org/300",
Body: body,
}
resIdx, err := indexResource(Resource{
URL: "https://example.org/300",
Time: time.Time{},
Body: body,
Headers: map[string]string{"Content-Type": "application/json"},
})
if err != nil {
t.FailNow()
}
if resIdx.URL != "https://example.org/300" {
t.Fail()
}
if resIdx.Title != "Creekorful Inc" {
t.Fail()
}
if resIdx.Body != msg.Body {
t.Fail()
}
if resIdx.Description != "Zhello world" {
t.Fail()
}
if resIdx.Meta["description"] != "Zhello world" {
t.Fail()
}
if resIdx.Meta["og:url"] != "https://example.org" {
t.Fail()
}
if resIdx.Headers["content-type"] != "application/json" {
t.Fail()
}
}