Browse Source

Ensure Validate succeeds on SnapshotCreateRepository

When settings are provided to set up `SnapshotCreateRepositoryService`,
we need to make sure that validation succeeds.

Close #854
tags/v6.1.28
Oliver Eilhard 1 year ago
parent
commit
a268a4f191
2 changed files with 5 additions and 2 deletions
  1. 1
    1
      snapshot_create_repository.go
  2. 4
    1
      snapshot_create_repository_test.go

+ 1
- 1
snapshot_create_repository.go View File

@@ -150,7 +150,7 @@ func (s *SnapshotCreateRepositoryService) Validate() error {
150 150
 	if s.repository == "" {
151 151
 		invalid = append(invalid, "Repository")
152 152
 	}
153
-	if s.bodyString == "" && s.bodyJson == nil {
153
+	if s.bodyString == "" && s.bodyJson == nil && len(s.settings) == 0 {
154 154
 		invalid = append(invalid, "BodyJson")
155 155
 	}
156 156
 	if len(invalid) > 0 {

+ 4
- 1
snapshot_create_repository_test.go View File

@@ -33,7 +33,7 @@ func TestSnapshotPutRepositoryURL(t *testing.T) {
33 33
 	}
34 34
 }
35 35
 
36
-func TestSnapshotPutRepositoryBody(t *testing.T) {
36
+func TestSnapshotPutRepositoryBodyWithSettings(t *testing.T) {
37 37
 	client := setupTestClient(t)
38 38
 
39 39
 	service := client.SnapshotCreateRepository("my_backup")
@@ -45,6 +45,9 @@ func TestSnapshotPutRepositoryBody(t *testing.T) {
45 45
 		Setting("compress", true).
46 46
 		Setting("chunk_size", 16*1024*1024)
47 47
 
48
+	if err := service.Validate(); err != nil {
49
+		t.Fatal(err)
50
+	}
48 51
 	src, err := service.buildBody()
49 52
 	if err != nil {
50 53
 		t.Fatal(err)

Loading…
Cancel
Save