Skip to content
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

add group uuid as parameter for deviceview endpoint #2266

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/routes/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ var devicesFilters = common.ComposeFilters(
QueryParam: "image_id",
DBField: "devices.image_id",
}),
// Filter handler for "groupUUID"
common.ContainFilterHandler(&common.Filter{
ldjebran marked this conversation as resolved.
Show resolved Hide resolved
QueryParam: "groupUUID",
DBField: "devices.group_uuid",
}),
common.SortFilterHandler("devices", "name", "ASC"),
)

Expand Down
88 changes: 88 additions & 0 deletions pkg/routes/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,91 @@ func TestGetDevicesViewWithinDevicesWitUUIDNotExist(t *testing.T) {
Expect(recorder.Code).To(Equal(http.StatusBadRequest))

}

func TestGetDevicesViewFilteringByGroup(t *testing.T) {
RegisterTestingT(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
orgID := faker.UUIDHyphenated()
account := faker.UUIDHyphenated()
imageSet := &models.ImageSet{
Name: "test",
Version: 1,
OrgID: orgID,
}

result := db.DB.Create(imageSet)
Expect(result.Error).ToNot(HaveOccurred())
imageV1 := &models.Image{
Commit: &models.Commit{
OSTreeCommit: faker.UUIDHyphenated(),
OrgID: orgID,
},
Status: models.ImageStatusSuccess,
ImageSetID: &imageSet.ID,
Version: 1,
OrgID: orgID,
}
result = db.DB.Create(imageV1)
Expect(result.Error).ToNot(HaveOccurred())
groupUUID := "123"
devices := []models.Device{
{
Name: faker.Name(),
UUID: faker.UUIDHyphenated(),
Account: account,
OrgID: orgID,
ImageID: imageV1.ID,
GroupUUID: groupUUID,
},
{
Name: faker.Name(),
UUID: faker.UUIDHyphenated(),
Account: account,
OrgID: orgID,
ImageID: imageV1.ID,
},
}
result = db.DB.Create(devices)
Expect(result.Error).ToNot(HaveOccurred())
deviceView := []models.DeviceView{
{
DeviceID: devices[0].ID,
DeviceUUID: devices[0].UUID,
GroupUUID: devices[0].GroupUUID,
},
}

var mockDeviceService *mock_services.MockDeviceServiceInterface
var router chi.Router
var mockServices *dependencies.EdgeAPIServices
ctrl = gomock.NewController(GinkgoT())

mockDeviceService = mock_services.NewMockDeviceServiceInterface(ctrl)
mockServices = &dependencies.EdgeAPIServices{
DeviceService: mockDeviceService,
Log: log.NewEntry(log.StandardLogger()),
}
router = chi.NewRouter()
router.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := dependencies.ContextWithServices(r.Context(), mockServices)
next.ServeHTTP(w, r.WithContext(ctx))
})
})
router.Route("/devices", MakeDevicesRouter)

mockDeviceService.EXPECT().GetDevicesCount(gomock.Any()).Return(int64(1), nil)
mockDeviceService.EXPECT().GetDevicesView(30, 0, gomock.Any()).Return(&models.DeviceViewList{Total: 1, Devices: deviceView}, nil)

url := fmt.Sprintf("/devices/devicesview?groupUUID=%v", groupUUID)
req, err := http.NewRequest("GET", url, nil)
fmt.Printf(req.URL.Host)
if err != nil {
Expect(err).ToNot(HaveOccurred())
}
rr := httptest.NewRecorder()
router.ServeHTTP(rr, req)
Expect(rr.Code).To(Equal(http.StatusOK))

}
2 changes: 1 addition & 1 deletion pkg/routes/query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func initalizeQueryParamsArray() map[string][]string {
m = make(map[string][]string)
m["device-groups"] = []string{"limit", "offset", "name", "created_at", "updated_at", "sort_by"}
m["devices"] = []string{"per_page", "page", "order_how", "hostname_or_id", "order_by"}
m["devicesview"] = []string{"limit", "offset", "name", "uuid", "update_available", "image_id", "sort_by", "created_at"}
m["devicesview"] = []string{"limit", "offset", "name", "uuid", "update_available", "image_id", "sort_by", "created_at", "groupUUID"}
m["images"] = []string{"limit", "offset", "status", "name", "distribution", "created_at", "sort_by"}
m["image-sets"] = []string{"id", "limit", "offset", "status", "name", "version", "sort_by"}
m["thirdpartyrepo"] = []string{"limit", "offset", "name", "created_at", "updated_at", "imageID", "sort_by"}
Expand Down