File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -128,10 +128,12 @@ func ExtractWorkspaceAndAgentParam(db database.Store) func(http.Handler) http.Ha
128
128
return
129
129
}
130
130
131
- // If we have more than 1 workspace agent, we need to specify which one to use.
132
131
var agent database.WorkspaceAgent
133
132
var found bool
134
- if len (agents ) > 1 {
133
+ // If we have more than 1 workspace agent, we need to specify which one to use.
134
+ // If the user specified an agent, we need to make sure that agent
135
+ // actually exists.
136
+ if len (workspaceParts ) > 1 || len (agents ) > 1 {
135
137
for _ , otherAgent := range agents {
136
138
if otherAgent .Name == workspaceParts [1 ] {
137
139
agent = otherAgent
@@ -141,7 +143,7 @@ func ExtractWorkspaceAndAgentParam(db database.Store) func(http.Handler) http.Ha
141
143
}
142
144
if ! found {
143
145
httpapi .Write (rw , http .StatusBadRequest , codersdk.Response {
144
- Message : fmt .Sprintf ("No agent exists with the name %s " , workspaceParts [1 ]),
146
+ Message : fmt .Sprintf ("No agent exists with the name %q " , workspaceParts [1 ]),
145
147
})
146
148
return
147
149
}
Original file line number Diff line number Diff line change @@ -175,6 +175,36 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
175
175
ExpectedStatusCode : http .StatusBadRequest ,
176
176
ExpectedError : "More than one agent exists, but no agent specified" ,
177
177
},
178
+ {
179
+ Name : "NotExistsOneAgent" ,
180
+ WorkspaceName : "dev" ,
181
+ Agents : map [string ][]string {
182
+ "resource-a" : {
183
+ "agent-one" ,
184
+ },
185
+ },
186
+ UrlParam : "dev.not-exists" ,
187
+ ExpectedStatusCode : http .StatusBadRequest ,
188
+ ExpectedError : "No agent exists with the name" ,
189
+ },
190
+ {
191
+ Name : "NotExistsMultipleAgents" ,
192
+ WorkspaceName : "dev" ,
193
+ Agents : map [string ][]string {
194
+ "resource-a" : {
195
+ "agent-one" ,
196
+ },
197
+ "resource-b" : {
198
+ "agent-two" ,
199
+ },
200
+ "resource-c" : {
201
+ "agent-three" ,
202
+ },
203
+ },
204
+ UrlParam : "dev.not-exists" ,
205
+ ExpectedStatusCode : http .StatusBadRequest ,
206
+ ExpectedError : "No agent exists with the name" ,
207
+ },
178
208
179
209
// OKs
180
210
{
You can’t perform that action at this time.
0 commit comments