Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make migrations_test.go tests consistent with other tests in pkg/migrations #568

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions pkg/migrations/migrations_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
// SPDX-License-Identifier: Apache-2.0

package migrations
package migrations_test

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/xataio/pgroll/pkg/migrations"
"github.com/xataio/pgroll/pkg/schema"
)

func TestMigrationsIsolated(t *testing.T) {
migration := Migration{
t.Parallel()

migration := migrations.Migration{
Name: "sql",
Operations: Operations{
&OpRawSQL{
Operations: migrations.Operations{
&migrations.OpRawSQL{
Up: `foo`,
},
&OpCreateTable{Name: "foo"},
&migrations.OpCreateTable{Name: "foo"},
},
}

err := migration.Validate(context.TODO(), schema.New())
var wantErr InvalidMigrationError
var wantErr migrations.InvalidMigrationError
assert.ErrorAs(t, err, &wantErr)
}

func TestMigrationsIsolatedValid(t *testing.T) {
migration := Migration{
t.Parallel()

migration := migrations.Migration{
Name: "sql",
Operations: Operations{
&OpRawSQL{
Operations: migrations.Operations{
&migrations.OpRawSQL{
Up: `foo`,
},
},
Expand All @@ -40,14 +45,16 @@ func TestMigrationsIsolatedValid(t *testing.T) {
}

func TestOnCompleteSQLMigrationsAreNotIsolated(t *testing.T) {
migration := Migration{
t.Parallel()

migration := migrations.Migration{
Name: "sql",
Operations: Operations{
&OpRawSQL{
Operations: migrations.Operations{
&migrations.OpRawSQL{
Up: `foo`,
OnComplete: true,
},
&OpCreateTable{Name: "foo"},
&migrations.OpCreateTable{Name: "foo"},
},
}
err := migration.Validate(context.TODO(), schema.New())
Expand Down