A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

39 linhas
918 B

  1. package writefreely
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "strings"
  6. "testing"
  7. "github.com/gorilla/mux"
  8. )
  9. func TestCacheControlForStaticFiles(t *testing.T) {
  10. app := NewApp("testdata/config.ini")
  11. if err := app.LoadConfig(); err != nil {
  12. t.Fatalf("Could not create an app; %v", err)
  13. }
  14. router := mux.NewRouter()
  15. app.InitStaticRoutes(router)
  16. rec := httptest.NewRecorder()
  17. req := httptest.NewRequest("GET", "/style.css", nil)
  18. router.ServeHTTP(rec, req)
  19. if code := rec.Result().StatusCode; code != http.StatusOK {
  20. t.Fatalf("Could not get /style.css, got HTTP status %d", code)
  21. }
  22. actual := rec.Result().Header.Get("Cache-Control")
  23. expectedDirectives := []string{
  24. "public",
  25. "max-age",
  26. "immutable",
  27. }
  28. for _, expected := range expectedDirectives {
  29. if !strings.Contains(actual, expected) {
  30. t.Errorf("Expected Cache-Control header to contain '%s', but was '%s'", expected, actual)
  31. }
  32. }
  33. }