Added user-agent test, Fixed failing test

This commit is contained in:
Musab Gültekin 2019-08-05 16:18:44 +03:00
parent 85597219e6
commit 86d4e80596

View File

@ -1,6 +1,7 @@
package geziyor_test package geziyor_test
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/fortytw2/leaktest" "github.com/fortytw2/leaktest"
@ -10,6 +11,7 @@ import (
"github.com/geziyor/geziyor/client" "github.com/geziyor/geziyor/client"
"github.com/geziyor/geziyor/export" "github.com/geziyor/geziyor/export"
"github.com/geziyor/geziyor/metrics" "github.com/geziyor/geziyor/metrics"
"github.com/stretchr/testify/assert"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
@ -25,6 +27,19 @@ func TestSimple(t *testing.T) {
}).Start() }).Start()
} }
func TestUserAgent(t *testing.T) {
geziyor.NewGeziyor(&geziyor.Options{
StartURLs: []string{"https://httpbin.org/anything"},
ParseFunc: func(g *geziyor.Geziyor, r *client.Response) {
var data map[string]interface{}
err := json.Unmarshal(r.Body, &data)
assert.NoError(t, err)
assert.Equal(t, client.DefaultUserAgent, data["headers"].(map[string]interface{})["User-Agent"])
},
}).Start()
}
func TestCache(t *testing.T) { func TestCache(t *testing.T) {
defer leaktest.Check(t)() defer leaktest.Check(t)()
geziyor.NewGeziyor(&geziyor.Options{ geziyor.NewGeziyor(&geziyor.Options{
@ -71,7 +86,6 @@ func TestAllLinks(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("skipping test in short mode.") t.Skip("skipping test in short mode.")
} }
defer leaktest.Check(t)()
geziyor.NewGeziyor(&geziyor.Options{ geziyor.NewGeziyor(&geziyor.Options{
AllowedDomains: []string{"books.toscrape.com"}, AllowedDomains: []string{"books.toscrape.com"},