MCPcopy Create free account
hub / github.com/RTradeLtd/Lens / TestEngine_Index

Function TestEngine_Index

engine/engine_test.go:17–113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestEngine_Index(t *testing.T) {
18 type args struct {
19 object *models.ObjectV2
20 reindex bool
21 }
22 tests := []struct {
23 name string
24 args args
25 wantIndexed bool
26 }{
27 {"no hash",
28 args{&models.ObjectV2{
29 MD: models.MetaDataV2{},
30 }, false},
31 false,
32 },
33 {"ok",
34 args{&models.ObjectV2{
35 Hash: "abcde",
36 MD: models.MetaDataV2{},
37 }, false},
38 true,
39 },
40 {"with tags and some metadata",
41 args{&models.ObjectV2{
42 Hash: "oishii",
43 MD: models.MetaDataV2{
44 DisplayName: "rtrade",
45 Category: "startup",
46 Tags: []string{"ipfs", "decentralized"},
47 },
48 }, true},
49 true,
50 },
51 }
52 for _, tt := range tests {
53 t.Run(tt.name, func(t *testing.T) {
54 var l = zaptest.NewLogger(t).Sugar()
55 e, err := New(l, Opts{
56 StorePath: filepath.Join("tmp", t.Name()),
57 Queue: queue.Options{
58 Rate: 500 * time.Millisecond,
59 BatchSize: 1,
60 }})
61 if err != nil {
62 t.Error("failed to create engine: " + err.Error())
63 return
64 }
65 defer os.RemoveAll("tmp")
66 go e.Run()
67
68 // insert bogus doc if testing reindex
69 if tt.args.reindex {
70 var bogus = *tt.args.object
71 bogus.MD.Tags = []string{"i", "am", "fake"}
72 if err = e.Index(Document{&bogus, "", true}); (err == nil) != tt.wantIndexed {
73 t.Errorf("wanted Index error = %v, got %v", !tt.wantIndexed, err)
74 e.Close()

Callers

nothing calls this directly

Calls 6

NewFunction · 0.70
IndexMethod · 0.65
CloseMethod · 0.65
IsIndexedMethod · 0.65
SearchMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected