2021-06-11 13:27:42 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
2021-06-15 15:36:41 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2021-06-11 13:27:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_robotsTXT(t *testing.T) {
|
|
|
|
|
|
|
|
app := &goBlog{
|
|
|
|
cfg: &config{
|
|
|
|
Server: &configServer{
|
|
|
|
PublicAddress: "https://example.com",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-07-27 10:51:08 +00:00
|
|
|
h := http.HandlerFunc(app.serveRobotsTXT)
|
|
|
|
assert.HTTPStatusCode(t, h, http.MethodGet, "", nil, 200)
|
|
|
|
txt := assert.HTTPBody(h, http.MethodGet, "", nil)
|
|
|
|
assert.Equal(t, "User-agent: *\nSitemap: https://example.com/sitemap.xml", txt)
|
|
|
|
|
|
|
|
app.cfg.PrivateMode = &configPrivateMode{
|
|
|
|
Enabled: true,
|
|
|
|
}
|
|
|
|
|
2021-06-15 15:36:41 +00:00
|
|
|
h = http.HandlerFunc(app.serveRobotsTXT)
|
|
|
|
assert.HTTPStatusCode(t, h, http.MethodGet, "", nil, 200)
|
|
|
|
txt = assert.HTTPBody(h, http.MethodGet, "", nil)
|
2021-07-27 10:51:08 +00:00
|
|
|
assert.Equal(t, "User-agent: *\nDisallow: /", txt)
|
2021-06-11 13:27:42 +00:00
|
|
|
|
|
|
|
}
|