MCPcopy Index your code
hub / github.com/supabase/auth / TestDatabaseCleanup

Method TestDatabaseCleanup

internal/api/middleware_test.go:783–835  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

781}
782
783func (ts *MiddlewareTestSuite) TestDatabaseCleanup() {
784 testHandler := func(statusCode int) http.HandlerFunc {
785 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
786 w.WriteHeader(statusCode)
787 b, _ := json.Marshal(map[string]interface{}{"message": "ok"})
788 w.Write([]byte(b))
789 })
790 }
791
792 cases := []struct {
793 desc string
794 statusCode int
795 method string
796 }{
797 {
798 desc: "Run cleanup successfully",
799 statusCode: http.StatusOK,
800 method: http.MethodPost,
801 },
802 {
803 desc: "Skip cleanup if GET",
804 statusCode: http.StatusOK,
805 method: http.MethodGet,
806 },
807 {
808 desc: "Skip cleanup if 3xx",
809 statusCode: http.StatusSeeOther,
810 method: http.MethodPost,
811 },
812 {
813 desc: "Skip cleanup if 4xx",
814 statusCode: http.StatusBadRequest,
815 method: http.MethodPost,
816 },
817 {
818 desc: "Skip cleanup if 5xx",
819 statusCode: http.StatusInternalServerError,
820 method: http.MethodPost,
821 },
822 }
823
824 mockCleanup := new(MockCleanup)
825 mockCleanup.On("Clean", mock.Anything).Return(0, nil)
826 for _, c := range cases {
827 ts.Run("DatabaseCleanup", func() {
828 req := httptest.NewRequest(c.method, "http://localhost", nil)
829 w := httptest.NewRecorder()
830 ts.API.databaseCleanup(mockCleanup)(testHandler(c.statusCode)).ServeHTTP(w, req)
831 require.Equal(ts.T(), c.statusCode, w.Code)
832 })
833 }
834 mockCleanup.AssertNumberOfCalls(ts.T(), "Clean", 1)
835}
836
837func (ts *MiddlewareTestSuite) TestRequireAdminCredentialsSessionCheck() {
838 models.TruncateAll(ts.API.db)

Callers

nothing calls this directly

Calls 8

MarshalMethod · 0.80
databaseCleanupMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
testHandlerStruct · 0.50
WriteHeaderMethod · 0.45
WriteMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected