Skip to content

Commit

Permalink
Added enhancement for #57 and UT coverage for #13
Browse files Browse the repository at this point in the history
- Added query filter for attack status
- Added more UT coverage
  • Loading branch information
nmalhotra committed Mar 2, 2019
1 parent d0a78e9 commit 23586db
Show file tree
Hide file tree
Showing 13 changed files with 793 additions and 22 deletions.
6 changes: 3 additions & 3 deletions internal/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type IDispatcher interface {
// Get the attack status, params and ID for a single attack
Get(string) (*models.AttackResponse, error)
// List the attack status, params and ID for all submitted attacks.
List() []*models.AttackResponse
List(models.FilterParams) []*models.AttackResponse
}

type dispatcher struct {
Expand Down Expand Up @@ -181,12 +181,12 @@ func (d *dispatcher) Get(id string) (*models.AttackResponse, error) {
}

// List all submitted attacks
func (d *dispatcher) List() []*models.AttackResponse {
func (d *dispatcher) List(filters models.FilterParams) []*models.AttackResponse {
d.log(nil).Debug("getting attack list")

responses := make([]*models.AttackResponse, 0)

for _, attackDetails := range d.db.GetAll() {
for _, attackDetails := range d.db.GetAll(filters) {
resp := models.AttackResponse(attackDetails.AttackInfo)
responses = append(responses, &resp)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/dispatcher/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ func Test_dispatcher_Get_Error_GetByID(t *testing.T) {
func Test_dispatcher_List(t *testing.T) {
mockStore := &smocks.IAttackStore{}

mockStore.On("GetAll").Return([]models.AttackDetails{{}})
mockStore.On("GetAll", make(models.FilterParams)).Return([]models.AttackDetails{{}})

d := setupDispatcher(mockStore)

got := d.List()
got := d.List(make(models.FilterParams))
if len(got) == 0 {
t.Fail()
}
Expand All @@ -327,11 +327,11 @@ func Test_dispatcher_List(t *testing.T) {
func Test_dispatcher_List_Empty(t *testing.T) {
mockStore := &smocks.IAttackStore{}

mockStore.On("GetAll").Return([]models.AttackDetails{})
mockStore.On("GetAll", make(models.FilterParams)).Return([]models.AttackDetails{})

d := setupDispatcher(mockStore)

got := d.List()
got := d.List(make(models.FilterParams))
if len(got) != 0 {
t.Fail()
}
Expand Down
10 changes: 5 additions & 5 deletions internal/dispatcher/mocks/IDispatcher.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

161 changes: 161 additions & 0 deletions internal/dispatcher/mocks/ITask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions internal/dispatcher/mocks/ITaskActions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 23586db

Please sign in to comment.