Skip to content

Commit

Permalink
Add TestUniqueConstraintViolation
Browse files Browse the repository at this point in the history
  • Loading branch information
ostafen committed Apr 20, 2024
1 parent 8721fc8 commit 18e6955
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion embedded/document/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: BUSL-1.1
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://mariadb.com/bsl11/
https://mariadb.com/bsl11/
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -374,6 +374,41 @@ func TestListCollections(t *testing.T) {
require.Equal(t, len(collections), len(collectionList))
}

func TestUniqueConstraintViolation(t *testing.T) {
engine := makeEngine(t)

err := engine.CreateCollection(
context.Background(),
"admin",
"testCollection",
"",
[]*protomodel.Field{
{Name: "name", Type: protomodel.FieldType_STRING},
{Name: "surname", Type: protomodel.FieldType_STRING},
},
[]*protomodel.Index{
{Fields: []string{"name"}, IsUnique: true},
},
)
require.NoError(t, err)

_, _, err = engine.InsertDocument(context.Background(), "admin", "testCollection", &structpb.Struct{
Fields: map[string]*structpb.Value{
"name": structpb.NewStringValue("John"),
"surname": structpb.NewStringValue("Doe"),
},
})
require.NoError(t, err)

_, _, err = engine.InsertDocument(context.Background(), "admin", "testCollection", &structpb.Struct{
Fields: map[string]*structpb.Value{
"name": structpb.NewStringValue("John"),
"surname": structpb.NewStringValue("Moore"),
},
})
require.ErrorIs(t, err, ErrConflict)
}

func TestGetDocument(t *testing.T) {
ctx := context.Background()
engine := makeEngine(t)
Expand Down

0 comments on commit 18e6955

Please sign in to comment.