Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions internal/gen/dbmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,20 @@ func expand(drivers []string) set {
// RegisterNewDrivers registers in xo/dburl all database/sql.Drivers()
// that are not present in provided existing list.
func RegisterNewDrivers(existing []string) []string {
return RegisterCurrentDrivers(existing, sql.Drivers())
}

func RegisterCurrentDrivers(existing []string, current []string) []string {
existingAll := expand(existing)
newDrivers := findNew(sql.Drivers(), existingAll)
newDrivers := findNew(current, existingAll)

for _, driver := range newDrivers {
// We have validated that the schemes we are unregistering are not from linked drivers.
dburl.Unregister(driver)
scheme := getScheme(driver, existingAll)
dburl.Unregister(scheme.Aliases[0])
for _, alias := range scheme.Aliases {
dburl.Unregister(alias)
}

dburl.Register(scheme)
}
Expand Down
13 changes: 11 additions & 2 deletions internal/gen/dbmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@ var csvqSourceSpec = copyTestSpec{
}

func TestRegisterNewDrivers(t *testing.T) {
newDrivers := gen.RegisterNewDrivers(sql.Drivers())
require.Empty(t, newDrivers)
t.Run("empty", func(t *testing.T) {
newDrivers := gen.RegisterNewDrivers(sql.Drivers())
require.Empty(t, newDrivers)
})
}

func TestRegisterCurrentDrivers(t *testing.T) {
t.Run("short name", func(t *testing.T) {
newDrivers := gen.RegisterCurrentDrivers(nil, []string{"d1"})
require.Equal(t, []string{"d1"}, newDrivers)
})
}
Comment on lines +65 to 70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new test TestRegisterCurrentDrivers is great for covering the short driver name case that this PR fixes. To make the tests for the newly exported RegisterCurrentDrivers function more comprehensive, consider adding a few more sub-tests to cover other scenarios:

  • A driver that already exists in the existing slice (should result in no new drivers).
  • A driver with a long name that will generate an alias.
  • A mix of new, existing, short, and long driver names.

This would increase confidence in the refactored logic and prevent future regressions.


func TestSimpleCopyWithInsert_SqliteDest(t *testing.T) {
Expand Down
Loading