diff --git a/test/int_bulkblocks.go b/test/int_bulkblocks.go index 761b7d3..371ff80 100644 --- a/test/int_bulkblocks.go +++ b/test/int_bulkblocks.go @@ -1,10 +1,12 @@ package main import ( + "fmt" "net/http" "net/url" "testing" + "github.com/dmwm/dbs2go/dbs" "github.com/dmwm/dbs2go/web" ) @@ -106,3 +108,38 @@ func getBulkBlocksLargeFileLumiInsertTestTable(t *testing.T) EndpointTestCase { }, } } + +// test that we will get DBSError when use the same block with bulkblocks API +func bulkblocksTheSameBlockInsertTestTable(t *testing.T) EndpointTestCase { + // there are multiple blocks to insert, but everything is started from parent blocks + bName := TestData.ParentStepchainBlock + reason := fmt.Sprintf("Block %s already exists", bName) + msg := "Data already exist in DBS" + dbsError := dbs.DBSError{ + Function: "dbs.bulkblocks.checkBlockExist", + Code: dbs.BlockAlreadyExists, + Reason: reason, + Message: msg, + } + hrec := createHTTPError("POST", "/dbs/bulkblocks") + errorResp := createServerErrorResponse(hrec, &dbsError) + return EndpointTestCase{ + description: "Test concurrent bulkblocks with the same block name twice", + defaultHandler: web.BulkBlocksHandler, + defaultEndpoint: "/dbs/bulkblocks", + testCases: []testCase{ + { + description: "Test POST with the same block", + serverType: "DBSWriter", + method: "POST", + concurrentBulkBlocks: true, + input: BulkBlocksData.ConcurrentParentData, + output: []Response{ + errorResp, + }, + handler: web.BulkBlocksHandler, + respCode: http.StatusBadRequest, + }, + }, + } +} diff --git a/test/integration_cases.go b/test/integration_cases.go index d4e6d1c..e61ea15 100644 --- a/test/integration_cases.go +++ b/test/integration_cases.go @@ -570,6 +570,7 @@ func LoadTestCases(t *testing.T, filepath string, bulkblockspath string, largeBu fileParentsTestTable := getFileParentsTestTable(t) largeFileLumiInsertTestTable := getBulkBlocksLargeFileLumiInsertTestTable(t) filesReaderAfterChunkTestTable := getFileLumiChunkTestTable(t) + theSameBlockWithBulkblocks := bulkblocksTheSameBlockInsertTestTable(t) endpointTestCases = append( endpointTestCases, @@ -599,6 +600,7 @@ func LoadTestCases(t *testing.T, filepath string, bulkblockspath string, largeBu fileParentsTestTable, largeFileLumiInsertTestTable, filesReaderAfterChunkTestTable, + theSameBlockWithBulkblocks, ) // endpointTestCases = append(endpointTestCases, largeFileLumiInsertTestTable) // endpointTestCases = append(endpointTestCases, filesReaderAfterChunkTestTable) diff --git a/test/integration_test.go b/test/integration_test.go index 7359717..3c56ed9 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -94,7 +94,8 @@ func runTestWorkflow(t *testing.T, c EndpointTestCase) { var d []dbs.Record // decode and verify the GET request // Also handles fileArray using POST to fetch data - if v.method == "GET" || (v.method == "POST" && strings.Contains(endpoint, "fileArray")) { + if v.method == "GET" || (v.method == "POST" && strings.Contains(endpoint, "fileArray")) || (v.method == "POST" && strings.Contains(endpoint, "bulkblocks")) { + // if v.method == "GET" || (v.method == "POST" && strings.Contains(endpoint, "fileArray")) { err = json.NewDecoder(r.Body).Decode(&d) if err != nil { t.Fatalf("Failed to decode body, %v", err) @@ -108,6 +109,9 @@ func runTestWorkflow(t *testing.T, c EndpointTestCase) { } else if v.method == "POST" { rURL := parseURL(t, server.URL, endpoint, v.params) rr, err := respRecorder("GET", rURL.RequestURI(), nil, handler) + // VK: why we use respRecorder with GET method here? + // I would expect something like: + // rr, err := respRecorder("POST", endpoint, reader, handler) if err != nil { t.Error(err) }