Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pkg/cmd/rules/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ func runImportCmd(opts *ImportOptions) error {
opts.IO.StopProgressIndicator()
return err
}
res, err := client.SaveRules(
client.NewApiSaveRulesRequest(opts.Index, rules).
WithForwardToReplicas(opts.ForwardToReplicas),
)
request := client.NewApiSaveRulesRequest(opts.Index, rules).
WithForwardToReplicas(opts.ForwardToReplicas)
if clearExistingRules {
request = request.WithClearExistingRules(true)
}
res, err := client.SaveRules(request)
if err != nil {
opts.IO.StopProgressIndicator()
return err
Expand Down
24 changes: 24 additions & 0 deletions pkg/cmd/rules/import/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,30 @@ func Test_runExportCmd(t *testing.T) {
wantOut: "✓ Successfully imported 0 rules to foo\n",
setup: func(r *httpmock.Registry) {},
},
{
name: "from small batch clear existing",
cli: "foo -c -y -F -",
stdin: `{"objectID":"test"}`,
wantOut: "✓ Successfully imported 1 rules to foo\n",
setup: func(r *httpmock.Registry) {
r.Register(httpmock.Matcher(func(req *http.Request) bool {
return httpmock.REST("POST", "1/indexes/foo/rules/batch")(req) &&
req.URL.Query().Get("clearExistingRules") == "true"
}), httpmock.JSONResponse(search.UpdatedAtResponse{}))
},
},
{
name: "from small batch without clear existing",
cli: "foo -F -",
stdin: `{"objectID":"test"}`,
wantOut: "✓ Successfully imported 1 rules to foo\n",
setup: func(r *httpmock.Registry) {
r.Register(httpmock.Matcher(func(req *http.Request) bool {
return httpmock.REST("POST", "1/indexes/foo/rules/batch")(req) &&
req.URL.Query().Get("clearExistingRules") == ""
}), httpmock.JSONResponse(search.UpdatedAtResponse{}))
},
},
{
name: "from large batch clear existing",
cli: "foo -c -y -F -",
Expand Down
10 changes: 6 additions & 4 deletions pkg/cmd/synonyms/import/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ func runImportCmd(opts *ImportOptions) error {
opts.IO.StopProgressIndicator()
return err
}
res, err := client.SaveSynonyms(
client.NewApiSaveSynonymsRequest(opts.Index, synonyms).
WithForwardToReplicas(opts.ForwardToReplicas),
)
request := client.NewApiSaveSynonymsRequest(opts.Index, synonyms).
WithForwardToReplicas(opts.ForwardToReplicas)
if clearExistingSynonyms {
request = request.WithReplaceExistingSynonyms(true)
}
res, err := client.SaveSynonyms(request)
if err != nil {
opts.IO.StopProgressIndicator()
return err
Expand Down
24 changes: 24 additions & 0 deletions pkg/cmd/synonyms/import/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,30 @@ func Test_runExportCmd(t *testing.T) {
wantOut: "✓ Successfully imported 0 synonyms to foo\n",
setup: func(r *httpmock.Registry) {},
},
{
name: "from small batch with clear existing",
cli: "foo -r -F -",
stdin: `{"objectID":"test","type":"synonym","synonyms":["test"]}`,
wantOut: "✓ Successfully imported 1 synonyms to foo\n",
setup: func(r *httpmock.Registry) {
r.Register(httpmock.Matcher(func(req *http.Request) bool {
return httpmock.REST("POST", "1/indexes/foo/synonyms/batch")(req) &&
req.URL.Query().Get("replaceExistingSynonyms") == "true"
}), httpmock.JSONResponse(search.UpdatedAtResponse{}))
},
},
{
name: "from small batch without clear existing",
cli: "foo -F -",
stdin: `{"objectID":"test","type":"synonym","synonyms":["test"]}`,
wantOut: "✓ Successfully imported 1 synonyms to foo\n",
setup: func(r *httpmock.Registry) {
r.Register(httpmock.Matcher(func(req *http.Request) bool {
return httpmock.REST("POST", "1/indexes/foo/synonyms/batch")(req) &&
req.URL.Query().Get("replaceExistingSynonyms") == ""
}), httpmock.JSONResponse(search.UpdatedAtResponse{}))
},
},
{
name: "from large batch with clear existing",
cli: "foo -r -F -",
Expand Down