MCPcopy
hub / github.com/ent/ent / TestBatchCreate

Function TestBatchCreate

dialect/sql/sqlgraph/graph_test.go:1471–1671  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1469}
1470
1471func TestBatchCreate(t *testing.T) {
1472 tests := []struct {
1473 name string
1474 spec *BatchCreateSpec
1475 expect func(sqlmock.Sqlmock)
1476 wantErr bool
1477 }{
1478 {
1479 name: "empty",
1480 spec: &BatchCreateSpec{},
1481 expect: func(m sqlmock.Sqlmock) {
1482 m.ExpectBegin()
1483 m.ExpectCommit()
1484 },
1485 },
1486 {
1487 name: "fields with modifiers",
1488 spec: &BatchCreateSpec{
1489 Nodes: []*CreateSpec{
1490 {
1491 Table: "users",
1492 ID: &FieldSpec{Column: "id", Type: field.TypeInt},
1493 Fields: []*FieldSpec{
1494 {Column: "age", Type: field.TypeInt, Value: 32},
1495 {Column: "name", Type: field.TypeString, Value: "a8m"},
1496 {Column: "active", Type: field.TypeBool, Value: false},
1497 },
1498 },
1499 {
1500 Table: "users",
1501 ID: &FieldSpec{Column: "id", Type: field.TypeInt},
1502 Fields: []*FieldSpec{
1503 {Column: "age", Type: field.TypeInt, Value: 30},
1504 {Column: "name", Type: field.TypeString, Value: "nati"},
1505 {Column: "active", Type: field.TypeBool, Value: true},
1506 },
1507 },
1508 },
1509 OnConflict: []sql.ConflictOption{
1510 sql.ResolveWithIgnore(),
1511 },
1512 },
1513 expect: func(m sqlmock.Sqlmock) {
1514 m.ExpectExec(escape("INSERT INTO `users` (`active`, `age`, `name`) VALUES (?, ?, ?), (?, ?, ?) ON DUPLICATE KEY UPDATE `active` = `users`.`active`, `age` = `users`.`age`, `name` = `users`.`name`")).
1515 WithArgs(false, 32, "a8m", true, 30, "nati").
1516 WillReturnResult(sqlmock.NewResult(10, 2))
1517 },
1518 },
1519 {
1520 name: "no tx",
1521 spec: &BatchCreateSpec{
1522 Nodes: []*CreateSpec{
1523 {
1524 Table: "users",
1525 ID: &FieldSpec{Column: "id", Type: field.TypeInt},
1526 Fields: []*FieldSpec{
1527 {Column: "age", Type: field.TypeInt, Value: 32},
1528 {Column: "name", Type: field.TypeString, Value: "a8m"},

Callers

nothing calls this directly

Calls 6

ResolveWithIgnoreFunction · 0.92
OpenDBFunction · 0.92
BatchCreateFunction · 0.85
RunMethod · 0.80
NewMethod · 0.80
escapeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…