-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
500 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package meilisearch | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
|
||
// Type for experimental features with additional client field | ||
type ExperimentalFeatures struct { | ||
client *client | ||
ExperimentalFeaturesBase | ||
} | ||
|
||
func (m *meilisearch) ExperimentalFeatures() *ExperimentalFeatures { | ||
return &ExperimentalFeatures{client: m.client} | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetVectorStore(vectorStore bool) *ExperimentalFeatures { | ||
ef.VectorStore = &vectorStore | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetLogsRoute(logsRoute bool) *ExperimentalFeatures { | ||
ef.LogsRoute = &logsRoute | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetMetrics(metrics bool) *ExperimentalFeatures { | ||
ef.Metrics = &metrics | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetEditDocumentsByFunction(editDocumentsByFunction bool) *ExperimentalFeatures { | ||
ef.EditDocumentsByFunction = &editDocumentsByFunction | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) SetContainsFilter(containsFilter bool) *ExperimentalFeatures { | ||
ef.ContainsFilter = &containsFilter | ||
return ef | ||
} | ||
|
||
func (ef *ExperimentalFeatures) Get() (*ExperimentalFeaturesResult, error) { | ||
return ef.GetWithContext(context.Background()) | ||
} | ||
|
||
func (ef *ExperimentalFeatures) GetWithContext(ctx context.Context) (*ExperimentalFeaturesResult, error) { | ||
resp := new(ExperimentalFeaturesResult) | ||
req := &internalRequest{ | ||
endpoint: "/experimental-features", | ||
method: http.MethodGet, | ||
withRequest: nil, | ||
withResponse: &resp, | ||
withQueryParams: map[string]string{}, | ||
acceptedStatusCodes: []int{http.StatusOK}, | ||
functionName: "GetExperimentalFeatures", | ||
} | ||
|
||
if err := ef.client.executeRequest(ctx, req); err != nil { | ||
return nil, err | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
func (ef *ExperimentalFeatures) Update() (*ExperimentalFeaturesResult, error) { | ||
return ef.UpdateWithContext(context.Background()) | ||
} | ||
|
||
func (ef *ExperimentalFeatures) UpdateWithContext(ctx context.Context) (*ExperimentalFeaturesResult, error) { | ||
request := ExperimentalFeaturesBase{ | ||
VectorStore: ef.VectorStore, | ||
LogsRoute: ef.LogsRoute, | ||
Metrics: ef.Metrics, | ||
EditDocumentsByFunction: ef.EditDocumentsByFunction, | ||
ContainsFilter: ef.ContainsFilter, | ||
} | ||
resp := new(ExperimentalFeaturesResult) | ||
req := &internalRequest{ | ||
endpoint: "/experimental-features", | ||
method: http.MethodPatch, | ||
contentType: contentTypeJSON, | ||
withRequest: request, | ||
withResponse: resp, | ||
withQueryParams: nil, | ||
acceptedStatusCodes: []int{http.StatusOK}, | ||
functionName: "UpdateExperimentalFeatures", | ||
} | ||
if err := ef.client.executeRequest(ctx, req); err != nil { | ||
return nil, err | ||
} | ||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package meilisearch | ||
|
||
import ( | ||
"crypto/tls" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGet_ExperimentalFeatures(t *testing.T) { | ||
sv := setup(t, "") | ||
customSv := setup(t, "", WithCustomClientWithTLS(&tls.Config{ | ||
InsecureSkipVerify: true, | ||
})) | ||
|
||
tests := []struct { | ||
name string | ||
client ServiceManager | ||
}{ | ||
{ | ||
name: "TestGetStats", | ||
client: sv, | ||
}, | ||
{ | ||
name: "TestGetStatsWithCustomClient", | ||
client: customSv, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ef := tt.client.ExperimentalFeatures() | ||
gotResp, err := ef.Get() | ||
require.NoError(t, err) | ||
require.NotNil(t, gotResp, "ExperimentalFeatures.Get() should not return nil value") | ||
}) | ||
} | ||
} | ||
|
||
func TestUpdate_ExperimentalFeatures(t *testing.T) { | ||
sv := setup(t, "") | ||
customSv := setup(t, "", WithCustomClientWithTLS(&tls.Config{ | ||
InsecureSkipVerify: true, | ||
})) | ||
|
||
tests := []struct { | ||
name string | ||
client ServiceManager | ||
}{ | ||
{ | ||
name: "TestUpdateStats", | ||
client: sv, | ||
}, | ||
{ | ||
name: "TestUpdateStatsWithCustomClient", | ||
client: customSv, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ef := tt.client.ExperimentalFeatures() | ||
ef.SetVectorStore(true) | ||
ef.SetLogsRoute(true) | ||
ef.SetMetrics(true) | ||
ef.SetEditDocumentsByFunction(true) | ||
ef.SetContainsFilter(true) | ||
gotResp, err := ef.Update() | ||
require.NoError(t, err) | ||
require.Equal(t, true, gotResp.VectorStore, "ExperimentalFeatures.Update() should return vectorStore as true") | ||
require.Equal(t, true, gotResp.LogsRoute, "ExperimentalFeatures.Update() should return logsRoute as true") | ||
require.Equal(t, true, gotResp.Metrics, "ExperimentalFeatures.Update() should return metrics as true") | ||
require.Equal(t, true, gotResp.EditDocumentsByFunction, "ExperimentalFeatures.Update() should return editDocumentsByFunction as true") | ||
require.Equal(t, true, gotResp.ContainsFilter, "ExperimentalFeatures.Update() should return containsFilter as true") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.