Open platform to collect and prioritize feedback
fix: resolve broken tests
goenning2f335b2aa4d2
diff --git a/app/middlewares/cache_test.go b/app/middlewares/cache_test.goindex a5fa7af8b..1430292d0 100644--- a/app/middlewares/cache_test.go+++ b/app/middlewares/cache_test.go@@ -38,5 +38,5 @@ func TestCache_StatusNotFound(t *testing.T) {status, response := server.Execute(handler)Expect(status).Equals(http.StatusNotFound)- Expect(response.Header().Get("Cache-Control")).Equals("")+ Expect(response.Header().Get("Cache-Control")).Equals("no-cache, no-store")}diff --git a/app/middlewares/maintenance.go b/app/middlewares/maintenance.goindex c1b61872f..653243abb 100644--- a/app/middlewares/maintenance.go+++ b/app/middlewares/maintenance.go@@ -15,7 +15,6 @@ func Maintenance() web.MiddlewareFunc {return next(c)}- c.Response.Header().Set("Cache-Control", "no-cache, no-store")c.Response.Header().Set("Retry-After", "3600")return c.Render(http.StatusServiceUnavailable, "maintenance.html", web.Props{diff --git a/app/pkg/env/env.go b/app/pkg/env/env.goindex cdf5406db..46f15c3d7 100644--- a/app/pkg/env/env.go+++ b/app/pkg/env/env.go@@ -40,9 +40,6 @@ type config struct {HostDomain string `env:"HOST_DOMAIN,required"`Locale string `env:"LOCALE,default=en"`JWTSecret string `env:"JWT_SECRET,required"`- Rendergun struct {- URL string `env:"RENDERGUN_URL"`- }Experimental_SSR_SEO bool `env:"EXPERIMENTAL_SSR_SEO,default=false"`Database struct {URL string `env:"DATABASE_URL,required"`diff --git a/app/pkg/web/context.go b/app/pkg/web/context.goindex d52f4914a..0d54b0b4e 100644--- a/app/pkg/web/context.go+++ b/app/pkg/web/context.go@@ -5,7 +5,6 @@ import ("context""encoding/json""fmt"- "io""net/http""net/url""strconv"@@ -17,10 +16,8 @@ import ("github.com/getfider/fider/app""github.com/getfider/fider/app/actions"- "github.com/getfider/fider/app/models/cmd""github.com/getfider/fider/app/models/dto""github.com/getfider/fider/app/models/entity"- "github.com/getfider/fider/app/pkg/bus""github.com/getfider/fider/app/pkg/env""github.com/getfider/fider/app/pkg/errors""github.com/getfider/fider/app/pkg/log"@@ -295,12 +292,6 @@ func (c *Context) BadRequest(dict Map) error {//Page returns a page with given variablesfunc (c *Context) Page(props Props) error {- if len(env.Config.Rendergun.URL) > 0 && c.Request.IsCrawler() {- html := new(bytes.Buffer)- c.engine.renderer.Render(html, http.StatusOK, "index.html", props, c)- return c.prerender(http.StatusOK, html)- }-return c.Render(http.StatusOK, "index.html", props)}@@ -316,34 +307,6 @@ func (c *Context) Render(code int, template string, props Props) error {return c.Blob(code, UTF8HTMLContentType, buf.Bytes())}-func (c *Context) prerender(code int, html io.Reader) error {- req := &cmd.HTTPRequest{- Method: "POST",- URL: fmt.Sprintf("%s/render?url=%s", env.Config.Rendergun.URL, c.Request.URL.String()),- Body: html,- Headers: map[string]string{- "Content-Type": "text/html",- "x-rendergun-wait-until": "networkidle0",- "x-rendergun-block-ads": "true",- "x-rendergun-abort-request": "assets\\/css\\/(common|vendor|main)\\.",- },- }- err := bus.Dispatch(c, req)- if err != nil {- log.Error(c, errors.Wrap(err, "failed to execute rendergun"))- return c.TryAgainLater(24 * time.Hour)- }-- return c.Blob(code, UTF8HTMLContentType, req.ResponseBody)-}--//TryAgainLater returns a service unavailable response with Retry-After header-func (c *Context) TryAgainLater(d time.Duration) error {- c.Response.Header().Set("Cache-Control", "no-cache, no-store")- c.Response.Header().Set("Retry-After", fmt.Sprintf("%.0f", d.Seconds()))- return c.NoContent(http.StatusServiceUnavailable)-}-//AddParam add a single param to route parameters listfunc (c *Context) AddParam(name, value string) {c.params[name] = value@@ -477,7 +440,7 @@ func (c *Context) Image(contentType string, b []byte) error {// Blob sends a blob response with status code and content type.func (c *Context) Blob(code int, contentType string, b []byte) error {if code >= 400 {- c.Response.Header().Del("Cache-Control")+ c.Response.Header().Set("Cache-Control", "no-cache, no-store")}c.Response.Header().Set("Content-Type", contentType)@@ -490,7 +453,7 @@ func (c *Context) Blob(code int, contentType string, b []byte) error {// NoContent sends a response with no body and a status code.func (c *Context) NoContent(code int) error {if code >= 400 {- c.Response.Header().Del("Cache-Control")+ c.Response.Header().Set("Cache-Control", "no-cache, no-store")}c.ResponseStatusCode = codediff --git a/app/pkg/web/context_test.go b/app/pkg/web/context_test.goindex f6d45a0e4..d829defda 100644--- a/app/pkg/web/context_test.go+++ b/app/pkg/web/context_test.go@@ -2,12 +2,10 @@ package web_testimport ("crypto/tls"- "net/http""net/http/httptest""net/url""strings""testing"- "time""github.com/getfider/fider/app/models/entity". "github.com/getfider/fider/app/pkg/assert"@@ -193,19 +191,6 @@ func TestCanonicalURL_DifferentDomain(t *testing.T) {Expect(ctx.Value("Canonical-URL")).Equals(`http://feedback.theavengers.com/page-b/abc.html`)}-func TestTryAgainLater(t *testing.T) {- RegisterT(t)-- ctx := newGetContext("http://demo.test.fider.io:3000", nil)- err := ctx.TryAgainLater(24 * time.Hour)- Expect(err).IsNil()- resp := ctx.Response.(*httptest.ResponseRecorder)- Expect(ctx.ResponseStatusCode).Equals(http.StatusServiceUnavailable)- Expect(resp.Code).Equals(http.StatusServiceUnavailable)- Expect(resp.Header().Get("Cache-Control")).Equals("no-cache, no-store")- Expect(resp.Header().Get("Retry-After")).Equals("86400")-}-func TestGetOAuthBaseURL(t *testing.T) {RegisterT(t)diff --git a/app/pkg/web/engine.go b/app/pkg/web/engine.goindex bdc6ada49..d99cec672 100644--- a/app/pkg/web/engine.go+++ b/app/pkg/web/engine.go@@ -296,7 +296,7 @@ func (g *Group) Static(prefix, root string) {http.ServeFile(c.Response, c.Request.instance, filePath)return nil}- c.Response.Header().Del("Cache-Control")+ c.Response.Header().Set("Cache-Control", "no-cache, no-store")return c.NotFound()}} else {diff --git a/e2e/features/http.feature b/e2e/features/http.featureindex c7d2b8889..a1c75daa7 100644--- a/e2e/features/http.feature+++ b/e2e/features/http.feature@@ -8,4 +8,4 @@ Feature: HTTPScenario: Cache Control is not set on invalid resourcesGiven I send a "GET" request to "/assets/invalid.js"Then I should see http status 404- And I should not see a "Cache-Control" header\ No newline at end of file+ And I should see a "Cache-Control" header with value "no-cache, no-store"\ No newline at end of file