Skip to content

Commit

Permalink
review revisions
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Keister <jordan@nimblewidget.com>
  • Loading branch information
grokspawn committed Aug 15, 2024
1 parent 916366e commit 3997726
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 105 deletions.
57 changes: 4 additions & 53 deletions alpha/action/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,18 @@ import (
"github.com/stretchr/testify/require"

"github.com/operator-framework/operator-registry/alpha/action"
"github.com/operator-framework/operator-registry/alpha/action/migrations"
"github.com/operator-framework/operator-registry/alpha/declcfg"
"github.com/operator-framework/operator-registry/pkg/containertools"
"github.com/operator-framework/operator-registry/pkg/image"
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
)

type fauxMigration struct {
token string
help string
migrate func(*declcfg.DeclarativeConfig) error
}

func (m fauxMigration) Token() migrations.MigrationToken {
return migrations.MigrationToken(m.token)
}
func (m fauxMigration) Help() string {
return m.help
}
func (m fauxMigration) Migrate(config *declcfg.DeclarativeConfig) error {
return m.migrate(config)
}

func TestMigrate(t *testing.T) {
type spec struct {
name string
migrate action.Migrate
expectedFiles map[string]string
expectErr error
migrationCount int
name string
migrate action.Migrate
expectedFiles map[string]string
expectErr error
}

sqliteBundles := map[image.Reference]string{
Expand All @@ -57,11 +39,6 @@ func TestMigrate(t *testing.T) {
reg, err := newMigrateRegistry(t, sqliteBundles)
require.NoError(t, err)

migrationCounter := 0
testMigrations := []migrations.Migration{
fauxMigration{"faux-migration", "my help text", func(_ *declcfg.DeclarativeConfig) error { migrationCounter++; return nil }},
}

specs := []spec{
{
name: "SqliteImage/Success",
Expand Down Expand Up @@ -137,31 +114,9 @@ func TestMigrate(t *testing.T) {
"bar/catalog.yaml": migrateBarCatalogSqlite(),
},
},
{
name: "SqliteImage/Success/WithMigrations",
migrate: action.Migrate{
CatalogRef: "test.registry/migrate/catalog:sqlite",
WriteFunc: declcfg.WriteYAML,
FileExt: ".yaml",
Registry: reg,
Migrations: &migrations.Migrations{
Migrations: testMigrations,
},
},
expectedFiles: map[string]string{
"foo/catalog.yaml": migrateFooCatalogSqlite(),
"bar/catalog.yaml": migrateBarCatalogSqlite(),
},
migrationCount: 1,
},
}
for _, s := range specs {
t.Run(s.name, func(t *testing.T) {
var migrationPre int
if s.migrationCount != 0 {
migrationPre = migrationCounter
}

s.migrate.OutputDir = t.TempDir()

err := s.migrate.Run(context.Background())
Expand All @@ -182,10 +137,6 @@ func TestMigrate(t *testing.T) {
require.Equal(t, expectedData, string(actualData))
return nil
})

if s.migrationCount != 0 {
require.Equal(t, migrationCounter, migrationPre+s.migrationCount)
}
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions alpha/action/migrations/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestMigrations(t *testing.T) {
allMigrations, err := NewMigrations(AllMigrations)
require.NoError(t, err)

evaluators := map[MigrationToken]func(*declcfg.DeclarativeConfig) error{
migrationPhaseEvaluators := map[MigrationToken]func(*declcfg.DeclarativeConfig) error{
MigrationToken(NoMigrations): func(d *declcfg.DeclarativeConfig) error {
if diff := cmp.Diff(*d, unmigratedCatalogFBC()); diff != "" {
return fmt.Errorf("'none' migrator is not expected to change the config\n%s", diff)
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestMigrations(t *testing.T) {
for _, m := range test.migrators.Migrations {
err := m.Migrate(&config)
require.NoError(t, err)
err = evaluators[m.Token()](&config)
err = migrationPhaseEvaluators[m.Token()](&config)
require.NoError(t, err)
}
})
Expand Down
Loading

0 comments on commit 3997726

Please sign in to comment.