Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 7aa74a5

Browse files
committed
fix: allowed nil values
1 parent 026716e commit 7aa74a5

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

es.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,19 +1186,19 @@ func (c *Client) SnapshotAllIndicesWithBodyParams(repository string, snapshot st
11861186
return errors.New("empty string for snapshot is not allowed")
11871187
}
11881188

1189-
if bodyParams == nil {
1190-
return errors.New("no body params provided, please use SnapshotAllIndices Function instead")
1191-
}
1192-
11931189
parsedJSON, parsingErr := json.Marshal(bodyParams)
11941190

11951191
if parsingErr != nil {
11961192
return parsingErr
11971193
}
11981194

1199-
agent := c.buildPutRequest(fmt.Sprintf("_snapshot/%s/%s", repository, snapshot)).
1200-
Set("Content-Type", "application/json").
1201-
Send(string(parsedJSON))
1195+
agent := c.buildPutRequest(fmt.Sprintf("_snapshot/%s/%s", repository, snapshot))
1196+
1197+
if bodyParams != nil {
1198+
agent = agent.
1199+
Set("Content-Type", "application/json").
1200+
Send(string(parsedJSON))
1201+
}
12021202

12031203
_, err := handleErrWithBytes(agent)
12041204

es_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,11 +1430,10 @@ func TestSnapshotAllIndicesWithAdditionalParametersIncludeGlobalState(t *testing
14301430
}
14311431
}
14321432

1433-
func TestSnapshotAllIndicesWithAdditionalParametersErr(t *testing.T) {
1433+
func TestSnapshotAllIndicesWithAdditionalParametersNilValue(t *testing.T) {
14341434
testSetup := &ServerSetup{
14351435
Method: "PUT",
14361436
Path: "/_snapshot/backup-repo/snapshot1",
1437-
Body: `{"metadata":{"taken_because":"backup before upgrading","taken_by":"user123"}}`,
14381437
Response: `{"acknowledged": true }`,
14391438
}
14401439

@@ -1444,8 +1443,8 @@ func TestSnapshotAllIndicesWithAdditionalParametersErr(t *testing.T) {
14441443

14451444
err := client.SnapshotAllIndicesWithBodyParams("backup-repo", "snapshot1", nil)
14461445

1447-
if err == nil {
1448-
t.Fatalf("should have thrown an error")
1446+
if err != nil {
1447+
t.Fatalf("Should be able to take Nil body params: %s", err)
14491448
}
14501449
}
14511450

0 commit comments

Comments
 (0)