@@ -30,8 +30,60 @@ import (
30
30
"github.com/gravitational/teleport/api/types"
31
31
"github.com/gravitational/teleport/lib/backend"
32
32
"github.com/gravitational/teleport/lib/backend/memory"
33
+ "github.com/gravitational/trace"
33
34
)
34
35
36
+ func TestGetWindowsDesktops (t * testing.T ) {
37
+ t .Parallel ()
38
+
39
+ ctx := context .Background ()
40
+ clock := clockwork .NewFakeClock ()
41
+
42
+ bk , err := memory .New (memory.Config {
43
+ Context : ctx ,
44
+ Clock : clock ,
45
+ })
46
+ require .NoError (t , err )
47
+
48
+ service := NewWindowsDesktopService (bk )
49
+
50
+ d1 , err := types .NewWindowsDesktopV3 ("apple" , nil , types.WindowsDesktopSpecV3 {Addr : "_" , HostID : "test-host-id-1" })
51
+ require .NoError (t , err )
52
+ require .NoError (t , service .CreateWindowsDesktop (ctx , d1 ))
53
+
54
+ d2 , err := types .NewWindowsDesktopV3 ("apple" , nil , types.WindowsDesktopSpecV3 {Addr : "_" , HostID : "test-host-id-2" })
55
+ require .NoError (t , err )
56
+ require .NoError (t , service .CreateWindowsDesktop (ctx , d2 ))
57
+
58
+ d3 , err := types .NewWindowsDesktopV3 ("carrot" , nil , types.WindowsDesktopSpecV3 {Addr : "_" , HostID : "test-host-id-2" })
59
+ require .NoError (t , err )
60
+ require .NoError (t , service .CreateWindowsDesktop (ctx , d3 ))
61
+
62
+ // search by name and host ID
63
+ result , err := service .GetWindowsDesktops (ctx , types.WindowsDesktopFilter {Name : "apple" , HostID : "test-host-id-2" })
64
+ require .NoError (t , err )
65
+ require .Len (t , result , 1 )
66
+ require .Equal (t , d1 .GetName (), result [0 ].GetName ())
67
+
68
+ // search by host ID
69
+ result , err = service .GetWindowsDesktops (ctx , types.WindowsDesktopFilter {HostID : "test-host-id-2" })
70
+ require .NoError (t , err )
71
+ require .Len (t , result , 2 )
72
+ require .Equal (t , d2 .GetName (), result [0 ].GetName ())
73
+ require .Equal (t , d3 .GetName (), result [1 ].GetName ())
74
+
75
+ // no filter
76
+ result , err = service .GetWindowsDesktops (ctx , types.WindowsDesktopFilter {})
77
+ require .NoError (t , err )
78
+ require .Len (t , result , 3 )
79
+
80
+ // non-matching filter
81
+ result , err = service .GetWindowsDesktops (ctx , types.WindowsDesktopFilter {Name : "foo" , HostID : "bar" })
82
+ require .Error (t , err )
83
+ require .True (t , trace .IsNotFound (err ))
84
+ require .Empty (t , result )
85
+ }
86
+
35
87
func TestListWindowsDesktops (t * testing.T ) {
36
88
t .Parallel ()
37
89
0 commit comments