-
Notifications
You must be signed in to change notification settings - Fork 16
/
search_test.go
52 lines (47 loc) · 1020 Bytes
/
search_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"strings"
"testing"
"golang.org/x/oscar/internal/storage"
)
func TestSearchPageTemplate(t *testing.T) {
page := searchPage{
Query: "some query",
Results: []searchResult{
{
Title: "t1",
VResult: storage.VectorResult{
ID: "https://example.com/x",
Score: 0.987654321,
},
IDIsURL: true,
},
{
VResult: storage.VectorResult{
ID: "https://example.com/y",
Score: 0.876,
},
IDIsURL: false,
},
},
}
var buf bytes.Buffer
if err := searchPageTmpl.Execute(&buf, page); err != nil {
t.Fatal(err)
}
wants := []string{page.Query}
for _, sr := range page.Results {
wants = append(wants, sr.VResult.ID)
}
got := buf.String()
t.Logf("%s", got)
for _, w := range wants {
if !strings.Contains(got, w) {
t.Errorf("did not find %q in HTML", w)
}
}
}