MCPcopy Index your code
hub / github.com/prest/prest / TestScriptHandler_Execute_WithCache

Function TestScriptHandler_Execute_WithCache

controllers/script_test.go:75–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

73}
74
75func 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
109func TestScriptHandler_ExecuteScriptQuery_GetScriptError(t *testing.T) {
110 ctrl := gomock.NewController(t)

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
EXPECTMethod · 0.95
EXPECTMethod · 0.95
EXPECTMethod · 0.95
ExecuteMethod · 0.95
NewMockScriptRunnerFunction · 0.92
NewMockScannerFunction · 0.92
NewMockQueryExecutorFunction · 0.92
NewMockDatabaseRegistryFunction · 0.92
NewScriptHandlerFunction · 0.85
withTestTimeoutFunction · 0.85
GetScriptMethod · 0.65

Tested by

no test coverage detected