Skip to content

Commit c6d94e0

Browse files
test(bytes): implement unit tests for redundancy level validation in bytes upload handler
1 parent 3fd49f8 commit c6d94e0

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

pkg/api/bytes_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,36 @@ func TestBytesDirectUpload(t *testing.T) {
408408
}),
409409
)
410410
}
411+
412+
func TestBytesRedundancyLevel(t *testing.T) {
413+
t.Parallel()
414+
415+
client, _, _, _ := newTestServer(t, testServerOptions{
416+
Storer: mockstorer.New(),
417+
Post: mockpost.New(mockpost.WithAcceptAll()),
418+
})
419+
420+
tests := []struct {
421+
name string
422+
level string
423+
wantStatus int
424+
}{
425+
{"level 0 (NONE) is valid", "0", http.StatusCreated},
426+
{"level 1 (MEDIUM) is valid", "1", http.StatusCreated},
427+
{"level 2 (STRONG) is valid", "2", http.StatusCreated},
428+
{"level 3 (INSANE) is valid", "3", http.StatusCreated},
429+
{"level 4 (PARANOID) is valid", "4", http.StatusCreated},
430+
{"level 5 is invalid", "5", http.StatusBadRequest},
431+
}
432+
433+
for _, tt := range tests {
434+
t.Run(tt.name, func(t *testing.T) {
435+
jsonhttptest.Request(t, client, http.MethodPost, "/bytes", tt.wantStatus,
436+
jsonhttptest.WithRequestHeader(api.SwarmDeferredUploadHeader, "true"),
437+
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
438+
jsonhttptest.WithRequestHeader(api.SwarmRedundancyLevelHeader, tt.level),
439+
jsonhttptest.WithRequestBody(bytes.NewReader([]byte("test"))),
440+
)
441+
})
442+
}
443+
}

0 commit comments

Comments
 (0)