(t *testing.T)
| 1126 | } |
| 1127 | |
| 1128 | func 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 | |
| 1170 | func TestIssue197Context(t *testing.T) { |
| 1171 | // this test actually tests for a bug in database/sql: |
nothing calls this directly
no test coverage detected