mirror of
https://github.com/hanzoai/docdb.git
synced 2026-10-30 18:39:39 +00:00
zip's registration is a verb method on the group, so an operation reads as the group answering it rather than a function taking the group, and a route that is not a typed operation says which method it answers with. The package-level form and the Router interface it existed to accept any target through are both gone. The toolchain and the pin move together, deliberately. Below zip v1.36.50 the JSON encoder was selected on a build tag, so a repo whose go directive rises first writes a wire that is neither the old release's nor the new one's until the pin catches up. Co-authored-by: Hanzo Dev <[email protected]>
142 lines
3.9 KiB
Go
142 lines
3.9 KiB
Go
// Copyright 2021 DocDB Inc.
|
|
//
|
|
// 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 integration
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
"github.com/hanzoai/docdb/integration/setup"
|
|
"github.com/hanzoai/docdb/integration/shareddata"
|
|
)
|
|
|
|
// TestDeleteSimple checks simple cases of doc deletion.
|
|
func TestDeleteSimple(t *testing.T) {
|
|
t.Parallel()
|
|
ctx, collection := setup.Setup(t, shareddata.Scalars, shareddata.Composites)
|
|
|
|
for name, tc := range map[string]struct {
|
|
collection string
|
|
expectedCount int64
|
|
}{
|
|
"DeleteOne": {
|
|
collection: collection.Name(),
|
|
expectedCount: 1,
|
|
},
|
|
"DeleteFromNonExistingCollection": {
|
|
collection: "doesnotexist",
|
|
expectedCount: 0,
|
|
},
|
|
} {
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
cursor, err := collection.Database().Collection(tc.collection).DeleteOne(ctx, bson.D{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, tc.expectedCount, cursor.DeletedCount)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDelete(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for name, tc := range map[string]struct {
|
|
deletes bson.A // required, set to deletes parameter
|
|
|
|
err *mongo.CommandError // optional, expected error from MongoDB
|
|
altMessage string // optional, alternative error message for DocDB, ignored if empty
|
|
skip string // TODO https://github.com/hanzoai/docdb-DocumentDB/issues/1086
|
|
failsForDocDB string
|
|
}{
|
|
"QueryNotSet": {
|
|
deletes: bson.A{bson.D{}},
|
|
err: &mongo.CommandError{
|
|
Code: 40414,
|
|
Name: "Location40414",
|
|
Message: "BSON field 'delete.deletes.q' is missing but a required field",
|
|
},
|
|
},
|
|
"NotSet": {
|
|
deletes: bson.A{bson.D{{"q", bson.D{{"v", "foo"}}}}},
|
|
err: &mongo.CommandError{
|
|
Code: 40414,
|
|
Name: "Location40414",
|
|
Message: "BSON field 'delete.deletes.limit' is missing but a required field",
|
|
},
|
|
},
|
|
"ValidFloat": {
|
|
deletes: bson.A{bson.D{{"q", bson.D{{"v", "foo"}}}, {"limit", 1.00}}},
|
|
},
|
|
"ValidString": {
|
|
deletes: bson.A{bson.D{{"q", bson.D{{"v", "foo"}}}, {"limit", "1"}}},
|
|
},
|
|
"InvalidFloat": {
|
|
deletes: bson.A{bson.D{{"q", bson.D{{"v", "foo"}}}, {"limit", 42.13}}},
|
|
err: &mongo.CommandError{
|
|
Code: 9,
|
|
Name: "FailedToParse",
|
|
Message: "The limit field in delete objects must be 0 or 1. Got 42.13",
|
|
},
|
|
altMessage: "The limit field in delete objects must be 0 or 1. Got 42",
|
|
},
|
|
"InvalidInt": {
|
|
deletes: bson.A{bson.D{{"q", bson.D{{"v", "foo"}}}, {"limit", 100}}},
|
|
err: &mongo.CommandError{
|
|
Code: 9,
|
|
Name: "FailedToParse",
|
|
Message: "The limit field in delete objects must be 0 or 1. Got 100",
|
|
},
|
|
altMessage: "The 'delete.deletes.limit' field must be 0 or 1. Got 100",
|
|
},
|
|
} {
|
|
t.Run(name, func(tt *testing.T) {
|
|
if tc.skip != "" {
|
|
tt.Skip(tc.skip)
|
|
}
|
|
|
|
tt.Parallel()
|
|
|
|
var t testing.TB = tt
|
|
|
|
if tc.failsForDocDB != "" {
|
|
t = setup.FailsForDocDB(tt, tc.failsForDocDB)
|
|
}
|
|
|
|
require.NotNil(t, tc.deletes, "deletes must not be nil")
|
|
|
|
ctx, collection := setup.Setup(tt)
|
|
|
|
var res bson.D
|
|
err := collection.Database().RunCommand(ctx, bson.D{
|
|
{"delete", collection.Name()},
|
|
{"deletes", tc.deletes},
|
|
}).Decode(&res)
|
|
if tc.err != nil {
|
|
assert.Nil(t, res)
|
|
AssertEqualAltCommandError(t, *tc.err, tc.altMessage, err)
|
|
|
|
return
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
}
|