diff --git a/tool/tctl/common/edit_command_test.go b/tool/tctl/common/edit_command_test.go index 42f9dee0043e..d8cb6f471445 100644 --- a/tool/tctl/common/edit_command_test.go +++ b/tool/tctl/common/edit_command_test.go @@ -91,6 +91,10 @@ func TestEditResources(t *testing.T) { kind: types.KindAutoUpdateVersion, edit: testEditAutoUpdateVersion, }, + { + kind: types.KindDynamicWindowsDesktop, + edit: testEditDynamicWindowsDesktop, + }, } for _, test := range tests { @@ -619,3 +623,35 @@ func testEditAutoUpdateVersion(t *testing.T, clt *authclient.Client) { "tools_autoupdate should have been modified by edit") assert.Equal(t, expected.GetSpec().GetToolsVersion(), actual.GetSpec().GetToolsVersion()) } + +func testEditDynamicWindowsDesktop(t *testing.T, clt *authclient.Client) { + ctx := context.Background() + + expected, err := types.NewDynamicWindowsDesktopV1("test", nil, types.DynamicWindowsDesktopSpecV1{ + Addr: "test", + }) + require.NoError(t, err) + created, err := clt.DynamicDesktopClient().CreateDynamicWindowsDesktop(ctx, expected) + require.NoError(t, err) + + editor := func(name string) error { + f, err := os.Create(name) + if err != nil { + return trace.Wrap(err, "opening file to edit") + } + + expected.SetRevision(created.GetRevision()) + expected.Spec.Addr = "test2" + + collection := &dynamicWindowsDesktopCollection{desktops: []types.DynamicWindowsDesktop{expected}} + return trace.NewAggregate(writeYAML(collection, f), f.Close()) + } + + _, err = runEditCommand(t, clt, []string{"edit", "dynamic_windows_desktop/test"}, withEditor(editor)) + require.NoError(t, err) + + actual, err := clt.DynamicDesktopClient().GetDynamicWindowsDesktop(ctx, expected.GetName()) + require.NoError(t, err) + expected.SetRevision(actual.GetRevision()) + require.Empty(t, cmp.Diff(expected, actual, protocmp.Transform())) +} diff --git a/tool/tctl/common/resource_command_test.go b/tool/tctl/common/resource_command_test.go index 1eb4b6ee34bf..d4e4a718b752 100644 --- a/tool/tctl/common/resource_command_test.go +++ b/tool/tctl/common/resource_command_test.go @@ -1419,6 +1419,10 @@ func TestCreateResources(t *testing.T) { kind: types.KindAutoUpdateVersion, create: testCreateAutoUpdateVersion, }, + { + kind: types.KindDynamicWindowsDesktop, + create: testCreateDynamicWindowsDesktop, + }, } for _, test := range tests { @@ -2357,6 +2361,35 @@ version: v1 )) } +func testCreateDynamicWindowsDesktop(t *testing.T, clt *authclient.Client) { + const resourceYAML = `kind: dynamic_windows_desktop +metadata: + name: test + revision: 3a43b44a-201e-4d7f-aef1-ae2f6d9811ed +spec: + addr: test +version: v1 +` + + // Create the resource. + resourceYAMLPath := filepath.Join(t.TempDir(), "resource.yaml") + require.NoError(t, os.WriteFile(resourceYAMLPath, []byte(resourceYAML), 0644)) + _, err := runResourceCommand(t, clt, []string{"create", resourceYAMLPath}) + require.NoError(t, err) + + // Get the resource + buf, err := runResourceCommand(t, clt, []string{"get", types.KindDynamicWindowsDesktop, "--format=json"}) + require.NoError(t, err) + resources := mustDecodeJSON[[]types.DynamicWindowsDesktopV1](t, buf) + require.Len(t, resources, 1) + + var expected types.DynamicWindowsDesktopV1 + require.NoError(t, yaml.Unmarshal([]byte(resourceYAML), &expected)) + expected.SetRevision(resources[0].GetRevision()) + + require.Empty(t, cmp.Diff([]types.DynamicWindowsDesktopV1{expected}, resources, protocmp.Transform())) +} + func TestPluginResourceWrapper(t *testing.T) { tests := []struct { name string