-
Notifications
You must be signed in to change notification settings - Fork 9
Add bricks filter #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add bricks filter #335
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -53,9 +53,9 @@ func NewService( | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func (s *Service) List() (BrickListResult, error) { | ||||||||||||||
| res := BrickListResult{Bricks: make([]BrickListItem, len(s.bricksIndex.ListBricks()))} | ||||||||||||||
| for i, brick := range s.bricksIndex.ListBricks() { | ||||||||||||||
| func (s *Service) List(filter bricksindex.BrickFilter) (BrickListResult, error) { | ||||||||||||||
| res := BrickListResult{Bricks: make([]BrickListItem, len(s.bricksIndex.ListBricks(nil)))} | ||||||||||||||
| for i, brick := range s.bricksIndex.ListBricks(filter) { | ||||||||||||||
| res.Bricks[i] = BrickListItem{ | ||||||||||||||
|
Comment on lines
+57
to
59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure, but I guess s.bricksIndex.ListBricks(...) should have the same param?
Suggested change
|
||||||||||||||
| ID: brick.ID, | ||||||||||||||
| Name: brick.Name, | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -322,3 +322,90 @@ func TestLoadBrickYamlBrickIndex(t *testing.T) { | |||||
| }) | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| func TestListBricksWithFilter(t *testing.T) { | ||||||
| brick1 := Brick{ID: "1", Name: "brick1", Category: "catA"} | ||||||
| brick2 := Brick{ID: "2", Name: "brick2", Category: "catB"} | ||||||
| brick3 := Brick{ID: "3", Name: "brick3", Category: "catB"} | ||||||
| appBricks := []Brick{brick1, brick2, brick3} | ||||||
|
|
||||||
| tests := []struct { | ||||||
| name string | ||||||
| filter BrickFilter | ||||||
| wantBricks []Brick | ||||||
| }{ | ||||||
| { | ||||||
| name: "Nil filter does not apply any filter", | ||||||
| filter: nil, | ||||||
| wantBricks: appBricks, | ||||||
| }, | ||||||
| { | ||||||
| name: "Filters out catB bricks", | ||||||
| filter: func(b Brick) bool { return b.Category == "catB" }, | ||||||
| wantBricks: []Brick{brick1}, | ||||||
| }, | ||||||
| { | ||||||
| name: "Filters out catA bricks", | ||||||
| filter: func(b Brick) bool { return b.Category == "catA" }, | ||||||
| wantBricks: []Brick{brick2, brick3}, | ||||||
| }, | ||||||
| } | ||||||
|
|
||||||
| for _, tt := range tests { | ||||||
| t.Run(tt.name, func(t *testing.T) { | ||||||
| b := &BricksIndex{ | ||||||
| AppBricks: appBricks, | ||||||
| } | ||||||
|
|
||||||
| // act | ||||||
| got := b.ListBricks(tt.filter) | ||||||
| require.Equal(t, len(tt.wantBricks), len(got)) | ||||||
| require.Equal(t, tt.wantBricks[0].ID, got[0].ID) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about the this?
Suggested change
|
||||||
| }) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| func TestUnsupportedBoardFilter(t *testing.T) { | ||||||
| brickEmptySupportedList := Brick{ID: "1", Name: "brick1", SupportedBoards: []string{}} | ||||||
| brickMyBoard := Brick{ID: "2", Name: "brick2", SupportedBoards: []string{"MyBoard"}} | ||||||
| brickOneQ := Brick{ID: "3", Name: "brickOneQ", SupportedBoards: []string{"UnoQ"}} | ||||||
| brickOneQVentunoQ := Brick{ID: "4", Name: "brickOneQVentunoQ", SupportedBoards: []string{"UnoQ", "VentunoQ"}} | ||||||
| brickVentunoQ := Brick{ID: "5", Name: "brickVentunoQ", SupportedBoards: []string{"VentunoQ"}} | ||||||
|
|
||||||
| boardProvider = "UnoQ" | ||||||
|
|
||||||
| tests := []struct { | ||||||
| name string | ||||||
| initialBricks []Brick | ||||||
| wantBricks []Brick | ||||||
| }{ | ||||||
| { | ||||||
| name: "Empty board list means all supported", | ||||||
| initialBricks: []Brick{brickEmptySupportedList}, | ||||||
| wantBricks: []Brick{brickEmptySupportedList}, | ||||||
| }, | ||||||
| { | ||||||
| name: "Only OneQ board supported bricks with two candidate bricks", | ||||||
| initialBricks: []Brick{brickOneQ, brickOneQVentunoQ, brickVentunoQ}, | ||||||
| wantBricks: []Brick{brickOneQ, brickOneQVentunoQ}, | ||||||
| }, | ||||||
| { | ||||||
| name: "Only OneQ board supported bricks with no candidate bricks", | ||||||
| initialBricks: []Brick{brickMyBoard, brickVentunoQ}, | ||||||
| wantBricks: []Brick{}, | ||||||
| }, | ||||||
| } | ||||||
|
|
||||||
| for _, tt := range tests { | ||||||
| t.Run(tt.name, func(t *testing.T) { | ||||||
| b := &BricksIndex{ | ||||||
| AppBricks: tt.initialBricks, | ||||||
| } | ||||||
|
|
||||||
| // act | ||||||
| got := b.ListBricks(UnsupportedBrickFilter) | ||||||
| require.Equal(t, len(tt.wantBricks), len(got)) | ||||||
| require.Equal(t, tt.wantBricks, got) | ||||||
| }) | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated generation of the description.. something wrong with the docs.go??