Skip to content

fix: Fix properly selecting workspace apps by agent #3684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 29, 2022
Prev Previous commit
Next Next commit
Linting
  • Loading branch information
Emyrk committed Aug 24, 2022
commit f44f5c05eb4e6466a52ce23751db9de437941ddc
23 changes: 12 additions & 11 deletions coderd/httpmw/workspaceparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
Name string
// Agents are mapped to a resource
Agents map[string][]string
UrlParam string
URLParam string
WorkspaceName string
ExpectedAgent string
ExpectedStatusCode int
Expand All @@ -143,7 +143,7 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
Name: "NoAgents",
WorkspaceName: "dev",
Agents: map[string][]string{},
UrlParam: "dev",
URLParam: "dev",
ExpectedError: "No agents exist",
ExpectedStatusCode: http.StatusBadRequest,
},
Expand All @@ -156,7 +156,7 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
"agent-two",
},
},
UrlParam: "dev",
URLParam: "dev",
ExpectedStatusCode: http.StatusBadRequest,
ExpectedError: "More than one agent exists, but no agent specified",
},
Expand All @@ -171,7 +171,7 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
"agent-two",
},
},
UrlParam: "dev",
URLParam: "dev",
ExpectedStatusCode: http.StatusBadRequest,
ExpectedError: "More than one agent exists, but no agent specified",
},
Expand All @@ -183,7 +183,7 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
"agent-one",
},
},
UrlParam: "dev.not-exists",
URLParam: "dev.not-exists",
ExpectedStatusCode: http.StatusBadRequest,
ExpectedError: "No agent exists with the name",
},
Expand All @@ -201,7 +201,7 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
"agent-three",
},
},
UrlParam: "dev.not-exists",
URLParam: "dev.not-exists",
ExpectedStatusCode: http.StatusBadRequest,
ExpectedError: "No agent exists with the name",
},
Expand All @@ -216,7 +216,7 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
"agent-one",
},
},
UrlParam: "dev",
URLParam: "dev",
ExpectedAgent: "agent-one",
ExpectedStatusCode: http.StatusOK,
},
Expand All @@ -228,7 +228,7 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
"agent-one",
},
},
UrlParam: "dev",
URLParam: "dev",
ExpectedAgent: "agent-one",
ExpectedStatusCode: http.StatusOK,
},
Expand All @@ -242,7 +242,7 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
"agent-selected",
},
},
UrlParam: "dev.agent-selected",
URLParam: "dev.agent-selected",
ExpectedAgent: "agent-selected",
ExpectedStatusCode: http.StatusOK,
},
Expand All @@ -261,7 +261,7 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
"agent-three",
},
},
UrlParam: "dev.agent-selected",
URLParam: "dev.agent-selected",
ExpectedAgent: "agent-selected",
ExpectedStatusCode: http.StatusOK,
},
Expand All @@ -270,12 +270,13 @@ func TestWorkspaceAgentByNameParam(t *testing.T) {
for _, c := range testCases {
c := c
t.Run(c.Name, func(t *testing.T) {
t.Parallel()
db, r := setupWorkspaceWithAgents(t, setupConfig{
WorkspaceName: c.WorkspaceName,
Agents: c.Agents,
})

chi.RouteContext(r.Context()).URLParams.Add("workspacename_and_agent", c.UrlParam)
chi.RouteContext(r.Context()).URLParams.Add("workspacename_and_agent", c.URLParam)

rtr := chi.NewRouter()
rtr.Use(
Expand Down