Skip to content

Commit

Permalink
Added a unit test for workflow state in get workflow command
Browse files Browse the repository at this point in the history
Signed-off-by: parauliya <aman@infracloud.io>
  • Loading branch information
parauliya committed Apr 20, 2021
1 parent 004d131 commit 9b817ce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
3 changes: 1 addition & 2 deletions grpc-server/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (s *server) ShowWorkflowEvents(req *workflow.GetRequest, stream workflow.Wo
}

// This function will provide the workflow state on the basis of the state of the actions
// For e.g. : If an action has Tailed or Timeout then the workflow state will also be
// For e.g. : If an action has Failed or Timeout then the workflow state will also be
// considered as Failed/Timeout. And If an action is successful then the workflow state
// will be considered as Running until the last action of the workflow is executed successfully.

Expand All @@ -284,7 +284,6 @@ func getWorkflowState(db db.Database, ctx context.Context, id string) workflow.S
if wfCtx.CurrentActionState != workflow.State_STATE_SUCCESS {
return wfCtx.CurrentActionState
} else {
//wfacts, _ := db.GetWorkflowActions(ctx, id)
if wfCtx.GetCurrentActionIndex() == wfCtx.GetTotalNumberOfActions()-1 {
return workflow.State_STATE_SUCCESS
} else {
Expand Down
32 changes: 32 additions & 0 deletions grpc-server/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestGetWorkflow(t *testing.T) {
args struct {
db mock.DB
wfTemplate, wfHardware string
state workflow.State
}
want struct {
expectedError bool
Expand Down Expand Up @@ -148,6 +149,7 @@ func TestGetWorkflow(t *testing.T) {
return "", "", templateData, nil
},
},
state: workflow.State_STATE_SUCCESS,
wfTemplate: templateID,
wfHardware: hw,
},
Expand All @@ -167,6 +169,35 @@ func TestGetWorkflow(t *testing.T) {
expectedError: true,
},
},
"GetWorkflowState": {
args: args{
db: mock.DB{
GetWorkflowFunc: func(ctx context.Context, workflowID string) (db.Workflow, error) {
return db.Workflow{
ID: workflowID,
Template: templateID,
Hardware: hw}, nil
},
GetWorkflowContextsFunc: func(ctx context.Context, wfID string) (*workflow.WorkflowContext, error) {
return &workflow.WorkflowContext{
WorkflowId: wfID,
CurrentActionState: workflow.State_STATE_SUCCESS,
CurrentActionIndex: 0,
TotalNumberOfActions: 2,
}, nil
},
GetTemplateFunc: func(ctx context.Context, fields map[string]string, deleted bool) (string, string, string, error) {
return "", "", templateData, nil
},
},
state: workflow.State_STATE_RUNNING,
wfTemplate: templateID,
wfHardware: hw,
},
want: want{
expectedError: false,
},
},
}

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
Expand All @@ -183,6 +214,7 @@ func TestGetWorkflow(t *testing.T) {
assert.True(t, tc.want.expectedError)
return
}
assert.Equal(t, tc.args.state, res.State)
assert.NoError(t, err)
assert.NotEmpty(t, res)
assert.False(t, tc.want.expectedError)
Expand Down

0 comments on commit 9b817ce

Please sign in to comment.