Skip to content

Commit 729a94c

Browse files
authored
Move integration tests into integration dir (#649)
* fix: moved integration tests into integration dir * fix: test case error * test: Add tests for ErrorBody with encoder * chore: Update Go version in tests workflow * chore: Remove ignore rule in codecov.yml * chore: Update Go versions in test workflow * chore: tests.yml: Improve integration tests workflow * feat: ci: Add unit tests and coverage merging * chore: update gocovmerge tool * chore: fix version of tool * chore: workflow: Update Go versions for pre-release tests * test: Add SearchRequest validation tests * tests: fix add get document by ids to integration dir * fix: rename locates to locales * fix: integration tests * fix: revert locates changes * fix: reverted latest version * chore: fix reverted struct error * ci: remove need linter * chore: fix conflicts * chore: revert break change * chore: remove VectorStore field from types * fix: remove vector store
1 parent 0165e9b commit 729a94c

17 files changed

+1261
-1184
lines changed

.github/workflows/tests.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,16 @@ jobs:
6161
fi
6262
- name: Meilisearch setup (latest version) with Docker
6363
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey --no-analytics
64+
- name: Run unit tests
65+
run: |
66+
go test --race -v -gcflags=-l -coverprofile=unit_coverage.txt -covermode=atomic $(go list ./... | grep -v /integration)
6467
- name: Run integration tests
65-
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
68+
run: |
69+
go test --race -v -gcflags=-l -coverprofile=integration_coverage.txt -covermode=atomic -coverpkg=./... ./integration
70+
- name: Merge coverage reports
71+
run: |
72+
go install github.com/ja7ad/gocovmerge/cmd/[email protected]
73+
gocovmerge unit_coverage.txt integration_coverage.txt > coverage.txt
6674
- name: Upload coverage report
6775
uses: codecov/codecov-action@v5
6876
env:

codecov.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
ignore:
2-
- "types_easyjson.go"
31
coverage:
42
range: 60..80
53
round: down

encoding_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"errors"
7+
"fmt"
78
"github.com/stretchr/testify/assert"
89
"github.com/stretchr/testify/require"
910
"io"
@@ -29,6 +30,24 @@ func (e *errorReader) Read(p []byte) (int, error) {
2930
return 0, errors.New("read error")
3031
}
3132

33+
type mockEncoder struct{}
34+
35+
func (m *mockEncoder) Encode(r io.Reader) (io.ReadCloser, error) {
36+
return nil, nil
37+
}
38+
39+
func (m *mockEncoder) Decode(data []byte, v interface{}) error {
40+
msg, ok := v.(*meilisearchApiError)
41+
if !ok {
42+
return fmt.Errorf("wrong type")
43+
}
44+
msg.Message = "mocked message"
45+
msg.Code = "mocked code"
46+
msg.Type = "mocked type"
47+
msg.Link = "mocked link"
48+
return nil
49+
}
50+
3251
func Test_Encode_ErrorOnNewWriter(t *testing.T) {
3352
g := &gzipEncoder{
3453
gzWriterPool: &sync.Pool{

error_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package meilisearch
22

33
import (
44
"fmt"
5+
"io"
56
"net/http"
67
"testing"
78

@@ -47,3 +48,36 @@ func TestError_VersionErrorHintMessage(t *testing.T) {
4748
})
4849
}
4950
}
51+
52+
type failEncoder struct{}
53+
54+
func (f *failEncoder) Encode(r io.Reader) (io.ReadCloser, error) {
55+
return nil, nil
56+
}
57+
func (f *failEncoder) Decode(_ []byte, v interface{}) error {
58+
return fmt.Errorf("decode failed")
59+
}
60+
61+
func TestError_ErrorBody_WithEncoder(t *testing.T) {
62+
63+
err := &Error{
64+
encoder: &mockEncoder{},
65+
}
66+
body := []byte(`{"message":"should not be used"}`)
67+
err.ErrorBody(body)
68+
require.Equal(t, "mocked message", err.MeilisearchApiError.Message)
69+
require.Equal(t, "mocked code", err.MeilisearchApiError.Code)
70+
require.Equal(t, "mocked type", err.MeilisearchApiError.Type)
71+
require.Equal(t, "mocked link", err.MeilisearchApiError.Link)
72+
73+
err2 := &Error{
74+
encoder: &failEncoder{},
75+
}
76+
body2 := []byte(`{"message":"should not be used"}`)
77+
err2.ErrorBody(body2)
78+
// Should not set MeilisearchApiError fields
79+
require.Empty(t, err2.MeilisearchApiError.Message)
80+
require.Empty(t, err2.MeilisearchApiError.Code)
81+
require.Empty(t, err2.MeilisearchApiError.Type)
82+
require.Empty(t, err2.MeilisearchApiError.Link)
83+
}

features_test.go renamed to integration/features_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
package meilisearch
1+
package integration
22

33
import (
44
"crypto/tls"
55
"testing"
66

7+
"github.com/meilisearch/meilisearch-go"
78
"github.com/stretchr/testify/require"
89
)
910

1011
func TestGet_ExperimentalFeatures(t *testing.T) {
1112
sv := setup(t, "")
12-
customSv := setup(t, "", WithCustomClientWithTLS(&tls.Config{
13+
customSv := setup(t, "", meilisearch.WithCustomClientWithTLS(&tls.Config{
1314
InsecureSkipVerify: true,
1415
}))
1516

1617
tests := []struct {
1718
name string
18-
client ServiceManager
19+
client meilisearch.ServiceManager
1920
}{
2021
{
2122
name: "TestGetStats",
@@ -39,13 +40,13 @@ func TestGet_ExperimentalFeatures(t *testing.T) {
3940

4041
func TestUpdate_ExperimentalFeatures(t *testing.T) {
4142
sv := setup(t, "")
42-
customSv := setup(t, "", WithCustomClientWithTLS(&tls.Config{
43+
customSv := setup(t, "", meilisearch.WithCustomClientWithTLS(&tls.Config{
4344
InsecureSkipVerify: true,
4445
}))
4546

4647
tests := []struct {
4748
name string
48-
client ServiceManager
49+
client meilisearch.ServiceManager
4950
}{
5051
{
5152
name: "TestUpdateStats",
@@ -68,6 +69,7 @@ func TestUpdate_ExperimentalFeatures(t *testing.T) {
6869
ef.SetCompositeEmbedders(true)
6970
gotResp, err := ef.Update()
7071
require.NoError(t, err)
72+
7173
require.Equal(t, true, gotResp.LogsRoute, "ExperimentalFeatures.Update() should return logsRoute as true")
7274
require.Equal(t, true, gotResp.Metrics, "ExperimentalFeatures.Update() should return metrics as true")
7375
require.Equal(t, true, gotResp.EditDocumentsByFunction, "ExperimentalFeatures.Update() should return editDocumentsByFunction as true")

0 commit comments

Comments
 (0)