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

Function TestScriptHandler_Execute_DefaultDatabase

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

Source from the content-addressed store, hash-verified

43}
44
45func 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
75func TestScriptHandler_Execute_WithCache(t *testing.T) {
76 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