(t *testing.T)
| 43 | } |
| 44 | |
| 45 | func TestScriptHandler_Execute_DefaultDatabase(t *testing.T) { |
| 46 | ctrl := gomock.NewController(t) |
| 47 | defer ctrl.Finish() |
| 48 | |
| 49 | scripts := mockgen.NewMockScriptRunner(ctrl) |
| 50 | scripts.EXPECT().GetScript(http.MethodGet, "queries", "ping").Return("/tmp/ping.sql", nil) |
| 51 | scripts.EXPECT().ParseScript(gomock.Any(), gomock.Any()).Return(`SELECT 1`, nil, nil) |
| 52 | |
| 53 | scanner := mockgen.NewMockScanner(ctrl) |
| 54 | scanner.EXPECT().Err().Return(nil) |
| 55 | scanner.EXPECT().Bytes().Return([]byte(`[]`)) |
| 56 | |
| 57 | executor := mockgen.NewMockQueryExecutor(ctrl) |
| 58 | executor.EXPECT().ExecuteScriptsCtx(gomock.Any(), http.MethodGet, `SELECT 1`, gomock.Any()).Return(scanner) |
| 59 | |
| 60 | db := mockgen.NewMockDatabaseRegistry(ctrl) |
| 61 | db.EXPECT().SetDatabase("prest-test") |
| 62 | db.EXPECT().GetDatabase().Return("prest-test").AnyTimes() |
| 63 | |
| 64 | h := NewScriptHandler(Deps{Scripts: scripts, Executor: executor, DB: db, PGDatabase: "prest-test"}) |
| 65 | req := httptest.NewRequest(http.MethodGet, "/queries/ping", nil) |
| 66 | req = mux.SetURLVars(req, map[string]string{"queriesLocation": "queries", "script": "ping"}) |
| 67 | req = req.WithContext(withTestTimeout(req.Context())) |
| 68 | rec := httptest.NewRecorder() |
| 69 | |
| 70 | h.Execute(rec, req) |
| 71 | |
| 72 | require.Equal(t, http.StatusOK, rec.Code) |
| 73 | } |
| 74 | |
| 75 | func TestScriptHandler_Execute_WithCache(t *testing.T) { |
| 76 | ctrl := gomock.NewController(t) |
nothing calls this directly
no test coverage detected