package webserver_test import ( "testing" "net/http" "net/http/httptest" "github.com/andybalholm/cascadia" "github.com/stretchr/testify/require" "gitlab.com/offline-twitter/twitter_offline_engine/internal/webserver" "gitlab.com/offline-twitter/twitter_offline_engine/pkg/persistence" ) type CapturingWriter struct { Writes [][]byte } func (w *CapturingWriter) Write(p []byte) (int, error) { w.Writes = append(w.Writes, p) return len(p), nil } var profile persistence.Profile func init() { var err error profile, err = persistence.LoadProfile("../../sample_data/profile") if err != nil { panic(err) } } func selector(s string) cascadia.Sel { ret, err := cascadia.Parse(s) if err != nil { panic(err) } return ret } func do_request(req *http.Request) *http.Response { recorder := httptest.NewRecorder() app := webserver.NewApp(profile) app.IsScrapingDisabled = true app.ServeHTTP(recorder, req) return recorder.Result() } // Homepage // -------- // Should redirect to the timeline func TestHomepage(t *testing.T) { require := require.New(t) resp := do_request(httptest.NewRequest("GET", "/", nil)) require.Equal(resp.StatusCode, 303) require.Equal(resp.Header.Get("Location"), "/timeline") }