-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwrite_test.go
43 lines (34 loc) · 883 Bytes
/
write_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
package meili_test
import (
"context"
"encoding/json"
"testing"
"time"
"github.com/fortytw2/meili"
)
func TestAddDocumentToIndex(t *testing.T) {
client := getCleanTestInstance(t)
err := client.CreateIndex(context.TODO(), "test", "test", &meili.IndexSettings{
PrimaryKey: "id",
})
if err != nil {
t.Fatalf("could not create index: %s", err)
}
document, _ := json.Marshal(map[string]interface{}{
"id": 1,
"name": "potatoes",
})
_, err = client.WriteOne(context.TODO(), "test", json.RawMessage(document))
if err != nil {
t.Fatalf("could not add documen to index: %s", err)
}
// TODO: this should use SynchronousWrite
time.Sleep(time.Second)
results, err := client.Search(context.TODO(), "test", "potatoes")
if err != nil {
t.Fatalf("could not add documen to index: %s", err)
}
if len(results) != 1 {
t.Fatalf("did not get one result")
}
}