(t *testing.T)
| 448 | } |
| 449 | |
| 450 | func TestMigrateGet(t *testing.T) { |
| 451 | t.Parallel() |
| 452 | |
| 453 | ctx := context.Background() |
| 454 | |
| 455 | type testBundle struct { |
| 456 | migratorStub *MigratorStub |
| 457 | out *bytes.Buffer |
| 458 | } |
| 459 | |
| 460 | setup := func(t *testing.T) (*migrateGet, *testBundle) { |
| 461 | t.Helper() |
| 462 | |
| 463 | cmd, out := withCommandBase(t, &migrateGet{}) |
| 464 | |
| 465 | migratorStub := &MigratorStub{} |
| 466 | migratorStub.allVersionsStub = func() []rivermigrate.Migration { return testMigrationAll } |
| 467 | migratorStub.getVersionStub = func(version int) (rivermigrate.Migration, error) { |
| 468 | switch version { |
| 469 | case 1: |
| 470 | return testMigration01, nil |
| 471 | case 2: |
| 472 | return testMigration02, nil |
| 473 | case 3: |
| 474 | return testMigration03, nil |
| 475 | } |
| 476 | return rivermigrate.Migration{}, fmt.Errorf("unknown version: %d", version) |
| 477 | } |
| 478 | migratorStub.existingVersionsStub = func(ctx context.Context) ([]rivermigrate.Migration, error) { return nil, nil } |
| 479 | |
| 480 | cmd.GetCommandBase().DriverProcurer = &DriverProcurerStub{ |
| 481 | getMigratorStub: func(config *rivermigrate.Config) (MigratorInterface, error) { return migratorStub, nil }, |
| 482 | } |
| 483 | |
| 484 | return cmd, &testBundle{ |
| 485 | out: out, |
| 486 | migratorStub: migratorStub, |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | t.Run("DownMigration", func(t *testing.T) { |
| 491 | t.Parallel() |
| 492 | |
| 493 | cmd, bundle := setup(t) |
| 494 | |
| 495 | _, err := runCommand(ctx, t, cmd, &migrateGetOpts{Down: true, Version: []int{1}}) |
| 496 | require.NoError(t, err) |
| 497 | |
| 498 | require.Equal(t, strings.TrimSpace(` |
| 499 | -- River main migration 001 [down] |
| 500 | SELECT 'down 1' FROM river_table |
| 501 | `), strings.TrimSpace(bundle.out.String())) |
| 502 | }) |
| 503 | |
| 504 | t.Run("UpMigration", func(t *testing.T) { |
| 505 | t.Parallel() |
| 506 | |
| 507 | cmd, bundle := setup(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…