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

Function TestEmbeddedMapsContext

sqlx_context_test.go:1128–1168  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1126}
1127
1128func TestEmbeddedMapsContext(t *testing.T) {
1129 var schema = Schema{
1130 create: `
1131 CREATE TABLE message (
1132 string text,
1133 properties text
1134 );`,
1135 drop: `drop table message;`,
1136 }
1137
1138 RunWithSchemaContext(context.Background(), schema, t, func(ctx context.Context, db *DB, t *testing.T) {
1139 messages := []Message{
1140 {"Hello, World", PropertyMap{"one": "1", "two": "2"}},
1141 {"Thanks, Joy", PropertyMap{"pull": "request"}},
1142 }
1143 q1 := `INSERT INTO message (string, properties) VALUES (:string, :properties);`
1144 for _, m := range messages {
1145 _, err := db.NamedExecContext(ctx, q1, m)
1146 if err != nil {
1147 t.Fatal(err)
1148 }
1149 }
1150 var count int
1151 err := db.GetContext(ctx, &count, "SELECT count(*) FROM message")
1152 if err != nil {
1153 t.Fatal(err)
1154 }
1155 if count != len(messages) {
1156 t.Fatalf("Expected %d messages in DB, found %d", len(messages), count)
1157 }
1158
1159 var m Message
1160 err = db.GetContext(ctx, &m, "SELECT * FROM message LIMIT 1;")
1161 if err != nil {
1162 t.Fatal(err)
1163 }
1164 if m.Properties == nil {
1165 t.Fatal("Expected m.Properties to not be nil, but it was.")
1166 }
1167 })
1168}
1169
1170func TestIssue197Context(t *testing.T) {
1171 // this test actually tests for a bug in database/sql:

Callers

nothing calls this directly

Calls 3

RunWithSchemaContextFunction · 0.85
NamedExecContextMethod · 0.45
GetContextMethod · 0.45

Tested by

no test coverage detected