MCPcopy
hub / github.com/jmoiron/sqlx / TestBindMap

Function TestBindMap

sqlx_test.go:1359–1390  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1357}
1358
1359func TestBindMap(t *testing.T) {
1360 // Test that it works..
1361 q1 := `INSERT INTO foo (a, b, c, d) VALUES (:name, :age, :first, :last)`
1362 am := map[string]interface{}{
1363 "name": "Jason Moiron",
1364 "age": 30,
1365 "first": "Jason",
1366 "last": "Moiron",
1367 }
1368
1369 bq, args, _ := bindMap(QUESTION, q1, am)
1370 expect := `INSERT INTO foo (a, b, c, d) VALUES (?, ?, ?, ?)`
1371 if bq != expect {
1372 t.Errorf("Interpolation of query failed: got `%v`, expected `%v`\n", bq, expect)
1373 }
1374
1375 if args[0].(string) != "Jason Moiron" {
1376 t.Errorf("Expected `Jason Moiron`, got %v\n", args[0])
1377 }
1378
1379 if args[1].(int) != 30 {
1380 t.Errorf("Expected 30, got %v\n", args[1])
1381 }
1382
1383 if args[2].(string) != "Jason" {
1384 t.Errorf("Expected Jason, got %v\n", args[2])
1385 }
1386
1387 if args[3].(string) != "Moiron" {
1388 t.Errorf("Expected Moiron, got %v\n", args[3])
1389 }
1390}
1391
1392// Test for #117, embedded nil maps
1393

Callers

nothing calls this directly

Calls 2

bindMapFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected