8000 feat: Workspace filters case insensitive by Emyrk · Pull Request #2646 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: Workspace filters case insensitive #2646

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 5 commits into from
Jun 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: Add unit test to verify case insensitive
  • Loading branch information
Emyrk committed Jun 24, 2022
commit c406946d582478d0b2a28887ea908f5315ec8729
37 changes: 29 additions & 8 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,19 +428,19 @@ func TestWorkspaceFilter(t *testing.T) {
{
Name: "Owner",
Filter: codersdk.WorkspaceFilter{
Owner: users[2].User.Username,
Owner: strings.ToUpper(users[2].User.Username),
},
FilterF: func(f codersdk.WorkspaceFilter, workspace madeWorkspace) bool {
return workspace.Owner.Username == f.Owner
return strings.EqualFold(workspace.Owner.Username, f.Owner)
},
},
{
Name: "TemplateName",
Filter: codersdk.WorkspaceFilter{
Template: allWorkspaces[5].Template.Name,
Template: strings.ToUpper(allWorkspaces[5].Template.Name),
},
FilterF: func(f codersdk.WorkspaceFilter, workspace madeWorkspace) bool {
return workspace.Template.Name == f.Template
return strings.EqualFold(workspace.Template.Name, f.Template)
},
},
{
Expand All @@ -450,16 +450,25 @@ func TestWorkspaceFilter(t *testing.T) {
Name: "a",
},
FilterF: func(f codersdk.WorkspaceFilter, workspace madeWorkspace) bool {
return strings.Contains(workspace.Workspace.Name, f.Name)
return strings.ContainsAny(workspace.Workspace.Name, "Aa")
},
},
{
Name: "Q-Owner/Name",
Filter: codersdk.WorkspaceFilter{
FilterQuery: allWorkspaces[5].Owner.Username + "/" + allWorkspaces[5].Workspace.Name,
},
FilterF: func(_ codersdk.WorkspaceFilter, workspace madeWorkspace) bool {
return workspace.Workspace.ID == allWorkspaces[5].Workspace.ID
FilterF: func(f codersdk.WorkspaceFilter, workspace madeWorkspace) bool {
if strings.EqualFold(workspace.Owner.Username, f.Owner) {
return true
}
if strings.EqualFold(workspace.Owner.Email, f.Owner) {
return true
< 865F /td> }
if strings.EqualFold(workspace.Workspace.Name, f.Name) {
return true
}
return false
},
},
{
Expand All @@ -470,7 +479,19 @@ func TestWorkspaceFilter(t *testing.T) {
Name: allWorkspaces[3].Workspace.Name,
},
FilterF: func(f codersdk.WorkspaceFilter, workspace madeWorkspace) bool {
return workspace.Workspace.ID == allWorkspaces[3].Workspace.ID
if strings.EqualFold(workspace.Owner.Username, f.Owner) {
return true
}
if strings.EqualFold(workspace.Owner.Email, f.Owner) {
return true
}
if strings.EqualFold(workspace.Workspace.Name, f.Name) {
return true
}
if strings.EqualFold(workspace.Template.Name, f.Template) {
return true
}
return false
},
},
}
Expand Down
0