File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,24 @@ func TestSupportedDialectorWithErrDuplicatedKeyNegative(t *testing.T) {
218218 if ! errors .Is (err , gorm .ErrDuplicatedKey ) {
219219 t .Errorf ("expected ErrDuplicatedKey on unique Code, got: %v" , err )
220220 }
221+
222+ var cities []City
223+ if err := db .Find (& cities , "code = ?" , "P1" ).Error ; err != nil {
224+ t .Fatalf ("failed to fetch cities: %v" , err )
225+ }
226+ if len (cities ) != 1 {
227+ t .Fatalf ("expected 1 city with code 'P1', found %d" , len (cities ))
228+ }
229+ if cities [0 ].Name != "Paris" {
230+ t .Errorf ("expected city name 'Paris', got '%s'" , cities [0 ].Name )
231+ }
232+
233+ if err := db .Create (& City {Name : "NullCodeCity" , Code : "" }).Error ; err != nil {
234+ t .Fatalf ("failed to create record with empty Code: %v" , err )
235+ }
236+ if err := db .Create (& City {Name : "NullCodeCity2" }).Error ; err != nil {
237+ t .Fatalf ("failed to create second record with NULL Code: %v" , err )
238+ }
221239}
222240
223241func TestSupportedDialectorWithErrForeignKeyViolatedNegative (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments