search: browse bounded recent items with kind-only queries
This commit is contained in:
@@ -9,6 +9,10 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coder/websocket"
|
||||
"github.com/coder/websocket/wsjson"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/cli"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
@@ -102,4 +106,42 @@ func TestCLISearchEndToEndEveryKind(t *testing.T) {
|
||||
if _, err := runCLI("search", "zephyr", "--type", "bogus"); err == nil || !strings.Contains(err.Error(), "unknown search kind") {
|
||||
t.Fatalf("invalid kind must error, got %v", err)
|
||||
}
|
||||
|
||||
// The browser sends an actual empty query, not an invented wildcard. Exercise
|
||||
// that unchanged wire shape over /connect against this throwaway store.
|
||||
wireCtx, wireCancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer wireCancel()
|
||||
conn, _, err := websocket.Dial(wireCtx, url, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.CloseNow()
|
||||
for _, kind := range append(append([]string{}, protocol.SearchKinds...), "", "bogus") {
|
||||
request := protocol.Message{Type: protocol.Search, ID: "recent-" + kind, Search: &protocol.SearchRequest{Query: "", Kind: kind, Limit: 1}}
|
||||
if err := wsjson.Write(wireCtx, conn, request); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var reply protocol.Message
|
||||
for reply.ID != request.ID {
|
||||
if err := wsjson.Read(wireCtx, conn, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if kind == "bogus" {
|
||||
if !strings.Contains(reply.Error, "unknown search kind") {
|
||||
t.Fatalf("blank text must not bypass kind validation: %+v", reply)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if reply.SearchResults == nil || reply.SearchResults.Cap != 1 || reply.SearchResults.Query != "" {
|
||||
t.Fatalf("invalid kind-only reply: %+v", reply)
|
||||
}
|
||||
if kind == "" {
|
||||
if len(reply.SearchResults.Results) != 0 {
|
||||
t.Fatalf("blank unfiltered query must remain a no-op: %+v", reply)
|
||||
}
|
||||
} else if hits := reply.SearchResults.Results; len(hits) != 1 || hits[0].Kind != kind {
|
||||
t.Fatalf("missing bounded kind-only result for %q: %+v", kind, reply)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user