2021-06-11 13:27:42 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2022-02-12 21:29:45 +00:00
|
|
|
"net/http/httptest"
|
2021-06-11 13:27:42 +00:00
|
|
|
"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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-02-12 21:29:45 +00:00
|
|
|
rec := httptest.NewRecorder()
|
|
|
|
req := httptest.NewRequest("GET", "/robots.txt", nil)
|
|
|
|
app.serveRobotsTXT(rec, req)
|
|
|
|
assert.Equal(t, http.StatusOK, rec.Code)
|
|
|
|
assert.Equal(t, "User-agent: *\nAllow: /\n\nSitemap: https://example.com/sitemap.xml\n", rec.Body.String())
|
2021-07-27 10:51:08 +00:00
|
|
|
|
|
|
|
app.cfg.PrivateMode = &configPrivateMode{
|
|
|
|
Enabled: true,
|
|
|
|
}
|
2022-02-12 21:29:45 +00:00
|
|
|
assert.True(t, app.isPrivate())
|
2021-07-27 10:51:08 +00:00
|
|
|
|
2022-02-12 21:29:45 +00:00
|
|
|
rec = httptest.NewRecorder()
|
|
|
|
req = httptest.NewRequest("GET", "/robots.txt", nil)
|
|
|
|
app.serveRobotsTXT(rec, req)
|
|
|
|
assert.Equal(t, http.StatusOK, rec.Code)
|
|
|
|
assert.Equal(t, "User-agent: *\nDisallow: /\n", rec.Body.String())
|
2021-06-11 13:27:42 +00:00
|
|
|
|
|
|
|
}
|