(t *testing.T)
| 125 | } |
| 126 | |
| 127 | func TestScriptHandler_ExecuteScriptQuery_ExecuteError(t *testing.T) { |
| 128 | ctrl := gomock.NewController(t) |
| 129 | defer ctrl.Finish() |
| 130 | |
| 131 | scripts := mockgen.NewMockScriptRunner(ctrl) |
| 132 | scripts.EXPECT().GetScript(http.MethodGet, "queries", "bad").Return("/tmp/bad.sql", nil) |
| 133 | scripts.EXPECT().ParseScript("/tmp/bad.sql", gomock.Any()).Return(`SELECT bad`, nil, nil) |
| 134 | |
| 135 | scanner := mockgen.NewMockScanner(ctrl) |
| 136 | scanner.EXPECT().Err().Return(errors.New("syntax error")) |
| 137 | |
| 138 | executor := mockgen.NewMockQueryExecutor(ctrl) |
| 139 | executor.EXPECT().ExecuteScriptsCtx(gomock.Any(), http.MethodGet, `SELECT bad`, gomock.Any()).Return(scanner) |
| 140 | |
| 141 | db := mockgen.NewMockDatabaseRegistry(ctrl) |
| 142 | db.EXPECT().SetDatabase("prest-test") |
| 143 | |
| 144 | h := NewScriptHandler(Deps{Scripts: scripts, Executor: executor, DB: db, PGDatabase: "prest-test"}) |
| 145 | req := httptest.NewRequest(http.MethodGet, "/queries/bad", nil) |
| 146 | req = req.WithContext(withTestTimeout(req.Context())) |
| 147 | |
| 148 | _, err := h.ExecuteScriptQuery(req, "queries", "bad") |
| 149 | require.Error(t, err) |
| 150 | require.Contains(t, err.Error(), "could not execute sql") |
| 151 | } |
| 152 | |
| 153 | func TestExtractHeaders(t *testing.T) { |
| 154 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
nothing calls this directly
no test coverage detected