Skip to content

Commit bc37f62

Browse files
committed
Add new integration test to test injection of the same block
1 parent 4b8fa39 commit bc37f62

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

test/int_bulkblocks.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package main
22

33
import (
4+
"fmt"
45
"net/http"
56
"net/url"
67
"testing"
78

9+
"github.com/dmwm/dbs2go/dbs"
810
"github.com/dmwm/dbs2go/web"
911
)
1012

@@ -106,3 +108,38 @@ func getBulkBlocksLargeFileLumiInsertTestTable(t *testing.T) EndpointTestCase {
106108
},
107109
}
108110
}
111+
112+
// test that we will get DBSError when use the same block with bulkblocks API
113+
func bulkblocksTheSameBlockInsertTestTable(t *testing.T) EndpointTestCase {
114+
// there are multiple blocks to insert, but everything is started from parent blocks
115+
bName := TestData.ParentStepchainBlock
116+
reason := fmt.Sprintf("Block %s already exists", bName)
117+
msg := "Data already exist in DBS"
118+
dbsError := dbs.DBSError{
119+
Function: "dbs.bulkblocks.checkBlockExist",
120+
Code: dbs.BlockAlreadyExists,
121+
Reason: reason,
122+
Message: msg,
123+
}
124+
hrec := createHTTPError("POST", "/dbs/bulkblocks")
125+
errorResp := createServerErrorResponse(hrec, &dbsError)
126+
return EndpointTestCase{
127+
description: "Test concurrent bulkblocks with the same block name twice",
128+
defaultHandler: web.BulkBlocksHandler,
129+
defaultEndpoint: "/dbs/bulkblocks",
130+
testCases: []testCase{
131+
{
132+
description: "Test POST with the same block",
133+
serverType: "DBSWriter",
134+
method: "POST",
135+
concurrentBulkBlocks: true,
136+
input: BulkBlocksData.ConcurrentParentData,
137+
output: []Response{
138+
errorResp,
139+
},
140+
handler: web.BulkBlocksHandler,
141+
respCode: http.StatusBadRequest,
142+
},
143+
},
144+
}
145+
}

test/integration_cases.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ func LoadTestCases(t *testing.T, filepath string, bulkblockspath string, largeBu
570570
fileParentsTestTable := getFileParentsTestTable(t)
571571
largeFileLumiInsertTestTable := getBulkBlocksLargeFileLumiInsertTestTable(t)
572572
filesReaderAfterChunkTestTable := getFileLumiChunkTestTable(t)
573+
theSameBlockWithBulkblocks := bulkblocksTheSameBlockInsertTestTable(t)
573574

574575
endpointTestCases = append(
575576
endpointTestCases,
@@ -599,6 +600,7 @@ func LoadTestCases(t *testing.T, filepath string, bulkblockspath string, largeBu
599600
fileParentsTestTable,
600601
largeFileLumiInsertTestTable,
601602
filesReaderAfterChunkTestTable,
603+
theSameBlockWithBulkblocks,
602604
)
603605
// endpointTestCases = append(endpointTestCases, largeFileLumiInsertTestTable)
604606
// endpointTestCases = append(endpointTestCases, filesReaderAfterChunkTestTable)

test/integration_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ func runTestWorkflow(t *testing.T, c EndpointTestCase) {
9494
var d []dbs.Record
9595
// decode and verify the GET request
9696
// Also handles fileArray using POST to fetch data
97-
if v.method == "GET" || (v.method == "POST" && strings.Contains(endpoint, "fileArray")) {
97+
if v.method == "GET" || (v.method == "POST" && strings.Contains(endpoint, "fileArray")) || (v.method == "POST" && strings.Contains(endpoint, "bulkblocks")) {
98+
// if v.method == "GET" || (v.method == "POST" && strings.Contains(endpoint, "fileArray")) {
9899
err = json.NewDecoder(r.Body).Decode(&d)
99100
if err != nil {
100101
t.Fatalf("Failed to decode body, %v", err)
@@ -108,6 +109,9 @@ func runTestWorkflow(t *testing.T, c EndpointTestCase) {
108109
} else if v.method == "POST" {
109110
rURL := parseURL(t, server.URL, endpoint, v.params)
110111
rr, err := respRecorder("GET", rURL.RequestURI(), nil, handler)
112+
// VK: why we use respRecorder with GET method here?
113+
// I would expect something like:
114+
// rr, err := respRecorder("POST", endpoint, reader, handler)
111115
if err != nil {
112116
t.Error(err)
113117
}

0 commit comments

Comments
 (0)