@@ -88,9 +88,6 @@ func TestTemplateList(t *testing.T) {
88
88
client := coderdtest .New (t , & coderdtest.Options {})
89
89
owner := coderdtest .CreateFirstUser (t , client )
90
90
91
- org , err := client .Organization (context .Background (), owner .OrganizationID )
92
- require .NoError (t , err )
93
-
94
91
templateAdmin , _ := coderdtest .CreateAnotherUser (t , client , owner .OrganizationID , rbac .RoleTemplateAdmin ())
95
92
96
93
inv , root := clitest .New (t , "templates" , "list" )
@@ -110,8 +107,42 @@ func TestTemplateList(t *testing.T) {
110
107
111
108
require .NoError (t , <- errC )
112
109
113
- pty .ExpectMatch ("No templates found in" )
114
- pty .ExpectMatch (org .Name )
110
+ pty .ExpectMatch ("No templates found" )
115
111
pty .ExpectMatch ("Create one:" )
116
112
})
113
+
114
+ t .Run ("MultiOrg" , func (t * testing.T ) {
115
+ t .Parallel ()
116
+ client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerDaemon : true })
117
+ owner := coderdtest .CreateFirstUser (t , client )
118
+
119
+ // Template in the first organization
120
+ firstVersion := coderdtest .CreateTemplateVersion (t , client , owner .OrganizationID , nil )
121
+ _ = coderdtest .AwaitTemplateVersionJobCompleted (t , client , firstVersion .ID )
122
+ _ = coderdtest .CreateTemplate (t , client , owner .OrganizationID , firstVersion .ID )
123
+
124
+ secondOrg := coderdtest .CreateOrganization (t , client , coderdtest.CreateOrganizationOptions {
125
+ IncludeProvisionerDaemon : true ,
126
+ })
127
+ secondVersion := coderdtest .CreateTemplateVersion (t , client , secondOrg .ID , nil )
128
+ _ = coderdtest .CreateTemplate (t , client , secondOrg .ID , secondVersion .ID )
129
+
130
+ // Create a site wide template admin
131
+ templateAdmin , _ := coderdtest .CreateAnotherUser (t , client , owner .OrganizationID , rbac .RoleTemplateAdmin ())
132
+
133
+ inv , root := clitest .New (t , "templates" , "list" , "--output=json" )
134
+ clitest .SetupConfig (t , templateAdmin , root )
135
+
136
+ ctx , cancelFunc := context .WithTimeout (context .Background (), testutil .WaitLong )
137
+ defer cancelFunc ()
138
+
139
+ out := bytes .NewBuffer (nil )
140
+ inv .Stdout = out
141
+ err := inv .WithContext (ctx ).Run ()
142
+ require .NoError (t , err )
143
+
144
+ var templates []codersdk.Template
145
+ require .NoError (t , json .Unmarshal (out .Bytes (), & templates ))
146
+ require .Len (t , templates , 2 )
147
+ })
117
148
}
0 commit comments