MCPcopy Index your code
hub / github.com/coder/coder / TestSearchAudit

Function TestSearchAudit

coderd/searchquery/search_test.go:526–594  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

524}
525
526func TestSearchAudit(t *testing.T) {
527 t.Parallel()
528 testCases := []struct {
529 Name string
530 Query string
531 Expected database.GetAuditLogsOffsetParams
532 ExpectedCountParams database.CountAuditLogsParams
533 ExpectedErrorContains string
534 }{
535 {
536 Name: "Empty",
537 Query: "",
538 Expected: database.GetAuditLogsOffsetParams{},
539 },
540 // Failures
541 {
542 Name: "ExtraColon",
543 Query: `search:name:extra`,
544 ExpectedErrorContains: "can only contain 1 ':'",
545 },
546 {
547 Name: "ExtraKeys",
548 Query: `foo:bar`,
549 ExpectedErrorContains: `"foo" is not a valid query param`,
550 },
551 {
552 Name: "Dates",
553 Query: "date_from:2006",
554 ExpectedErrorContains: "valid date format",
555 },
556 {
557 Name: "ResourceTarget",
558 Query: "resource_target:foo",
559 Expected: database.GetAuditLogsOffsetParams{
560 ResourceTarget: "foo",
561 },
562 ExpectedCountParams: database.CountAuditLogsParams{
563 ResourceTarget: "foo",
564 },
565 },
566 {
567 Name: "RequestID",
568 Query: "request_id:foo",
569 ExpectedErrorContains: "valid uuid",
570 },
571 }
572
573 for _, c := range testCases {
574 t.Run(c.Name, func(t *testing.T) {
575 t.Parallel()
576 // Do not use a real database, this is only used for an
577 // organization lookup.
578 db, _ := dbtestutil.NewDB(t)
579 values, countValues, errs := searchquery.AuditLogs(context.Background(), db, c.Query)
580 if c.ExpectedErrorContains != "" {
581 require.True(t, len(errs) > 0, "expect some errors")
582 var s strings.Builder
583 for _, err := range errs {

Callers

nothing calls this directly

Calls 8

NewDBFunction · 0.92
AuditLogsFunction · 0.92
WriteStringMethod · 0.80
RunMethod · 0.65
ContainsMethod · 0.45
StringMethod · 0.45
LenMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected