Manager: Tests, allow mocking requests that are not Worker-authenticated
This commit is contained in:
parent
2f0b77f45b
commit
e57de8ab53
@ -65,7 +65,8 @@ func TestTaskUpdate(t *testing.T) {
|
||||
mf.logStorage.EXPECT().Write(gomock.Any(), jobID, taskID, "line1\nline2\n")
|
||||
|
||||
// Do the call.
|
||||
echoCtx := mf.prepareMockedJSONRequest(&worker, taskUpdate)
|
||||
echoCtx := mf.prepareMockedJSONRequest(taskUpdate)
|
||||
requestWorkerStore(echoCtx, &worker)
|
||||
err := mf.flamenco.TaskUpdate(echoCtx, taskID)
|
||||
|
||||
// Check the saved task.
|
||||
|
@ -48,26 +48,25 @@ func newMockedFlamenco(mockCtrl *gomock.Controller) mockedFlamenco {
|
||||
}
|
||||
|
||||
// prepareMockedJSONRequest returns an `echo.Context` that has a JSON request body attached to it.
|
||||
func (mf *mockedFlamenco) prepareMockedJSONRequest(worker *persistence.Worker, requestBody interface{}) echo.Context {
|
||||
func (mf *mockedFlamenco) prepareMockedJSONRequest(requestBody interface{}) echo.Context {
|
||||
bodyBytes, err := json.MarshalIndent(requestBody, "", " ")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c := mf.prepareMockedRequest(worker, bytes.NewBuffer(bodyBytes))
|
||||
c := mf.prepareMockedRequest(bytes.NewBuffer(bodyBytes))
|
||||
c.Request().Header.Add(echo.HeaderContentType, "application/json")
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
// prepareMockedJSONRequest returns an `echo.Context` that has an empty request body attached to it.
|
||||
func (mf *mockedFlamenco) prepareMockedRequest(worker *persistence.Worker, body io.Reader) echo.Context {
|
||||
func (mf *mockedFlamenco) prepareMockedRequest(body io.Reader) echo.Context {
|
||||
e := echo.New()
|
||||
|
||||
req := httptest.NewRequest(http.MethodPost, "/", body)
|
||||
rec := httptest.NewRecorder()
|
||||
c := e.NewContext(req, rec)
|
||||
requestWorkerStore(c, worker)
|
||||
|
||||
return c
|
||||
}
|
||||
|
@ -23,7 +23,8 @@ func TestTaskScheduleHappy(t *testing.T) {
|
||||
mf := newMockedFlamenco(mockCtrl)
|
||||
worker := testWorker()
|
||||
|
||||
echo := mf.prepareMockedRequest(&worker, nil)
|
||||
echo := mf.prepareMockedRequest(nil)
|
||||
requestWorkerStore(echo, &worker)
|
||||
|
||||
// Expect a call into the persistence layer, which should return a scheduled task.
|
||||
job := persistence.Job{
|
||||
@ -54,7 +55,8 @@ func TestTaskScheduleNonActiveStatus(t *testing.T) {
|
||||
// Explicitly NO expected calls to the persistence layer. Since the worker is
|
||||
// not in a state that allows task execution, there should be no DB queries.
|
||||
|
||||
echoCtx := mf.prepareMockedRequest(&worker, nil)
|
||||
echoCtx := mf.prepareMockedRequest(nil)
|
||||
requestWorkerStore(echoCtx, &worker)
|
||||
err := mf.flamenco.ScheduleTask(echoCtx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@ -73,7 +75,8 @@ func TestTaskScheduleOtherStatusRequested(t *testing.T) {
|
||||
// Explicitly NO expected calls to the persistence layer. Since the worker is
|
||||
// not in a state that allows task execution, there should be no DB queries.
|
||||
|
||||
echoCtx := mf.prepareMockedRequest(&worker, nil)
|
||||
echoCtx := mf.prepareMockedRequest(nil)
|
||||
requestWorkerStore(echoCtx, &worker)
|
||||
err := mf.flamenco.ScheduleTask(echoCtx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@ -112,7 +115,8 @@ func TestWorkerSignoffTaskRequeue(t *testing.T) {
|
||||
|
||||
// Signing off should be handled completely, even when the HTTP connection
|
||||
// breaks. This means using a different context than the one passed by Echo.
|
||||
echo := mf.prepareMockedRequest(&worker, nil)
|
||||
echo := mf.prepareMockedRequest(nil)
|
||||
requestWorkerStore(echo, &worker)
|
||||
expectCtx := gomock.Not(gomock.Eq(echo.Request().Context()))
|
||||
|
||||
// Expect worker's tasks to be re-queued.
|
||||
|
Loading…
x
Reference in New Issue
Block a user