@@ -39,11 +39,76 @@ func (noopStatusReporter) TaskEnqueued(taskRun *store.TaskRun) {}
3939func (noopStatusReporter ) TaskRunning (taskRun * store.TaskRun ) {}
4040func (noopStatusReporter ) TaskCompleted (taskRun * store.TaskRun ) {}
4141func (noopStatusReporter ) TaskFailed (taskRun * store.TaskRun ) {}
42+ func (noopStatusReporter ) TaskNotFound (taskIdentifier string ) {}
4243
4344func (f * fakeServerFactory ) NewHandler (socket net.Listener , input taskserver.GetInput200JSONResponse , getSubtaskResultFunc taskserver.GetSubtaskResultFunc , startSubtaskFunc taskserver.StartSubtaskFunc ) * taskserver.ServerHandler {
4445 return f .newHandler (socket , input , getSubtaskResultFunc , startSubtaskFunc )
4546}
4647
48+ type recordingStatusReporter struct {
49+ noopStatusReporter
50+ notFoundIdentifier string
51+ }
52+
53+ func (r * recordingStatusReporter ) TaskNotFound (taskIdentifier string ) {
54+ r .notFoundIdentifier = taskIdentifier
55+ }
56+
57+ func TestStartTaskNotFound (t * testing.T ) {
58+ ctx := context .Background ()
59+
60+ s := store .NewTaskStore ()
61+
62+ tasks := []taskserver.Task {
63+ {
64+ Name : "test-task" ,
65+ },
66+ }
67+
68+ postTasksChan := make (chan taskserver.PostRegisterTasksRequestObject , 1 )
69+ postTasksChan <- taskserver.PostRegisterTasksRequestObject {
70+ Body : & taskserver.PostRegisterTasksJSONRequestBody {
71+ Tasks : tasks ,
72+ },
73+ }
74+
75+ socketTracker , err := orchestrator .NewSocketTracker (ctx )
76+ require .NoError (t , err )
77+
78+ reporter := & recordingStatusReporter {}
79+ coordinator := orchestrator .NewCoordinator (
80+ ctx ,
81+ s ,
82+ & fakeSdkExec {
83+ startService : func (ctx context.Context , taskRunID string , socket string , mode orchestrator.Mode ) (func () error , <- chan error , error ) {
84+ return func () error { return nil }, neverExits (), nil
85+ },
86+ },
87+ socketTracker ,
88+ & fakeServerFactory {
89+ newHandler : func (socket net.Listener , input taskserver.GetInput200JSONResponse , getSubtaskResultFunc taskserver.GetSubtaskResultFunc , startSubtaskFunc taskserver.StartSubtaskFunc ) * taskserver.ServerHandler {
90+ return & taskserver.ServerHandler {
91+ Socket : socket ,
92+ Input : input ,
93+ Channels : taskserver.ServerChannels {
94+ PostCallback : make (chan taskserver.PostCallbackRequestObject ),
95+ PostTasks : postTasksChan ,
96+ },
97+ }
98+ },
99+ },
100+ reporter ,
101+ )
102+
103+ _ , err = coordinator .StartTask (ctx , "nonexistent-task" , []byte {}, nil )
104+ require .Error (t , err )
105+
106+ var taskNotFoundErr * orchestrator.TaskNotFoundError
107+ require .ErrorAs (t , err , & taskNotFoundErr )
108+ require .Equal (t , "nonexistent-task" , taskNotFoundErr .TaskIdentifier )
109+ require .Equal (t , "nonexistent-task" , reporter .notFoundIdentifier )
110+ }
111+
47112func TestStartTask (t * testing.T ) {
48113 ctx := context .Background ()
49114
0 commit comments