microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
393 stars 62 forks source link

Refactor tools package, to enable dependency injection of run method #266

Open stuartpa opened 1 year ago

stuartpa commented 1 year ago

We need a better way of unit testing the sqlcmd code to launch 3rd party UI tools, like ADS and SSMS.

Comment from code reviews:

if !test.IsRunningInTestExecutor() {
    return t.tool.Run(args)
} else {
    return 0, nil
}

"this is another opportunity to introduce dependency inversion where the tests can inject an alternate Run method for a tool. That will enable the tests to validate the correct args are passed based on the current config. It also allows removal of test-environment-specific code from the product code. " - David

"Agree, this is a good idea and great feedback (I'd become a bit stuck on approach here). I've entered an issue to refactor this package. We've been asked to add SSMS support as well, so when I do that, I'll also refactor with the appropriate interfaces to enable DI here." - Stuart