Skip to content

Commit 5c7300f

Browse files
heiytorgustavosbarreto
authored andcommitted
remove(api): unused heartbeat endpoints
1 parent 5ae956c commit 5c7300f

File tree

7 files changed

+269
-118
lines changed

7 files changed

+269
-118
lines changed

api/routes/device.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const (
1818
DeleteDeviceURL = "/devices/:uid"
1919
RenameDeviceURL = "/devices/:uid"
2020
OfflineDeviceURL = "/devices/:uid/offline"
21-
HeartbeatDeviceURL = "/devices/:uid/heartbeat"
2221
LookupDeviceURL = "/lookup"
2322
UpdateDeviceStatusURL = "/devices/:uid/:status"
2423
CreateTagURL = "/devices/:uid/tags" // Add a tag to a device.
@@ -234,19 +233,6 @@ func (h *Handler) UpdateDeviceStatus(c gateway.Context) error {
234233
return c.NoContent(http.StatusOK)
235234
}
236235

237-
func (h *Handler) HeartbeatDevice(c gateway.Context) error {
238-
var req requests.DeviceHeartbeat
239-
if err := c.Bind(&req); err != nil {
240-
return err
241-
}
242-
243-
if err := c.Validate(&req); err != nil {
244-
return err
245-
}
246-
247-
return h.service.DeviceHeartbeat(c.Ctx(), models.UID(req.UID))
248-
}
249-
250236
func (h *Handler) CreateDeviceTag(c gateway.Context) error {
251237
var req requests.DeviceCreateTag
252238
if err := c.Bind(&req); err != nil {

api/routes/device_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -549,57 +549,6 @@ func TestLookupDevice(t *testing.T) {
549549
}
550550
}
551551

552-
func TestHeartbeatDevice(t *testing.T) {
553-
mock := new(mocks.Service)
554-
555-
cases := []struct {
556-
title string
557-
uid string
558-
requiredMocks func()
559-
expectedStatus int
560-
}{
561-
{
562-
title: "fails when bind fails to validate uid",
563-
uid: "",
564-
requiredMocks: func() {},
565-
expectedStatus: http.StatusBadRequest,
566-
},
567-
{
568-
title: "fails when try to heartbeat non-existing device",
569-
uid: "1234",
570-
requiredMocks: func() {
571-
mock.On("DeviceHeartbeat", gomock.Anything, models.UID("1234")).Return(svc.ErrNotFound).Once()
572-
},
573-
expectedStatus: http.StatusNotFound,
574-
},
575-
{
576-
title: "success when try to heartbeat of a existing device",
577-
uid: "123",
578-
requiredMocks: func() {
579-
mock.On("DeviceHeartbeat", gomock.Anything, models.UID("123")).Return(nil).Once()
580-
},
581-
expectedStatus: http.StatusOK,
582-
},
583-
}
584-
585-
for _, tc := range cases {
586-
t.Run(tc.title, func(t *testing.T) {
587-
tc.requiredMocks()
588-
589-
req := httptest.NewRequest(http.MethodPost, fmt.Sprintf("/internal/devices/%s/heartbeat", tc.uid), nil)
590-
req.Header.Set("Content-Type", "application/json")
591-
req.Header.Set("X-Role", guard.RoleOwner)
592-
req.Header.Set("X-Tenant-ID", "tenant-id")
593-
rec := httptest.NewRecorder()
594-
595-
e := NewRouter(mock)
596-
e.ServeHTTP(rec, req)
597-
598-
assert.Equal(t, tc.expectedStatus, rec.Result().StatusCode)
599-
})
600-
}
601-
}
602-
603552
func TestRemoveDeviceTag(t *testing.T) {
604553
mock := new(mocks.Service)
605554

api/routes/routes.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func NewRouter(service services.Service) *echo.Echo {
3232

3333
internalAPI.GET(GetDeviceByPublicURLAddress, gateway.Handler(handler.GetDeviceByPublicURLAddress))
3434
internalAPI.POST(OfflineDeviceURL, gateway.Handler(handler.OfflineDevice))
35-
internalAPI.POST(HeartbeatDeviceURL, gateway.Handler(handler.HeartbeatDevice))
3635
internalAPI.GET(LookupDeviceURL, gateway.Handler(handler.LookupDevice))
3736

3837
internalAPI.PATCH(SetSessionAuthenticatedURL, gateway.Handler(handler.SetSessionAuthenticated))

api/services/device.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type DeviceService interface {
2626
LookupDevice(ctx context.Context, namespace, name string) (*models.Device, error)
2727
OffineDevice(ctx context.Context, uid models.UID, online bool) error
2828
UpdateDeviceStatus(ctx context.Context, tenant string, uid models.UID, status models.DeviceStatus) error
29-
DeviceHeartbeat(ctx context.Context, uid models.UID) error
3029
UpdateDevice(ctx context.Context, tenant string, uid models.UID, name *string, publicURL *bool) error
3130
}
3231

@@ -296,14 +295,6 @@ func (s *service) UpdateDeviceStatus(ctx context.Context, tenant string, uid mod
296295
return s.store.DeviceUpdateStatus(ctx, uid, status)
297296
}
298297

299-
func (s *service) DeviceHeartbeat(ctx context.Context, uid models.UID) error {
300-
if err := s.store.DeviceSetOnline(ctx, uid, clock.Now(), true); err != nil {
301-
return NewErrDeviceNotFound(uid, err)
302-
}
303-
304-
return nil
305-
}
306-
307298
func (s *service) UpdateDevice(ctx context.Context, tenant string, uid models.UID, name *string, publicURL *bool) error {
308299
device, err := s.store.DeviceGetByUID(ctx, uid, tenant)
309300
if err != nil {

api/services/device_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,24 +3214,6 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
32143214
mock.AssertExpectations(t)
32153215
}
32163216

3217-
func TestDeviceHeartbeat(t *testing.T) {
3218-
mock := new(mocks.Store)
3219-
3220-
ctx := context.TODO()
3221-
3222-
uid := models.UID("uid")
3223-
3224-
clockMock.On("Now").Return(now).Once()
3225-
3226-
mock.On("DeviceSetOnline", ctx, uid, now, true).Return(nil).Once()
3227-
3228-
service := NewService(store.Store(mock), privateKey, publicKey, storecache.NewNullCache(), clientMock, nil)
3229-
err := service.DeviceHeartbeat(ctx, uid)
3230-
assert.NoError(t, err)
3231-
3232-
mock.AssertExpectations(t)
3233-
}
3234-
32353217
func TestDeviceUpdate(t *testing.T) {
32363218
mock := new(mocks.Store)
32373219
service := NewService(store.Store(mock), privateKey, publicKey, storecache.NewNullCache(), clientMock, nil)

0 commit comments

Comments
 (0)