Skip to content

Commit ef9a7a0

Browse files
authored
Merge pull request #203 from haydenhoang/alnr/master
Add integration test for PR #202
2 parents b71651b + 5a521fc commit ef9a7a0

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,21 @@ Update the generated files,
503503
go generate ./...
504504
```
505505

506+
Run all tests
507+
508+
```bash
509+
# In Windows Powershell
510+
# $env:TYPESENSE_API_KEY="xyz"
511+
# $env:TYPESENSE_URL="http://localhost:8108"
512+
513+
export TYPESENSE_URL="http://localhost:8108"
514+
export TYPESENSE_API_KEY="xyz"
515+
516+
go test ./... -tags=integration -v
517+
```
518+
519+
520+
506521
## License
507522

508523
`typesense-go` is distributed under the Apache 2 license.

typesense/test/import_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,26 @@ func TestDocumentsImport(t *testing.T) {
2727
newDocument("123"),
2828
newDocument("125", withCompanyName("Company2")),
2929
newDocument("127", withCompanyName("Company3")),
30+
// Bad doc
31+
map[string]interface{}{"bad_doc": true, "content": map[string]interface{}{"bad_field": "bad_value"}},
32+
"[Bad string",
3033
}
3134

32-
params := &api.ImportDocumentsParams{Action: pointer.Any(api.Create), DirtyValues: pointer.Any(api.CoerceOrDrop)}
35+
params := &api.ImportDocumentsParams{Action: pointer.Any(api.Create), DirtyValues: pointer.Any(api.CoerceOrDrop), ReturnDoc: pointer.True(), ReturnId: pointer.True()}
3336
responses, err := typesenseClient.Collection(collectionName).Documents().Import(context.Background(), documents, params)
3437

3538
require.NoError(t, err)
36-
for _, response := range responses {
37-
require.True(t, response.Success, "document import failed")
39+
for i, response := range responses {
40+
if i < 3 {
41+
require.True(t, response.Success, "document import failed")
42+
43+
} else if i == 3 {
44+
require.False(t, response.Success, "failed to handle bad document")
45+
require.Equal(t, `{"bad_doc":true,"content":{"bad_field":"bad_value"}}`, response.Document)
46+
} else {
47+
require.False(t, response.Success, "failed to handle bad string")
48+
require.Equal(t, `"[Bad string"`, response.Document)
49+
}
3850
}
3951

4052
results := retrieveDocuments(t, collectionName, "123", "125", "127")

0 commit comments

Comments
 (0)