Commit dddfa6eb authored by Anatolie Lupacescu's avatar Anatolie Lupacescu Committed by GitHub

Using the correct http response codes when creating a resource (#1611)

parent 06eac55a
...@@ -47,7 +47,7 @@ paths: ...@@ -47,7 +47,7 @@ paths:
type: string type: string
format: binary format: binary
responses: responses:
"200": "201":
description: Ok description: Ok
headers: headers:
"swarm-tag": "swarm-tag":
...@@ -138,7 +138,7 @@ paths: ...@@ -138,7 +138,7 @@ paths:
type: string type: string
format: binary format: binary
responses: responses:
"200": "201":
description: Ok description: Ok
headers: headers:
"swarm-tag": "swarm-tag":
...@@ -198,7 +198,7 @@ paths: ...@@ -198,7 +198,7 @@ paths:
type: string type: string
format: binary format: binary
responses: responses:
"200": "201":
description: Ok description: Ok
headers: headers:
"swarm-tag": "swarm-tag":
...@@ -375,7 +375,9 @@ paths: ...@@ -375,7 +375,9 @@ paths:
"400": "400":
$ref: "SwarmCommon.yaml#/components/responses/400" $ref: "SwarmCommon.yaml#/components/responses/400"
"403": "403":
$ref: "SwarmCommon.yaml#/components/responses/403" $ref: "SwarmCommon.yaml#/components/responses/403"
"404":
$ref: "SwarmCommon.yaml#/components/responses/404"
"500": "500":
$ref: "SwarmCommon.yaml#/components/responses/500" $ref: "SwarmCommon.yaml#/components/responses/500"
default: default:
...@@ -451,7 +453,7 @@ paths: ...@@ -451,7 +453,7 @@ paths:
tags: tags:
- Root hash pinning - Root hash pinning
responses: responses:
"200": "201":
description: Pinning root hash with address description: Pinning root hash with address
content: content:
application/json: application/json:
...@@ -546,7 +548,7 @@ paths: ...@@ -546,7 +548,7 @@ paths:
required: false required: false
description: Recipient publickey description: Recipient publickey
responses: responses:
"200": "201":
description: Subscribed to topic description: Subscribed to topic
"400": "400":
$ref: "SwarmCommon.yaml#/components/responses/400" $ref: "SwarmCommon.yaml#/components/responses/400"
...@@ -761,7 +763,7 @@ paths: ...@@ -761,7 +763,7 @@ paths:
required: false required: false
description: An optional label for this batch description: An optional label for this batch
responses: responses:
"200": "201":
description: Returns the newly created postage batch ID description: Returns the newly created postage batch ID
content: content:
application/json: application/json:
......
...@@ -482,7 +482,7 @@ paths: ...@@ -482,7 +482,7 @@ paths:
tags: tags:
- Chequebook - Chequebook
responses: responses:
"200": "201":
description: OK description: OK
content: content:
application/json: application/json:
...@@ -553,7 +553,7 @@ paths: ...@@ -553,7 +553,7 @@ paths:
tags: tags:
- Chequebook - Chequebook
responses: responses:
"200": "201":
description: Transaction hash of the deposit transaction description: Transaction hash of the deposit transaction
content: content:
application/json: application/json:
...@@ -579,7 +579,7 @@ paths: ...@@ -579,7 +579,7 @@ paths:
tags: tags:
- Chequebook - Chequebook
responses: responses:
"200": "201":
description: Transaction hash of the withdraw transaction description: Transaction hash of the withdraw transaction
content: content:
application/json: application/json:
......
...@@ -290,7 +290,7 @@ func TestPostageHeaderError(t *testing.T) { ...@@ -290,7 +290,7 @@ func TestPostageHeaderError(t *testing.T) {
}) })
t.Run(endpoint+": ok batch", func(t *testing.T) { t.Run(endpoint+": ok batch", func(t *testing.T) {
hexbatch := hex.EncodeToString(batchOk) hexbatch := hex.EncodeToString(batchOk)
expCode := http.StatusOK expCode := http.StatusCreated
jsonhttptest.Request(t, client, http.MethodPost, "/"+endpoint, expCode, jsonhttptest.Request(t, client, http.MethodPost, "/"+endpoint, expCode,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, hexbatch), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, hexbatch),
jsonhttptest.WithRequestHeader(api.ContentTypeHeader, "application/octet-stream"), jsonhttptest.WithRequestHeader(api.ContentTypeHeader, "application/octet-stream"),
......
...@@ -95,7 +95,7 @@ func (s *server) bytesUploadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -95,7 +95,7 @@ func (s *server) bytesUploadHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set(SwarmTagHeader, fmt.Sprint(tag.Uid)) w.Header().Set(SwarmTagHeader, fmt.Sprint(tag.Uid))
w.Header().Set("Access-Control-Expose-Headers", SwarmTagHeader) w.Header().Set("Access-Control-Expose-Headers", SwarmTagHeader)
jsonhttp.OK(w, bytesPostResponse{ jsonhttp.Created(w, bytesPostResponse{
Reference: address, Reference: address,
}) })
} }
......
...@@ -54,7 +54,7 @@ func TestBytes(t *testing.T) { ...@@ -54,7 +54,7 @@ func TestBytes(t *testing.T) {
t.Run("upload", func(t *testing.T) { t.Run("upload", func(t *testing.T) {
chunkAddr := swarm.MustParseHexAddress(expHash) chunkAddr := swarm.MustParseHexAddress(expHash)
jsonhttptest.Request(t, client, http.MethodPost, resource, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, resource, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(content)), jsonhttptest.WithRequestBody(bytes.NewReader(content)),
jsonhttptest.WithExpectedJSONResponse(api.BytesPostResponse{ jsonhttptest.WithExpectedJSONResponse(api.BytesPostResponse{
...@@ -77,7 +77,7 @@ func TestBytes(t *testing.T) { ...@@ -77,7 +77,7 @@ func TestBytes(t *testing.T) {
t.Run("upload-with-pinning", func(t *testing.T) { t.Run("upload-with-pinning", func(t *testing.T) {
var res api.BytesPostResponse var res api.BytesPostResponse
jsonhttptest.Request(t, client, http.MethodPost, resource, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, resource, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(content)), jsonhttptest.WithRequestBody(bytes.NewReader(content)),
jsonhttptest.WithRequestHeader(api.SwarmPinHeader, "true"), jsonhttptest.WithRequestHeader(api.SwarmPinHeader, "true"),
......
...@@ -254,7 +254,7 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request, store ...@@ -254,7 +254,7 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request, store
w.Header().Set("ETag", fmt.Sprintf("%q", manifestReference.String())) w.Header().Set("ETag", fmt.Sprintf("%q", manifestReference.String()))
w.Header().Set(SwarmTagHeader, fmt.Sprint(tag.Uid)) w.Header().Set(SwarmTagHeader, fmt.Sprint(tag.Uid))
w.Header().Set("Access-Control-Expose-Headers", SwarmTagHeader) w.Header().Set("Access-Control-Expose-Headers", SwarmTagHeader)
jsonhttp.OK(w, bzzUploadResponse{ jsonhttp.Created(w, bzzUploadResponse{
Reference: manifestReference, Reference: manifestReference,
}) })
} }
......
...@@ -91,7 +91,7 @@ func TestBzzFiles(t *testing.T) { ...@@ -91,7 +91,7 @@ func TestBzzFiles(t *testing.T) {
}, },
}) })
address := swarm.MustParseHexAddress("f30c0aa7e9e2a0ef4c9b1b750ebfeaeb7c7c24da700bb089da19a46e3677824b") address := swarm.MustParseHexAddress("f30c0aa7e9e2a0ef4c9b1b750ebfeaeb7c7c24da700bb089da19a46e3677824b")
jsonhttptest.Request(t, client, http.MethodPost, fileUploadResource, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, fileUploadResource, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(tr), jsonhttptest.WithRequestBody(tr),
jsonhttptest.WithRequestHeader("Content-Type", api.ContentTypeTar), jsonhttptest.WithRequestHeader("Content-Type", api.ContentTypeTar),
...@@ -141,7 +141,7 @@ func TestBzzFiles(t *testing.T) { ...@@ -141,7 +141,7 @@ func TestBzzFiles(t *testing.T) {
}, },
}) })
address := swarm.MustParseHexAddress("f30c0aa7e9e2a0ef4c9b1b750ebfeaeb7c7c24da700bb089da19a46e3677824b") address := swarm.MustParseHexAddress("f30c0aa7e9e2a0ef4c9b1b750ebfeaeb7c7c24da700bb089da19a46e3677824b")
jsonhttptest.Request(t, client, http.MethodPost, fileUploadResource, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, fileUploadResource, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestHeader(api.SwarmPinHeader, "true"), jsonhttptest.WithRequestHeader(api.SwarmPinHeader, "true"),
jsonhttptest.WithRequestBody(tr), jsonhttptest.WithRequestBody(tr),
...@@ -176,7 +176,7 @@ func TestBzzFiles(t *testing.T) { ...@@ -176,7 +176,7 @@ func TestBzzFiles(t *testing.T) {
var resp api.BzzUploadResponse var resp api.BzzUploadResponse
jsonhttptest.Request(t, client, http.MethodPost, jsonhttptest.Request(t, client, http.MethodPost,
fileUploadResource+"?name="+fileName, http.StatusOK, fileUploadResource+"?name="+fileName, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(simpleData)), jsonhttptest.WithRequestBody(bytes.NewReader(simpleData)),
jsonhttptest.WithRequestHeader(api.SwarmEncryptHeader, "True"), jsonhttptest.WithRequestHeader(api.SwarmEncryptHeader, "True"),
...@@ -207,7 +207,7 @@ func TestBzzFiles(t *testing.T) { ...@@ -207,7 +207,7 @@ func TestBzzFiles(t *testing.T) {
rootHash := "4f9146b3813ccbd7ce45a18be23763d7e436ab7a3982ef39961c6f3cd4da1dcf" rootHash := "4f9146b3813ccbd7ce45a18be23763d7e436ab7a3982ef39961c6f3cd4da1dcf"
jsonhttptest.Request(t, client, http.MethodPost, jsonhttptest.Request(t, client, http.MethodPost,
fileUploadResource+"?name="+fileName, http.StatusOK, fileUploadResource+"?name="+fileName, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(simpleData)), jsonhttptest.WithRequestBody(bytes.NewReader(simpleData)),
jsonhttptest.WithExpectedJSONResponse(api.BzzUploadResponse{ jsonhttptest.WithExpectedJSONResponse(api.BzzUploadResponse{
...@@ -248,7 +248,7 @@ func TestBzzFiles(t *testing.T) { ...@@ -248,7 +248,7 @@ func TestBzzFiles(t *testing.T) {
</html>` </html>`
rcvdHeader := jsonhttptest.Request(t, client, http.MethodPost, rcvdHeader := jsonhttptest.Request(t, client, http.MethodPost,
fileUploadResource+"?name="+fileName, http.StatusOK, fileUploadResource+"?name="+fileName, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(strings.NewReader(sampleHtml)), jsonhttptest.WithRequestBody(strings.NewReader(sampleHtml)),
jsonhttptest.WithExpectedJSONResponse(api.BzzUploadResponse{ jsonhttptest.WithExpectedJSONResponse(api.BzzUploadResponse{
...@@ -287,7 +287,7 @@ func TestBzzFiles(t *testing.T) { ...@@ -287,7 +287,7 @@ func TestBzzFiles(t *testing.T) {
rootHash := "65148cd89b58e91616773f5acea433f7b5a6274f2259e25f4893a332b74a7e28" rootHash := "65148cd89b58e91616773f5acea433f7b5a6274f2259e25f4893a332b74a7e28"
jsonhttptest.Request(t, client, http.MethodPost, jsonhttptest.Request(t, client, http.MethodPost,
fileUploadResource+"?name="+fileName, http.StatusOK, fileUploadResource+"?name="+fileName, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(simpleData)), jsonhttptest.WithRequestBody(bytes.NewReader(simpleData)),
jsonhttptest.WithExpectedJSONResponse(api.BzzUploadResponse{ jsonhttptest.WithExpectedJSONResponse(api.BzzUploadResponse{
...@@ -416,7 +416,7 @@ func TestBzzFilesRangeRequests(t *testing.T) { ...@@ -416,7 +416,7 @@ func TestBzzFilesRangeRequests(t *testing.T) {
testOpts = append(testOpts, jsonhttptest.WithRequestHeader(api.SwarmCollectionHeader, "True")) testOpts = append(testOpts, jsonhttptest.WithRequestHeader(api.SwarmCollectionHeader, "True"))
} }
jsonhttptest.Request(t, client, http.MethodPost, upload.uploadEndpoint, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, upload.uploadEndpoint, http.StatusCreated,
testOpts..., testOpts...,
) )
...@@ -541,7 +541,7 @@ func TestFeedIndirection(t *testing.T) { ...@@ -541,7 +541,7 @@ func TestFeedIndirection(t *testing.T) {
} }
// verify directory tar upload response // verify directory tar upload response
jsonhttptest.Request(t, client, http.MethodPost, "/bzz", http.StatusOK, options...) jsonhttptest.Request(t, client, http.MethodPost, "/bzz", http.StatusCreated, options...)
if resp.Reference.String() == "" { if resp.Reference.String() == "" {
t.Fatalf("expected file reference, did not got any") t.Fatalf("expected file reference, did not got any")
......
...@@ -138,7 +138,7 @@ func (s *server) chunkUploadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -138,7 +138,7 @@ func (s *server) chunkUploadHandler(w http.ResponseWriter, r *http.Request) {
} }
w.Header().Set("Access-Control-Expose-Headers", SwarmTagHeader) w.Header().Set("Access-Control-Expose-Headers", SwarmTagHeader)
jsonhttp.OK(w, chunkAddressResponse{Reference: chunk.Address()}) jsonhttp.Created(w, chunkAddressResponse{Reference: chunk.Address()})
} }
func (s *server) chunkGetHandler(w http.ResponseWriter, r *http.Request) { func (s *server) chunkGetHandler(w http.ResponseWriter, r *http.Request) {
......
...@@ -61,7 +61,7 @@ func TestChunkUploadDownload(t *testing.T) { ...@@ -61,7 +61,7 @@ func TestChunkUploadDownload(t *testing.T) {
}) })
t.Run("ok", func(t *testing.T) { t.Run("ok", func(t *testing.T) {
jsonhttptest.Request(t, client, http.MethodPost, chunksEndpoint, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, chunksEndpoint, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())), jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())),
jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: chunk.Address()}), jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: chunk.Address()}),
...@@ -80,7 +80,7 @@ func TestChunkUploadDownload(t *testing.T) { ...@@ -80,7 +80,7 @@ func TestChunkUploadDownload(t *testing.T) {
}) })
t.Run("pin-invalid-value", func(t *testing.T) { t.Run("pin-invalid-value", func(t *testing.T) {
jsonhttptest.Request(t, client, http.MethodPost, chunksEndpoint, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, chunksEndpoint, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())), jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())),
jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: chunk.Address()}), jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: chunk.Address()}),
...@@ -93,7 +93,7 @@ func TestChunkUploadDownload(t *testing.T) { ...@@ -93,7 +93,7 @@ func TestChunkUploadDownload(t *testing.T) {
} }
}) })
t.Run("pin-header-missing", func(t *testing.T) { t.Run("pin-header-missing", func(t *testing.T) {
jsonhttptest.Request(t, client, http.MethodPost, chunksEndpoint, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, chunksEndpoint, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())), jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())),
jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: chunk.Address()}), jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: chunk.Address()}),
...@@ -106,7 +106,7 @@ func TestChunkUploadDownload(t *testing.T) { ...@@ -106,7 +106,7 @@ func TestChunkUploadDownload(t *testing.T) {
}) })
t.Run("pin-ok", func(t *testing.T) { t.Run("pin-ok", func(t *testing.T) {
address := chunk.Address() address := chunk.Address()
jsonhttptest.Request(t, client, http.MethodPost, chunksEndpoint, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, chunksEndpoint, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())), jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())),
jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: address}), jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: address}),
......
...@@ -109,7 +109,7 @@ func (s *server) dirUploadHandler(w http.ResponseWriter, r *http.Request, storer ...@@ -109,7 +109,7 @@ func (s *server) dirUploadHandler(w http.ResponseWriter, r *http.Request, storer
} }
w.Header().Set(SwarmTagHeader, fmt.Sprint(tag.Uid)) w.Header().Set(SwarmTagHeader, fmt.Sprint(tag.Uid))
jsonhttp.OK(w, bzzUploadResponse{ jsonhttp.Created(w, bzzUploadResponse{
Reference: reference, Reference: reference,
}) })
} }
......
...@@ -404,7 +404,7 @@ func TestDirs(t *testing.T) { ...@@ -404,7 +404,7 @@ func TestDirs(t *testing.T) {
} }
// verify directory tar upload response // verify directory tar upload response
jsonhttptest.Request(t, client, http.MethodPost, dirUploadResource, http.StatusOK, options...) jsonhttptest.Request(t, client, http.MethodPost, dirUploadResource, http.StatusCreated, options...)
if resp.Reference.String() == "" { if resp.Reference.String() == "" {
t.Fatalf("expected file reference, did not got any") t.Fatalf("expected file reference, did not got any")
...@@ -437,7 +437,7 @@ func TestDirs(t *testing.T) { ...@@ -437,7 +437,7 @@ func TestDirs(t *testing.T) {
} }
// verify directory tar upload response // verify directory tar upload response
jsonhttptest.Request(t, client, http.MethodPost, dirUploadResource, http.StatusOK, options...) jsonhttptest.Request(t, client, http.MethodPost, dirUploadResource, http.StatusCreated, options...)
if resp.Reference.String() == "" { if resp.Reference.String() == "" {
t.Fatalf("expected file reference, did not got any") t.Fatalf("expected file reference, did not got any")
......
...@@ -67,14 +67,14 @@ func TestGatewayMode(t *testing.T) { ...@@ -67,14 +67,14 @@ func TestGatewayMode(t *testing.T) {
}) })
// should work without pinning // should work without pinning
jsonhttptest.Request(t, client, http.MethodPost, "/chunks", http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/chunks", http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())), jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())),
) )
jsonhttptest.Request(t, client, http.MethodPost, "/chunks/0773a91efd6547c754fc1d95fb1c62c7d1b47f959c2caa685dfec8736da95c1c", http.StatusForbidden, forbiddenResponseOption, headerOption) jsonhttptest.Request(t, client, http.MethodPost, "/chunks/0773a91efd6547c754fc1d95fb1c62c7d1b47f959c2caa685dfec8736da95c1c", http.StatusForbidden, forbiddenResponseOption, headerOption)
jsonhttptest.Request(t, client, http.MethodPost, "/bytes", http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/bytes", http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())), jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())),
) // should work without pinning ) // should work without pinning
...@@ -91,7 +91,7 @@ func TestGatewayMode(t *testing.T) { ...@@ -91,7 +91,7 @@ func TestGatewayMode(t *testing.T) {
Code: http.StatusForbidden, Code: http.StatusForbidden,
}) })
jsonhttptest.Request(t, client, http.MethodPost, "/bytes", http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/bytes", http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())), jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())),
) // should work without pinning ) // should work without pinning
......
...@@ -44,7 +44,7 @@ func (s *server) pinRootHash(w http.ResponseWriter, r *http.Request) { ...@@ -44,7 +44,7 @@ func (s *server) pinRootHash(w http.ResponseWriter, r *http.Request) {
return return
} }
jsonhttp.OK(w, nil) jsonhttp.Created(w, nil)
} }
// unpinRootHash unpin's an already pinned root hash. This method is idempotent. // unpinRootHash unpin's an already pinned root hash. This method is idempotent.
......
...@@ -45,10 +45,10 @@ func checkPinHandlers(t *testing.T, client *http.Client, rootHash string) { ...@@ -45,10 +45,10 @@ func checkPinHandlers(t *testing.T, client *http.Client, rootHash string) {
}), }),
) )
jsonhttptest.Request(t, client, http.MethodPost, pinsAddressPath, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, pinsAddressPath, http.StatusCreated,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK), Message: http.StatusText(http.StatusCreated),
Code: http.StatusOK, Code: http.StatusCreated,
}), }),
) )
...@@ -93,7 +93,7 @@ func TestPinHandlers(t *testing.T) { ...@@ -93,7 +93,7 @@ func TestPinHandlers(t *testing.T) {
t.Run("bytes", func(t *testing.T) { t.Run("bytes", func(t *testing.T) {
const rootHash = "838d0a193ecd1152d1bb1432d5ecc02398533b2494889e23b8bd5ace30ac2aeb" const rootHash = "838d0a193ecd1152d1bb1432d5ecc02398533b2494889e23b8bd5ace30ac2aeb"
jsonhttptest.Request(t, client, http.MethodPost, "/bytes", http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/bytes", http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(strings.NewReader("this is a simple text")), jsonhttptest.WithRequestBody(strings.NewReader("this is a simple text")),
jsonhttptest.WithExpectedJSONResponse(api.BzzUploadResponse{ jsonhttptest.WithExpectedJSONResponse(api.BzzUploadResponse{
...@@ -110,7 +110,7 @@ func TestPinHandlers(t *testing.T) { ...@@ -110,7 +110,7 @@ func TestPinHandlers(t *testing.T) {
dir: "", dir: "",
}}) }})
rootHash := "9e178dbd1ed4b748379e25144e28dfb29c07a4b5114896ef454480115a56b237" rootHash := "9e178dbd1ed4b748379e25144e28dfb29c07a4b5114896ef454480115a56b237"
jsonhttptest.Request(t, client, http.MethodPost, "/bzz", http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/bzz", http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(tarReader), jsonhttptest.WithRequestBody(tarReader),
jsonhttptest.WithRequestHeader("Content-Type", api.ContentTypeTar), jsonhttptest.WithRequestHeader("Content-Type", api.ContentTypeTar),
...@@ -122,7 +122,7 @@ func TestPinHandlers(t *testing.T) { ...@@ -122,7 +122,7 @@ func TestPinHandlers(t *testing.T) {
checkPinHandlers(t, client, rootHash) checkPinHandlers(t, client, rootHash)
rootHash = "dd13a5a6cc9db3ef514d645e6719178dbfb1a90b49b9262cafce35b0d27cf245" rootHash = "dd13a5a6cc9db3ef514d645e6719178dbfb1a90b49b9262cafce35b0d27cf245"
jsonhttptest.Request(t, client, http.MethodPost, "/bzz?name=somefile.txt", http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/bzz?name=somefile.txt", http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestHeader("Content-Type", "text/plain"), jsonhttptest.WithRequestHeader("Content-Type", "text/plain"),
jsonhttptest.WithRequestBody(strings.NewReader("this is a simple text")), jsonhttptest.WithRequestBody(strings.NewReader("this is a simple text")),
...@@ -138,7 +138,7 @@ func TestPinHandlers(t *testing.T) { ...@@ -138,7 +138,7 @@ func TestPinHandlers(t *testing.T) {
chunk = testingc.GenerateTestRandomChunk() chunk = testingc.GenerateTestRandomChunk()
rootHash = chunk.Address().String() rootHash = chunk.Address().String()
) )
jsonhttptest.Request(t, client, http.MethodPost, "/chunks", http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/chunks", http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())), jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())),
jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{ jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{
......
...@@ -68,7 +68,7 @@ func (s *server) postageCreateHandler(w http.ResponseWriter, r *http.Request) { ...@@ -68,7 +68,7 @@ func (s *server) postageCreateHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
jsonhttp.OK(w, &postageCreateResponse{ jsonhttp.Created(w, &postageCreateResponse{
BatchID: batchID, BatchID: batchID,
}) })
} }
......
...@@ -50,7 +50,7 @@ func TestPostageCreateStamp(t *testing.T) { ...@@ -50,7 +50,7 @@ func TestPostageCreateStamp(t *testing.T) {
PostageContract: contract, PostageContract: contract,
}) })
jsonhttptest.Request(t, client, http.MethodPost, createBatch(initialBalance, depth, label), http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, createBatch(initialBalance, depth, label), http.StatusCreated,
jsonhttptest.WithExpectedJSONResponse(&api.PostageCreateResponse{ jsonhttptest.WithExpectedJSONResponse(&api.PostageCreateResponse{
BatchID: batchID, BatchID: batchID,
}), }),
......
...@@ -94,7 +94,7 @@ func (s *server) pssPostHandler(w http.ResponseWriter, r *http.Request) { ...@@ -94,7 +94,7 @@ func (s *server) pssPostHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
jsonhttp.OK(w, nil) jsonhttp.Created(w, nil)
} }
func (s *server) pssWsHandler(w http.ResponseWriter, r *http.Request) { func (s *server) pssWsHandler(w http.ResponseWriter, r *http.Request) {
......
...@@ -229,7 +229,7 @@ func TestPssSend(t *testing.T) { ...@@ -229,7 +229,7 @@ func TestPssSend(t *testing.T) {
t.Run("ok batch", func(t *testing.T) { t.Run("ok batch", func(t *testing.T) {
hexbatch := hex.EncodeToString(batchOk) hexbatch := hex.EncodeToString(batchOk)
jsonhttptest.Request(t, client, http.MethodPost, "/pss/send/to/12", http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/pss/send/to/12", http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, hexbatch), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, hexbatch),
jsonhttptest.WithRequestBody(bytes.NewReader(payload)), jsonhttptest.WithRequestBody(bytes.NewReader(payload)),
) )
...@@ -243,12 +243,12 @@ func TestPssSend(t *testing.T) { ...@@ -243,12 +243,12 @@ func TestPssSend(t *testing.T) {
}) })
t.Run("ok", func(t *testing.T) { t.Run("ok", func(t *testing.T) {
jsonhttptest.Request(t, client, http.MethodPost, "/pss/send/testtopic/12?recipient="+recipient, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/pss/send/testtopic/12?recipient="+recipient, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(payload)), jsonhttptest.WithRequestBody(bytes.NewReader(payload)),
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: "OK", Message: "Created",
Code: http.StatusOK, Code: http.StatusCreated,
}), }),
) )
waitDone(t, &mtx, &done) waitDone(t, &mtx, &done)
...@@ -264,12 +264,12 @@ func TestPssSend(t *testing.T) { ...@@ -264,12 +264,12 @@ func TestPssSend(t *testing.T) {
}) })
t.Run("without recipient", func(t *testing.T) { t.Run("without recipient", func(t *testing.T) {
jsonhttptest.Request(t, client, http.MethodPost, "/pss/send/testtopic/12", http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, "/pss/send/testtopic/12", http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(payload)), jsonhttptest.WithRequestBody(bytes.NewReader(payload)),
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: "OK", Message: "Created",
Code: http.StatusOK, Code: http.StatusCreated,
}), }),
) )
waitDone(t, &mtx, &done) waitDone(t, &mtx, &done)
......
...@@ -106,13 +106,13 @@ func TestTags(t *testing.T) { ...@@ -106,13 +106,13 @@ func TestTags(t *testing.T) {
jsonhttptest.WithUnmarshalJSONResponse(&tr), jsonhttptest.WithUnmarshalJSONResponse(&tr),
) )
_ = jsonhttptest.Request(t, client, http.MethodPost, chunksResource, http.StatusOK, _ = jsonhttptest.Request(t, client, http.MethodPost, chunksResource, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())), jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())),
jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: chunk.Address()}), jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: chunk.Address()}),
) )
rcvdHeaders := jsonhttptest.Request(t, client, http.MethodPost, chunksResource, http.StatusOK, rcvdHeaders := jsonhttptest.Request(t, client, http.MethodPost, chunksResource, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())), jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())),
jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: chunk.Address()}), jsonhttptest.WithExpectedJSONResponse(api.ChunkAddressResponse{Reference: chunk.Address()}),
...@@ -232,7 +232,7 @@ func TestTags(t *testing.T) { ...@@ -232,7 +232,7 @@ func TestTags(t *testing.T) {
addr := test.RandomAddress() addr := test.RandomAddress()
// upload content with tag // upload content with tag
jsonhttptest.Request(t, client, http.MethodPost, chunksResource, http.StatusOK, jsonhttptest.Request(t, client, http.MethodPost, chunksResource, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())), jsonhttptest.WithRequestBody(bytes.NewReader(chunk.Data())),
jsonhttptest.WithRequestHeader(api.SwarmTagHeader, fmt.Sprint(tagId)), jsonhttptest.WithRequestHeader(api.SwarmTagHeader, fmt.Sprint(tagId)),
...@@ -272,7 +272,7 @@ func TestTags(t *testing.T) { ...@@ -272,7 +272,7 @@ func TestTags(t *testing.T) {
expectedResponse := api.BzzUploadResponse{Reference: expectedHash} expectedResponse := api.BzzUploadResponse{Reference: expectedHash}
respHeaders := jsonhttptest.Request(t, client, http.MethodPost, respHeaders := jsonhttptest.Request(t, client, http.MethodPost,
bzzResource+"?name=somefile", http.StatusOK, bzzResource+"?name=somefile", http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader([]byte("some data"))), jsonhttptest.WithRequestBody(bytes.NewReader([]byte("some data"))),
jsonhttptest.WithExpectedJSONResponse(expectedResponse), jsonhttptest.WithExpectedJSONResponse(expectedResponse),
...@@ -295,7 +295,7 @@ func TestTags(t *testing.T) { ...@@ -295,7 +295,7 @@ func TestTags(t *testing.T) {
expectedHash := swarm.MustParseHexAddress("42bc27c9137c93705ffbc2945fa1aab0e8e1826f1500b7f06f6e3f86f617213b") expectedHash := swarm.MustParseHexAddress("42bc27c9137c93705ffbc2945fa1aab0e8e1826f1500b7f06f6e3f86f617213b")
expectedResponse := api.BzzUploadResponse{Reference: expectedHash} expectedResponse := api.BzzUploadResponse{Reference: expectedHash}
respHeaders := jsonhttptest.Request(t, client, http.MethodPost, bzzResource, http.StatusOK, respHeaders := jsonhttptest.Request(t, client, http.MethodPost, bzzResource, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(tarReader), jsonhttptest.WithRequestBody(tarReader),
jsonhttptest.WithRequestHeader(api.SwarmCollectionHeader, "True"), jsonhttptest.WithRequestHeader(api.SwarmCollectionHeader, "True"),
...@@ -334,7 +334,7 @@ func TestTags(t *testing.T) { ...@@ -334,7 +334,7 @@ func TestTags(t *testing.T) {
copy(content[swarm.ChunkSize:], dataChunk) copy(content[swarm.ChunkSize:], dataChunk)
copy(content[:swarm.ChunkSize], dataChunk) copy(content[:swarm.ChunkSize], dataChunk)
rcvdHeaders := jsonhttptest.Request(t, client, http.MethodPost, bytesResource, http.StatusOK, rcvdHeaders := jsonhttptest.Request(t, client, http.MethodPost, bytesResource, http.StatusCreated,
jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr),
jsonhttptest.WithRequestBody(bytes.NewReader(content)), jsonhttptest.WithRequestBody(bytes.NewReader(content)),
jsonhttptest.WithExpectedJSONResponse(fileUploadResponse{ jsonhttptest.WithExpectedJSONResponse(fileUploadResponse{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment