Commit d6667744 authored by Nemanja Zbiljić's avatar Nemanja Zbiljić Committed by GitHub

Simplify JSON response extraction in tests (#1085)

parent 781f7330
......@@ -8,7 +8,6 @@ import (
"archive/tar"
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
......@@ -279,12 +278,12 @@ Disallow: /`),
// tar all the test case files
tarReader := tarFiles(t, tc.files)
var respBytes []byte
var resp api.FileUploadResponse
options := []jsonhttptest.Option{
jsonhttptest.WithRequestBody(tarReader),
jsonhttptest.WithRequestHeader("Content-Type", api.ContentTypeTar),
jsonhttptest.WithPutResponseBody(&respBytes),
jsonhttptest.WithUnmarshalJSONResponse(&resp),
}
if tc.indexFilenameOption != nil {
options = append(options, tc.indexFilenameOption)
......@@ -299,15 +298,6 @@ Disallow: /`),
// verify directory tar upload response
jsonhttptest.Request(t, client, http.MethodPost, dirUploadResource, http.StatusOK, options...)
read := bytes.NewReader(respBytes)
// get the reference
var resp api.FileUploadResponse
err := json.NewDecoder(read).Decode(&resp)
if err != nil {
t.Fatal(err)
}
if resp.Reference.String() == "" {
t.Fatalf("expected file reference, did not got any")
}
......
......@@ -346,12 +346,9 @@ func TestRangeRequests(t *testing.T) {
uploadReference := upload.reference
var respBytes []byte
jsonhttptest.Request(t, client, http.MethodPost, upload.uploadEndpoint, http.StatusOK,
jsonhttptest.WithRequestBody(upload.reader),
jsonhttptest.WithRequestHeader("Content-Type", upload.contentType),
jsonhttptest.WithPutResponseBody(&respBytes),
)
for _, tc := range ranges {
......
......@@ -5,8 +5,6 @@
package api_test
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"testing"
......@@ -71,20 +69,13 @@ func TestPinBzzHandler(t *testing.T) {
expectedChunkCount := 7
var respBytes []byte
// get the reference as everytime it will change because of random encryption key
var resp api.ListPinnedChunksResponse
jsonhttptest.Request(t, client, http.MethodGet, pinChunksResource, http.StatusOK,
jsonhttptest.WithPutResponseBody(&respBytes),
jsonhttptest.WithUnmarshalJSONResponse(&resp),
)
read := bytes.NewReader(respBytes)
var resp api.ListPinnedChunksResponse
err := json.NewDecoder(read).Decode(&resp)
if err != nil {
t.Fatal(err)
}
if expectedChunkCount != len(resp.Chunks) {
t.Fatalf("expected to find %d pinned chunks, got %d", expectedChunkCount, len(resp.Chunks))
}
......
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