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