-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathsearch_test.go
79 lines (71 loc) · 1.91 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package lib
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/qri-io/qri/base/params"
"github.com/qri-io/qri/config"
testcfg "github.com/qri-io/qri/config/test"
"github.com/qri-io/qri/event"
"github.com/qri-io/qri/p2p"
"github.com/qri-io/qri/registry/regclient"
testrepo "github.com/qri-io/qri/repo/test"
)
func TestSearch(t *testing.T) {
ctx, done := context.WithCancel(context.Background())
defer done()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(mockResponse)
}))
rc := regclient.NewClient(®client.Config{Location: server.URL})
mr, err := testrepo.NewTestRepo()
if err != nil {
t.Fatalf("error allocating test repo: %s", err.Error())
}
node, err := p2p.NewQriNode(mr, testcfg.DefaultP2PForTesting(), event.NilBus, nil)
if err != nil {
t.Fatal(err.Error())
}
inst := NewInstanceFromConfigAndNode(ctx, config.DefaultConfig(), node)
inst.registry = rc
p := &SearchParams{Query: "nuun", List: params.List{Offset: 0, Limit: 100}}
got, err := inst.Search().Search(ctx, p)
if err != nil {
t.Error(err)
}
if 1 != len(got) {
t.Errorf("expected: %d results, got: %d", 1, len(got))
}
}
var mockResponse = []byte(`{"data":[
{
"type": "dataset",
"id": "/ipfs/QmZEnjt3Y5RxXsoZyufJfFzcogicBEwfaimJSyDuC7nySA",
"url": "https://qri.cloud/nuun/nuun",
"value": {
"commit": {
"qri": "cm:0",
"timestamp": "2019-08-31T12:07:56.212858Z",
"title": "change to 10"
},
"meta": {
"keywords": [
"joke"
],
"qri": "md:0",
"title": "this is a d"
},
"name": "nuun",
"path": "/ipfs/QmZEnjt3Y5RxXsoZyufJfFzcogicBEwfaimJSyDuC7nySA",
"peername": "nuun",
"qri": "ds:0",
"structure": {
"entries": 3,
"format": "csv",
"length": 36,
"qri": "st:0"
}
}
}
],"meta":{"code":200}}`)