Skip to content

Commit

Permalink
Add tests for OpAlterColumn.IsRenameOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-farries committed May 21, 2024
1 parent 4c7eb21 commit 00c7712
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/migrations/op_alter_column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,51 @@ func TestAlterColumnMultipleSubOperations(t *testing.T) {
})
}

func TestIsRenameOnly(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
op migrations.OpAlterColumn
expected bool
}{
{
name: "rename-only operation",
op: migrations.OpAlterColumn{
Table: "events",
Column: "name",
Name: ptr("event_name"),
},
expected: true,
},
{
name: "rename operation with other sub-operations",
op: migrations.OpAlterColumn{
Table: "events",
Column: "name",
Name: ptr("event_name"),
Nullable: ptr(false),
},
expected: false,
},
{
name: "alter column with no rename",
op: migrations.OpAlterColumn{
Table: "events",
Column: "name",
Nullable: ptr(false),
},
expected: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.expected, tc.op.IsRenameOnly())
})
}
}

func TestAlterColumnValidation(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 00c7712

Please sign in to comment.