diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2018-05-02 22:37:26 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2018-05-02 22:37:26 +0200 |
| commit | fc023fb7387772b70496d24449e301cd856634ff (patch) | |
| tree | 2f48bbe0abea40586de9679d229da9e3666357a2 | |
| parent | 714ac4546a1378fec6fbec94096c6ec315214081 (diff) | |
| download | go-schwift-fc023fb7387772b70496d24449e301cd856634ff.tar.gz | |
test coverage for bulk-delete fallback code path
| -rw-r--r-- | bulk.go | 4 | ||||
| -rw-r--r-- | capabilities/package.go | 29 | ||||
| -rw-r--r-- | tests/bulk_delete_test.go | 81 |
3 files changed, 81 insertions, 33 deletions
@@ -26,6 +26,8 @@ import ( "net/url" "strconv" "strings" + + "github.com/majewsky/schwift/capabilities" ) //BulkUploadFormat enumerates possible archive formats for Container.BulkUpload(). @@ -160,7 +162,7 @@ func (a *Account) BulkDelete(objects []*Object, containers []*Container, opts *R if err != nil { return 0, 0, err } - if caps.BulkDelete == nil { + if caps.BulkDelete == nil || !capabilities.AllowBulkDelete { return a.bulkDeleteSingle(objects, containers, opts) } chunkSize := int(caps.BulkDelete.MaximumDeletesPerRequest) diff --git a/capabilities/package.go b/capabilities/package.go new file mode 100644 index 0000000..021f28b --- /dev/null +++ b/capabilities/package.go @@ -0,0 +1,29 @@ +/****************************************************************************** +* +* Copyright 2018 Stefan Majewsky <majewsky@gmx.net> +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +******************************************************************************/ + +//Package capabilities contains feature switches that Schwift's unit tests can +//set to exercise certain fallback code paths in Schwift that they could not +//trigger otherwise. +// +//THIS IS A PRIVATE MODULE. It is not covered by any forwards or backwards +//compatiblity and may be gone at a moment's notice. +package capabilities + +//AllowBulkDelete can be set to false to force Schwift to act as if the server +//does not support bulk deletion. +var AllowBulkDelete = true diff --git a/tests/bulk_delete_test.go b/tests/bulk_delete_test.go index dfe8468..472feb8 100644 --- a/tests/bulk_delete_test.go +++ b/tests/bulk_delete_test.go @@ -24,52 +24,62 @@ import ( "testing" "github.com/majewsky/schwift" + "github.com/majewsky/schwift/capabilities" ) func TestBulkDeleteSuccess(t *testing.T) { testWithAccount(t, func(a *schwift.Account) { - c, err := a.Container("schwift-test-bulkdelete").EnsureExists() - expectSuccess(t, err) - objs, err := createTestObjects(c) - expectSuccess(t, err) + testWithAndWithoutBulkDeleteSupport(func() { + c, err := a.Container("schwift-test-bulkdelete").EnsureExists() + expectSuccess(t, err) + objs, err := createTestObjects(c) + expectSuccess(t, err) - numDeleted, numNotFound, err := c.Account().BulkDelete(objs, nil, nil) - expectSuccess(t, err) - expectInt(t, numDeleted, len(objs)) - expectInt(t, numNotFound, 0) - expectContainerExistence(t, c, true) + numDeleted, numNotFound, err := c.Account().BulkDelete(objs, nil, nil) + expectSuccess(t, err) + expectInt(t, numDeleted, len(objs)) + expectInt(t, numNotFound, 0) + expectContainerExistence(t, c, true) - numDeleted, numNotFound, err = c.Account().BulkDelete(objs, nil, nil) - expectSuccess(t, err) - expectInt(t, numDeleted, 0) - expectInt(t, numNotFound, len(objs)) - expectContainerExistence(t, c, true) + numDeleted, numNotFound, err = c.Account().BulkDelete(objs, nil, nil) + expectSuccess(t, err) + expectInt(t, numDeleted, 0) + expectInt(t, numNotFound, len(objs)) + expectContainerExistence(t, c, true) - objs, err = createTestObjects(c) - expectSuccess(t, err) - cs := []*schwift.Container{c} + objs, err = createTestObjects(c) + expectSuccess(t, err) + cs := []*schwift.Container{c} - numDeleted, numNotFound, err = c.Account().BulkDelete(objs, cs, nil) - expectSuccess(t, err) - expectInt(t, numDeleted, len(objs)+1) - expectInt(t, numNotFound, 0) - expectContainerExistence(t, c, false) + numDeleted, numNotFound, err = c.Account().BulkDelete(objs, cs, nil) + expectSuccess(t, err) + expectInt(t, numDeleted, len(objs)+1) + expectInt(t, numNotFound, 0) + expectContainerExistence(t, c, false) + }) }) } func TestBulkDeleteError(t *testing.T) { testWithContainer(t, func(c *schwift.Container) { - objs, err := createTestObjects(c) - expectSuccess(t, err) - objs = objs[1:] - cs := []*schwift.Container{c} + testWithAndWithoutBulkDeleteSupport(func() { + objs, err := createTestObjects(c) + expectSuccess(t, err) + objs = objs[1:] + cs := []*schwift.Container{c} - //not deleting all objects should lead to 409 Conflict when deleting the Container - numDeleted, numNotFound, err := c.Account().BulkDelete(objs, cs, nil) - expectInt(t, numDeleted, len(objs)) - expectInt(t, numNotFound, 0) - expectError(t, err, "400 Bad Request (+1 object errors)") - expectContainerExistence(t, c, true) + //not deleting all objects should lead to 409 Conflict when deleting the Container + //(NOTE: actual Swift returns 400 here although I don't understand why + //even after reading its code) + numDeleted, numNotFound, err := c.Account().BulkDelete(objs, cs, nil) + expectInt(t, numDeleted, len(objs)) + expectInt(t, numNotFound, 0) + t.Logf("err = %#v\n", err) + if err.Error() != "400 Bad Request (+1 object errors)" { + expectError(t, err, "409 Conflict: Conflict (+1 object errors)") + } + expectContainerExistence(t, c, true) + }) }) } @@ -85,3 +95,10 @@ func createTestObjects(c *schwift.Container) ([]*schwift.Object, error) { } return objs, nil } + +func testWithAndWithoutBulkDeleteSupport(action func()) { + capabilities.AllowBulkDelete = false + action() + capabilities.AllowBulkDelete = true + action() +} |
