(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func TestScriptHandler_Execute_WithCache(t *testing.T) { |
| 76 | ctrl := gomock.NewController(t) |
| 77 | defer ctrl.Finish() |
| 78 | |
| 79 | scripts := mockgen.NewMockScriptRunner(ctrl) |
| 80 | scripts.EXPECT().GetScript(http.MethodGet, "queries", "list").Return("/tmp/list.sql", nil) |
| 81 | scripts.EXPECT().ParseScript(gomock.Any(), gomock.Any()).Return(`SELECT 1`, nil, nil) |
| 82 | |
| 83 | scanner := mockgen.NewMockScanner(ctrl) |
| 84 | scanner.EXPECT().Err().Return(nil) |
| 85 | scanner.EXPECT().Bytes().Return([]byte(`cached`)) |
| 86 | |
| 87 | executor := mockgen.NewMockQueryExecutor(ctrl) |
| 88 | executor.EXPECT().ExecuteScriptsCtx(gomock.Any(), http.MethodGet, `SELECT 1`, gomock.Any()).Return(scanner) |
| 89 | |
| 90 | db := mockgen.NewMockDatabaseRegistry(ctrl) |
| 91 | db.EXPECT().SetDatabase("prest-test") |
| 92 | |
| 93 | cacher := &recordingCacher{} |
| 94 | h := NewScriptHandler(Deps{Scripts: scripts, Executor: executor, DB: db, PGDatabase: "prest-test", Cache: cacher}) |
| 95 | |
| 96 | url := "/queries/list?x=1" |
| 97 | req := httptest.NewRequest(http.MethodGet, url, nil) |
| 98 | req = mux.SetURLVars(req, map[string]string{"queriesLocation": "queries", "script": "list", "database": "prest-test"}) |
| 99 | req = req.WithContext(withTestTimeout(req.Context())) |
| 100 | rec := httptest.NewRecorder() |
| 101 | |
| 102 | h.Execute(rec, req) |
| 103 | |
| 104 | require.Equal(t, http.StatusOK, rec.Code) |
| 105 | require.Equal(t, url, cacher.key) |
| 106 | require.Equal(t, "cached", cacher.value) |
| 107 | } |
| 108 | |
| 109 | func TestScriptHandler_ExecuteScriptQuery_GetScriptError(t *testing.T) { |
| 110 | ctrl := gomock.NewController(t) |
nothing calls this directly
no test coverage detected