Skip to content

Commit

Permalink
chore: add test for reportportal.GetFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
b1zzu committed Feb 1, 2022
1 parent 4a1ae31 commit f9e189c
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pkg/reportportal/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import (
"net/url"
)

type IFilterService interface {
GetByID(projectName string, id int) (*Filter, *Response, error)
GetByName(projectName, name string) (*Filter, *Response, error)
Create(projectName string, f *NewFilter) (int, *Response, error)
Update(projectName string, id int, f *UpdateFilter) (string, *Response, error)
}

type FilterService service

type FilterList struct {
Expand Down
20 changes: 20 additions & 0 deletions pkg/reportportal/moks.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ func (s *MockWidgetService) Post(projectName string, w *NewWidget) (int, *Respon
return s.PostM(projectName, w)
}

type MockFilterService struct {
GetByIDM func(projectName string, id int) (*Filter, *Response, error)
GetByNameM func(projectName, name string) (*Filter, *Response, error)
CreateM func(projectName string, f *NewFilter) (int, *Response, error)
UpdateM func(projectName string, id int, f *UpdateFilter) (string, *Response, error)
}

func (s *MockFilterService) GetByID(projectName string, id int) (*Filter, *Response, error) {
return s.GetByIDM(projectName, id)
}
func (s *MockFilterService) GetByName(projectName, name string) (*Filter, *Response, error) {
return s.GetByNameM(projectName, name)
}
func (s *MockFilterService) Create(projectName string, f *NewFilter) (int, *Response, error) {
return s.CreateM(projectName, f)
}
func (s *MockFilterService) Update(projectName string, id int, f *UpdateFilter) (string, *Response, error) {
return s.UpdateM(projectName, id, f)
}

type MockProjectSettingsService struct {
GetM func(projectName string) (*ProjectSettings, *Response, error)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/reportportal/reportportal.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Client struct {
// Services used for talking to different parts of the ReportPortal API.
Dashboard IDashboardService
Widget IWidgetService
Filter *FilterService
Filter IFilterService
ProjectSettings IProjectSettingsService
}

Expand Down
90 changes: 90 additions & 0 deletions pkg/rpdac/reportportal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,93 @@ func TestGetDashboard(t *testing.T) {
}
testDeepEqual(t, got, want, opts)
}

func TestGetFilter(t *testing.T) {

filter := &reportportal.Filter{
Owner: "dbizzarr",
Share: true,
ID: 2,
Name: "mk-e2e-test-suite",
Conditions: []reportportal.FilterCondition{
{
FilteringField: "name",
Condition: "eq",
Value: "mk-e2e-test-suite",
},
},
Orders: []reportportal.FilterOrder{
{
SortingColumn: "startTime",
IsAsc: false,
},
{
SortingColumn: "number",
IsAsc: false,
},
},
Type: "Launch",
}

mockFilter := &reportportal.MockFilterService{
GetByIDM: func(projectName string, id int) (*reportportal.Filter, *reportportal.Response, error) {
testEqual(t, projectName, "test_project")
testEqual(t, id, 2)
return filter, nil, nil
},
}

r := NewReportPortal(&reportportal.Client{
Filter: mockFilter,
})

got, err := r.GetFilter("test_project", 2)
if err != nil {
t.Errorf("ReportPortal.GetDashboard returned error: %v", err)
}

want := &Filter{
Kind: "Filter",
Name: "mk-e2e-test-suite",
Type: "Launch",
Description: "",
Conditions: []FilterCondition{
{FilteringField: "name", Condition: "eq", Value: "mk-e2e-test-suite"},
},
Orders: []FilterOrder{
{SortingColumn: "startTime", IsAsc: false},
{SortingColumn: "number", IsAsc: false},
},
origin: filter,
}

testDeepEqual(t, got, want, cmp.AllowUnexported(Filter{}))
}

func TestGetDashboardByName(t *testing.T) {

}
func TestGetDashboardByName_NotFound(t *testing.T) {

}
func TestGetFilterByName(t *testing.T) {

}
func TestGetFilterByName_NotFound(t *testing.T) {

}
func TestCreateDashboard(t *testing.T) {

}
func TestCreateFilter(t *testing.T) {

}
func TestDeleteDashboard(t *testing.T) {

}
func TestApplyDashboard(t *testing.T) {

}
func TestApplyFilter(t *testing.T) {

}

0 comments on commit f9e189c

Please sign in to comment.