(t *testing.T)
| 195 | } |
| 196 | |
| 197 | func TestDml(t *testing.T) { |
| 198 | if skipIntegrateTest { |
| 199 | t.Skip("Integration tests skipped") |
| 200 | } |
| 201 | |
| 202 | ctx, cancel := context.WithTimeout(context.Background(), 180*time.Second) |
| 203 | defer cancel() |
| 204 | |
| 205 | session, tableId, tearDown := setup(t, ctx, []string{}) |
| 206 | defer tearDown() |
| 207 | |
| 208 | stmt, err := BuildStatement(fmt.Sprintf("INSERT INTO %s (id, active) VALUES (1, true), (2, false)", tableId)) |
| 209 | if err != nil { |
| 210 | t.Fatalf("invalid statement: error=%s", err) |
| 211 | } |
| 212 | |
| 213 | result, err := stmt.Execute(ctx, session) |
| 214 | if err != nil { |
| 215 | t.Fatalf("unexpected error happened: %s", err) |
| 216 | } |
| 217 | |
| 218 | compareResult(t, result, &Result{ |
| 219 | AffectedRows: 2, |
| 220 | IsMutation: true, |
| 221 | }) |
| 222 | |
| 223 | // check by query |
| 224 | query := spanner.NewStatement(fmt.Sprintf("SELECT id, active FROM %s ORDER BY id ASC", tableId)) |
| 225 | iter := session.client.Single().Query(ctx, query) |
| 226 | defer iter.Stop() |
| 227 | var gotStructs []testTableSchema |
| 228 | for { |
| 229 | row, err := iter.Next() |
| 230 | if err == iterator.Done { |
| 231 | break |
| 232 | } |
| 233 | if err != nil { |
| 234 | t.Fatalf("unexpected error: %s", err) |
| 235 | } |
| 236 | var got testTableSchema |
| 237 | if err := row.ToStruct(&got); err != nil { |
| 238 | t.Fatalf("unexpected error: %s", err) |
| 239 | } |
| 240 | gotStructs = append(gotStructs, got) |
| 241 | } |
| 242 | expectedStructs := []testTableSchema{ |
| 243 | {1, true}, |
| 244 | {2, false}, |
| 245 | } |
| 246 | if !cmp.Equal(gotStructs, expectedStructs) { |
| 247 | t.Errorf("diff: %s", cmp.Diff(gotStructs, expectedStructs)) |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | func TestReadWriteTransaction(t *testing.T) { |
| 252 | if skipIntegrateTest { |
nothing calls this directly
no test coverage detected