@@ -1147,6 +1147,146 @@ func TestTools(t *testing.T) {
11471147 })
11481148 }
11491149 })
1150+
1151+ t .Run ("WorkspaceListApps" , func (t * testing.T ) {
1152+ t .Parallel ()
1153+
1154+ // nolint:gocritic // This is in a test package and does not end up in the build
1155+ _ = dbfake .WorkspaceBuild (t , store , database.WorkspaceTable {
1156+ Name : "list-app-workspace-one-agent" ,
1157+ OrganizationID : owner .OrganizationID ,
1158+ OwnerID : member .ID ,
1159+ }).WithAgent (func (agents []* proto.Agent ) []* proto.Agent {
1160+ agents [0 ].Apps = []* proto.App {
1161+ {
1162+ Slug : "zero" ,
1163+ Url : "http://zero.dev.coder.com" ,
1164+ },
1165+ }
1166+ return agents
1167+ }).Do ()
1168+
1169+ // nolint:gocritic // This is in a test package and does not end up in the build
1170+ _ = dbfake .WorkspaceBuild (t , store , database.WorkspaceTable {
1171+ Name : "list-app-workspace-multi-agent" ,
1172+ OrganizationID : owner .OrganizationID ,
1173+ OwnerID : member .ID ,
1174+ }).WithAgent (func (agents []* proto.Agent ) []* proto.Agent {
1175+ agents [0 ].Apps = []* proto.App {
1176+ {
1177+ Slug : "one" ,
1178+ Url : "http://one.dev.coder.com" ,
1179+ },
1180+ {
1181+ Slug : "two" ,
1182+ Url : "http://two.dev.coder.com" ,
1183+ },
1184+ {
1185+ Slug : "three" ,
1186+ Url : "http://three.dev.coder.com" ,
1187+ },
1188+ }
1189+ agents = append (agents , & proto.Agent {
1190+ Id : uuid .NewString (),
1191+ Name : "dev2" ,
1192+ Auth : & proto.Agent_Token {
1193+ Token : uuid .NewString (),
1194+ },
1195+ Env : map [string ]string {},
1196+ Apps : []* proto.App {
1197+ {
1198+ Slug : "four" ,
1199+ Url : "http://four.dev.coder.com" ,
1200+ },
1201+ },
1202+ })
1203+ return agents
1204+ }).Do ()
1205+
1206+ tests := []struct {
1207+ name string
1208+ args toolsdk.WorkspaceListAppsArgs
1209+ expected []toolsdk.WorkspaceListApp
1210+ error string
1211+ }{
1212+ {
1213+ name : "NonExistentWorkspace" ,
1214+ args : toolsdk.WorkspaceListAppsArgs {
1215+ Workspace : "list-appp-workspace-does-not-exist" ,
1216+ },
1217+ error : "failed to find workspace" ,
1218+ },
1219+ {
1220+ name : "OneAgentOneApp" ,
1221+ args : toolsdk.WorkspaceListAppsArgs {
1222+ Workspace : "list-app-workspace-one-agent" ,
1223+ },
1224+ expected : []toolsdk.WorkspaceListApp {
1225+ {
1226+ Name : "zero" ,
1227+ URL : "http://zero.dev.coder.com" ,
1228+ },
1229+ },
1230+ },
1231+ {
1232+ name : "MultiAgent" ,
1233+ args : toolsdk.WorkspaceListAppsArgs {
1234+ Workspace : "list-app-workspace-multi-agent" ,
1235+ },
1236+ error : "multiple agents found, please specify the agent name" ,
1237+ },
1238+ {
1239+ name : "MultiAgentOneApp" ,
1240+ args : toolsdk.WorkspaceListAppsArgs {
1241+ Workspace : "list-app-workspace-multi-agent.dev2" ,
1242+ },
1243+ expected : []toolsdk.WorkspaceListApp {
1244+ {
1245+ Name : "four" ,
1246+ URL : "http://four.dev.coder.com" ,
1247+ },
1248+ },
1249+ },
1250+ {
1251+ name : "MultiAgentMultiApp" ,
1252+ args : toolsdk.WorkspaceListAppsArgs {
1253+ Workspace : "list-app-workspace-multi-agent.dev" ,
1254+ },
1255+ expected : []toolsdk.WorkspaceListApp {
1256+ {
1257+ Name : "one" ,
1258+ URL : "http://one.dev.coder.com" ,
1259+ },
1260+ {
1261+ Name : "three" ,
1262+ URL : "http://three.dev.coder.com" ,
1263+ },
1264+ {
1265+ Name : "two" ,
1266+ URL : "http://two.dev.coder.com" ,
1267+ },
1268+ },
1269+ },
1270+ }
1271+
1272+ for _ , tt := range tests {
1273+ t .Run (tt .name , func (t * testing.T ) {
1274+ t .Parallel ()
1275+
1276+ tb , err := toolsdk .NewDeps (memberClient )
1277+ require .NoError (t , err )
1278+
1279+ res , err := testTool (t , toolsdk .WorkspaceListApps , tb , tt .args )
1280+ if tt .error != "" {
1281+ require .Error (t , err )
1282+ require .ErrorContains (t , err , tt .error )
1283+ } else {
1284+ require .NoError (t , err )
1285+ require .Equal (t , tt .expected , res .Apps )
1286+ }
1287+ })
1288+ }
1289+ })
11501290}
11511291
11521292// TestedTools keeps track of which tools have been tested.
0 commit comments