-
Notifications
You must be signed in to change notification settings - Fork 887
chore: add organization search query to workspaces #14474
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/database/dbgen" | ||
"github.com/coder/coder/v2/coderd/database/dbmem" | ||
"github.com/coder/coder/v2/coderd/searchquery" | ||
"github.com/coder/coder/v2/codersdk" | ||
|
@@ -25,6 +26,7 @@ func TestSearchWorkspace(t *testing.T) { | |
Query string | ||
Expected database.GetWorkspacesParams | ||
ExpectedErrorContains string | ||
Setup func(t *testing.T, db database.Store) | ||
}{ | ||
{ | ||
Name: "Empty", | ||
|
@@ -195,6 +197,31 @@ func TestSearchWorkspace(t *testing.T) { | |
ParamValues: []string{"bar"}, | ||
}, | ||
}, | ||
{ | ||
Name: "Organization", | ||
Query: `organization:4fe722f0-49bc-4a90-a3eb-4ac439bfce20`, | ||
Setup: func(t *testing.T, db database.Store) { | ||
dbgen.Organization(t, db, database.Organization{ | ||
ID: uuid.MustParse("4fe722f0-49bc-4a90-a3eb-4ac439bfce20"), | ||
}) | ||
}, | ||
Expected: database.GetWorkspacesParams{ | ||
OrganizationID: uuid.MustParse("4fe722f0-49bc-4a90-a3eb-4ac439bfce20"), | ||
}, | ||
}, | ||
{ | ||
Name: "OrganizationByName", | ||
Query: `organization:foobar`, | ||
Setup: func(t *testing.T, db database.Store) { | ||
dbgen.Organization(t, db, database.Organization{ | ||
ID: uuid.MustParse("08eb6715-02f8-45c5-b86d-03786fcfbb4e"), | ||
Name: "foobar", | ||
}) | ||
}, | ||
Expected: database.GetWorkspacesParams{ | ||
OrganizationID: uuid.MustParse("08eb6715-02f8-45c5-b86d-03786fcfbb4e"), | ||
}, | ||
}, | ||
|
||
// Failures | ||
{ | ||
|
@@ -243,7 +270,12 @@ func TestSearchWorkspace(t *testing.T) { | |
c := c | ||
t.Run(c.Name, func(t *testing.T) { | ||
t.Parallel() | ||
values, errs := searchquery.Workspaces(c.Query, codersdk.Pagination{}, 0) | ||
// TODO: Replace this with the mock database. | ||
db := dbmem.New() | ||
if c.Setup != nil { | ||
c.Setup(t, db) | ||
} | ||
values, errs := searchquery.Workspaces(context.Background(), db, c.Query, codersdk.Pagination{}, 0) | ||
Comment on lines
+274
to
+278
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we not use the traditional way of getting a DB in tests so this can run against postgres too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer not to for this. What would be even better is if I used the mock database, but I haven't messed with that at all yet. |
||
if c.ExpectedErrorContains != "" { | ||
assert.True(t, len(errs) > 0, "expect some errors") | ||
var s strings.Builder | ||
|
@@ -270,7 +302,7 @@ func TestSearchWorkspace(t *testing.T) { | |
|
||
query := `` | ||
timeout := 1337 * time.Second | ||
values, errs := searchquery.Workspaces(query, codersdk.Pagination{}, timeout) | ||
values, errs := searchquery.Workspaces(context.Background(), dbmem.New(), query, codersdk.Pagination{}, timeout) | ||
require.Empty(t, errs) | ||
require.Equal(t, int64(timeout.Seconds()), values.AgentInactiveDisconnectTimeoutSeconds) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aside: I see why we do it in this package, but this is kind of a weird naming scheme for something that returns database query params.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair. Maybe it should be named
WorkspacesFilter
or something. I won't address here though