@@ -34,6 +34,7 @@ func TestReportWorkflowStartFirst(t *testing.T) {
3434 Type : "action" ,
3535 ID : "action--test" ,
3636 Name : "ssh-tests" ,
37+ Description : "test step" ,
3738 StepVariables : cacao .NewVariables (expectedVariables ),
3839 Commands : []cacao.Command {expectedCommand },
3940 Cases : map [string ]string {},
@@ -67,7 +68,8 @@ func TestReportWorkflowStartFirst(t *testing.T) {
6768 playbook := cacao.Playbook {
6869 ID : "test" ,
6970 Type : "test" ,
70- Name : "ssh-test" ,
71+ Name : "ssh-test-playbook" ,
72+ Description : "Playbook description" ,
7173 WorkflowStart : step1 .ID ,
7274 AuthenticationInfoDefinitions : map [string ]cacao.AuthenticationInformation {"id" : expectedAuth },
7375 AgentDefinitions : map [string ]cacao.AgentTarget {"agent1" : expectedAgent },
@@ -82,29 +84,49 @@ func TestReportWorkflowStartFirst(t *testing.T) {
8284 timeNow , _ := time .Parse (layout , str )
8385 mock_time .On ("Now" ).Return (timeNow )
8486
85- expectedExecutionEntry := cache_model.ExecutionEntry {
86- ExecutionId : executionId0 ,
87- PlaybookId : "test" ,
88- StepResults : map [string ]cache_model.StepResult {},
89- Status : cache_model .Ongoing ,
90- Started : timeNow ,
91- Ended : time.Time {},
87+ err := cacheReporter .ReportWorkflowStart (executionId0 , playbook )
88+ if err != nil {
89+ t .Fail ()
9290 }
9391
94- err := cacheReporter .ReportWorkflowStart (executionId0 , playbook )
92+ mock_time .On ("Now" ).Return (timeNow )
93+
94+ err = cacheReporter .ReportStepStart (executionId0 , step1 , cacao .NewVariables (expectedVariables ))
95+ if err != nil {
96+ t .Fail ()
97+ }
98+
99+ mock_time .On ("Now" ).Return (timeNow )
100+ err = cacheReporter .ReportStepEnd (executionId0 , step1 , cacao .NewVariables (), nil )
95101 if err != nil {
96102 t .Fail ()
97103 }
98104
99105 expectedStarted , _ := time .Parse (layout , "2014-11-12T11:45:26.371Z" )
100106 expectedEnded , _ := time .Parse (layout , "0001-01-01T00:00:00Z" )
107+ expetedStepReport := cache_model.StepResult {
108+ ExecutionId : executionId0 ,
109+ StepId : "action--test" ,
110+ Name : "ssh-tests" ,
111+ Description : "test step" ,
112+ IsAutomated : true ,
113+ Started : timeNow ,
114+ Ended : timeNow ,
115+ CommandsB64 : []string {b64 .StdEncoding .EncodeToString ([]byte (expectedCommand .Command ))},
116+ Variables : cacao .NewVariables (),
117+ Status : cache_model .SuccessfullyExecuted ,
118+ Error : nil ,
119+ }
120+
101121 expectedExecutions := []cache_model.ExecutionEntry {
102122 {
103123 ExecutionId : executionId0 ,
104124 PlaybookId : "test" ,
125+ Name : "ssh-test-playbook" ,
126+ Description : "Playbook description" ,
105127 Started : expectedStarted ,
106128 Ended : expectedEnded ,
107- StepResults : map [string ]cache_model.StepResult {},
129+ StepResults : map [string ]cache_model.StepResult {expetedStepReport . StepId : expetedStepReport },
108130 Error : nil ,
109131 Status : 2 ,
110132 },
@@ -114,12 +136,13 @@ func TestReportWorkflowStartFirst(t *testing.T) {
114136
115137 exec , err := cacheReporter .GetExecutionReport (executionId0 )
116138 assert .Equal (t , expectedExecutions , returnedExecutions )
117- assert .Equal (t , expectedExecutionEntry .ExecutionId , exec .ExecutionId )
118- assert .Equal (t , expectedExecutionEntry .PlaybookId , exec .PlaybookId )
119- assert .Equal (t , expectedExecutionEntry .StepResults , exec .StepResults )
120- assert .Equal (t , expectedExecutionEntry .Started , timeNow )
121- assert .Equal (t , expectedExecutionEntry .Ended , time.Time {})
122- assert .Equal (t , expectedExecutionEntry .Status , exec .Status )
139+ assert .Equal (t , len (expectedExecutions ), 1 )
140+ assert .Equal (t , expectedExecutions [0 ].ExecutionId , exec .ExecutionId )
141+ assert .Equal (t , expectedExecutions [0 ].PlaybookId , exec .PlaybookId )
142+ assert .Equal (t , expectedExecutions [0 ].StepResults , exec .StepResults )
143+ assert .Equal (t , expectedExecutions [0 ].Started , timeNow )
144+ assert .Equal (t , expectedExecutions [0 ].Ended , time.Time {})
145+ assert .Equal (t , expectedExecutions [0 ].Status , exec .Status )
123146 assert .Equal (t , err , nil )
124147 mock_time .AssertExpectations (t )
125148}
@@ -143,6 +166,7 @@ func TestReportWorkflowStartFifo(t *testing.T) {
143166 Type : "action" ,
144167 ID : "action--test" ,
145168 Name : "ssh-tests" ,
169+ Description : "step description" ,
146170 StepVariables : cacao .NewVariables (expectedVariables ),
147171 Commands : []cacao.Command {expectedCommand },
148172 Cases : map [string ]string {},
@@ -176,7 +200,8 @@ func TestReportWorkflowStartFifo(t *testing.T) {
176200 playbook := cacao.Playbook {
177201 ID : "test" ,
178202 Type : "test" ,
179- Name : "ssh-test" ,
203+ Name : "ssh-test-playbook" ,
204+ Description : "Playbook description" ,
180205 WorkflowStart : step1 .ID ,
181206 AuthenticationInfoDefinitions : map [string ]cacao.AuthenticationInformation {"id" : expectedAuth },
182207 AgentDefinitions : map [string ]cacao.AgentTarget {"agent1" : expectedAgent },
@@ -209,6 +234,8 @@ func TestReportWorkflowStartFifo(t *testing.T) {
209234 entry := cache_model.ExecutionEntry {
210235 ExecutionId : executionId ,
211236 PlaybookId : "test" ,
237+ Name : "ssh-test-playbook" ,
238+ Description : "Playbook description" ,
212239 Started : expectedStarted ,
213240 Ended : expectedEnded ,
214241 StepResults : map [string ]cache_model.StepResult {},
@@ -224,6 +251,8 @@ func TestReportWorkflowStartFifo(t *testing.T) {
224251 entry := cache_model.ExecutionEntry {
225252 ExecutionId : executionId ,
226253 PlaybookId : "test" ,
254+ Name : "ssh-test-playbook" ,
255+ Description : "Playbook description" ,
227256 Started : expectedStarted ,
228257 Ended : expectedEnded ,
229258 StepResults : map [string ]cache_model.StepResult {},
@@ -283,6 +312,7 @@ func TestReportWorkflowEnd(t *testing.T) {
283312 Type : "action" ,
284313 ID : "action--test" ,
285314 Name : "ssh-tests" ,
315+ Description : "step 1" ,
286316 StepVariables : cacao .NewVariables (expectedVariables ),
287317 Commands : []cacao.Command {expectedCommand },
288318 Cases : map [string ]string {},
@@ -316,7 +346,8 @@ func TestReportWorkflowEnd(t *testing.T) {
316346 playbook := cacao.Playbook {
317347 ID : "test" ,
318348 Type : "test" ,
319- Name : "ssh-test" ,
349+ Name : "ssh-test-playbook" ,
350+ Description : "Playbook description" ,
320351 WorkflowStart : step1 .ID ,
321352 AuthenticationInfoDefinitions : map [string ]cacao.AuthenticationInformation {"id" : expectedAuth },
322353 AgentDefinitions : map [string ]cacao.AgentTarget {"agent1" : expectedAgent },
@@ -343,6 +374,8 @@ func TestReportWorkflowEnd(t *testing.T) {
343374 expectedExecutionEntry := cache_model.ExecutionEntry {
344375 ExecutionId : executionId0 ,
345376 PlaybookId : "test" ,
377+ Name : "ssh-test-playbook" ,
378+ Description : "Playbook description" ,
346379 Started : timeNow ,
347380 Ended : timeNow ,
348381 StepResults : map [string ]cache_model.StepResult {},
0 commit comments