(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestScriptHandler_Execute_Success(t *testing.T) { |
| 16 | ctrl := gomock.NewController(t) |
| 17 | defer ctrl.Finish() |
| 18 | |
| 19 | scripts := mockgen.NewMockScriptRunner(ctrl) |
| 20 | scripts.EXPECT().GetScript(http.MethodGet, "queries", "list").Return("/tmp/list.sql", nil) |
| 21 | scripts.EXPECT().ParseScript("/tmp/list.sql", gomock.Any()).Return(`SELECT 1`, nil, nil) |
| 22 | |
| 23 | scanner := mockgen.NewMockScanner(ctrl) |
| 24 | scanner.EXPECT().Err().Return(nil) |
| 25 | scanner.EXPECT().Bytes().Return([]byte(`[{"n":1}]`)) |
| 26 | |
| 27 | executor := mockgen.NewMockQueryExecutor(ctrl) |
| 28 | executor.EXPECT().ExecuteScriptsCtx(gomock.Any(), http.MethodGet, `SELECT 1`, gomock.Any()).Return(scanner) |
| 29 | |
| 30 | db := mockgen.NewMockDatabaseRegistry(ctrl) |
| 31 | db.EXPECT().SetDatabase("prest-test") |
| 32 | |
| 33 | h := NewScriptHandler(Deps{Scripts: scripts, Executor: executor, DB: db, PGDatabase: "prest-test"}) |
| 34 | req := httptest.NewRequest(http.MethodGet, "/queries/list", nil) |
| 35 | req = mux.SetURLVars(req, map[string]string{"queriesLocation": "queries", "script": "list", "database": "prest-test"}) |
| 36 | req = req.WithContext(withTestTimeout(req.Context())) |
| 37 | rec := httptest.NewRecorder() |
| 38 | |
| 39 | h.Execute(rec, req) |
| 40 | |
| 41 | require.Equal(t, http.StatusOK, rec.Code) |
| 42 | require.Contains(t, rec.Body.String(), `"n":1`) |
| 43 | } |
| 44 | |
| 45 | func TestScriptHandler_Execute_DefaultDatabase(t *testing.T) { |
| 46 | ctrl := gomock.NewController(t) |
nothing calls this directly
no test coverage detected