diff --git a/internal/reporter/downstream_reporter/cache/cache.go b/internal/reporter/downstream_reporter/cache/cache.go index f96973e0..2b3464b4 100644 --- a/internal/reporter/downstream_reporter/cache/cache.go +++ b/internal/reporter/downstream_reporter/cache/cache.go @@ -229,6 +229,8 @@ func (cacheReporter *Cache) ReportWorkflowStart(executionId uuid.UUID, playbook newExecutionEntry := cache_report.ExecutionEntry{ ExecutionId: executionId, PlaybookId: playbook.ID, + Name: playbook.Name, + Description: playbook.Description, Started: cacheReporter.timeUtil.Now(), Ended: time.Time{}, StepResults: map[string]cache_report.StepResult{}, @@ -266,6 +268,8 @@ func (cacheReporter *Cache) ReportStepStart(executionId uuid.UUID, step cacao.St newStep := cache_report.StepResult{ ExecutionId: executionId, StepId: step.ID, + Name: step.Name, + Description: step.Description, Started: cacheReporter.timeUtil.Now(), Ended: time.Time{}, Variables: variables, diff --git a/test/unittest/reporters/downstream_reporter/cache_test.go b/test/unittest/reporters/downstream_reporter/cache_test.go index 30f58d0b..9728a61a 100644 --- a/test/unittest/reporters/downstream_reporter/cache_test.go +++ b/test/unittest/reporters/downstream_reporter/cache_test.go @@ -34,6 +34,7 @@ func TestReportWorkflowStartFirst(t *testing.T) { Type: "action", ID: "action--test", Name: "ssh-tests", + Description: "test step", StepVariables: cacao.NewVariables(expectedVariables), Commands: []cacao.Command{expectedCommand}, Cases: map[string]string{}, @@ -67,7 +68,8 @@ func TestReportWorkflowStartFirst(t *testing.T) { playbook := cacao.Playbook{ ID: "test", Type: "test", - Name: "ssh-test", + Name: "ssh-test-playbook", + Description: "Playbook description", WorkflowStart: step1.ID, AuthenticationInfoDefinitions: map[string]cacao.AuthenticationInformation{"id": expectedAuth}, AgentDefinitions: map[string]cacao.AgentTarget{"agent1": expectedAgent}, @@ -82,29 +84,43 @@ func TestReportWorkflowStartFirst(t *testing.T) { timeNow, _ := time.Parse(layout, str) mock_time.On("Now").Return(timeNow) - expectedExecutionEntry := cache_model.ExecutionEntry{ - ExecutionId: executionId0, - PlaybookId: "test", - StepResults: map[string]cache_model.StepResult{}, - Status: cache_model.Ongoing, - Started: timeNow, - Ended: time.Time{}, - } - err := cacheReporter.ReportWorkflowStart(executionId0, playbook) if err != nil { t.Fail() } + mock_time.On("Now").Return(timeNow) + + cacheReporter.ReportStepStart(executionId0, step1, cacao.NewVariables(expectedVariables)) + + mock_time.On("Now").Return(timeNow) + cacheReporter.ReportStepEnd(executionId0, step1, cacao.NewVariables(), nil) + expectedStarted, _ := time.Parse(layout, "2014-11-12T11:45:26.371Z") expectedEnded, _ := time.Parse(layout, "0001-01-01T00:00:00Z") + expetedStepReport := cache_model.StepResult{ + ExecutionId: executionId0, + StepId: "action--test", + Name: "ssh-tests", + Description: "test step", + IsAutomated: true, + Started: timeNow, + Ended: timeNow, + CommandsB64: []string{b64.StdEncoding.EncodeToString([]byte(expectedCommand.Command))}, + Variables: cacao.NewVariables(), + Status: cache_model.SuccessfullyExecuted, + Error: nil, + } + expectedExecutions := []cache_model.ExecutionEntry{ { ExecutionId: executionId0, PlaybookId: "test", + Name: "ssh-test-playbook", + Description: "Playbook description", Started: expectedStarted, Ended: expectedEnded, - StepResults: map[string]cache_model.StepResult{}, + StepResults: map[string]cache_model.StepResult{expetedStepReport.StepId: expetedStepReport}, Error: nil, Status: 2, }, @@ -114,12 +130,13 @@ func TestReportWorkflowStartFirst(t *testing.T) { exec, err := cacheReporter.GetExecutionReport(executionId0) assert.Equal(t, expectedExecutions, returnedExecutions) - assert.Equal(t, expectedExecutionEntry.ExecutionId, exec.ExecutionId) - assert.Equal(t, expectedExecutionEntry.PlaybookId, exec.PlaybookId) - assert.Equal(t, expectedExecutionEntry.StepResults, exec.StepResults) - assert.Equal(t, expectedExecutionEntry.Started, timeNow) - assert.Equal(t, expectedExecutionEntry.Ended, time.Time{}) - assert.Equal(t, expectedExecutionEntry.Status, exec.Status) + assert.Equal(t, len(expectedExecutions), 1) + assert.Equal(t, expectedExecutions[0].ExecutionId, exec.ExecutionId) + assert.Equal(t, expectedExecutions[0].PlaybookId, exec.PlaybookId) + assert.Equal(t, expectedExecutions[0].StepResults, exec.StepResults) + assert.Equal(t, expectedExecutions[0].Started, timeNow) + assert.Equal(t, expectedExecutions[0].Ended, time.Time{}) + assert.Equal(t, expectedExecutions[0].Status, exec.Status) assert.Equal(t, err, nil) mock_time.AssertExpectations(t) } @@ -143,6 +160,7 @@ func TestReportWorkflowStartFifo(t *testing.T) { Type: "action", ID: "action--test", Name: "ssh-tests", + Description: "step description", StepVariables: cacao.NewVariables(expectedVariables), Commands: []cacao.Command{expectedCommand}, Cases: map[string]string{}, @@ -176,7 +194,8 @@ func TestReportWorkflowStartFifo(t *testing.T) { playbook := cacao.Playbook{ ID: "test", Type: "test", - Name: "ssh-test", + Name: "ssh-test-playbook", + Description: "Playbook description", WorkflowStart: step1.ID, AuthenticationInfoDefinitions: map[string]cacao.AuthenticationInformation{"id": expectedAuth}, AgentDefinitions: map[string]cacao.AgentTarget{"agent1": expectedAgent}, @@ -209,6 +228,8 @@ func TestReportWorkflowStartFifo(t *testing.T) { entry := cache_model.ExecutionEntry{ ExecutionId: executionId, PlaybookId: "test", + Name: "ssh-test-playbook", + Description: "Playbook description", Started: expectedStarted, Ended: expectedEnded, StepResults: map[string]cache_model.StepResult{}, @@ -224,6 +245,8 @@ func TestReportWorkflowStartFifo(t *testing.T) { entry := cache_model.ExecutionEntry{ ExecutionId: executionId, PlaybookId: "test", + Name: "ssh-test-playbook", + Description: "Playbook description", Started: expectedStarted, Ended: expectedEnded, StepResults: map[string]cache_model.StepResult{}, @@ -283,6 +306,7 @@ func TestReportWorkflowEnd(t *testing.T) { Type: "action", ID: "action--test", Name: "ssh-tests", + Description: "step 1", StepVariables: cacao.NewVariables(expectedVariables), Commands: []cacao.Command{expectedCommand}, Cases: map[string]string{}, @@ -316,7 +340,8 @@ func TestReportWorkflowEnd(t *testing.T) { playbook := cacao.Playbook{ ID: "test", Type: "test", - Name: "ssh-test", + Name: "ssh-test-playbook", + Description: "Playbook description", WorkflowStart: step1.ID, AuthenticationInfoDefinitions: map[string]cacao.AuthenticationInformation{"id": expectedAuth}, AgentDefinitions: map[string]cacao.AgentTarget{"agent1": expectedAgent}, @@ -343,6 +368,8 @@ func TestReportWorkflowEnd(t *testing.T) { expectedExecutionEntry := cache_model.ExecutionEntry{ ExecutionId: executionId0, PlaybookId: "test", + Name: "ssh-test-playbook", + Description: "Playbook description", Started: timeNow, Ended: timeNow, StepResults: map[string]cache_model.StepResult{},