(t *testing.T)
| 234 | } |
| 235 | |
| 236 | func TestSchemaDiffMultiDB_RequiresDatabaseDirective(t *testing.T) { |
| 237 | schema := []byte(` |
| 238 | # dbinfo:postgres,140000,public |
| 239 | |
| 240 | type users { |
| 241 | id: Bigint! @id |
| 242 | name: CharacterVarying! |
| 243 | } |
| 244 | |
| 245 | type events @database(name: analytics) { |
| 246 | id: Bigint! @id |
| 247 | event_type: CharacterVarying! |
| 248 | } |
| 249 | |
| 250 | type audit_logs { |
| 251 | id: Bigint! @id |
| 252 | action: CharacterVarying! |
| 253 | } |
| 254 | `) |
| 255 | |
| 256 | connections := map[string]*sql.DB{ |
| 257 | "analytics": nil, |
| 258 | "logs": nil, |
| 259 | } |
| 260 | dbTypes := map[string]string{ |
| 261 | "analytics": "postgres", |
| 262 | "logs": "postgres", |
| 263 | } |
| 264 | |
| 265 | _, err := SchemaDiffMultiDB(connections, dbTypes, schema, nil, DiffOptions{}) |
| 266 | if err == nil { |
| 267 | t.Fatal("expected error for tables missing @database directive, got nil") |
| 268 | } |
| 269 | |
| 270 | errMsg := err.Error() |
| 271 | |
| 272 | // Verify the error mentions the missing tables (sorted order) |
| 273 | if !strings.Contains(errMsg, "audit_logs") { |
| 274 | t.Errorf("error should mention 'audit_logs', got: %s", errMsg) |
| 275 | } |
| 276 | if !strings.Contains(errMsg, "users") { |
| 277 | t.Errorf("error should mention 'users', got: %s", errMsg) |
| 278 | } |
| 279 | |
| 280 | // Verify the error mentions available databases |
| 281 | if !strings.Contains(errMsg, "analytics") { |
| 282 | t.Errorf("error should mention available database 'analytics', got: %s", errMsg) |
| 283 | } |
| 284 | if !strings.Contains(errMsg, "logs") { |
| 285 | t.Errorf("error should mention available database 'logs', got: %s", errMsg) |
| 286 | } |
| 287 | |
| 288 | // Verify it mentions the @database directive |
| 289 | if !strings.Contains(errMsg, "@database") { |
| 290 | t.Errorf("error should mention '@database' directive, got: %s", errMsg) |
| 291 | } |
| 292 | } |
| 293 |
nothing calls this directly
no test coverage detected