Skip to content

Commit

Permalink
add windows_desktop to listResources (#40711)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex McGrath authored Apr 23, 2024
1 parent 7019d05 commit 8e07a03
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/services/local/presence.go
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,9 @@ func (s *PresenceService) listResources(ctx context.Context, req proto.ListResou
case types.KindWindowsDesktopService:
keyPrefix = []string{windowsDesktopServicesPrefix}
unmarshalItemFunc = backendItemToWindowsDesktopService
case types.KindWindowsDesktop:
keyPrefix = []string{windowsDesktopsPrefix}
unmarshalItemFunc = backendItemToWindowsDesktop
case types.KindKubeServer:
keyPrefix = []string{kubeServersPrefix}
unmarshalItemFunc = backendItemToKubernetesServer
Expand Down Expand Up @@ -1925,6 +1928,17 @@ func backendItemToServer(kind string) backendItemToResourceFunc {
}
}

// backendItemToWindowsDesktop unmarshals `backend.Item` into a
// `types.WindowsDesktop`, returning it as a `types.ResourceWithLabels`.
func backendItemToWindowsDesktop(item backend.Item) (types.ResourceWithLabels, error) {
return services.UnmarshalWindowsDesktop(
item.Value,
services.WithResourceID(item.ID),
services.WithExpires(item.Expires),
services.WithRevision(item.Revision),
)
}

// backendItemToWindowsDesktopService unmarshals `backend.Item` into a
// `types.WindowsDesktopService`, returning it as a `types.ResourceWithLabels`.
func backendItemToWindowsDesktopService(item backend.Item) (types.ResourceWithLabels, error) {
Expand Down
19 changes: 19 additions & 0 deletions lib/services/local/presence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,25 @@ func TestListResources(t *testing.T) {
return presence.DeleteAllWindowsDesktopServices(ctx)
},
},
"WindowsDesktop": {
resourceType: types.KindWindowsDesktop,
createResourceFunc: func(ctx context.Context, presence *PresenceService, name string, labels map[string]string) error {
desktopService := NewWindowsDesktopService(presence.Backend)
desktop, err := types.NewWindowsDesktopV3(name, labels, types.WindowsDesktopSpecV3{
Addr: "localhost:1234",
})
if err != nil {
return err
}

err = desktopService.UpsertWindowsDesktop(ctx, desktop)
return err
},
deleteAllResourcesFunc: func(ctx context.Context, presence *PresenceService) error {
desktopService := NewWindowsDesktopService(presence.Backend)
return desktopService.DeleteAllWindowsDesktops(ctx)
},
},
}

for testName, test := range tests {
Expand Down

0 comments on commit 8e07a03

Please sign in to comment.